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 2018/02/08 20:47:05 UTC

[GitHub] markusthoemmes commented on a change in pull request #3256: Refactor some bits of the triggers API.

markusthoemmes commented on a change in pull request #3256: Refactor some bits of the triggers API.
URL: https://github.com/apache/incubator-openwhisk/pull/3256#discussion_r167062270
 
 

 ##########
 File path: core/controller/src/main/scala/whisk/core/controller/Triggers.scala
 ##########
 @@ -305,59 +292,56 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
   private def activateRules(user: Identity,
                             args: JsObject,
                             rulesToActivate: Map[FullyQualifiedEntityName, ReducedRule])(
-    implicit transid: TransactionId): Iterable[Future[JsObject]] = {
-    rulesToActivate.map {
+    implicit transid: TransactionId): Future[Iterable[RuleActivationResult]] = {
+    val ruleResults = rulesToActivate.map {
       case (ruleName, rule) =>
         // Invoke the action. Retain action results for inclusion in the trigger activation record
-        val actionActivationResult: Future[JsObject] = postActivation(user, rule, args)
+        postActivation(user, rule, args)
           .flatMap { response =>
             response.status match {
               case OK | Accepted =>
                 Unmarshal(response.entity).to[JsObject].map { activationResponse =>
-                  val activationId: JsValue = activationResponse.fields("activationId")
+                  val activationId = activationResponse.fields("activationId").convertTo[ActivationId]
                   logging.debug(this, s"trigger-fired action '${rule.action}' invoked with activation $activationId")
-                  ruleResult(ActivationResponse.Success, ruleName, rule.action, Some(activationId))
+                  RuleActivationResult(ActivationResponse.Success, ruleName, rule.action, Right(activationId))
                 }
 
-              // all proper controller responses are JSON objects that deserialize to an ErrorResponse instance
-              case code if (response.entity.contentType == ContentTypes.`application/json`) =>
-                Unmarshal(response.entity).to[ErrorResponse].map { e =>
-                  val statusCode =
-                    if (code != InternalServerError) {
-                      logging
-                        .debug(
-                          this,
-                          s"trigger-fired action '${rule.action}' failed to invoke with ${e.error}, ${e.code}")
-                      ActivationResponse.ApplicationError
-                    } else {
+              case code =>
+                Unmarshal(response.entity).to[String].map { error =>
+                  val failureType = code match {
+                    case _: ServerError => ActivationResponse.WhiskError // all 500s are to be considered whisk errors
+                    case _              => ActivationResponse.ApplicationError
+                  }
+                  val errorMessage: String = Try(error.parseJson.convertTo[ErrorResponse])
+                    .map { e =>
+                      def logMsg = s"trigger-fired action '${rule.action}' failed to invoke with ${e.error}, ${e.code}"
 
 Review comment:
   Note this is a refactor. This is copied from the current code.

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