steven0711dong commented on a change in pull request #479: Trigger parameter issue URL: https://github.com/apache/openwhisk-cli/pull/479#discussion_r378531063
########## File path: commands/trigger.go ########## @@ -436,47 +442,108 @@ func (t *Trigger) Create(Client *whisk.Client, args []string) error { return NewQualifiedNameError(args[0], err) } - paramArray := Flags.common.param annotationArray := Flags.common.annotation - feedParam := Flags.common.feed authToken := Client.Config.AuthToken // if a feed is specified, create additional parameters which must be passed to the feed - feedName, feedParams := feedParameters(feedParam, FEED_CREATE, triggerName, authToken) - // the feed receives all the parameters that are specified on the command line so we merge - // the feed lifecycle parameters with the command line ones - parameters := getParameters(append(paramArray, feedParams...), feedName == nil, false) + feedQualifiedName, additionalFeedParams := feedParameters(Flags.common.feed, FEED_CREATE, triggerName, authToken) // if a feed is specified, add feed annotation the annotations declared on the command line // TODO: add test to ensure that generated annotation has precedence - if feedName != nil { - annotationArray = append(annotationArray, getFormattedJSON("feed", feedName.GetFullQualifiedName())) + if feedQualifiedName != nil { + annotationArray = append(annotationArray, getFormattedJSON("feed", feedQualifiedName.GetFullQualifiedName())) } annotations := getParameters(annotationArray, true, true) + //Within this if statement, we process users' trigger command using the old way. + if userIndicatesToUseOldTriggerCommand() { + //if user also issued new trigger command then we stop execution + if userIssuedNewTriggerCmd() { + return nil + } + // the feed receives all the parameters that are specified on the command line so we merge + // the feed lifecycle parameters with the command line ones + parameters := getParameters(append(Flags.common.param, additionalFeedParams...), feedQualifiedName == nil, false) + + trigger := &whisk.Trigger{ + Name: triggerName.GetEntityName(), + Annotations: annotations.(whisk.KeyValueArr), + } + + if feedQualifiedName == nil { + // parameters are only attached to the trigger in there is no feed, otherwise + // parameters are passed to the feed instead + trigger.Parameters = parameters.(whisk.KeyValueArr) + } + + createOrUpdate(Client, triggerName, trigger, false) + + // Invoke the specified feed action to configure the trigger feed + if feedQualifiedName != nil { + res, err := invokeAction(*feedQualifiedName, parameters, true, false) + if err != nil { + whisk.Debug(whisk.DbgError, "Failed configuring feed '%s' failed: %s\n", feedQualifiedName.GetFullQualifiedName(), err) + + // TODO: should we do this at all? Keeping for now. + printFailedBlockingInvocationResponse(*feedQualifiedName, false, res, err) + + reason := wski18n.T(FEED_CONFIGURATION_FAILURE, map[string]interface{}{"feedname": feedQualifiedName.GetFullQualifiedName(), "err": err}) + errStr := wski18n.T("Unable to create trigger '{{.name}}': {{.err}}", + map[string]interface{}{"name": trigger.Name, "err": reason}) + werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) + + // Delete trigger that was created for this feed + err = deleteTrigger(triggerName.GetEntityName()) + if err != nil { + whisk.Debug(whisk.DbgWarn, "Ignoring deleteTrigger(%s) failure: %s\n", triggerName.GetEntityName(), err) + } + + return werr + } else { + whisk.Debug(whisk.DbgInfo, "Successfully configured trigger feed via feed action '%s'\n", Flags.common.feed) + + // preserve existing behavior where output of feed activation is emitted to console + printInvocationMsg(*feedQualifiedName, true, true, res, color.Output) + } + } + + fmt.Fprintf(color.Output, + wski18n.T("{{.ok}} created trigger {{.name}}\n", + map[string]interface{}{"ok": color.GreenString("ok:"), "name": boldString(trigger.Name)})) + return nil + } + + //if execution reached this line, it means that users intend to create or update trigger using the new way + //by using --feed-param or --trigger-param flag + if feedQualifiedName == nil && len(Flags.trigger.feedParam) > 0 { + //trigger without feed names cannot have a feed param + errMsg := fmt.Sprintf("Incorrect usage. trigger without a feed cannot have feed parameters. \n") + fmt.Fprintf(os.Stderr, "%s%s", color.RedString("error: "), errors.New(errMsg)) + return nil Review comment: OK, I'll have both return error. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services