override def activate()

in core/controller/src/main/scala/org/apache/openwhisk/core/controller/Triggers.scala [128:191]


  override def activate(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])(
    implicit transid: TransactionId) = {
    extractRequest { request =>
      val context = UserContext(user, request)

      entity(as[Option[JsObject]]) { payload =>
        getEntity(WhiskTrigger.get(entityStore, entityName.toDocId), Some {
          trigger: WhiskTrigger =>
            // List of active rules associated with the trigger
            val activeRules: Map[FullyQualifiedEntityName, ReducedRule] =
              trigger.rules.map(_.filter(_._2.status == Status.ACTIVE)).getOrElse(Map.empty)

            if (activeRules.nonEmpty) {
              val triggerActivationId = activationIdFactory.make()
              logging.info(this, s"[POST] trigger activation id: ${triggerActivationId}")
              val triggerActivation = WhiskActivation(
                namespace = user.namespace.name.toPath, // all activations should end up in the one space regardless trigger.namespace
                entityName.name,
                user.subject,
                triggerActivationId,
                Instant.now(Clock.systemUTC()),
                Instant.EPOCH,
                response = ActivationResponse.success(payload orElse Some(JsObject.empty)),
                version = trigger.version,
                duration = None)
              val headers = JsObject(
                Map(new WebApiDirectives().headers -> request.headers
                  .collect {
                    case h if h.name != `Timeout-Access`.name => h.lowercaseName -> h.value
                  }
                  .toMap
                  .toJson))

              val mergedPayload = Some {
                (headers.fields ++ (payload getOrElse JsObject.empty).fields).toJson.asJsObject
              }

              val args: JsObject = trigger.parameters.merge(mergedPayload).getOrElse(JsObject.empty)

              activateRules(user, args, trigger.rules.getOrElse(Map.empty))
                .map(results => triggerActivation.withLogs(ActivationLogs(results.map(_.toJson.compactPrint).toVector)))
                .recover {
                  case e =>
                    logging.error(this, s"Failed to write action activation results to trigger activation: $e")
                    triggerActivation
                }
                .map { activation =>
                  activationStore.storeAfterCheck(activation, false, None, None, context)
                }

              respondWithActivationIdHeader(triggerActivationId) {
                complete(Accepted, triggerActivationId.toJsObject)
              }
            } else {
              logging
                .debug(
                  this,
                  s"[POST] trigger without an active rule was activated; no trigger activation record created for $entityName")
              complete(NoContent)
            }
        })
      }
    }
  }