| 430 | } |
| 431 | |
| 432 | func (t *Trigger) Create(Client *whisk.Client, args []string) error { |
| 433 | if whiskErr := CheckArgs(args, 1, 1, "Trigger create", |
| 434 | wski18n.T("A trigger name is required.")); whiskErr != nil { |
| 435 | return whiskErr |
| 436 | } |
| 437 | |
| 438 | //1. if the command line arguments user provides contains only --param flags |
| 439 | //2. if the command line arguments user provides contains no --param flags at all |
| 440 | //we should process the trigger create command in the old way. |
| 441 | if userIndicatesToUseOldTriggerCommand() { |
| 442 | triggerName, err := NewQualifiedName(args[0]) |
| 443 | if err != nil { |
| 444 | return NewQualifiedNameError(args[0], err) |
| 445 | } |
| 446 | |
| 447 | //if user also issued new trigger command then we stop execution |
| 448 | if triggerUsageErr := userIssuedNewTriggerCmd(); triggerUsageErr != nil { |
| 449 | return triggerUsageErr |
| 450 | } |
| 451 | |
| 452 | annotationArray := Flags.common.annotation |
| 453 | authToken := Client.Config.AuthToken |
| 454 | |
| 455 | // if a feed is specified, create additional parameters which must be passed to the feed |
| 456 | feedQualifiedName, additionalFeedParams := feedParameters(Flags.common.feed, FEED_CREATE, triggerName, authToken) |
| 457 | |
| 458 | // if a feed is specified, add feed annotation the annotations declared on the command line |
| 459 | // TODO: add test to ensure that generated annotation has precedence |
| 460 | if feedQualifiedName != nil { |
| 461 | annotationArray = append(annotationArray, getFormattedJSON("feed", feedQualifiedName.GetFullQualifiedName())) |
| 462 | } |
| 463 | annotations := getParameters(annotationArray, true, true) |
| 464 | |
| 465 | // the feed receives all the parameters that are specified on the command line so we merge |
| 466 | // the feed lifecycle parameters with the command line ones |
| 467 | parameters := getParameters(append(Flags.common.param, additionalFeedParams...), feedQualifiedName == nil, false) |
| 468 | |
| 469 | trigger := &whisk.Trigger{ |
| 470 | Name: triggerName.GetEntityName(), |
| 471 | Annotations: annotations.(whisk.KeyValueArr), |
| 472 | } |
| 473 | |
| 474 | if feedQualifiedName == nil { |
| 475 | // parameters are only attached to the trigger in there is no feed, otherwise |
| 476 | // parameters are passed to the feed instead |
| 477 | trigger.Parameters = parameters.(whisk.KeyValueArr) |
| 478 | } |
| 479 | |
| 480 | createOrUpdate(Client, triggerName, trigger, false) |
| 481 | |
| 482 | // Invoke the specified feed action to configure the trigger feed |
| 483 | if feedQualifiedName != nil { |
| 484 | res, err := invokeAction(*feedQualifiedName, parameters, true, false) |
| 485 | if err != nil { |
| 486 | whisk.Debug(whisk.DbgError, "Failed configuring feed '%s' failed: %s\n", feedQualifiedName.GetFullQualifiedName(), err) |
| 487 | |
| 488 | // TODO: should we do this at all? Keeping for now. |
| 489 | printFailedBlockingInvocationResponse(*feedQualifiedName, false, res, err) |