You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dg...@apache.org on 2022/08/15 13:40:53 UTC
[openwhisk-runtime-docker] branch master updated: Support array result include sequence action (#92)
This is an automated email from the ASF dual-hosted git repository.
dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-docker.git
The following commit(s) were added to refs/heads/master by this push:
new 2c8df9b Support array result include sequence action (#92)
2c8df9b is described below
commit 2c8df9bec039229609d5381862974a959cad4814
Author: ningyougang <41...@qq.com>
AuthorDate: Mon Aug 15 21:40:48 2022 +0800
Support array result include sequence action (#92)
---
README.md | 15 ++++++++++
core/actionProxy/actionproxy.py | 8 ++---
.../ActionProxyContainerTests.scala | 35 +++++++++++++++++++++-
3 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 20e97b2..c0406b2 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,21 @@ echo \
'#!/bin/bash
echo "{\"message\":\"Hello World\"}"' > exec
```
+
+For the return result, not only support `dictionary` but also support `array`
+```
+echo \
+'#!/bin/bash
+echo '["a", "b"]'' > exec
+```
+
+And support array result for sequence action as well, the first action's array result can be used as next action's input parameter
+```
+echo \
+'#!/bin/bash
+echo $1' > exec
+```
+
```
chmod +x exec
zip myAction.zip exec
diff --git a/core/actionProxy/actionproxy.py b/core/actionProxy/actionproxy.py
index 1812918..d174ce0 100644
--- a/core/actionProxy/actionproxy.py
+++ b/core/actionProxy/actionproxy.py
@@ -135,7 +135,7 @@ class ActionRunner:
def error(msg):
# fall through (exception and else case are handled the same way)
sys.stdout.write('%s\n' % msg)
- return (502, {'error': 'The action did not return a dictionary.'})
+ return (502, {'error': 'The action did not return a dictionary or array.'})
try:
input = json.dumps(args)
@@ -186,7 +186,7 @@ class ActionRunner:
try:
json_output = json.loads(lastLine)
- if isinstance(json_output, dict):
+ if isinstance(json_output, dict) or isinstance(json_output, list):
return (200, json_output)
else:
return error(lastLine)
@@ -258,7 +258,7 @@ def init(message=None):
def run(message=None):
def error():
- response = flask.jsonify({'error': 'The action did not receive a dictionary as an argument.'})
+ response = flask.jsonify({'error': 'The action did not receive a dictionary or array as an argument.'})
response.status_code = 404
return complete(response)
@@ -269,7 +269,7 @@ def run(message=None):
return error()
else:
args = message.get('value', {}) if message else {}
- if not isinstance(args, dict):
+ if not (isinstance(args, dict) or isinstance(args, list)):
return error()
if runner.verify():
diff --git a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
index acf83b9..97e6227 100644
--- a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
@@ -227,7 +227,7 @@ class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSyst
initCode should be(200)
val (runCode, out) = c.run(JsNull)
runCode should be(502)
- out should be(Some(JsObject("error" -> JsString("The action did not return a dictionary."))))
+ out should be(Some(JsObject("error" -> JsString("The action did not return a dictionary or array."))))
}
checkStreams(out, err, {
@@ -270,4 +270,37 @@ class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSyst
runRes.get.fields.get("pwd_cmd") shouldBe Some(JsString("/action"))
}
}
+
+ it should "support return array result" in {
+ withActionContainer() { c =>
+ val code = """
+ |#!/bin/bash
+ |echo '["a", "b"]'
+ """.stripMargin.trim
+
+ val (initCode, initRes) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.runForJsArray(runPayload(JsObject()))
+ runCode should be(200)
+ runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+ }
+ }
+
+ it should "support array as input param" in {
+ withActionContainer() { c =>
+ val code = """
+ |#!/bin/bash
+ |arr=$1
+ |echo $arr
+ """.stripMargin.trim
+
+ val (initCode, initRes) = c.init(initPayload(code))
+ initCode should be(200)
+
+ val (runCode, runRes) = c.runForJsArray(runPayload(JsArray(JsString("a"), JsString("b"))))
+ runCode should be(200)
+ runRes shouldBe Some(JsArray(JsString("a"), JsString("b")))
+ }
+ }
}