This is an automated email from the ASF dual-hosted git repository.

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 59c2ff3  WIP Support retrieving status and configuration of feed 
triggers in CLI (#2893)
59c2ff3 is described below

commit 59c2ff3c77eec016f2665c755fc32464e2ded9ec
Author: Adnan Baruni <abar...@users.noreply.github.com>
AuthorDate: Wed Nov 8 16:01:20 2017 -0600

    WIP Support retrieving status and configuration of feed triggers in CLI 
(#2893)
    
    * invoke feed action in trigger get command when appropriate to fetch 
configuration and status
    
    * account for annotations for non-feed triggers
    
    * scanCode
    
    * remove unused param
    
    * add tests validating correct lifecycle event. update feeds.md with new 
lifecycle event
    
    * scalafmt
    
    * remove commented block
    
    * combine feed trigger tests into one
---
 docs/feeds.md                                      |  4 +--
 .../whisk/core/cli/test/WskBasicUsageTests.scala   | 20 +++++++++--
 tools/cli/go-whisk-cli/commands/trigger.go         | 39 ++++++++++++++++------
 3 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/docs/feeds.md b/docs/feeds.md
index 2a2fdf9..9e034bf 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', 'DELETE', 'PAUSE', or 'UNPAUSE'.
+* **lifecycleEvent**: one of 'CREATE', 'READ', '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`.    
+A similar feed action protocol occurs for `wsk trigger delete` 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 85e9fc8..265b22f 100644
--- a/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
+++ b/tests/src/test/scala/whisk/core/cli/test/WskBasicUsageTests.scala
@@ -27,10 +27,8 @@ import scala.language.postfixOps
 import scala.concurrent.duration.Duration
 import scala.concurrent.duration.DurationInt
 import scala.util.Random
-
 import org.junit.runner.RunWith
 import org.scalatest.junit.JUnitRunner
-
 import common.TestHelpers
 import common.TestUtils
 import common.TestUtils._
@@ -1125,6 +1123,24 @@ 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(
+    wskprops) { (wp, assetHelper) =>
+    val actionName = "echo"
+    val triggerName = "feedTest"
+
+    assetHelper.withCleaner(wsk.action, actionName) { (action, _) =>
+      action.create(actionName, 
Some(TestUtils.getTestActionFilename("echo.js")))
+    }
+
+    try {
+      wsk.trigger.create(triggerName, feed = Some(actionName)).stdout should 
include(""""lifecycleEvent": "CREATE"""")
+
+      wsk.trigger.get(triggerName).stdout should include(""""lifecycleEvent": 
"READ"""")
+    } finally {
+      wsk.trigger.delete(triggerName).stdout should 
include(""""lifecycleEvent": "DELETE"""")
+    }
+  }
+
   it should "denote bound trigger parameters for trigger summaries" in 
withAssetCleaner(wskprops) { (wp, assetHelper) =>
     val trgBoundParams = "trgBoundParams"
     val trgParamAnnot = "trgParamAnnot"
diff --git a/tools/cli/go-whisk-cli/commands/trigger.go 
b/tools/cli/go-whisk-cli/commands/trigger.go
index 7a464ce..39e3833 100644
--- a/tools/cli/go-whisk-cli/commands/trigger.go
+++ b/tools/cli/go-whisk-cli/commands/trigger.go
@@ -32,6 +32,7 @@ const FEED_LIFECYCLE_EVENT  = "lifecycleEvent"
 const FEED_TRIGGER_NAME     = "triggerName"
 const FEED_AUTH_KEY         = "authKey"
 const FEED_CREATE           = "CREATE"
+const FEED_READ             = "READ"
 const FEED_DELETE           = "DELETE"
 
 // triggerCmd represents the trigger command
@@ -294,6 +295,7 @@ var triggerGetCmd = &cobra.Command{
     RunE: func(cmd *cobra.Command, args []string) error {
         var err error
         var field string
+        var fullFeedName string
         var qualifiedName = new(QualifiedName)
 
         if whiskErr := CheckArgs(args, 1, 2, "Trigger get", wski18n.T("A 
trigger name is required.")); whiskErr != nil {
@@ -326,18 +328,35 @@ var triggerGetCmd = &cobra.Command{
             return werr
         }
 
-        if (flags.trigger.summary) {
-            printSummary(retTrigger)
+        // 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")
+        }
+
+        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_READ))
+            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 = configureFeed(qualifiedName.GetEntityName(), fullFeedName)
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "configureFeed(%s, %s) failed: 
%s\n", qualifiedName.GetEntityName(), fullFeedName, err)
+            }
         } else {
-            if len(field) > 0 {
-                fmt.Fprintf(color.Output, wski18n.T("{{.ok}} got trigger 
{{.name}}, displaying field {{.field}}\n",
-                    map[string]interface{}{"ok": color.GreenString("ok:"), 
"name": boldString(qualifiedName.GetEntityName()),
-                    "field": boldString(field)}))
-                printField(retTrigger, field)
+            if (flags.trigger.summary) {
+                printSummary(retTrigger)
             } else {
-                fmt.Fprintf(color.Output, wski18n.T("{{.ok}} got trigger 
{{.name}}\n",
-                        map[string]interface{}{"ok": color.GreenString("ok:"), 
"name": boldString(qualifiedName.GetEntityName())}))
-                printJSON(retTrigger)
+                if len(field) > 0 {
+                    fmt.Fprintf(color.Output, wski18n.T("{{.ok}} got trigger 
{{.name}}, displaying field {{.field}}\n",
+                        map[string]interface{}{"ok": color.GreenString("ok:"), 
"name": boldString(qualifiedName.GetEntityName()),
+                        "field": boldString(field)}))
+                    printField(retTrigger, field)
+                } else {
+                    fmt.Fprintf(color.Output, wski18n.T("{{.ok}} got trigger 
{{.name}}\n",
+                            map[string]interface{}{"ok": 
color.GreenString("ok:"), "name": boldString(qualifiedName.GetEntityName())}))
+                    printJSON(retTrigger)
+                }
             }
         }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].

Reply via email to