You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/11/16 19:58:02 UTC

[GitHub] abaruni closed pull request #2976: WIP Support for updating feed triggers

abaruni closed pull request #2976: WIP Support for updating feed triggers
URL: https://github.com/apache/incubator-openwhisk/pull/2976
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/docs/feeds.md b/docs/feeds.md
index 9e034bfaeb..a0204c6b6f 100644
--- a/docs/feeds.md
+++ b/docs/feeds.md
@@ -38,7 +38,7 @@ but technically distinct concepts.
 #  Implementing Feed Actions
 
 The *feed action* is a normal OpenWhisk *action*, but it should accept the following parameters:
-* **lifecycleEvent**: one of 'CREATE', 'READ', 'DELETE', 'PAUSE', or 'UNPAUSE'.
+* **lifecycleEvent**: one of 'CREATE', 'READ', 'UPDATE', 'DELETE', 'PAUSE', or 'UNPAUSE'.
 * **triggerName**: the fully-qualified name of the trigger which contains events produced from this feed.
 * **authKey**: the Basic auth credentials of the OpenWhisk user who owns the trigger just mentioned.
 
@@ -58,7 +58,7 @@ The feed action named *changes* takes these parameters, and is expected to take
 
 For the Cloudant *changes* feed, the action happens to talk directly to a *cloudant trigger* service we've implemented with a connection-based architecture.   We'll discuss the other architectures below.
 
-A similar feed action protocol occurs for `wsk trigger delete` and `wsk trigger get`.    
+A similar feed action protocol occurs for `wsk trigger delete`, `wsk trigger update` and `wsk trigger get`.    
 
 # Implementing Feeds with Hooks
 
diff --git a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
index 265b22fec7..54dc3f8b3c 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -1123,7 +1123,7 @@ class WskBasicUsageTests extends TestHelpers with WskTestHelpers {
     }
   }
 
-  it should "invoke a feed action with the correct lifecyle event when creating, retrieving and deleting a feed trigger" in withAssetCleaner(
+  it should "invoke a feed action with the correct lifecyle event when creating, retrieving updating, and deleting a feed trigger" in withAssetCleaner(
     wskprops) { (wp, assetHelper) =>
     val actionName = "echo"
     val triggerName = "feedTest"
@@ -1136,6 +1136,8 @@ class WskBasicUsageTests extends TestHelpers with WskTestHelpers {
       wsk.trigger.create(triggerName, feed = Some(actionName)).stdout should include(""""lifecycleEvent": "CREATE"""")
 
       wsk.trigger.get(triggerName).stdout should include(""""lifecycleEvent": "READ"""")
+
+      wsk.trigger.create(triggerName, update = true).stdout should include(""""lifecycleEvent": "UPDATE""")
     } finally {
       wsk.trigger.delete(triggerName).stdout should include(""""lifecycleEvent": "DELETE"""")
     }
diff --git a/tools/cli/go-whisk-cli/commands/trigger.go b/tools/cli/go-whisk-cli/commands/trigger.go
index 39e38335e6..f26322704d 100644
--- a/tools/cli/go-whisk-cli/commands/trigger.go
+++ b/tools/cli/go-whisk-cli/commands/trigger.go
@@ -33,6 +33,7 @@ const FEED_TRIGGER_NAME     = "triggerName"
 const FEED_AUTH_KEY         = "authKey"
 const FEED_CREATE           = "CREATE"
 const FEED_READ             = "READ"
+const FEED_UPDATE           = "UPDATE"
 const FEED_DELETE           = "DELETE"
 
 // triggerCmd represents the trigger command
@@ -225,6 +226,7 @@ var triggerUpdateCmd = &cobra.Command{
     PreRunE: SetupClientConfig,
     RunE: func(cmd *cobra.Command, args []string) error {
         var err error
+        var fullFeedName string
         var qualifiedName = new(QualifiedName)
 
         if whiskErr := CheckArgs(args, 1, 1, "Trigger update",
@@ -238,50 +240,82 @@ var triggerUpdateCmd = &cobra.Command{
 
         Client.Namespace = qualifiedName.GetNamespace()
 
-        // Convert the trigger's list of default parameters from a string into []KeyValue
-        // The 1 or more --param arguments have all been combined into a single []string
-        // e.g.   --p arg1,arg2 --p arg3,arg4   ->  [arg1, arg2, arg3, arg4]
-
-        whisk.Debug(whisk.DbgInfo, "Parsing parameters: %#v\n", flags.common.param)
-        parameters, err := getJSONFromStrings(flags.common.param, true)
-
+        retTrigger, _, err := Client.Triggers.Get(qualifiedName.GetEntityName())
         if err != nil {
-            whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, true) failed: %s\n", flags.common.param, err)
-            errStr := wski18n.T("Invalid parameter argument '{{.param}}': {{.err}}",
-                    map[string]interface{}{"param": fmt.Sprintf("%#v",flags.common.param), "err": err})
-            werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
+            whisk.Debug(whisk.DbgError, "Client.Triggers.Get(%s) failed: %s\n", qualifiedName.GetEntityName(), err)
+            errStr := wski18n.T("Unable to get trigger '{{.name}}': {{.err}}",
+                    map[string]interface{}{"name": qualifiedName.GetEntityName(), "err": err})
+            werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
             return werr
         }
 
-        whisk.Debug(whisk.DbgInfo, "Parsing annotations: %#v\n", flags.common.annotation)
-        annotations, err := getJSONFromStrings(flags.common.annotation, true)
-
-        if err != nil {
-            whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, true) failed: %s\n", flags.common.annotation, err)
-            errStr := wski18n.T("Invalid annotation argument '{{.annotation}}': {{.err}}",
-                    map[string]interface{}{"annotation": fmt.Sprintf("%#v",flags.common.annotation), "err": err})
-            werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
-            return werr
+        // Get full feed name from trigger get request as it is needed to get the feed
+        if retTrigger != nil && retTrigger.Annotations != nil {
+            fullFeedName = getValueString(retTrigger.Annotations, "feed")
         }
 
-        trigger := &whisk.Trigger{
-            Name:        qualifiedName.GetEntityName(),
-            Parameters:  parameters.(whisk.KeyValueArr),
-            Annotations: annotations.(whisk.KeyValueArr),
-        }
+        if len(fullFeedName) > 0 {
+            fullTriggerName := fmt.Sprintf("/%s/%s", qualifiedName.GetNamespace(), qualifiedName.GetEntityName())
+            flags.common.param = append(flags.common.param, getFormattedJSON(FEED_LIFECYCLE_EVENT, FEED_UPDATE))
+            flags.common.param = append(flags.common.param, getFormattedJSON(FEED_TRIGGER_NAME, fullTriggerName))
+            flags.common.param = append(flags.common.param, getFormattedJSON(FEED_AUTH_KEY, Client.Config.AuthToken))
 
-        _, _, err = Client.Triggers.Insert(trigger, true)
-        if err != nil {
-            whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v,true) failed: %s\n", trigger, err)
-            errStr := wski18n.T("Unable to update trigger '{{.name}}': {{.err}}",
-                    map[string]interface{}{"name": trigger.Name, "err": err})
-            werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
-            return werr
+            // Invoke the specified feed action to configure the trigger feed
+            err = configureFeed(qualifiedName.GetEntityName(), fullFeedName)
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "configureFeed(%s, %s) failed: %s\n", qualifiedName.GetEntityName(), flags.common.feed,
+                    err)
+                errStr := wski18n.T("Unable to create trigger '{{.name}}': {{.err}}",
+                        map[string]interface{}{"name": qualifiedName.GetEntityName(), "err": err})
+                werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+                return werr
+            }
+        } else {
+            // Convert the trigger's list of default parameters from a string into []KeyValue
+            // The 1 or more --param arguments have all been combined into a single []string
+            // e.g.   --p arg1,arg2 --p arg3,arg4   ->  [arg1, arg2, arg3, arg4]
+
+            whisk.Debug(whisk.DbgInfo, "Parsing parameters: %#v\n", flags.common.param)
+            parameters, err := getJSONFromStrings(flags.common.param, true)
+
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, true) failed: %s\n", flags.common.param, err)
+                errStr := wski18n.T("Invalid parameter argument '{{.param}}': {{.err}}",
+                        map[string]interface{}{"param": fmt.Sprintf("%#v",flags.common.param), "err": err})
+                werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
+                return werr
+            }
+
+            whisk.Debug(whisk.DbgInfo, "Parsing annotations: %#v\n", flags.common.annotation)
+            annotations, err := getJSONFromStrings(flags.common.annotation, true)
+
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, true) failed: %s\n", flags.common.annotation, err)
+                errStr := wski18n.T("Invalid annotation argument '{{.annotation}}': {{.err}}",
+                        map[string]interface{}{"annotation": fmt.Sprintf("%#v",flags.common.annotation), "err": err})
+                werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
+                return werr
+            }
+
+            trigger := &whisk.Trigger{
+                Name:        qualifiedName.GetEntityName(),
+                Parameters:  parameters.(whisk.KeyValueArr),
+                Annotations: annotations.(whisk.KeyValueArr),
+            }
+
+            _, _, err = Client.Triggers.Insert(trigger, true)
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v,true) failed: %s\n", trigger, err)
+                errStr := wski18n.T("Unable to update trigger '{{.name}}': {{.err}}",
+                        map[string]interface{}{"name": trigger.Name, "err": err})
+                werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+                return werr
+            }
         }
 
         fmt.Fprintf(color.Output,
             wski18n.T("{{.ok}} updated trigger {{.name}}\n",
-                map[string]interface{}{"ok": color.GreenString("ok:"), "name": boldString(trigger.Name)}))
+                map[string]interface{}{"ok": color.GreenString("ok:"), "name": boldString(qualifiedName.GetEntityName())}))
         return nil
     },
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services