You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2019/08/22 14:41:18 UTC

[openwhisk-runtime-nodejs] branch envvar created (now ef38897)

This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a change to branch envvar
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-nodejs.git.


      at ef38897  Update test

This branch includes the following new commits:

     new d3761f5  Export activation arguments to environment during initialization, before loading the code.
     new ef38897  Update test

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[openwhisk-runtime-nodejs] 01/02: Export activation arguments to environment during initialization, before loading the code.

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch envvar
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-nodejs.git

commit d3761f5aca0b1a37af8d118b3d4bf14dfbd2408d
Author: Rodric Rabbah <ro...@gmail.com>
AuthorDate: Thu Apr 18 13:13:34 2019 -0400

    Export activation arguments to environment during initialization, before loading the code.
---
 core/nodejsActionBase/app.js                          |  8 ++++----
 core/nodejsActionBase/src/service.js                  | 11 +++++++++++
 .../actionContainers/NodeJsActionContainerTests.scala | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/core/nodejsActionBase/app.js b/core/nodejsActionBase/app.js
index d825dc3..c50647d 100644
--- a/core/nodejsActionBase/app.js
+++ b/core/nodejsActionBase/app.js
@@ -17,10 +17,10 @@
 
 // __OW_ALLOW_CONCURRENT: see docs/concurrency.md
 var config = {
-        'port': 8080,
-        'apiHost': process.env.__OW_API_HOST,
-        'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT,
-        'requestBodyLimit': "48mb"
+    'port': 8080,
+    'apiHost': process.env.__OW_API_HOST,
+    'allowConcurrent': process.env.__OW_ALLOW_CONCURRENT,
+    'requestBodyLimit': "48mb"
 };
 
 var bodyParser = require('body-parser');
diff --git a/core/nodejsActionBase/src/service.js b/core/nodejsActionBase/src/service.js
index 4d994af..e781210 100644
--- a/core/nodejsActionBase/src/service.js
+++ b/core/nodejsActionBase/src/service.js
@@ -160,6 +160,17 @@ function NodeActionService(config) {
     };
 
     function doInit(message) {
+        if (message.env && typeof message.env == 'object') {
+            Object.keys(message.env).forEach(k => {
+                let val = message.env[k];
+                if (typeof val !== 'object' || val == null) {
+                    process.env[k] = val ? val.toString() : "";
+                } else {
+                    process.env[k] = JSON.stringify(val);
+                }
+            });
+        }
+
         return initializeActionHandler(message)
             .then(handler => {
                 userCodeRunner = new NodeActionRunner(handler);
diff --git a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
index 63f30fd..f1647cf 100644
--- a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
@@ -87,6 +87,25 @@ abstract class NodeJsActionContainerTests extends BasicActionRunnerTests with Ws
       """.stripMargin.trim)
   }
 
+  override val testEnvPartition = {
+    // the environment variables are ready at load time to ensure
+    // variables are already available in the runtime
+    TestConfig("""
+        |const envargs = {
+        |    "ARRAY": process.env.ARRAY,
+        |    "OBJECT": process.env.OBJECT,
+        |    "STRING": process.env.STRING,
+        |    "NUMBER": process.env.NUMBER,
+        |    "BOOL": process.env.BOOL,
+        |    "NULL": process.env.NULL
+        |}
+        |
+        |function main(args) {
+        |    return envargs
+        |}
+      """.stripMargin.trim)
+  }
+
   override val testInitCannotBeCalledMoreThanOnce = {
     TestConfig("""
         |function main(args) {


[openwhisk-runtime-nodejs] 02/02: Update test

Posted by ra...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch envvar
in repository https://gitbox.apache.org/repos/asf/openwhisk-runtime-nodejs.git

commit ef3889774ea3bf3b01bf644f531d639b98c470e9
Author: Rodric Rabbah <ro...@gmail.com>
AuthorDate: Thu Aug 22 10:40:42 2019 -0400

    Update test
---
 .../runtime/actionContainers/NodeJsActionContainerTests.scala     | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
index f1647cf..f96a94c 100644
--- a/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/NodeJsActionContainerTests.scala
@@ -92,12 +92,8 @@ abstract class NodeJsActionContainerTests extends BasicActionRunnerTests with Ws
     // variables are already available in the runtime
     TestConfig("""
         |const envargs = {
-        |    "ARRAY": process.env.ARRAY,
-        |    "OBJECT": process.env.OBJECT,
-        |    "STRING": process.env.STRING,
-        |    "NUMBER": process.env.NUMBER,
-        |    "BOOL": process.env.BOOL,
-        |    "NULL": process.env.NULL
+        |    "SOME_VAR": process.env.SOME_VAR,
+        |    "ANOTHER_VAR": process.env.ANOTHER_VAR
         |}
         |
         |function main(args) {