This is an automated email from the ASF dual-hosted git repository. csantanapr 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 301c38b Return 202 for trigger fire requests (#3031) 301c38b is described below commit 301c38ba672b2b6aca09390e002b5dfa985ff7b2 Author: Mark Deuser <mdeu...@us.ibm.com> AuthorDate: Mon Dec 4 16:40:35 2017 -0500 Return 202 for trigger fire requests (#3031) * Return 202 for trigger fire requests - asynchronously write the trigger activation record to the db --- .../scala/whisk/core/controller/Triggers.scala | 25 ++++++++++------------ tests/src/test/scala/common/rest/WskRest.scala | 2 +- .../core/controller/test/TriggersApiTests.scala | 22 +++++++++++++------ 3 files changed, 27 insertions(+), 22 deletions(-) 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 93a7a51..f0fbf52 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 a38ba16..a8f93ba 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 63a18f3..382d08d 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)) } } -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].