4040 runID string
4141 outputDir string
4242 nodesFlag string
43+ filesFlag string
4344)
4445
4546// OutputCmd represents the download command
@@ -67,6 +68,13 @@ The YAML config file should be formatted like:
6768 }
6869 }
6970
71+ var files []string
72+ if filesFlag != "" {
73+ for _ , file := range strings .Split (filesFlag , "," ) {
74+ files = append (files , file )
75+ }
76+ }
77+
7078 path := util .FormatPath ()
7179 if path == "" {
7280 if len (args ) == 0 {
@@ -144,7 +152,7 @@ The YAML config file should be formatted like:
144152 runs = []types.Run {* run }
145153 }
146154
147- if numberOfRuns == 1 && ( runs [0 ].Status == "SCHEDULED" || runs [ 0 ]. CreationType == types . RunCreationScheduled ) {
155+ if numberOfRuns == 1 && runs [0 ].Status == "SCHEDULED" {
148156 runs = GetRuns (workflow .ID , numberOfRuns + 1 )
149157 runs = append (runs , runs ... )
150158 }
@@ -161,7 +169,7 @@ The YAML config file should be formatted like:
161169 if run .Status == "SCHEDULED" {
162170 continue
163171 }
164- DownloadRunOutput (& run , nodes , version , path )
172+ DownloadRunOutput (& run , nodes , files , version , path )
165173 }
166174 },
167175}
@@ -173,9 +181,10 @@ func init() {
173181 OutputCmd .Flags ().StringVar (& runID , "run" , "" , "Download output data of a specific run" )
174182 OutputCmd .Flags ().StringVar (& outputDir , "output-dir" , "" , "Path to directory which should be used to store outputs" )
175183 OutputCmd .Flags ().StringVar (& nodesFlag , "nodes" , "" , "A comma-separated list of nodes whose outputs should be downloaded" )
184+ OutputCmd .Flags ().StringVar (& filesFlag , "files" , "" , "A comma-separated list of file names that should be downloaded from the selected node" )
176185}
177186
178- func DownloadRunOutput (run * types.Run , nodes map [string ]NodeInfo , version * types.WorkflowVersionDetailed , destinationPath string ) {
187+ func DownloadRunOutput (run * types.Run , nodes map [string ]NodeInfo , files [] string , version * types.WorkflowVersionDetailed , destinationPath string ) {
179188 if run .Status != "COMPLETED" && run .Status != "STOPPED" && run .Status != "FAILED" {
180189 fmt .Println ("The workflow run hasn't been completed yet!" )
181190 fmt .Println ("Run ID: " + run .ID .String () + " Status: " + run .Status )
@@ -246,7 +255,7 @@ func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, version *types
246255 }
247256 subJob .OutputsStatus = updatedSubJob .OutputsStatus
248257 }
249- getSubJobOutput (runDir , & subJob , true )
258+ getSubJobOutput (runDir , & subJob , files , true )
250259 }
251260 } else {
252261 noneFound := true
@@ -272,7 +281,7 @@ func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, version *types
272281 }
273282 subJob .OutputsStatus = updatedSubJob .OutputsStatus
274283 }
275- getSubJobOutput (runDir , & subJob , true )
284+ getSubJobOutput (runDir , & subJob , files , true )
276285 }
277286 }
278287 if noneFound {
@@ -287,7 +296,7 @@ func DownloadRunOutput(run *types.Run, nodes map[string]NodeInfo, version *types
287296 }
288297}
289298
290- func getSubJobOutput (savePath string , subJob * types.SubJob , fetchData bool ) []types.SubJobOutput {
299+ func getSubJobOutput (savePath string , subJob * types.SubJob , files [] string , fetchData bool ) []types.SubJobOutput {
291300 if subJob .OutputsStatus != "SAVED" && ! subJob .TaskGroup {
292301 return nil
293302 }
@@ -339,7 +348,7 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
339348 results := make ([]types.SubJobOutput , 0 )
340349 if subJob .Children != nil {
341350 for _ , child := range subJob .Children {
342- childRes := getSubJobOutput (savePath , & child , true )
351+ childRes := getSubJobOutput (savePath , & child , files , true )
343352 if childRes != nil {
344353 results = append (results , childRes ... )
345354 }
@@ -361,7 +370,8 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
361370 }
362371 }
363372
364- for i , output := range subJobOutputs .Results {
373+ subJobOutputResults := filterSubJobOutputsByFileNames (subJobOutputs .Results , files )
374+ for i , output := range subJobOutputResults {
365375 resp := request .Trickest .Post ().DoF ("subjob-output/%s/signed_url/" , output .ID )
366376 if resp == nil {
367377 fmt .Println ("Error: Couldn't get sub-job outputs signed URL." )
@@ -380,22 +390,22 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
380390 }
381391
382392 if resp .Status () == http .StatusNotFound {
383- subJobOutputs . Results [i ].SignedURL = "expired"
393+ subJobOutputResults [i ].SignedURL = "expired"
384394 } else {
385- subJobOutputs . Results [i ].SignedURL = signedURL .Url
395+ subJobOutputResults [i ].SignedURL = signedURL .Url
386396
387397 if fetchData {
388- fileName := subJobOutputs . Results [i ].FileName
398+ fileName := subJobOutputResults [i ].FileName
389399
390- if fileName != subJobOutputs . Results [i ].Path {
391- subDirsPath := strings .TrimSuffix (subJobOutputs . Results [i ].Path , fileName )
400+ if fileName != subJobOutputResults [i ].Path {
401+ subDirsPath := strings .TrimSuffix (subJobOutputResults [i ].Path , fileName )
392402 err := os .MkdirAll (subDirsPath , 0755 )
393403 if err != nil {
394404 fmt .Println (err )
395405 fmt .Println ("Couldn't create a directory to store run output!" )
396406 os .Exit (0 )
397407 }
398- fileName = subJobOutputs . Results [i ].Path
408+ fileName = subJobOutputResults [i ].Path
399409 }
400410
401411 fileName = path .Join (savePath , fileName )
@@ -446,7 +456,25 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
446456 }
447457 }
448458
449- return subJobOutputs .Results
459+ return subJobOutputResults
460+ }
461+
462+ func filterSubJobOutputsByFileNames (outputs []types.SubJobOutput , fileNames []string ) []types.SubJobOutput {
463+ if fileNames == nil {
464+ return outputs
465+ }
466+
467+ var matchingOutputs []types.SubJobOutput
468+ for _ , output := range outputs {
469+ for _ , fileName := range fileNames {
470+ if output .FileName == fileName {
471+ matchingOutputs = append (matchingOutputs , output )
472+ break
473+ }
474+ }
475+ }
476+
477+ return matchingOutputs
450478}
451479
452480func GetRunByID (id uuid.UUID ) * types.Run {
0 commit comments