Skip to content

Commit ccea0cc

Browse files
authored
Merge pull request #84 from trickest/update/api
Update API endpoints data structure
2 parents 7335b48 + b98d7b7 commit ccea0cc

File tree

12 files changed

+124
-131
lines changed

12 files changed

+124
-131
lines changed

cmd/execute/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package execute
33
import (
44
"errors"
55
"fmt"
6-
"gopkg.in/yaml.v3"
76
"io/ioutil"
87
"os"
98
"path"
109
"strconv"
1110
"strings"
1211
"trickest-cli/cmd/output"
1312
"trickest-cli/types"
13+
14+
"gopkg.in/yaml.v3"
1415
)
1516

1617
func readConfig(fileName string, wfVersion *types.WorkflowVersionDetailed, tool *types.Tool) (
@@ -510,13 +511,13 @@ func readConfigOutputs(config *map[string]interface{}) map[string]output.NodeInf
510511
return downloadNodes
511512
}
512513

513-
func readConfigMachines(config *map[string]interface{}, isTool bool, maximumMachines *types.Bees) *types.Bees {
514+
func readConfigMachines(config *map[string]interface{}, isTool bool, maximumMachines *types.Machines) *types.Machines {
514515
if !isTool && maximumMachines == nil {
515516
fmt.Println("No maximum machines specified!")
516517
os.Exit(0)
517518
}
518519

519-
execMachines := &types.Bees{}
520+
execMachines := &types.Machines{}
520521
if machines, exists := (*config)["machines"]; exists && machines != nil {
521522
machinesList, ok := machines.(map[string]interface{})
522523
if !ok {
@@ -610,9 +611,9 @@ func readConfigMachines(config *map[string]interface{}, isTool bool, maximumMach
610611
if isTool {
611612
oneMachine := 1
612613
if maxMachines {
613-
return &types.Bees{Large: &oneMachine}
614+
return &types.Machines{Large: &oneMachine}
614615
} else {
615-
return &types.Bees{Small: &oneMachine}
616+
return &types.Machines{Small: &oneMachine}
616617
}
617618
} else {
618619
if maxMachines {

cmd/execute/execute.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package execute
33
import (
44
"errors"
55
"fmt"
6-
"github.com/google/uuid"
76
"io/ioutil"
87
"math"
98
"os"
@@ -17,6 +16,8 @@ import (
1716
"trickest-cli/types"
1817
"trickest-cli/util"
1918

19+
"github.com/google/uuid"
20+
2021
"github.com/spf13/cobra"
2122
"gopkg.in/yaml.v3"
2223
)
@@ -26,8 +27,8 @@ var (
2627
configFile string
2728
watch bool
2829
showParams bool
29-
executionMachines types.Bees
30-
hive *types.Hive
30+
executionMachines types.Machines
31+
fleet *types.Fleet
3132
nodesToDownload = make(map[string]output.NodeInfo, 0)
3233
allNodes map[string]*types.TreeNode
3334
roots []*types.TreeNode
@@ -63,8 +64,8 @@ var ExecuteCmd = &cobra.Command{
6364
}
6465
}
6566

66-
hive = util.GetHiveInfo()
67-
if hive == nil {
67+
fleet = util.GetFleetInfo()
68+
if fleet == nil {
6869
return
6970
}
7071
var version *types.WorkflowVersionDetailed
@@ -755,7 +756,7 @@ func readWorkflowYAMLandCreateVersion(fileName string, workflowName string, obje
755756
}
756757

757758
func createToolWorkflow(wfName string, space *types.SpaceDetailed, project *types.Project, deleteProjectOnError bool,
758-
tool *types.Tool, primitiveNodes map[string]*types.PrimitiveNode, machine types.Bees) *types.WorkflowVersionDetailed {
759+
tool *types.Tool, primitiveNodes map[string]*types.PrimitiveNode, machine types.Machines) *types.WorkflowVersionDetailed {
759760
if tool == nil {
760761
fmt.Println("No tool specified, couldn't create a workflow!")
761762
os.Exit(0)

cmd/execute/helpers.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ func getScripts(pageSize int, search string, name string) []types.Script {
9797
return scripts.Results
9898
}
9999

100-
func createRun(versionID uuid.UUID, watch bool, machines *types.Bees, outputNodes []string, outputsDir string) {
100+
func createRun(versionID uuid.UUID, watch bool, machines *types.Machines, outputNodes []string, outputsDir string) {
101101
run := types.CreateRun{
102102
VersionID: versionID,
103-
HiveInfo: hive.ID,
104-
Bees: executionMachines,
103+
Vault: fleet.Vault,
104+
Machines: executionMachines,
105105
}
106106

107107
data, err := json.Marshal(run)
@@ -110,7 +110,7 @@ func createRun(versionID uuid.UUID, watch bool, machines *types.Bees, outputNode
110110
os.Exit(0)
111111
}
112112

113-
resp := request.Trickest.Post().Body(data).DoF("run/")
113+
resp := request.Trickest.Post().Body(data).DoF("execution/")
114114
if resp == nil {
115115
fmt.Println("Error: Couldn't create run!")
116116
os.Exit(0)
@@ -136,10 +136,10 @@ func createRun(versionID uuid.UUID, watch bool, machines *types.Bees, outputNode
136136
if watch {
137137
WatchRun(createRunResp.ID, outputsDir, nodesToDownload, nil, false, &executionMachines, showParams)
138138
} else {
139-
availableBees := GetAvailableMachines()
139+
availableMachines := GetAvailableMachines()
140140
fmt.Println("Run successfully created! ID: " + createRunResp.ID.String())
141141
fmt.Print("Machines:\n" + FormatMachines(*machines, false))
142-
fmt.Print("\nAvailable:\n" + FormatMachines(availableBees, false))
142+
fmt.Print("\nAvailable:\n" + FormatMachines(availableMachines, false))
143143
}
144144
}
145145

@@ -355,7 +355,7 @@ func processInvalidInputStructure() {
355355
os.Exit(0)
356356
}
357357

358-
func processMaxMachinesOverflow(maximumMachines types.Bees) {
358+
func processMaxMachinesOverflow(maximumMachines types.Machines) {
359359
fmt.Println("Invalid number or machines!")
360360
fmt.Println("The maximum number of machines you can allocate for this workflow: ")
361361
fmt.Println(FormatMachines(maximumMachines, false))
@@ -381,28 +381,28 @@ func processInvalidInputType(newPNode, existingPNode types.PrimitiveNode) {
381381
os.Exit(0)
382382
}
383383

384-
func GetAvailableMachines() types.Bees {
385-
hiveInfo := util.GetHiveInfo()
386-
availableBees := types.Bees{}
387-
for _, bee := range hiveInfo.Bees {
388-
if bee.Name == "small" {
389-
available := bee.Total - bee.Running
390-
availableBees.Small = &available
384+
func GetAvailableMachines() types.Machines {
385+
hiveInfo := util.GetFleetInfo()
386+
availableMachines := types.Machines{}
387+
for _, machine := range hiveInfo.Machines {
388+
if machine.Name == "small" {
389+
available := machine.Total - machine.Running
390+
availableMachines.Small = &available
391391
}
392-
if bee.Name == "medium" {
393-
available := bee.Total - bee.Running
394-
availableBees.Medium = &available
392+
if machine.Name == "medium" {
393+
available := machine.Total - machine.Running
394+
availableMachines.Medium = &available
395395
}
396-
if bee.Name == "large" {
397-
available := bee.Total - bee.Running
398-
availableBees.Large = &available
396+
if machine.Name == "large" {
397+
available := machine.Total - machine.Running
398+
availableMachines.Large = &available
399399
}
400400
}
401-
return availableBees
401+
return availableMachines
402402
}
403403

404404
func GetRunByID(id uuid.UUID) *types.Run {
405-
resp := request.Trickest.Get().DoF("run/%s/", id)
405+
resp := request.Trickest.Get().DoF("execution/%s/", id)
406406
if resp == nil {
407407
fmt.Println("Error: Couldn't get run!")
408408
os.Exit(0)
@@ -427,7 +427,7 @@ func GetSubJobs(runID uuid.UUID) []types.SubJob {
427427
fmt.Println("Couldn't list sub-jobs, no run ID parameter specified!")
428428
os.Exit(0)
429429
}
430-
urlReq := "subjob/?run=" + runID.String()
430+
urlReq := "subjob/?execution=" + runID.String()
431431
urlReq = urlReq + "&page_size=" + strconv.Itoa(math.MaxInt)
432432

433433
resp := request.Trickest.Get().DoF(urlReq)
@@ -451,7 +451,7 @@ func GetSubJobs(runID uuid.UUID) []types.SubJob {
451451
}
452452

453453
func stopRun(runID uuid.UUID) {
454-
resp := request.Trickest.Post().DoF("run/%s/stop/", runID)
454+
resp := request.Trickest.Post().DoF("execution/%s/stop/", runID)
455455
if resp == nil {
456456
fmt.Println("Error: Couldn't stop run!")
457457
os.Exit(0)
@@ -462,7 +462,7 @@ func stopRun(runID uuid.UUID) {
462462
}
463463
}
464464

465-
func setMachinesToMinimum(machines *types.Bees) {
465+
func setMachinesToMinimum(machines *types.Machines) {
466466
if machines.Small != nil {
467467
*machines.Small = 1
468468
}
@@ -474,7 +474,7 @@ func setMachinesToMinimum(machines *types.Bees) {
474474
}
475475
}
476476

477-
func FormatMachines(machines types.Bees, inline bool) string {
477+
func FormatMachines(machines types.Machines, inline bool) string {
478478
var small, medium, large string
479479
if machines.Small != nil {
480480
small = "small: " + strconv.Itoa(*machines.Small)
@@ -580,7 +580,7 @@ func uploadFilesIfNeeded(primitiveNodes map[string]*types.PrimitiveNode) {
580580
}
581581
}
582582

583-
func maxMachinesTypeCompatible(machines, maxMachines types.Bees) bool {
583+
func maxMachinesTypeCompatible(machines, maxMachines types.Machines) bool {
584584
if (machines.Small != nil && maxMachines.Small == nil) ||
585585
(machines.Medium != nil && maxMachines.Medium == nil) ||
586586
(machines.Large != nil && maxMachines.Large == nil) {

cmd/execute/layout.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func adjustChildrenHeight(root *types.TreeNode, nodesPerHeight *map[int][]*types
3131
child.Height = root.Height - 1
3232
found := false
3333
for _, node := range (*nodesPerHeight)[child.Height] {
34-
if node.NodeName == child.NodeName {
34+
if node.Name == child.Name {
3535
found = true
3636
break
3737
}
@@ -104,8 +104,8 @@ func generateNodesCoordinates(version *types.WorkflowVersionDetailed) {
104104
for height, nodes := range nodesPerHeight {
105105
maxInputs := 0
106106
for _, node := range nodes {
107-
if version.Data.Nodes[node.NodeName] != nil && len(version.Data.Nodes[node.NodeName].Inputs) > maxInputs {
108-
maxInputs = len(version.Data.Nodes[node.NodeName].Inputs)
107+
if version.Data.Nodes[node.Name] != nil && len(version.Data.Nodes[node.Name].Inputs) > maxInputs {
108+
maxInputs = len(version.Data.Nodes[node.Name].Inputs)
109109
}
110110
}
111111
maxInputsPerHeight[height] = maxInputs
@@ -116,7 +116,7 @@ func generateNodesCoordinates(version *types.WorkflowVersionDetailed) {
116116
for height := 0; height < len(nodesPerHeight); height++ {
117117
nodes := nodesPerHeight[height]
118118
sort.SliceStable(nodes, func(i, j int) bool {
119-
return nodes[i].NodeName < nodes[j].NodeName
119+
return nodes[i].Name < nodes[j].Name
120120
})
121121
total := (len(nodes) - 1) * distance
122122
start := -total / 2
@@ -126,31 +126,31 @@ func generateNodesCoordinates(version *types.WorkflowVersionDetailed) {
126126
previousHeightNodeSizeIndent = float64(distance * (maxInputsPerHeight[height-1] / 10))
127127
}
128128
for i, node := range nodes {
129-
if version.Data.Nodes[node.NodeName] != nil {
130-
version.Data.Nodes[node.NodeName].Meta.Coordinates.X = X
129+
if version.Data.Nodes[node.Name] != nil {
130+
version.Data.Nodes[node.Name].Meta.Coordinates.X = X
131131
if i == 0 && height > 0 {
132-
version.Data.Nodes[node.NodeName].Meta.Coordinates.X += nodeSizeIndent
132+
version.Data.Nodes[node.Name].Meta.Coordinates.X += nodeSizeIndent
133133
}
134-
version.Data.Nodes[node.NodeName].Meta.Coordinates.X += previousHeightNodeSizeIndent
135-
version.Data.Nodes[node.NodeName].Meta.Coordinates.Y = 1.2 * float64(start)
134+
version.Data.Nodes[node.Name].Meta.Coordinates.X += previousHeightNodeSizeIndent
135+
version.Data.Nodes[node.Name].Meta.Coordinates.Y = 1.2 * float64(start)
136136
start += distance
137-
if i+1 < len(nodes) && version.Data.Nodes[nodes[i+1].NodeName] != nil &&
138-
len(version.Data.Nodes[nodes[i+1].NodeName].Inputs) == maxInputsPerHeight[height] {
137+
if i+1 < len(nodes) && version.Data.Nodes[nodes[i+1].Name] != nil &&
138+
len(version.Data.Nodes[nodes[i+1].Name].Inputs) == maxInputsPerHeight[height] {
139139
start += int(nodeSizeIndent)
140140
}
141-
if len(version.Data.Nodes[node.NodeName].Inputs) == maxInputsPerHeight[height] {
141+
if len(version.Data.Nodes[node.Name].Inputs) == maxInputsPerHeight[height] {
142142
start += int(nodeSizeIndent)
143143
}
144-
} else if version.Data.PrimitiveNodes[node.NodeName] != nil {
145-
version.Data.PrimitiveNodes[node.NodeName].Coordinates.X = X
144+
} else if version.Data.PrimitiveNodes[node.Name] != nil {
145+
version.Data.PrimitiveNodes[node.Name].Coordinates.X = X
146146
if i == 0 && height > 0 {
147-
version.Data.PrimitiveNodes[node.NodeName].Coordinates.X += nodeSizeIndent
147+
version.Data.PrimitiveNodes[node.Name].Coordinates.X += nodeSizeIndent
148148
}
149-
version.Data.PrimitiveNodes[node.NodeName].Coordinates.X += previousHeightNodeSizeIndent
150-
version.Data.PrimitiveNodes[node.NodeName].Coordinates.Y = 1.2 * float64(start)
149+
version.Data.PrimitiveNodes[node.Name].Coordinates.X += previousHeightNodeSizeIndent
150+
version.Data.PrimitiveNodes[node.Name].Coordinates.Y = 1.2 * float64(start)
151151
start += distance
152-
if i+1 < len(nodes) && version.Data.Nodes[nodes[i+1].NodeName] != nil &&
153-
len(version.Data.Nodes[nodes[i+1].NodeName].Inputs) == maxInputsPerHeight[height] {
152+
if i+1 < len(nodes) && version.Data.Nodes[nodes[i+1].Name] != nil &&
153+
len(version.Data.Nodes[nodes[i+1].Name].Inputs) == maxInputsPerHeight[height] {
154154
start += int(nodeSizeIndent)
155155
}
156156
}

cmd/execute/watch.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/xlab/treeprint"
2222
)
2323

24-
func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]output.NodeInfo, filesToDownload []string, timestampOnly bool, machines *types.Bees, showParameters bool) {
24+
func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]output.NodeInfo, filesToDownload []string, timestampOnly bool, machines *types.Machines, showParameters bool) {
2525
const fmtStr = "%-12s %v\n"
2626
writer := uilive.New()
2727
writer.Start()
@@ -70,9 +70,9 @@ func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]o
7070
out := ""
7171
out += fmt.Sprintf(fmtStr, "Name:", run.WorkflowName)
7272
out += fmt.Sprintf(fmtStr, "Status:", strings.ToLower(run.Status))
73-
availableBees := GetAvailableMachines()
73+
availableMachines := GetAvailableMachines()
7474
out += fmt.Sprintf(fmtStr, "Machines:", FormatMachines(*machines, true)+
75-
" (currently available: "+FormatMachines(availableBees, true)+")")
75+
" (currently available: "+FormatMachines(availableMachines, true)+")")
7676
out += fmt.Sprintf(fmtStr, "Created:", run.CreatedDate.In(time.Local).Format(time.RFC1123)+
7777
" ("+util.FormatDuration(time.Since(run.CreatedDate))+" ago)")
7878
if run.Status != "PENDING" {
@@ -94,12 +94,14 @@ func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]o
9494

9595
subJobs := GetSubJobs(runID)
9696
for _, sj := range subJobs {
97-
allNodes[sj.NodeName].Status = strings.ToLower(sj.Status)
98-
allNodes[sj.NodeName].OutputStatus = strings.ReplaceAll(strings.ToLower(sj.OutputsStatus), "_", " ")
97+
allNodes[sj.Name].Status = strings.ToLower(sj.Status)
98+
allNodes[sj.Name].OutputStatus = strings.ReplaceAll(strings.ToLower(sj.OutputsStatus), "_", " ")
9999
if sj.Finished {
100-
allNodes[sj.NodeName].Duration = sj.FinishedDate.Sub(sj.StartedDate).Round(time.Second)
100+
allNodes[sj.Name].Duration = sj.FinishedDate.Sub(sj.StartedDate).Round(time.Second)
101+
} else if sj.StartedDate.IsZero() {
102+
allNodes[sj.Name].Duration = *new(time.Duration)
101103
} else {
102-
allNodes[sj.NodeName].Duration = time.Since(sj.StartedDate).Round(time.Second)
104+
allNodes[sj.Name].Duration = time.Since(sj.StartedDate).Round(time.Second)
103105
}
104106
}
105107

@@ -185,7 +187,7 @@ func printTree(node *types.TreeNode, branch *treeprint.Tree, allNodes *map[strin
185187
prefixSymbol = "\u274c " //❌
186188
}
187189

188-
printValue := prefixSymbol + node.Label + " (" + node.NodeName + ")"
190+
printValue := prefixSymbol + node.Label + " (" + node.Name + ")"
189191
if branch == nil {
190192
tree := treeprint.NewWithRoot(printValue)
191193
branch = &tree
@@ -231,12 +233,12 @@ func printTree(node *types.TreeNode, branch *treeprint.Tree, allNodes *map[strin
231233
}
232234

233235
for _, child := range node.Children {
234-
if !(*allNodes)[node.NodeName].Printed {
236+
if !(*allNodes)[node.Name].Printed {
235237
printTree(child, branch, allNodes, showParameters)
236238
}
237239
}
238240

239-
(*allNodes)[node.NodeName].Printed = true
241+
(*allNodes)[node.Name].Printed = true
240242

241243
return (*branch).String()
242244
}
@@ -247,7 +249,7 @@ func CreateTrees(wfVersion *types.WorkflowVersionDetailed, includePrimitiveNodes
247249

248250
for _, node := range wfVersion.Data.Nodes {
249251
allNodes[node.Name] = &types.TreeNode{
250-
NodeName: node.Name,
252+
Name: node.Name,
251253
Label: node.Meta.Label,
252254
Inputs: &node.Inputs,
253255
Status: "pending",
@@ -260,8 +262,8 @@ func CreateTrees(wfVersion *types.WorkflowVersionDetailed, includePrimitiveNodes
260262
if includePrimitiveNodes {
261263
for _, node := range wfVersion.Data.PrimitiveNodes {
262264
allNodes[node.Name] = &types.TreeNode{
263-
NodeName: node.Name,
264-
Label: node.Label,
265+
Name: node.Name,
266+
Label: node.Label,
265267
}
266268
}
267269
}

cmd/get/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var GetCmd = &cobra.Command{
6464
if runs[0].Status == "COMPLETED" && runs[0].CompletedDate.IsZero() {
6565
runs[0].Status = "RUNNING"
6666
}
67-
execute.WatchRun(runs[0].ID, "", map[string]output.NodeInfo{}, []string{}, !watch, &runs[0].Bees, showNodeParams)
67+
execute.WatchRun(runs[0].ID, "", map[string]output.NodeInfo{}, []string{}, !watch, &runs[0].Machines, showNodeParams)
6868
return
6969
} else {
7070
const fmtStr = "%-15s %v\n"

0 commit comments

Comments
 (0)