diff --git a/cmd/execute/execute.go b/cmd/execute/execute.go index 5c5066b..8a52e5a 100644 --- a/cmd/execute/execute.go +++ b/cmd/execute/execute.go @@ -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) @@ -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) } diff --git a/cmd/execute/watch.go b/cmd/execute/watch.go index 3783ff0..06d796e 100644 --- a/cmd/execute/watch.go +++ b/cmd/execute/watch.go @@ -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 diff --git a/cmd/output/output.go b/cmd/output/output.go index 1bdb7db..6078a9e 100644 --- a/cmd/output/output.go +++ b/cmd/output/output.go @@ -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 @@ -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) } }, } @@ -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) @@ -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 { diff --git a/util/util.go b/util/util.go index 5463554..b184d59 100644 --- a/util/util.go +++ b/util/util.go @@ -284,7 +284,7 @@ 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 { @@ -292,7 +292,13 @@ func ResolveObjectPath(path string, silent bool, isProject bool) (*types.SpaceDe } 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] + "!") @@ -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) { @@ -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)