This is an automated email from the ASF dual-hosted git repository. dubeejw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new 495a006 Shorten parameters for entity fetching utils (#3594) 495a006 is described below commit 495a00626f90895a6fa53291545d72895943e7f2 Author: James Dubee <jwdu...@us.ibm.com> AuthorDate: Wed May 2 17:12:19 2018 -0400 Shorten parameters for entity fetching utils (#3594) * Shorten parameters for entity fetching utils --- .../main/scala/whisk/core/controller/Actions.scala | 12 +++++----- .../scala/whisk/core/controller/Activations.scala | 12 +++------- .../scala/whisk/core/controller/ApiUtils.scala | 28 +++++++--------------- .../scala/whisk/core/controller/Packages.scala | 4 ++-- .../main/scala/whisk/core/controller/Rules.scala | 6 ++--- .../scala/whisk/core/controller/Triggers.scala | 4 ++-- 6 files changed, 24 insertions(+), 42 deletions(-) diff --git a/core/controller/src/main/scala/whisk/core/controller/Actions.scala b/core/controller/src/main/scala/whisk/core/controller/Actions.scala index 1fb47c0..fd5f943 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Actions.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Actions.scala @@ -141,7 +141,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with val right = collection.determineRight(m, Some(innername)) onComplete(entitlementProvider.check(user, right, packageResource)) { case Success(_) => - getEntity(WhiskPackage, entityStore, packageDocId, Some { + getEntity(WhiskPackage.get(entityStore, packageDocId), Some { if (right == Privilege.READ || right == Privilege.ACTIVATE) { // need to merge package with action, hence authorize subject for package // access (if binding, then subject must be authorized for both the binding @@ -219,7 +219,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with 'result ? false, 'timeout.as[FiniteDuration] ? WhiskActionsApi.maxWaitForBlockingActivation) { (blocking, result, waitOverride) => entity(as[Option[JsObject]]) { payload => - getEntity(WhiskActionMetaData, entityStore, entityName.toDocId, Some { + getEntity(WhiskActionMetaData.get(entityStore, entityName.toDocId), Some { act: WhiskActionMetaData => // resolve the action --- special case for sequences that may contain components with '_' as default package val action = act.resolve(user.namespace) @@ -314,14 +314,14 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with parameter('code ? true) { code => code match { case true => - getEntity(WhiskAction, entityStore, entityName.toDocId, Some { action: WhiskAction => + getEntity(WhiskAction.get(entityStore, entityName.toDocId), Some { action: WhiskAction => val mergedAction = env map { action inherit _ } getOrElse action complete(OK, mergedAction) }) case false => - getEntity(WhiskActionMetaData, entityStore, entityName.toDocId, Some { action: WhiskActionMetaData => + getEntity(WhiskActionMetaData.get(entityStore, entityName.toDocId), Some { action: WhiskActionMetaData => val mergedAction = env map { action inherit _ } getOrElse action @@ -534,7 +534,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with // and should hit the cache to ameliorate the cost; this can be improved // but requires communicating back from the authorization service the // resolved namespace - getEntity(WhiskPackage, entityStore, pkgName.toDocId, Some { (wp: WhiskPackage) => + getEntity(WhiskPackage.get(entityStore, pkgName.toDocId), Some { (wp: WhiskPackage) => val pkgns = wp.binding map { b => logging.debug(this, s"list actions in package binding '${wp.name}' -> '$b'") b.namespace.addPath(b.name) @@ -564,7 +564,7 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with logging.debug(this, s"fetching package '$docid' for reference") // already checked that subject is authorized for package and binding; // this fetch is redundant but should hit the cache to ameliorate cost - getEntity(WhiskPackage, entityStore, docid, Some { + getEntity(WhiskPackage.get(entityStore, docid), Some { mergeActionWithPackageAndDispatch(method, user, action, Some { wp }) _ }) } getOrElse { diff --git a/core/controller/src/main/scala/whisk/core/controller/Activations.scala b/core/controller/src/main/scala/whisk/core/controller/Activations.scala index 3c57d0d..ff31e4f 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Activations.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Activations.scala @@ -207,9 +207,7 @@ trait WhiskActivationsApi extends Directives with AuthenticatedRouteProvider wit val docid = DocId(WhiskEntity.qualifiedName(namespace, activationId)) pathEndOrSingleSlash { getEntity( - WhiskActivation, - activationStore, - docid, + WhiskActivation.get(activationStore, docid), postProcess = Some((activation: WhiskActivation) => complete(activation.toExtendedJson))) } ~ (pathPrefix(resultPath) & pathEnd) { fetchResponse(docid) } ~ @@ -226,9 +224,7 @@ trait WhiskActivationsApi extends Directives with AuthenticatedRouteProvider wit */ private def fetchResponse(docid: DocId)(implicit transid: TransactionId) = { getEntityAndProject( - WhiskActivation, - activationStore, - docid, + WhiskActivation.get(activationStore, docid), (activation: WhiskActivation) => Future.successful(activation.response.toExtendedJson)) } @@ -243,9 +239,7 @@ trait WhiskActivationsApi extends Directives with AuthenticatedRouteProvider wit private def fetchLogs(user: Identity, docid: DocId)(implicit transid: TransactionId) = { extractRequest { request => getEntityAndProject( - WhiskActivation, - activationStore, - docid, + WhiskActivation.get(activationStore, docid), (activation: WhiskActivation) => logStore.fetchLogs(user, activation, request).map(_.toJsonObject)) } } diff --git a/core/controller/src/main/scala/whisk/core/controller/ApiUtils.scala b/core/controller/src/main/scala/whisk/core/controller/ApiUtils.scala index ed52693..87e6576 100644 --- a/core/controller/src/main/scala/whisk/core/controller/ApiUtils.scala +++ b/core/controller/src/main/scala/whisk/core/controller/ApiUtils.scala @@ -27,9 +27,7 @@ import akka.http.scaladsl.model.StatusCodes.Conflict import akka.http.scaladsl.model.StatusCodes.InternalServerError import akka.http.scaladsl.model.StatusCodes.NotFound import akka.http.scaladsl.model.StatusCodes.OK -import akka.http.scaladsl.server.Directives -import akka.http.scaladsl.server.RequestContext -import akka.http.scaladsl.server.RouteResult +import akka.http.scaladsl.server.{Directives, RequestContext, RouteResult} import spray.json.DefaultJsonProtocol._ import spray.json.JsObject import spray.json.JsValue @@ -124,11 +122,9 @@ trait ReadOps extends Directives { } /** - * Gets an entity of type A from datastore. Terminates HTTP request. + * Waits on specified Future that returns an entity of type A from datastore. Terminates HTTP request. * - * @param factory the factory that can fetch entity of type A from datastore - * @param datastore the client to the database - * @param docid the document id to get + * @param entity future that returns an entity of type A fetched from datastore * @param postProcess an optional continuation to post process the result of the * get and terminate the HTTP request directly * @@ -137,14 +133,12 @@ trait ReadOps extends Directives { * - 404 Not Found * - 500 Internal Server Error */ - protected def getEntity[A <: DocumentRevisionProvider, Au >: A](factory: DocumentFactory[A], - datastore: ArtifactStore[Au], - docid: DocId, + protected def getEntity[A <: DocumentRevisionProvider, Au >: A](entity: Future[A], postProcess: Option[PostProcessEntity[A]] = None)( implicit transid: TransactionId, format: RootJsonFormat[A], ma: Manifest[A]) = { - onComplete(factory.get(datastore, docid)) { + onComplete(entity) { case Success(entity) => logging.debug(this, s"[GET] entity success") postProcess map { _(entity) } getOrElse complete(OK, entity) @@ -164,11 +158,9 @@ trait ReadOps extends Directives { } /** - * Gets an entity of type A from datastore and project fields for response. Terminates HTTP request. + * Waits on specified Future that returns an entity of type A from datastore. Terminates HTTP request. * - * @param factory the factory that can fetch entity of type A from datastore - * @param datastore the client to the database - * @param docid the document id to get + * @param entity future that returns an entity of type A fetched from datastore * @param project a function A => JSON which projects fields form A * * Responses are one of (Code, Message) @@ -177,11 +169,9 @@ trait ReadOps extends Directives { * - 500 Internal Server Error */ protected def getEntityAndProject[A <: DocumentRevisionProvider, Au >: A]( - factory: DocumentFactory[A], - datastore: ArtifactStore[Au], - docid: DocId, + entity: Future[A], project: A => Future[JsObject])(implicit transid: TransactionId, format: RootJsonFormat[A], ma: Manifest[A]) = { - onComplete(factory.get(datastore, docid)) { + onComplete(entity) { case Success(entity) => logging.debug(this, s"[PROJECT] entity success") diff --git a/core/controller/src/main/scala/whisk/core/controller/Packages.scala b/core/controller/src/main/scala/whisk/core/controller/Packages.scala index ef52f27..77000a8 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Packages.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Packages.scala @@ -157,7 +157,7 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities { */ override def fetch(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])( implicit transid: TransactionId) = { - getEntity(WhiskPackage, entityStore, entityName.toDocId, Some { mergePackageWithBinding() _ }) + getEntity(WhiskPackage.get(entityStore, entityName.toDocId), Some { mergePackageWithBinding() _ }) } /** @@ -297,7 +297,7 @@ trait WhiskPackagesApi extends WhiskCollectionAPI with ReferencedEntities { case b: Binding => val docid = b.fullyQualifiedName.toDocId logging.debug(this, s"fetching package '$docid' for reference") - getEntity(WhiskPackage, entityStore, docid, Some { + getEntity(WhiskPackage.get(entityStore, docid), Some { mergePackageWithBinding(Some { wp }) _ }) } getOrElse { diff --git a/core/controller/src/main/scala/whisk/core/controller/Rules.scala b/core/controller/src/main/scala/whisk/core/controller/Rules.scala index 0e88616..dc511be 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Rules.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Rules.scala @@ -134,7 +134,7 @@ trait WhiskRulesApi extends WhiskCollectionAPI with ReferencedEntities { extractStatusRequest { requestedState => val docid = entityName.toDocId - getEntity(WhiskRule, entityStore, docid, Some { + getEntity(WhiskRule.get(entityStore, docid), Some { rule: WhiskRule => val ruleName = rule.fullyQualifiedName(false) @@ -230,9 +230,7 @@ trait WhiskRulesApi extends WhiskCollectionAPI with ReferencedEntities { override def fetch(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])( implicit transid: TransactionId) = { getEntity( - WhiskRule, - entityStore, - entityName.toDocId, + WhiskRule.get(entityStore, entityName.toDocId), Some { rule: WhiskRule => val getRuleWithStatus = getTrigger(rule.trigger) map { trigger => getStatus(trigger, entityName) diff --git a/core/controller/src/main/scala/whisk/core/controller/Triggers.scala b/core/controller/src/main/scala/whisk/core/controller/Triggers.scala index 93dd988..8bf2de7 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Triggers.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Triggers.scala @@ -133,7 +133,7 @@ trait WhiskTriggersApi extends WhiskCollectionAPI { override def activate(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])( implicit transid: TransactionId) = { entity(as[Option[JsObject]]) { payload => - getEntity(WhiskTrigger, entityStore, entityName.toDocId, Some { + getEntity(WhiskTrigger.get(entityStore, entityName.toDocId), Some { trigger: WhiskTrigger => val triggerActivationId = activationIdFactory.make() logging.info(this, s"[POST] trigger activation id: ${triggerActivationId}") @@ -214,7 +214,7 @@ trait WhiskTriggersApi extends WhiskCollectionAPI { */ override def fetch(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])( implicit transid: TransactionId) = { - getEntity(WhiskTrigger, entityStore, entityName.toDocId, Some { trigger => + getEntity(WhiskTrigger.get(entityStore, entityName.toDocId), Some { trigger => completeAsTriggerResponse(trigger) }) } -- To stop receiving notification emails like this one, please contact dube...@apache.org.