in commands/trigger.go [524:595]
func CreateExtendedVersion(Client *whisk.Client, args []string) error {
triggerName, err := NewQualifiedName(args[0])
if err != nil {
return NewQualifiedNameError(args[0], err)
}
annotationArray := Flags.common.annotation
authToken := Client.Config.AuthToken
// if a feed is specified, create additional parameters which must be passed to the feed
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 feedQualifiedName != nil {
annotationArray = append(annotationArray, getFormattedJSON("feed", feedQualifiedName.GetFullQualifiedName()))
}
annotations := getParameters(annotationArray, true, true)
//if trigger contains no feed but user tries to update feed parameter, then we issue error.
if feedQualifiedName == nil && len(Flags.trigger.feedParam) > 0 {
errStr := wski18n.T("Incorrect usage. Trigger without a feed cannot have feed parameters")
return whisk.MakeWskError(errors.New(errStr), whisk.NOT_ALLOWED, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
}
triggerParams := getParameters(Flags.trigger.triggerParam, true, false)
//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
feedParams := getParameters(append(Flags.trigger.feedParam, additionalFeedParams...), feedQualifiedName == nil, false)
trigger := &whisk.Trigger{
Name: triggerName.GetEntityName(),
Annotations: annotations.(whisk.KeyValueArr),
Parameters: triggerParams.(whisk.KeyValueArr),
}
createOrUpdate(Client, triggerName, trigger, false)
// Invoke the specified feed action to configure the trigger feed
if feedQualifiedName != nil {
res, err := invokeAction(*feedQualifiedName, feedParams, 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
}
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
}