mdeuser commented on a change in pull request #3187: reduce rule activation
records
URL:
https://github.com/apache/incubator-openwhisk/pull/3187#discussion_r162055199
##########
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:
with this pr, only two kinds of activation records will be created - one for
the trigger and one for each associated action. the rule activation will no
longer be created. the trigger activation log entries shown above are meant to
assist in tracking down the action results that were generated in response to
the trigger event.
----------------------------------------------------------------
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