rabbah commented on a change in pull request #3187: reduce rule activation 
records
URL: 
https://github.com/apache/incubator-openwhisk/pull/3187#discussion_r162061502
 
 

 ##########
 File path: core/controller/src/main/scala/whisk/core/controller/Triggers.scala
 ##########
 @@ -122,72 +126,135 @@ trait WhiskTriggersApi extends WhiskCollectionAPI {
             version = trigger.version,
             duration = None)
 
-          logging.info(this, s"[POST] trigger activated, writing activation 
record to datastore: $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}";)
-
-          trigger.rules.map {
-            _.filter {
-              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,
-                  ruleActivationId,
-                  Instant.now(Clock.systemUTC()),
-                  Instant.EPOCH,
-                  cause = Some(triggerActivationId),
-                  response = ActivationResponse.success(),
-                  version = trigger.version,
-                  duration = None)
-                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 = {
-                  rule.action.path.relativePath.map { pkg =>
-                    (Path.SingleSlash + pkg.namespace) / 
rule.action.name.asString
-                  } getOrElse {
-                    Path.SingleSlash + rule.action.name.asString
-                  }
-                }.toString
-
-                val actionUrl = Path("/api/v1") / "namespaces" / 
actionNamespace / "actions"
-                val request = HttpRequest(
-                  method = POST,
-                  uri = url.withPath(actionUrl + actionPath),
-                  headers =
-                    
List(Authorization(BasicHttpCredentials(user.authkey.uuid.asString, 
user.authkey.key.asString))),
-                  entity = HttpEntity(MediaTypes.`application/json`, 
args.getOrElse(JsObject()).compactPrint))
-
-                Http().singleRequest(request).map {
-                  response =>
-                    response.status match {
-                      case OK | Accepted =>
-                        Unmarshal(response.entity).to[JsObject].map { a =>
-                          logging.info(this, s"${rule.action} activated 
${a.fields("activationId")}")
-                        }
-                      case NotFound =>
-                        response.discardEntityBytes()
-                        logging.info(this, s"${rule.action} failed, action not 
found")
-                      case _ =>
-                        Unmarshal(response.entity).to[String].map { error =>
-                          logging.warn(this, s"${rule.action} failed due to 
$error")
+          // List of active rules associated with the trigger
+          val activeRules = trigger.rules map { _.filter((r) => r._2.status == 
Status.ACTIVE) } getOrElse Map.empty
+
+          if (activeRules.nonEmpty) {
+            val args = trigger.parameters.merge(payload)
+
+            // Iterate through each active rule; invoking each mapped action
+            val actionLogList = activeRules
+              .map {
+                case (ruleName, rule) =>
+                  // Build the url to invoke an action mapped to the rule
+                  val actionNamespace = rule.action.path.root.asString
+                  val actionPath = {
+                    rule.action.path.relativePath.map { pkg =>
+                      (Path.SingleSlash + pkg.namespace) / 
rule.action.name.asString
+                    } getOrElse {
+                      Path.SingleSlash + rule.action.name.asString
+                    }
+                  }.toString
+
+                  val actionUrl = Path("/api/v1") / "namespaces" / 
actionNamespace / "actions"
+                  val request = HttpRequest(
+                    method = POST,
+                    uri = url.withPath(actionUrl + actionPath),
+                    headers =
+                      
List(Authorization(BasicHttpCredentials(user.authkey.uuid.asString, 
user.authkey.key.asString))),
+                    entity = HttpEntity(MediaTypes.`application/json`, 
args.getOrElse(JsObject()).compactPrint))
+
+                  // Invoke the action. Retain action results for inclusion in 
the trigger activation record
+                  Http()
+                    .singleRequest(request)
+                    .flatMap {
+                      response =>
+                        response.status match {
+                          case OK | Accepted =>
+                            Unmarshal(response.entity).to[JsObject].map { a =>
+                              logging.info(
+                                this,
+                                s"trigger-fired rule '${rule.action}' invoked 
with activation ${a.fields("activationId")}")
+                              (ruleName.asString -> triggerActivationLogMsg(
+                                entityName.asString,
+                                ruleName.asString,
+                                rule.action.asString,
+                                InfoLevel,
 
 Review comment:
   Yes. But here are some caveats. We can?t use the trigger activation result 
because it?s already used. It records the triggers incoming payload. 
   
   There are multiple results, one for each action that?s activated. 
   
   I do think we can use the activation response schema to record the result of 
its action that?s activated. And store these in an array. The question is do we 
log these as log lines as in the current form, use annotations or use a single 
log line that is formatted as a json string.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to