ningyougang opened a new pull request, #5290:
URL: https://github.com/apache/openwhisk/pull/5290

   <!--- Provide a concise summary of your changes in the Title -->
   
   ## Description
   <!--- Provide a detailed description of your changes. -->
   <!--- Include details of what problem you are solving and how your changes 
are tested. -->
   POEM document pr: https://github.com/apache/openwhisk/pull/5244
   This feature is:  provide support array result feature for common action and 
sequence action. e.g.
   * For common action
   ```
   # cat ~/hello-array.js 
   function main(params) {
       console.log("-------------log test---------")
       return [{"key1":"value1"},{"key2":"value2"}];
   }
   
   # wsk -i action create hello-array-nodejs --kind nodejs:10 ~/hello-array.js 
   # wsk -i action invoke hello-array-nodejs -r -v
   REQUEST:
   [POST]       
http://xxx.xxx.xxx.xxx:10001/api/v1/namespaces/_/actions/hello-array-nodejs?blocking=true&result=true
   ...
   ...
   Response body size is 37 bytes
   Response body received:
   [{"key1":"value1"},{"key2":"value2"}]
   ```
   * For sequence action
   ```
   # cat ~/split.js
   function main(msg) {
       var separator = msg.separator || /\r?\n/;
       var lines = payload.split(separator);
       return lines;
   }
   
   # cat ~/sort.js
   function main(msg) {
       var lines = msg || [];
       lines.sort();
       return lines;
   }
   
   # wsk -i action create /whisk.system/utils/split --kind nodejs:10 ~/split.js
   # wsk -i action create /whisk.system/utils/sort --kind nodejs:10 ~/sort.js
   # wsk -i action create mySequence --sequence 
/whisk.system/utils/split,/whisk.system/utils/sort
   # wsk -i action invoke --result mySequence --param payload "bbb\ncccc\naaaa" 
 -r -v
   REQUEST:
   [POST]       
http://xxx.xxx.xxx.xxx:10001/api/v1/namespaces/_/actions/mySequence?blocking=true&result=true
   ...
   Response body size is 22 bytes
   Response body received:
   ["aaaa","bbbb","cccc"]
   ```
   * Activation check in elasticsearch
   ```
   # curl -u xxx:xxx -H "Content-Type: application/json" 
'[http://xxx.xxx.xxx.xxx:9200/lambda-exp_whisk.system/_search?pretty=true' -d  
'{
     "query" : { "match" : { "activationId" : 
"9cc4dad8d81342fc84dad8d81302fc54" }},
     "from":0,
     "size":1
   }'
   {
     "took" : 3,
     ...
     "hits" : {
       "total" : 1,
       "max_score" : 5.1628795,
       "hits" : [
         {
           "_index" : "lambda-exp_whisk.system",
             ...
             "logs" : [
               "2022-07-21T06:53:16.543515915Z stdout: -------------log 
test---------"
             ],
             "name" : "hello-array-nodejs",
             ...
             "response" : {
               "result" : "[{\"key1\":\"value1\"},{\"key2\":\"value2\"}]",
               "size" : 37,
               "statusCode" : 0
             },
             ...
           }
         }
       ]
     }
   }
   
   # curl -u xxx:xxx -H "Content-Type: application/json" 
'[http://10.168.240.79:9200/lambda-exp_whisk.system/_search?pretty=true' -d  '{
     "query" : { "match" : { "activationId" : 
"9c774fe852de44cdb74fe852de94cd54" }},
     "from":0,
     "size":1
   }'
   ...
             "response" : {
               "result" : "[\"aaaa\",\"bbb\",\"cccc\"]",
               "size" : 21,
               "statusCode" : 0
             }
   ...
   ```
   The `response.result` must use `text` to store, because different activation 
use same filed may use different type, e.g.
   one activation's result's name filed value is string , e.g. {"name": "jack"}
   another activation's result's name filed value is int, e.g. {"name": 12}
   Elasticsearch doesn't support this, it store like this, it would report 
error.
   
   * Other works
   As above example, we already know, `nodejs` runtime supports this feature as 
well. 
   But other runtimes(e.g. go, java, php, etc) don't support,
   1. After this pr merged, there still has other works for runtime images, 
need to support subsequent prs for other images.
   2. And in CLI side, still has small mount works to parse the JSON array 
string to user.
   
   ## Related issue and scope
   <!--- Please include a link to a related issue if there is one. -->
   - [ ] I opened an issue to propose and discuss this change (#????)
   
   ## My changes affect the following components
   <!--- Select below all system components are affected by your change. -->
   <!--- Enter an `x` in all applicable boxes. -->
   - [ ] API
   - [x] Controller
   - [ ] Message Bus (e.g., Kafka)
   - [x] Loadbalancer
   - [ ] Scheduler
   - [x] Invoker
   - [ ] Intrinsic actions (e.g., sequences, conductors)
   - [ ] Data stores (e.g., CouchDB)
   - [x] Tests
   - [ ] Deployment
   - [ ] CLI
   - [ ] General tooling
   - [ ] Documentation
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Use `x` in all the 
boxes that apply: -->
   - [ ] Bug fix (generally a non-breaking change which closes an issue).
   - [x] Enhancement or new feature (adds new functionality).
   - [ ] Breaking change (a bug fix or enhancement which changes existing 
behavior).
   
   ## Checklist:
   <!--- Please review the points below which help you make sure you've covered 
all aspects of the change you're making. -->
   
   - [ ] I signed an [Apache 
CLA](https://github.com/apache/openwhisk/blob/master/CONTRIBUTING.md).
   - [ ] I reviewed the [style 
guides](https://github.com/apache/openwhisk/blob/master/CONTRIBUTING.md#coding-standards)
 and followed the recommendations (Travis CI will check :).
   - [ ] I added tests to cover my changes.
   - [ ] My changes require further changes to the documentation.
   - [ ] I updated the documentation where necessary.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to