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/12/04 21:40:39 UTC

[GitHub] csantanapr closed pull request #3031: Return 202 for trigger fire requests

csantanapr closed pull request #3031: Return 202 for trigger fire requests
URL: https://github.com/apache/incubator-openwhisk/pull/3031
 
 
   

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/core/controller/src/main/scala/whisk/core/controller/Triggers.scala b/core/controller/src/main/scala/whisk/core/controller/Triggers.scala
index 93a7a51e80..f0fbf52781 100644
--- a/core/controller/src/main/scala/whisk/core/controller/Triggers.scala
+++ b/core/controller/src/main/scala/whisk/core/controller/Triggers.scala
@@ -21,7 +21,6 @@ import java.time.Clock
 import java.time.Instant
 
 import scala.concurrent.Future
-import scala.util.{Failure, Success}
 
 import akka.actor.ActorSystem
 import akka.stream.ActorMaterializer
@@ -60,7 +59,6 @@ import whisk.core.entity.types.ActivationStore
 import whisk.core.entity.types.EntityStore
 import whisk.core.entity.Identity
 import whisk.core.entity.FullyQualifiedEntityName
-import whisk.http.ErrorResponse.terminate
 
 /** A trait implementing the triggers API. */
 trait WhiskTriggersApi extends WhiskCollectionAPI {
@@ -143,9 +141,11 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
             response = ActivationResponse.success(payload orElse Some(JsObject())),
             version = trigger.version,
             duration = None)
+
           logging.info(this, s"[POST] trigger activated, writing activation record to datastore: $triggerActivationId")
-          val saveTriggerActivation = WhiskActivation.put(activationStore, triggerActivation) map { _ =>
-            triggerActivationId
+          WhiskActivation.put(activationStore, triggerActivation) recover {
+            case t =>
+              logging.error(this, s"[POST] storing trigger activation $triggerActivationId failed: ${t.getMessage}")
           }
 
           val url = Uri(s"http://localhost:${whiskConfig.servicePort}")
@@ -155,19 +155,22 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
               case (ruleName, rule) => rule.status == Status.ACTIVE
             } foreach {
               case (ruleName, rule) =>
+                val ruleActivationId = activationIdFactory.make()
                 val ruleActivation = WhiskActivation(
                   namespace = user.namespace.toPath, // all activations should end up in the one space regardless trigger.namespace,
                   ruleName.name,
                   user.subject,
-                  activationIdFactory.make(),
+                  ruleActivationId,
                   Instant.now(Clock.systemUTC()),
                   Instant.EPOCH,
                   cause = Some(triggerActivationId),
                   response = ActivationResponse.success(),
                   version = trigger.version,
                   duration = None)
-                logging.info(this, s"[POST] rule ${ruleName} activated, writing activation record to datastore")
-                WhiskActivation.put(activationStore, ruleActivation)
+                WhiskActivation.put(activationStore, ruleActivation) recover {
+                  case t =>
+                    logging.error(this, s"[POST] storing rule activation $ruleActivationId failed: ${t.getMessage}")
+                }
 
                 val actionNamespace = rule.action.path.root.asString
                 val actionPath = {
@@ -205,13 +208,7 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
             }
           }
 
-          onComplete(saveTriggerActivation) {
-            case Success(activationId) =>
-              complete(OK, activationId.toJsObject)
-            case Failure(t: Throwable) =>
-              logging.error(this, s"[POST] storing trigger activation failed: ${t.getMessage}")
-              terminate(InternalServerError)
-          }
+          complete(Accepted, triggerActivationId.toJsObject)
       })
     }
   }
diff --git a/tests/src/test/scala/common/rest/WskRest.scala b/tests/src/test/scala/common/rest/WskRest.scala
index a38ba16531..a8f93ba6a5 100644
--- a/tests/src/test/scala/common/rest/WskRest.scala
+++ b/tests/src/test/scala/common/rest/WskRest.scala
@@ -510,7 +510,7 @@ class WskRestTrigger
   override def fire(name: String,
                     parameters: Map[String, JsValue] = Map(),
                     parameterFile: Option[String] = None,
-                    expectedExitCode: Int = OK.intValue)(implicit wp: WskProps): RestResult = {
+                    expectedExitCode: Int = Accepted.intValue)(implicit wp: WskProps): RestResult = {
     val path = getNamePath(noun, name)
     val params = parameterFile map { l =>
       val input = FileUtils.readFileToString(new File(l))
diff --git a/tests/src/test/scala/whisk/core/controller/test/TriggersApiTests.scala b/tests/src/test/scala/whisk/core/controller/test/TriggersApiTests.scala
index 63a18f38d4..382d08d290 100644
--- a/tests/src/test/scala/whisk/core/controller/test/TriggersApiTests.scala
+++ b/tests/src/test/scala/whisk/core/controller/test/TriggersApiTests.scala
@@ -19,6 +19,7 @@ package whisk.core.controller.test
 
 import java.time.Instant
 
+import scala.concurrent.duration.DurationInt
 import scala.language.postfixOps
 
 import org.junit.runner.RunWith
@@ -316,17 +317,20 @@ class TriggersApiTests extends ControllerTestCommon with WhiskTriggersApi {
     val content = JsObject("xxx" -> "yyy".toJson)
     put(entityStore, trigger)
     Post(s"$collectionPath/${trigger.name}", content) ~> Route.seal(routes(creds)) ~> check {
-      status should be(OK)
+      status should be(Accepted)
       val response = responseAs[JsObject]
       val JsString(id) = response.fields("activationId")
       val activationId = ActivationId(id)
       response.fields("activationId") should not be None
 
       val activationDoc = DocId(WhiskEntity.qualifiedName(namespace, activationId))
-      val activation = get(activationStore, activationDoc, WhiskActivation, garbageCollect = false)
-      del(activationStore, DocId(WhiskEntity.qualifiedName(namespace, activationId)), WhiskActivation)
-      activation.end should be(Instant.EPOCH)
-      activation.response.result should be(Some(content))
+      whisk.utils.retry({
+        println(s"trying to obtain async activation doc: '${activationDoc}'")
+        val activation = get(activationStore, activationDoc, WhiskActivation, garbageCollect = false)
+        del(activationStore, activationDoc, WhiskActivation)
+        activation.end should be(Instant.EPOCH)
+        activation.response.result should be(Some(content))
+      }, 30, Some(1.second))
     }
   }
 
@@ -338,8 +342,12 @@ class TriggersApiTests extends ControllerTestCommon with WhiskTriggersApi {
       val response = responseAs[JsObject]
       val JsString(id) = response.fields("activationId")
       val activationId = ActivationId(id)
-      del(activationStore, DocId(WhiskEntity.qualifiedName(namespace, activationId)), WhiskActivation)
-      response.fields("activationId") should not be None
+      val activationDoc = DocId(WhiskEntity.qualifiedName(namespace, activationId))
+      whisk.utils.retry({
+        println(s"trying to delete async activation doc: '${activationDoc}'")
+        del(activationStore, activationDoc, WhiskActivation)
+        response.fields("activationId") should not be None
+      }, 30, Some(1.second))
     }
   }
 


 

----------------------------------------------------------------
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