Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 07EB6200D55 for ; Sat, 9 Dec 2017 23:40:15 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 066B4160C0E; Sat, 9 Dec 2017 22:40:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2562B160BFE for ; Sat, 9 Dec 2017 23:40:13 +0100 (CET) Received: (qmail 72720 invoked by uid 500); 9 Dec 2017 22:40:13 -0000 Mailing-List: contact commits-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list commits@openwhisk.apache.org Received: (qmail 72711 invoked by uid 99); 9 Dec 2017 22:40:13 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Dec 2017 22:40:13 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id ACE0F80F94; Sat, 9 Dec 2017 22:40:11 +0000 (UTC) Date: Sat, 09 Dec 2017 22:40:11 +0000 To: "commits@openwhisk.apache.org" Subject: [incubator-openwhisk] branch master updated: Optionally fetch code when getting an action (#2908) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <151285921099.5023.162245096566467741@gitbox.apache.org> From: csantanapr@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-openwhisk X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 02626d7bb2dd4b10959d059c32af0302c5a5d639 X-Git-Newrev: 7bb04c554d5612ce5c7435e375bcdfe3262de039 X-Git-Rev: 7bb04c554d5612ce5c7435e375bcdfe3262de039 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Sat, 09 Dec 2017 22:40:15 -0000 This is an automated email from the ASF dual-hosted git repository. csantanapr 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 7bb04c5 Optionally fetch code when getting an action (#2908) 7bb04c5 is described below commit 7bb04c554d5612ce5c7435e375bcdfe3262de039 Author: James Dubee AuthorDate: Sat Dec 9 17:40:08 2017 -0500 Optionally fetch code when getting an action (#2908) --- .../src/main/scala/whisk/core/entity/Exec.scala | 27 +--------------------- .../src/main/resources/apiv1swagger.json | 7 ++++++ .../main/scala/whisk/core/controller/Actions.scala | 22 ++++++++++++++---- .../core/controller/test/ActionsApiTests.scala | 23 ++++++++++++++++++ 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/entity/Exec.scala b/common/scala/src/main/scala/whisk/core/entity/Exec.scala index 3ea1ec5..268fdbe 100644 --- a/common/scala/src/main/scala/whisk/core/entity/Exec.scala +++ b/common/scala/src/main/scala/whisk/core/entity/Exec.scala @@ -384,13 +384,7 @@ protected[core] object ExecMetaDataBase extends ArgNormalizer[ExecMetaDataBase] throw new DeserializationException( s"'image' must be a string defined in 'exec' for '${Exec.BLACKBOX}' actions") } - val code: Option[String] = obj.fields.get("code") match { - case Some(JsString(i)) => if (i.trim.nonEmpty) Some(i) else None - case Some(_) => - throw new DeserializationException( - s"if defined, 'code' must a string defined in 'exec' for '${Exec.BLACKBOX}' actions") - case None => None - } + val native = execManifests.blackboxImages.contains(image) BlackBoxExecMetaData(native) @@ -403,28 +397,9 @@ protected[core] object ExecMetaDataBase extends ArgNormalizer[ExecMetaDataBase] manifest.attached .map { a => - val jar: Attachment[String] = { - // java actions once stored the attachment in "jar" instead of "code" - obj.fields.get("code").orElse(obj.fields.get("jar")) - } map { - attFmt[String].read(_) - } getOrElse { - throw new DeserializationException( - s"'code' must be a valid base64 string in 'exec' for '$kind' actions") - } - val main = optMainField.orElse { - if (manifest.requireMain.exists(identity)) { - throw new DeserializationException(s"'main' must be a string defined in 'exec' for '$kind' actions") - } else None - } CodeExecMetaDataAsAttachment(manifest) } .getOrElse { - val code: String = obj.fields.get("code") match { - case Some(JsString(c)) => c - case _ => - throw new DeserializationException(s"'code' must be a string defined in 'exec' for '$kind' actions") - } CodeExecMetaDataAsString(manifest) } } diff --git a/core/controller/src/main/resources/apiv1swagger.json b/core/controller/src/main/resources/apiv1swagger.json index 2d32b7a..86e9460 100644 --- a/core/controller/src/main/resources/apiv1swagger.json +++ b/core/controller/src/main/resources/apiv1swagger.json @@ -203,6 +203,13 @@ "description": "Name of action to fetch", "required": true, "type": "string" + }, + { + "name": "code", + "in": "query", + "description": "Include action code in the result", + "required": false, + "type": "boolean" } ], "produces": [ 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 fcdea99..97489bf 100644 --- a/core/controller/src/main/scala/whisk/core/controller/Actions.scala +++ b/core/controller/src/main/scala/whisk/core/controller/Actions.scala @@ -294,10 +294,24 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with */ override def fetch(user: Identity, entityName: FullyQualifiedEntityName, env: Option[Parameters])( implicit transid: TransactionId) = { - getEntity(WhiskAction, entityStore, entityName.toDocId, Some { action: WhiskAction => - val mergedAction = env map { action inherit _ } getOrElse action - complete(OK, mergedAction) - }) + parameter('code ? true) { code => + code match { + case true => + getEntity(WhiskAction, 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 => + val mergedAction = env map { + action inherit _ + } getOrElse action + complete(OK, mergedAction) + }) + } + } } /** diff --git a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala index c841545..3696063 100644 --- a/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala +++ b/tests/src/test/scala/whisk/core/controller/test/ActionsApiTests.scala @@ -159,6 +159,29 @@ class ActionsApiTests extends ControllerTestCommon with WhiskActionsApi { } } + it should "get action using code query parameter" in { + implicit val tid = transid() + val action = WhiskAction(namespace, aname(), jsDefault("??"), Parameters("x", "b")) + + put(entityStore, action) + + Get(s"$collectionPath/${action.name}?code=false") ~> Route.seal(routes(creds)) ~> check { + status should be(OK) + val response = responseAs[JsObject] + response.fields("exec").asJsObject.fields should not(contain key "code") + responseAs[WhiskActionMetaData] shouldBe a[WhiskActionMetaData] + } + + Seq(s"$collectionPath/${action.name}", s"$collectionPath/${action.name}?code=true").foreach { path => + Get(path) ~> Route.seal(routes(creds)) ~> check { + status should be(OK) + val response = responseAs[JsObject] + response.fields("exec").asJsObject.fields("code") should be("??".toJson) + responseAs[WhiskAction] shouldBe a[WhiskAction] + } + } + } + it should "report NotFound for get non existent action" in { implicit val tid = transid() Get(s"$collectionPath/xyz") ~> Route.seal(routes(creds)) ~> check { -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" '].