Skip to content

Commit 44ce24a

Browse files
claireguyotteo
authored andcommitted
[OCTRL-701] Changes following PR review.
1 parent 40a3be1 commit 44ce24a

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

coconut/cmd/environment_create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Examples:
5050
* `+"`coconut env create -w github.com/AliceO2Group/MyConfRepo/myworkflow`"+` - loads a workflow from a specific git repository, HEAD of master branch
5151
* `+"`coconut env create -w myworkflow@rev`"+` - loads a workflow from default repository, on branch, tag or revision `+"`rev`"+`
5252
* `+"`coconut env create -w github.com/AliceO2Group/MyConfRepo/myworkflow@rev`"+` - loads a workflow from a specific git repository, on branch, tag or revision `+"`rev`"+`
53+
* `+"`coconut env create -c /home/myrepo/myconfigfile.json`"+`
54+
* `+"`coconut env create -c consul:///o2/runtime/COG-v1/TECHNICAL -w readout-dataflow@myBranch -e '{\"hosts\":\"[\\\"my-test-machine\\\"]\"}'`"+`
5355
5456
For more information on the %s workflow configuration system, see documentation for the `+"`coconut repository`"+` command.`, product.PRETTY_SHORTNAME, product.PRETTY_SHORTNAME),
5557
Run: control.WrapCall(control.CreateEnvironment),
@@ -59,8 +61,8 @@ func init() {
5961
environmentCmd.AddCommand(environmentCreateCmd)
6062

6163
environmentCreateCmd.Flags().StringP("configuration", "c", "", "high-level configuration payload to be loaded for the new environment")
62-
environmentCreateCmd.MarkFlagRequired("configuration")
6364
environmentCreateCmd.Flags().StringP("workflow-template", "w", "", "workflow to be loaded in the new environment")
65+
6466
environmentCreateCmd.Flags().BoolP("auto", "a", false, "create an autorun environment")
6567
environmentCreateCmd.Flags().BoolP("public", "p", true, "control public rights of the environment")
6668

coconut/control/control.go

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,42 +265,53 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
265265
err = errors.New("cannot get configuration payload value")
266266
return
267267
}
268-
if len(configPayload) == 0 {
269-
err = errors.New("cannot create environment with empty configuration payload")
270-
return
271-
}
272-
configPayloadDoc, err := os.ReadFile(configPayload)
268+
userWfPath, err := cmd.Flags().GetString("workflow-template")
273269
if err != nil {
274-
err = errors.New("cannot read configuration payload file")
270+
err = errors.New("cannot get workflow template value")
275271
return
276272
}
277-
payloadData := new(ConfigurationPayload)
278-
err = json.Unmarshal(configPayloadDoc, &payloadData)
279-
if err != nil {
280-
err = errors.New("cannot unmarshal configuration payload")
273+
if cmd.Flags().Changed("configuration") && len(configPayload) == 0 && cmd.Flags().Changed("workflow-template") && len(userWfPath) == 0 {
274+
err = errors.New("no configuration payload or workflow template provided")
281275
return
282276
}
283277

278+
payloadData := new(ConfigurationPayload)
284279
var wfPath string
285-
userWfPath, err := cmd.Flags().GetString("workflow-template")
286-
if err != nil {
287-
return
288-
}
289-
if cmd.Flags().Changed("workflow-template") && len(userWfPath) == 0 {
290-
if len(payloadData.Workflow) > 0 {
291-
wfPath = payloadData.Workflow
280+
if cmd.Flags().Changed("configuration") && len(configPayload) > 0 {
281+
configPayloadDoc, err := os.ReadFile(configPayload)
282+
if err != nil {
283+
err = errors.New("cannot read configuration payload file")
284+
return err
285+
}
286+
err = json.Unmarshal(configPayloadDoc, &payloadData)
287+
if err != nil {
288+
err = errors.New("cannot unmarshal configuration payload")
289+
return err
290+
}
291+
292+
if cmd.Flags().Changed("workflow-template") && len(userWfPath) == 0 {
293+
if len(payloadData.Workflow) > 0 {
294+
wfPath = payloadData.Workflow
295+
} else {
296+
err = errors.New("empty workflow template provided")
297+
return err
298+
}
299+
} else if cmd.Flags().Changed("workflow-template") && len(userWfPath) > 0 {
300+
wfPath = userWfPath
292301
} else {
293-
err = errors.New("empty workflow template provided")
294-
return
302+
if len(payloadData.Workflow) > 0 {
303+
wfPath = payloadData.Workflow
304+
} else {
305+
err = errors.New("no workflow template provided in config file")
306+
return err
307+
}
295308
}
296-
} else if cmd.Flags().Changed("workflow-template") && len(userWfPath) > 0 {
297-
wfPath = userWfPath
298309
} else {
299-
if len(payloadData.Workflow) > 0 {
300-
wfPath = payloadData.Workflow
310+
if cmd.Flags().Changed("workflow-template") && len(userWfPath) > 0 {
311+
wfPath = userWfPath
301312
} else {
302-
err = errors.New("no workflow template provided in config file")
303-
return
313+
err = errors.New("empty workflow template provided")
314+
return err
304315
}
305316
}
306317

@@ -325,9 +336,11 @@ func CreateEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
325336
for k, v := range userExtraVarsMap {
326337
extraVarsMap[k] = v
327338
}
328-
for k, v := range payloadData.Vars {
329-
if _, exists := extraVarsMap[k]; !exists {
330-
extraVarsMap[k] = v
339+
if cmd.Flags().Changed("configuration") && len(configPayload) > 0 {
340+
for k, v := range payloadData.Vars {
341+
if _, exists := extraVarsMap[k]; !exists {
342+
extraVarsMap[k] = v
343+
}
331344
}
332345
}
333346

0 commit comments

Comments
 (0)