@@ -31,7 +31,6 @@ import (
3131 "encoding/json"
3232 "errors"
3333 "fmt"
34- "github.com/AliceO2Group/Control/apricot"
3534 "io"
3635 "os"
3736 "regexp"
@@ -45,6 +44,7 @@ import (
4544
4645 "github.com/xlab/treeprint"
4746
47+ "github.com/AliceO2Group/Control/apricot"
4848 "github.com/AliceO2Group/Control/coconut"
4949 "github.com/AliceO2Group/Control/coconut/protos"
5050 "github.com/AliceO2Group/Control/common/logger"
@@ -59,8 +59,10 @@ import (
5959)
6060
6161const (
62- CALL_TIMEOUT = 55 * time .Second
63- SPINNER_TICK = 100 * time .Millisecond
62+ CALL_TIMEOUT = 55 * time .Second
63+ SPINNER_TICK = 100 * time .Millisecond
64+ HLCONFIG_COMPONENT_PREFIX = "COG-v1"
65+ HLCONFIG_PATH_PREFIX = "consul://o2/runtime/"
6466)
6567
6668var log = logger .New (logrus .StandardLogger (), "coconut" )
@@ -263,71 +265,62 @@ func GetEnvironments(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Com
263265func CreateEnvironment (cxt context.Context , rpc * coconut.RpcClient , cmd * cobra.Command , args []string , o io.Writer ) (err error ) {
264266 configPayload , err := cmd .Flags ().GetString ("configuration" )
265267 if err != nil {
266- err = errors .New ("cannot get configuration payload value" )
267- return
268+ return fmt .Errorf ("cannot get configuration payload value: %w" , err )
268269 }
269270 userWfPath , err := cmd .Flags ().GetString ("workflow-template" )
270271 if err != nil {
271- err = errors .New ("cannot get workflow template value" )
272- return
272+ return fmt .Errorf ("cannot get workflow template value: %w" , err )
273273 }
274274 if cmd .Flags ().Changed ("configuration" ) && len (configPayload ) == 0 && cmd .Flags ().Changed ("workflow-template" ) && len (userWfPath ) == 0 {
275- err = errors .New ("no configuration payload or workflow template provided" )
276- return
275+ return fmt .Errorf ("no configuration payload or workflow template provided: %w" , err )
277276 }
278277
279278 payloadData := new (ConfigurationPayload )
280279 var wfPath string
281280 if cmd .Flags ().Changed ("configuration" ) && len (configPayload ) > 0 {
282281 if strings .HasSuffix (strings .ToLower (configPayload ), ".json" ) {
283282 configPayloadDoc , err := os .ReadFile (configPayload )
283+ if err != nil {
284+ return fmt .Errorf ("cannot read local configuration payload: %w" , err )
285+ }
284286 err = json .Unmarshal (configPayloadDoc , & payloadData )
285287 if err != nil {
286- err = errors .New ("cannot unmarshal local configuration payload" )
287- return err
288+ return fmt .Errorf ("cannot unmarshal local configuration payload: %w" , err )
288289 }
289290 } else {
290- configPayloadSplit := strings .Split (configPayload , "/" )
291- if len (configPayloadSplit ) == 0 {
292- err = errors .New ("configuration payload file is not valid" )
293- return err
291+ if strings .HasPrefix (configPayload , HLCONFIG_PATH_PREFIX + HLCONFIG_COMPONENT_PREFIX ) {
292+ configPayload = strings .TrimPrefix (configPayload , HLCONFIG_PATH_PREFIX + HLCONFIG_COMPONENT_PREFIX )
294293 }
295- configPayloadUri := configPayloadSplit [len (configPayloadSplit )- 1 ]
296- configPayloadDoc , err := apricot .Instance ().GetRuntimeEntry ("COG-v1" , configPayloadUri )
294+ configPayloadDoc , err := apricot .Instance ().GetRuntimeEntry (HLCONFIG_COMPONENT_PREFIX , configPayload )
297295 if err != nil {
298- err = errors .New ("cannot retrieve file from consul under COG-v1 component" )
299- return err
296+ return fmt .Errorf ("cannot retrieve file from " + HLCONFIG_PATH_PREFIX + HLCONFIG_COMPONENT_PREFIX + ": %w" , err )
300297 }
301298 err = json .Unmarshal ([]byte (configPayloadDoc ), & payloadData )
302299 if err != nil {
303- err = errors .New ("cannot unmarshal remote configuration payload" )
304- return err
300+ return fmt .Errorf ("cannot unmarshal remote configuration payload: %w" , err )
305301 }
306302 }
307303
308304 if cmd .Flags ().Changed ("workflow-template" ) && len (userWfPath ) == 0 {
309305 if len (payloadData .Workflow ) > 0 {
310306 wfPath = payloadData .Workflow
311307 } else {
312- err = errors .New ("empty workflow template provided" )
313- return err
308+ return errors .New ("empty workflow template provided" )
314309 }
315310 } else if cmd .Flags ().Changed ("workflow-template" ) && len (userWfPath ) > 0 {
316311 wfPath = userWfPath
317312 } else {
318313 if len (payloadData .Workflow ) > 0 {
319314 wfPath = payloadData .Workflow
320315 } else {
321- err = errors .New ("no workflow template provided in config file" )
322- return err
316+ return errors .New ("no workflow template provided in config file" )
323317 }
324318 }
325319 } else {
326320 if cmd .Flags ().Changed ("workflow-template" ) && len (userWfPath ) > 0 {
327321 wfPath = userWfPath
328322 } else {
329- err = errors .New ("empty workflow template provided" )
330- return err
323+ return errors .New ("empty workflow template provided" )
331324 }
332325 }
333326
0 commit comments