You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by st...@apache.org on 2020/07/29 06:26:28 UTC

[openwhisk] branch master updated: Allow to get activation list by a binding package name (#4919)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4921a0e  Allow to get activation list by a binding package name (#4919)
4921a0e is described below

commit 4921a0eba7e3b35644a48c8b1c4e8bc313dbf360
Author: Seonghyun Oh <oh...@navercorp.com>
AuthorDate: Wed Jul 29 15:26:14 2020 +0900

    Allow to get activation list by a binding package name (#4919)
    
    * Support activation filter for binding package action
    
    * Add test case
    
    * Add new line
    
    * Update filter view version
    
    * Restore previous version filter view
---
 ...sign_document_for_activations_db_filters_v2.1.0.json |  0
 ...sign_document_for_activations_db_filters_v2.1.1.json | 10 ++++++++++
 ansible/tasks/recreateViews.yml                         |  2 +-
 common/scala/src/main/resources/application.conf        |  2 +-
 .../openwhisk/core/database/DocumentHandler.scala       |  2 +-
 .../elasticsearch/ElasticSearchActivationStore.scala    | 13 ++++++++++---
 core/standalone/src/main/resources/standalone.conf      |  2 +-
 .../test/behavior/ActivationStoreBehaviorBase.scala     | 11 +++++++++++
 .../test/behavior/ActivationStoreQueryBehaviors.scala   | 17 +++++++++++++++++
 tools/dev/README.md                                     |  4 ++--
 10 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.0.json b/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.0.json
old mode 100644
new mode 100755
diff --git a/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.1.json b/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.1.json
new file mode 100644
index 0000000..7cfed97
--- /dev/null
+++ b/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.1.json
@@ -0,0 +1,10 @@
+{
+  "_id": "_design/whisks-filters.v2.1.1",
+  "language": "javascript",
+  "views": {
+    "activations": {
+      "map": "function (doc) {\n  var PATHSEP = \"/\";\n  var isActivation = function (doc) { return (doc.activationId !== undefined) };\n  var summarize = function (doc) {\n    var endtime = doc.end !== 0 ? doc.end : undefined;\n    return {\n        namespace: doc.namespace,\n        name: doc.name,\n        version: doc.version,\n        publish: doc.publish,\n        annotations: doc.annotations,\n        activationId: doc.activationId,\n        start: doc.start,\n        end: endtim [...]
+      "reduce": "_count"
+    }
+  }
+}
diff --git a/ansible/tasks/recreateViews.yml b/ansible/tasks/recreateViews.yml
index 0d7eae4..ee1bdbf 100644
--- a/ansible/tasks/recreateViews.yml
+++ b/ansible/tasks/recreateViews.yml
@@ -31,7 +31,7 @@
     doc: "{{ lookup('file', '{{ item }}') }}"
   with_items:
     - "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_v2.1.0.json"
-    - "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.0.json"
+    - "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.1.json"
     - "{{ openwhisk_home }}/ansible/files/filter_design_document.json"
     - "{{ openwhisk_home }}/ansible/files/activations_design_document_for_activations_db.json"
     - "{{ openwhisk_home }}/ansible/files/logCleanup_design_document_for_activations_db.json"
diff --git a/common/scala/src/main/resources/application.conf b/common/scala/src/main/resources/application.conf
index 6e4a88b..a794ee2 100644
--- a/common/scala/src/main/resources/application.conf
+++ b/common/scala/src/main/resources/application.conf
@@ -219,7 +219,7 @@ whisk {
         subjects-ddoc = "subjects.v2.0.0"
         actions-ddoc = "whisks.v2.1.0"
         activations-ddoc = "whisks.v2.1.0"
-        activations-filter-ddoc = "whisks-filters.v2.1.0"
+        activations-filter-ddoc = "whisks-filters.v2.1.1"
 
         # Size limit for inlined attachments. Attachments having size less than this would
         # be inlined with there content encoded in attachmentName
diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/database/DocumentHandler.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/database/DocumentHandler.scala
index 33ecf4e..f61aacc 100644
--- a/common/scala/src/main/scala/org/apache/openwhisk/core/database/DocumentHandler.scala
+++ b/common/scala/src/main/scala/org/apache/openwhisk/core/database/DocumentHandler.scala
@@ -124,7 +124,7 @@ object ActivationHandler extends SimpleHandler {
   private val fieldsForView = commonFields ++ Seq("end", "response.statusCode")
 
   protected val supportedTables =
-    Set("activations/byDate", "whisks-filters.v2.1.0/activations", "whisks.v2.1.0/activations")
+    Set("activations/byDate", "whisks-filters.v2.1.1/activations", "whisks.v2.1.0/activations")
 
   override def computedFields(js: JsObject): JsObject = {
     val path = js.fields.get("namespace") match {
diff --git a/common/scala/src/main/scala/org/apache/openwhisk/core/database/elasticsearch/ElasticSearchActivationStore.scala b/common/scala/src/main/scala/org/apache/openwhisk/core/database/elasticsearch/ElasticSearchActivationStore.scala
index 5d97688..5d110a7 100644
--- a/common/scala/src/main/scala/org/apache/openwhisk/core/database/elasticsearch/ElasticSearchActivationStore.scala
+++ b/common/scala/src/main/scala/org/apache/openwhisk/core/database/elasticsearch/ElasticSearchActivationStore.scala
@@ -100,9 +100,16 @@ class ElasticSearchActivationStore(
     val start =
       transid.started(this, LoggingMarkers.DATABASE_SAVE, s"[PUT] 'activations' document: '${activation.docid}'")
 
-    val path = activation.annotations
-      .getAs[String](WhiskActivation.pathAnnotation)
-      .getOrElse(s"${activation.namespace}/${activation.name}")
+    val bindingPath = activation.annotations
+      .getAs[String](WhiskActivation.bindingAnnotation)
+      .toOption
+      .map(binding => s"$binding/${activation.name}")
+
+    val path = bindingPath.getOrElse(
+      activation.annotations
+        .getAs[String](WhiskActivation.pathAnnotation)
+        .getOrElse(s"${activation.namespace}/${activation.name}"))
+
     // Escape `_id` field as it's not permitted in ElasticSearch, add `path` field for search, and
     // convert annotations to JsObject as ElasticSearch doesn't support array with mixed types
     // response.result can be any type ElasticSearch also doesn't support that, so convert it to a string
diff --git a/core/standalone/src/main/resources/standalone.conf b/core/standalone/src/main/resources/standalone.conf
index 43f5995..0817680 100644
--- a/core/standalone/src/main/resources/standalone.conf
+++ b/core/standalone/src/main/resources/standalone.conf
@@ -113,7 +113,7 @@ whisk {
       ]
       activation-views = [
         "whisks_design_document_for_activations_db_v2.1.0.json",
-        "whisks_design_document_for_activations_db_filters_v2.1.0.json",
+        "whisks_design_document_for_activations_db_filters_v2.1.1.json",
         "filter_design_document.json",
         "activations_design_document_for_activations_db.json",
         "logCleanup_design_document_for_activations_db.json"
diff --git a/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreBehaviorBase.scala b/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreBehaviorBase.scala
index f8caad6..d1cf892 100644
--- a/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreBehaviorBase.scala
+++ b/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreBehaviorBase.scala
@@ -90,6 +90,17 @@ trait ActivationStoreBehaviorBase
       Instant.ofEpochMilli(start + 1000))
   }
 
+  protected def newBindingActivation(ns: String, actionName: String, binding: String, start: Long): WhiskActivation = {
+    WhiskActivation(
+      EntityPath(ns),
+      EntityName(actionName),
+      Subject(),
+      ActivationId.generate(),
+      Instant.ofEpochMilli(start),
+      Instant.ofEpochMilli(start + 1000),
+      annotations = Parameters(WhiskActivation.bindingAnnotation, binding))
+  }
+
   /**
    * Deletes all documents added to gc queue.
    */
diff --git a/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreQueryBehaviors.scala b/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreQueryBehaviors.scala
index c8123d5..59f4a3d 100644
--- a/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreQueryBehaviors.scala
+++ b/tests/src/test/scala/org/apache/openwhisk/core/database/test/behavior/ActivationStoreQueryBehaviors.scala
@@ -196,6 +196,23 @@ trait ActivationStoreQueryBehaviors extends ActivationStoreBehaviorBase {
     checkQueryActivations(namespace, Some(action1), context = context, expected = activations)
   }
 
+  it should "find all binding entities matching name" in {
+    implicit val tid: TransactionId = transId()
+    val namespace = s"ns_${Random.alphanumeric.take(4).mkString}"
+    val package1 = s"package1_${Random.alphanumeric.take(4).mkString}"
+    val action1 = s"action1_${Random.alphanumeric.take(4).mkString}"
+
+    val binding = s"$namespace/$package1"
+
+    val activations = (1000 until 1100 by 10).map(newBindingActivation(namespace, action1, binding, _))
+    activations foreach (store(_, context))
+
+    val activations2 = (1000 until 1100 by 10).map(newActivation(namespace, action1, _))
+    activations2 foreach (store(_, context))
+
+    checkQueryActivations(namespace, Some(s"$package1/$action1"), context = context, expected = activations)
+  }
+
   it should "support since and upto filters" in {
     implicit val tid: TransactionId = transId()
     val namespace = s"ns_${Random.alphanumeric.take(4).mkString}"
diff --git a/tools/dev/README.md b/tools/dev/README.md
index 46b795b..20a4022 100644
--- a/tools/dev/README.md
+++ b/tools/dev/README.md
@@ -57,8 +57,8 @@ Sample output
             - logCleanup-byDateWithLogs.js
     Processing whisks_design_document_for_all_entities_db_v2.1.0.json
             - all-whisks.v2.1.0-all.js
-    Processing whisks_design_document_for_activations_db_filters_v2.1.0.json
-            - whisks-filters.v2.1.0-activations.js
+    Processing whisks_design_document_for_activations_db_filters_v2.1.1.json
+            - whisks-filters.v2.1.1-activations.js
     Generated view json files in /path/too/tools/build/views
 
 ## IntelliJ Run Config Generator