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/01 03:00:09 UTC

[GitHub] rabbah commented on a change in pull request #3202: Support action continuations in the controller

rabbah commented on a change in pull request #3202: Support action continuations in the controller
URL: https://github.com/apache/incubator-openwhisk/pull/3202#discussion_r165244447
 
 

 ##########
 File path: core/controller/src/main/scala/whisk/core/controller/actions/PrimitiveActions.scala
 ##########
 @@ -139,6 +199,356 @@ protected[actions] trait PrimitiveActions {
     }
   }
 
+  /**
+   * Mutable cumulative accounting of what happened during the execution of a composition.
+   *
+   * Compositions are aborted if the number of action invocations exceeds a limit.
+   * The permitted max is n component invocations plus 2n+1 conductor invocations (where n is the actionSequenceLimit).
+   * The max is chosen to permit a sequence with up to n primitive actions.
+   *
+   * NOTE:
+   * A sequence invocation counts as one invocation irrespective of the number of action invocations in the sequence.
+   * If one component of a composition is also a composition, the caller and callee share the same accounting object.
+   * The counts are shared between callers and callees so the limit applies globally.
+   *
+   * @param components the current count of component actions already invoked
+   * @param conductors the current count of conductor actions already invoked
+   */
+  private case class CompositionAccounting(var components: Int = 0, var conductors: Int = 0)
+
+  /**
+   * A mutable session object to keep track of the execution of one composition.
+   *
+   * NOTE:
+   * The session object is not shared between callers and callees.
+   * A callee has a reference to the session object for the caller.
+   * This permits the callee to return to the caller when done.
+   *
+   * @param activationId the activationId for the composition (ie the activation record for the composition)
+   * @param start the start time for the composition
+   * @param action the conductor action responsible for the execution of the composition
+   * @param cause the cause of the composition (activationId of the enclosing sequence or composition if any)
+   * @param duration the "user" time so far executing the composition (sum of durations for
+   *        all actions invoked so far which is different from the total time spent executing the composition)
+   * @param maxMemory the maximum memory annotation observed so far for the conductor action and components
+   * @param state the json state object to inject in the parameter object of the next conductor invocation
+   * @param accounting the global accounting object used to abort compositions requiring too many action invocations
+   * @param logs a mutable buffer that is appended with new activation ids as the composition unfolds
+   *             (in contrast with sequences, the logs of a hierarchy of compositions is not flattened)
+   * @param caller the session object for the parent composition (caller) if any
+   * @param result a placeholder for returning the result of the composition invocation (blocking invocation only)
+   */
+  private case class Session(activationId: ActivationId,
+                             start: Instant,
+                             action: ExecutableWhiskActionMetaData,
+                             cause: Option[ActivationId],
+                             var duration: Long,
+                             var maxMemory: Int,
+                             var state: Option[JsObject],
+                             accounting: CompositionAccounting,
+                             logs: Buffer[ActivationId],
+                             caller: Option[Session],
+                             result: Option[Promise[Either[ActivationId, WhiskActivation]]])
+
+  /**
+   * A method that knows how to invoke a composition.
+   *
+   * The method instantiates the session object for the composition, invokes the conductor action for the composition,
+   * and waits for the composition result (resulting activation) if the invocation is blocking (up to timeout).
+   *
+   * @param user the identity invoking the action
+   * @param action the conductor action to invoke for the composition
+   * @param payload the dynamic arguments for the activation
+   * @param waitForResponse if not empty, wait upto specified duration for a response (this is used for blocking activations)
+   * @param cause the activation id that is responsible for this invoke/activation
+   * @param caller the session object for the caller if any
+   * @param transid a transaction id for logging
+   * @return a promise that completes with one of the following successful cases:
+   *            Right(WhiskActivation) if waiting for a response and response is ready within allowed duration,
+   *            Left(ActivationId) if not waiting for a response, or allowed duration has elapsed without a result ready
+   *         or an error
+   */
+  private def invokeComposition(
+    user: Identity,
+    action: ExecutableWhiskActionMetaData,
+    payload: Option[JsObject],
+    waitForResponse: Option[FiniteDuration],
+    cause: Option[ActivationId],
+    caller: Option[Session] = None)(implicit transid: TransactionId): Future[Either[ActivationId, WhiskActivation]] = {
+
+    val session = Session(
+      activationId = activationIdFactory.make(),
+      start = Instant.now(Clock.systemUTC()),
+      action,
+      cause,
+      duration = 0,
+      maxMemory = action.limits.memory.megabytes,
+      state = None,
+      accounting = caller.map { _.accounting }.getOrElse(CompositionAccounting()), // share accounting with caller
+      logs = Buffer.empty,
+      caller,
+      result = waitForResponse.map { _ =>
+        Promise[Either[ActivationId, WhiskActivation]]() // placeholder for result if blocking invoke
+      })
+
+    invokeConductor(user, payload, session)
+
+    // is caller waiting for the result of the activation?
+    waitForResponse
+      .map { timeout =>
+        // handle timeout
+        session.result.head.future
 
 Review comment:
   why .head not .get on an option?
   perhaps a comment that this is safe since if waitForResponse is defined, so the the session.result.

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