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/05/02 21:12:21 UTC
[GitHub] dubee closed pull request #3594: Shorten parameters for entity
fetching utils
dubee closed pull request #3594: Shorten parameters for entity fetching utils
URL: https://github.com/apache/incubator-openwhisk/pull/3594
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 1fb47c02ff..fd5f94340d 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 3c57d0d480..ff31e4fbf2 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 ed52693688..87e65763b3 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 ef52f274fc..77000a859f 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 0e886165b1..dc511be672 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 93dd98836b..8bf2de740f 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)
})
}
----------------------------------------------------------------
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