csantanapr closed pull request #176: Only fetch action code when saving or
copying an action
URL: https://github.com/apache/incubator-openwhisk-cli/pull/176
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/build.gradle b/build.gradle
index 29bedf25..c0716735 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,7 +24,7 @@ dependencies {
build(['name':'golang.org/x/sys/unix',
'version':'7f918dd405547ecb864d14a8ecbbfe205b5f930f', 'transitive':false])
build(['name':'gopkg.in/yaml.v2',
'version':'cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b', 'transitive':false])
build(['name':'github.com/ghodss/yaml',
'version':'0ca9ea5df5451ffdf184b4428c902747c2c11cd7', 'transitive':false])
-
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'a0864455f7c18db70d93d4dd2bc0b43d2334ed90','transitive':false])
+
build(['name':'github.com/apache/incubator-openwhisk-client-go/whisk','version':'72bf7128873a77d9973af0018a5ffad940b4691e','transitive':false])
// END - Imported from Godeps
test name:'github.com/stretchr/testify',
version:'b91bfb9ebec76498946beb6af7c0230c7cc7ba6c', transitive:false //, tag:
'v1.2.0'
test name:'github.com/spf13/viper',
version:'aafc9e6bc7b7bb53ddaa75a5ef49a17d6e654be5', transitive:false
diff --git a/commands/action.go b/commands/action.go
index 4d3be58f..f834a9ff 100644
--- a/commands/action.go
+++ b/commands/action.go
@@ -35,27 +35,29 @@ import (
)
const (
- MEMORY_LIMIT = 256
- TIMEOUT_LIMIT = 60000
- LOGSIZE_LIMIT = 10
- ACTIVATION_ID = "activationId"
- WEB_EXPORT_ANNOT = "web-export"
- RAW_HTTP_ANNOT = "raw-http"
- FINAL_ANNOT = "final"
- NODE_JS_EXT = ".js"
- PYTHON_EXT = ".py"
- JAVA_EXT = ".jar"
- SWIFT_EXT = ".swift"
- ZIP_EXT = ".zip"
- PHP_EXT = ".php"
- NODE_JS = "nodejs"
- PYTHON = "python"
- JAVA = "java"
- SWIFT = "swift"
- PHP = "php"
- DEFAULT = "default"
- BLACKBOX = "blackbox"
- SEQUENCE = "sequence"
+ MEMORY_LIMIT = 256
+ TIMEOUT_LIMIT = 60000
+ LOGSIZE_LIMIT = 10
+ ACTIVATION_ID = "activationId"
+ WEB_EXPORT_ANNOT = "web-export"
+ RAW_HTTP_ANNOT = "raw-http"
+ FINAL_ANNOT = "final"
+ NODE_JS_EXT = ".js"
+ PYTHON_EXT = ".py"
+ JAVA_EXT = ".jar"
+ SWIFT_EXT = ".swift"
+ ZIP_EXT = ".zip"
+ PHP_EXT = ".php"
+ NODE_JS = "nodejs"
+ PYTHON = "python"
+ JAVA = "java"
+ SWIFT = "swift"
+ PHP = "php"
+ DEFAULT = "default"
+ BLACKBOX = "blackbox"
+ SEQUENCE = "sequence"
+ FETCH_CODE = true
+ DO_NOT_FETCH_CODE = false
)
var actionCmd = &cobra.Command{
@@ -224,6 +226,7 @@ var actionGetCmd = &cobra.Command{
var field string
var action *whisk.Action
var qualifiedName = new(QualifiedName)
+ var fetchCode bool
if whiskErr := CheckArgs(args, 1, 2, "Action get",
wski18n.T("An action name is required.")); whiskErr != nil {
return whiskErr
@@ -242,9 +245,10 @@ var actionGetCmd = &cobra.Command{
}
Client.Namespace = qualifiedName.GetNamespace()
+ fetchCode = cmd.LocalFlags().Changed(SAVE_AS_FLAG) ||
cmd.LocalFlags().Changed(SAVE_FLAG)
- if action, _, err =
Client.Actions.Get(qualifiedName.GetEntityName()); err != nil {
- return actionGetError(qualifiedName.GetEntityName(),
err)
+ if action, _, err =
Client.Actions.Get(qualifiedName.GetEntityName(), fetchCode); err != nil {
+ return actionGetError(qualifiedName.GetEntityName(),
fetchCode, err)
}
if Flags.action.url {
@@ -413,8 +417,8 @@ func parseAction(cmd *cobra.Command, args []string, update
bool) (*whisk.Action,
Client.Namespace = copiedQualifiedName.GetNamespace()
- if existingAction, _, err =
Client.Actions.Get(copiedQualifiedName.GetEntityName()); err != nil {
- return nil,
actionGetError(copiedQualifiedName.GetEntityName(), err)
+ if existingAction, _, err =
Client.Actions.Get(copiedQualifiedName.GetEntityName(), FETCH_CODE); err != nil
{
+ return nil,
actionGetError(copiedQualifiedName.GetEntityName(), FETCH_CODE, err)
}
Client.Namespace = qualifiedName.GetNamespace()
@@ -628,11 +632,11 @@ func webActionAnnotations(
var err error
if preserveAnnotations {
- if action, _, err = Client.Actions.Get(entityName); err != nil {
+ if action, _, err = Client.Actions.Get(entityName,
DO_NOT_FETCH_CODE); err != nil {
whiskErr, isWhiskError := err.(*whisk.WskError)
if (isWhiskError && whiskErr.ExitCode !=
whisk.EXIT_CODE_NOT_FOUND) || !isWhiskError {
- return nil, actionGetError(entityName, err)
+ return nil, actionGetError(entityName,
DO_NOT_FETCH_CODE, err)
}
} else {
annotations =
whisk.KeyValueArr.AppendKeyValueArr(annotations, action.Annotations)
@@ -792,8 +796,8 @@ func actionDeleteError(entityName string, err error) error {
return nestedError(errMsg, err)
}
-func actionGetError(entityName string, err error) error {
- whisk.Debug(whisk.DbgError, "Client.Actions.Get(%s) error: %s\n",
entityName, err)
+func actionGetError(entityName string, fetchCode bool, err error) error {
+ whisk.Debug(whisk.DbgError, "Client.Actions.Get(%s, %t) error: %s\n",
entityName, fetchCode, err)
errMsg := wski18n.T(
"Unable to get action '{{.name}}': {{.err}}",
@@ -1016,10 +1020,10 @@ func isWebAction(client *whisk.Client, qname
QualifiedName) error {
client.Namespace = qname.GetNamespace()
fullActionName := "/" + qname.GetNamespace() + "/" +
qname.GetEntityName()
- action, _, err := client.Actions.Get(qname.GetEntityName())
+ action, _, err := client.Actions.Get(qname.GetEntityName(),
DO_NOT_FETCH_CODE)
if err != nil {
- whisk.Debug(whisk.DbgError, "client.Actions.Get(%s) error:
%s\n", fullActionName, err)
+ whisk.Debug(whisk.DbgError, "client.Actions.Get(%s, %t) error:
%s\n", fullActionName, DO_NOT_FETCH_CODE, err)
whisk.Debug(whisk.DbgError, "Unable to obtain action '%s' for
web action validation\n", fullActionName)
errMsg := wski18n.T("Unable to get action '{{.name}}':
{{.err}}",
map[string]interface{}{"name": fullActionName, "err":
err})
diff --git a/tests/src/test/scala/system/basic/WskActionTests.scala
b/tests/src/test/scala/system/basic/WskActionTests.scala
index 3fa080d9..f825e333 100644
--- a/tests/src/test/scala/system/basic/WskActionTests.scala
+++ b/tests/src/test/scala/system/basic/WskActionTests.scala
@@ -230,8 +230,6 @@ abstract class WskActionTests extends TestHelpers with
WskTestHelpers with JsHel
assetHelper.withCleaner(wsk.action, name) { (action, _) =>
action.create(name, Some(TestCLIUtils.getTestActionFilename("empty.js")))
}
- val rr = wsk.action.get(name)
- wsk.parseJsonString(rr.stdout).getFieldPath("exec", "code") shouldBe
Some(JsString(""))
}
it should "blocking invoke of nested blocking actions" in
withAssetCleaner(wskprops) { (wp, assetHelper) =>
diff --git a/tests/src/test/scala/system/basic/WskBasicTests.scala
b/tests/src/test/scala/system/basic/WskBasicTests.scala
index c78d7f17..bfcdcf5d 100644
--- a/tests/src/test/scala/system/basic/WskBasicTests.scala
+++ b/tests/src/test/scala/system/basic/WskBasicTests.scala
@@ -313,7 +313,7 @@ class WskBasicTests extends TestHelpers with WskTestHelpers
{
wsk.action.get(name, fieldFilter = Some("exec")).stdout should
include(s"""$successMsg""")
wsk.action
.get(name, fieldFilter = Some("exec"))
- .stdout should include regex (s"""$successMsg
exec\n\\{\\s+"kind":\\s+"nodejs:6",\\s+"code":\\s+"\\/\\*\\*[\\\\r]*\\\\n \\*
Hello, world.[\\\\r]*\\\\n \\*\\/[\\\\r]*\\\\nfunction main\\(params\\)
\\{[\\\\r]*\\\\n greeting \\= 'hello, ' \\+ params.payload \\+
'!'[\\\\r]*\\\\n console.log\\(greeting\\);[\\\\r]*\\\\n return
\\{payload: greeting\\}[\\\\r]*\\\\n\\}""")
+ .stdout should include regex (s"""$successMsg
exec\n\\{\\s+"kind":\\s+"nodejs:6",\\s+"binary":\\s+false\\s+\\}""")
wsk.action
.get(name, fieldFilter = Some("parameters"))
.stdout should include regex (s"""$successMsg
parameters\n\\[\\s+\\{\\s+"key":\\s+"payload",\\s+"value":\\s+"test"\\s+\\}\\s+\\]""")
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services