Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bug fixes and a light refactor to workflow output download #103

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func readWorkflowYAMLandCreateVersion(fileName string, workflowName string, obje
workflowName = wf.Name
}

space, project, workflow, _ := util.ResolveObjectPath(objectPath, true, false)
space, project, workflow, _ := util.ResolveObjectPath(objectPath, true)
if space == nil {
fmt.Println("Space " + strings.Split(objectPath, "/")[0] + " doesn't exist!")
os.Exit(0)
Expand Down Expand Up @@ -987,8 +987,8 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
var primitiveNodes map[string]*types.PrimitiveNode
projectCreated := false

space, project, workflow, _ := util.ResolveObjectPath(objectPath, false, false)
if workflow == nil {
space, project, workflow, _ := util.ResolveObjectPath(objectPath, true)
if util.URL != "" {
space, project, workflow, _ = util.ResolveObjectURL(util.URL)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/execute/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]o
}
if downloadAllNodes {
// DownloadRunOutputs downloads all outputs if no nodes were specified
output.DownloadRunOutput(run, nil, nil, nil, downloadPath)
output.DownloadRunOutput(run, nil, nil, downloadPath)
} else if len(nodesToDownload) > 0 {
output.DownloadRunOutput(run, nodesToDownload, filesToDownload, nil, downloadPath)
output.DownloadRunOutput(run, nodesToDownload, filesToDownload, downloadPath)
}
mutex.Unlock()
return
Expand Down
15 changes: 4 additions & 11 deletions cmd/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ The YAML config file should be formatted like:
runs = append(runs, runs...)
}

version := GetWorkflowVersionByID(*runs[0].WorkflowVersionInfo, uuid.Nil)
if version == nil {
return
}

path := util.FormatPath()
if outputDir != "" {
path = outputDir
Expand All @@ -152,7 +147,7 @@ The YAML config file should be formatted like:
if run.Status == "SCHEDULED" {
continue
}
DownloadRunOutput(&run, nodes, files, version, path)
DownloadRunOutput(&run, nodes, files, path)
}
},
}
Expand All @@ -167,16 +162,14 @@ func init() {
OutputCmd.Flags().StringVar(&filesFlag, "files", "", "A comma-separated list of file names that should be downloaded from the selected node")
}

func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, files []string, version *types.WorkflowVersionDetailed, destinationPath string) {
func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, files []string, destinationPath string) {
if run.Status != "COMPLETED" && run.Status != "STOPPED" && run.Status != "FAILED" {
fmt.Println("The workflow run hasn't been completed yet!")
fmt.Println("Run ID: " + run.ID.String() + " Status: " + run.Status)
return
}

if version == nil {
version = GetWorkflowVersionByID(*run.WorkflowVersionInfo, uuid.Nil)
}
version := GetWorkflowVersionByID(*run.WorkflowVersionInfo, uuid.Nil)

subJobs := getSubJobs(*run.ID)
labels := make(map[string]bool)
Expand Down Expand Up @@ -268,7 +261,7 @@ func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, files []string
}
}
if noneFound {
fmt.Println("Couldn't find any nodes that match given name(s)!")
fmt.Printf("No completed node outputs matching your query were found in the \"%s\" run.", run.StartedDate.Format(layout))
} else {
for nodeName, nodeInfo := range nodes {
if !nodeInfo.Found {
Expand Down
113 changes: 55 additions & 58 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,21 @@ func GetWorkflowByID(id uuid.UUID) *types.Workflow {
return &workflow
}

func ResolveObjectPath(path string, silent bool, isProject bool) (*types.SpaceDetailed, *types.Project, *types.Workflow, bool) {
func ResolveObjectPath(path string, silent bool) (*types.SpaceDetailed, *types.Project, *types.Workflow, bool) {
pathSplit := strings.Split(strings.Trim(path, "/"), "/")
if len(pathSplit) > 3 {
if !silent {
fmt.Println("Invalid object path!")
}
return nil, nil, nil, false
}
space := GetSpaceByName(pathSplit[0])

var space *types.SpaceDetailed
var project *types.Project
var workflow *types.Workflow

spaceName := pathSplit[0]
space = GetSpaceByName(spaceName)
if space == nil {
if !silent {
fmt.Println("Couldn't find space named " + pathSplit[0] + "!")
Expand All @@ -302,77 +308,68 @@ func ResolveObjectPath(path string, silent bool, isProject bool) (*types.SpaceDe

if len(pathSplit) == 1 {
return space, nil, nil, true
}

// Space and workflow with no project
var projectName string
var workflowName string
if len(pathSplit) == 2 {
if isProject {
projectName = pathSplit[1]
workflowName = ""
} else {
projectName = ""
workflowName = pathSplit[1]
}
} else {
projectName = pathSplit[1]
workflowName = pathSplit[2]
}

var project *types.Project
if space.Projects != nil && len(space.Projects) > 0 {
} else if len(pathSplit) == 2 {
objectName := pathSplit[1]
for _, proj := range space.Projects {
if proj.Name == projectName {
if objectName == proj.Name {
project = &proj
project.Workflows = GetWorkflows(project.ID, uuid.Nil, "", false)
break
return space, project, nil, true
}
}
}

var workflow *types.Workflow
if space.Workflows != nil && len(space.Workflows) > 0 {
for _, wf := range space.Workflows {
if wf.Name == workflowName {
workflow = &wf
break
if objectName == wf.Name {
workflow = GetWorkflowByID(wf.ID)
return space, nil, workflow, true
}
}
}

if len(pathSplit) == 2 {
if project != nil || workflow != nil {
return space, project, workflow, true
}
if workflow != nil {
return space, nil, workflow, true
}
if !silent {
fmt.Println("Couldn't find project or workflow named " + pathSplit[1] + " inside " +
pathSplit[0] + " space!")
fmt.Printf("Couldn't find project or workflow named %s inside %s space!", objectName, spaceName)
}
return space, nil, nil, false
}
} else {
projectName := pathSplit[1]
workflowName := pathSplit[2]

if project != nil && project.Workflows != nil && len(project.Workflows) > 0 {
for _, wf := range project.Workflows {
if wf.Name == pathSplit[2] {
fullWorkflow := GetWorkflowByID(wf.ID)
return space, project, fullWorkflow, true
for _, proj := range space.Projects {
if projectName == proj.Name {
project = &proj
project.Workflows = GetWorkflows(project.ID, uuid.Nil, "", false)
break
}
}
} else {
if !silent {
fmt.Println("No workflows found in " + pathSplit[0] + "/" + pathSplit[1])
if project == nil {
if project == nil {
if !silent {
fmt.Printf("Couldn't find project named %s inside %s space!", projectName, spaceName)
}
return space, nil, nil, false
}
}
if project.Workflows != nil {
for _, wf := range project.Workflows {
if workflowName == wf.Name {
workflow = GetWorkflowByID(wf.ID)
break
}
}
}
if project != nil && workflow != nil {
return space, project, workflow, true
} else {
if project == nil {
if !silent {
fmt.Printf("Couldn't find project named %s inside %s space!", projectName, spaceName)
}
return space, nil, nil, false
} else {
if !silent {
fmt.Printf("Couldn't find workflow named %s in %s/%s", workflowName, spaceName, projectName)
}
return space, project, nil, false
}
}
return space, project, nil, false
}

if !silent {
fmt.Println("Couldn't find workflow named " + pathSplit[2] + " in " + pathSplit[0] + "/" + pathSplit[1] + "/")
}
return space, project, nil, false
}

func ResolveObjectURL(objectURL string) (*types.SpaceDetailed, *types.Project, *types.Workflow, bool) {
Expand Down Expand Up @@ -472,7 +469,7 @@ func GetObjects(args []string) (*types.SpaceDetailed, *types.Project, *types.Wor

switch {
case path != "":
return ResolveObjectPath(path, true, false)
return ResolveObjectPath(path, true)

case URL != "":
return ResolveObjectURL(URL)
Expand Down