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 2018/07/05 20:31:13 UTC

[incubator-openwhisk-runtime-docker] branch master updated (650842a -> 891896f)

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

dgrove pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-docker.git.


    from 650842a  Add ActionProxyContainer tests (#47)
     new 470cd35  Remove files that are duplicates and result of repo splitting.
     new 891896f  Do not allow re-init of the action exec.

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.


Summary of changes:
 core/actionProxy/actionproxy.py                    |  13 ++-
 core/actionProxy/delete-build-run.sh               |  39 --------
 core/actionProxy/invoke.py                         | 102 ---------------------
 .../ActionProxyContainerTests.scala                |   1 +
 4 files changed, 13 insertions(+), 142 deletions(-)
 delete mode 100755 core/actionProxy/delete-build-run.sh
 delete mode 100755 core/actionProxy/invoke.py


[incubator-openwhisk-runtime-docker] 01/02: Remove files that are duplicates and result of repo splitting.

Posted by dg...@apache.org.
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/incubator-openwhisk-runtime-docker.git

commit 470cd3530bd7aeedf4cf6cb5d35e0192039e3963
Author: Rodric Rabbah <ro...@gmail.com>
AuthorDate: Thu Jul 5 14:39:32 2018 -0400

    Remove files that are duplicates and result of repo splitting.
---
 core/actionProxy/delete-build-run.sh |  39 --------------
 core/actionProxy/invoke.py           | 102 -----------------------------------
 2 files changed, 141 deletions(-)

diff --git a/core/actionProxy/delete-build-run.sh b/core/actionProxy/delete-build-run.sh
deleted file mode 100755
index cd1f995..0000000
--- a/core/actionProxy/delete-build-run.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Useful for local testing.
-# USE WITH CAUTION !!
-
-# This script is useful for testing the action proxy (or its derivatives)
-# in combination with [init,run].py. Use it to rebuild the container image
-# and start the proxy: delete-build-run.sh whisk/dockerskeleton.
-
-# Removes all previously built instances.
-remove=$(docker ps -a -q)
-if [[ !  -z  $remove  ]]; then
-    docker rm $remove
-fi
-
-image=${1:-openwhisk/dockerskeleton}
-docker build -t $image .
-
-echo ""
-echo "  ---- RUNNING ---- "
-echo ""
-
-docker run -i -t -p 8080:8080 $image
diff --git a/core/actionProxy/invoke.py b/core/actionProxy/invoke.py
deleted file mode 100755
index 92d8a6d..0000000
--- a/core/actionProxy/invoke.py
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/env python
-"""Executable Python script for testing the action proxy.
-
-  This script is useful for testing the action proxy (or its derivatives)
-  by simulating invoker interactions. Use it in combination with
-  delete-build-run.sh which builds and starts up the action proxy.
-  Examples:
-     ./delete-build-run.sh &
-     ./invoke.py init <action source file> # should return OK
-     ./invoke.py run '{"some":"json object as a string"}'
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-"""
-
-import os
-import re
-import sys
-import json
-import requests
-import codecs
-
-DOCKER_HOST = "localhost"
-if "DOCKER_HOST" in os.environ:
-    try:
-        DOCKER_HOST = re.compile("tcp://(.*):[\d]+").findall(
-            os.environ["DOCKER_HOST"])[0]
-    except Exception:
-        print("cannot determine docker host from %s" %
-              os.environ["DOCKER_HOST"])
-        sys.exit(-1)
-DEST = "http://%s:8080" % DOCKER_HOST
-
-
-def content_from_args(args):
-    if len(args) == 0:
-        return None
-
-    if len(args) == 1 and os.path.exists(args[0]):
-        with open(args[0]) as fp:
-            return json.load(fp)
-
-    # else...
-    in_str = " ".join(args)
-    try:
-        d = json.loads(in_str)
-        if isinstance(d, dict):
-            return d
-        else:
-            raise "Not a dict."
-    except:
-        return in_str
-
-
-def init(args):
-    main = args[1] if len(args) == 2 else "main"
-    args = args[0] if len(args) >= 1 else None
-
-    if args and args.endswith(".zip"):
-        with open(args, "rb") as fp:
-            contents = fp.read().encode("base64")
-        binary = True
-    elif args:
-        with(codecs.open(args, "r", "utf-8")) as fp:
-            contents = fp.read()
-        binary = False
-    else:
-        contents = None
-        binary = False
-
-    r = requests.post("%s/init" % DEST, json={"value": {"code": contents,
-                                                        "binary": binary,
-                                                        "main": main}})
-    print(r.text)
-
-
-def run(args):
-    value = content_from_args(args)
-    # print("Sending value: %s..." % json.dumps(value)[0:40])
-    r = requests.post("%s/run" % DEST, json={"value": value})
-    print(r.text)
-
-
-if sys.argv[1] == "init":
-    init(sys.argv[2:])
-elif sys.argv[1] == "run":
-    run(sys.argv[2:])
-else:
-    print("usage: 'init <filename>' or 'run JSON-as-string'")


[incubator-openwhisk-runtime-docker] 02/02: Do not allow re-init of the action exec.

Posted by dg...@apache.org.
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/incubator-openwhisk-runtime-docker.git

commit 891896f25c39bc336ef6dda53f80f466ac4ca3c8
Author: Rodric Rabbah <ro...@gmail.com>
AuthorDate: Thu Jul 5 15:19:21 2018 -0400

    Do not allow re-init of the action exec.
    
    Disables re-initialization of the executable unless explicitly permitted
    via an environment variable PROXY_ALLOW_REINIT == "1", which is generally
    useful for local testing and development.
---
 core/actionProxy/actionproxy.py                             | 13 ++++++++++++-
 .../actionContainers/ActionProxyContainerTests.scala        |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/core/actionProxy/actionproxy.py b/core/actionProxy/actionproxy.py
index bbe9902..0bca409 100644
--- a/core/actionProxy/actionproxy.py
+++ b/core/actionProxy/actionproxy.py
@@ -203,9 +203,12 @@ class ActionRunner:
 
 proxy = flask.Flask(__name__)
 proxy.debug = False
+# disable re-initialization of the executable unless explicitly allowed via an environment
+# variable PROXY_ALLOW_REINIT == "1" (this is generally useful for local testing and development)
+proxy.rejectReinit = 'PROXY_ALLOW_REINIT' not in os.environ or os.environ['PROXY_ALLOW_REINIT'] != "1"
+proxy.initialized = False
 runner = None
 
-
 def setRunner(r):
     global runner
     runner = r
@@ -213,6 +216,13 @@ def setRunner(r):
 
 @proxy.route('/init', methods=['POST'])
 def init():
+    if proxy.rejectReinit is True and proxy.initialized is True:
+        msg = 'Cannot initialize the action more than once.'
+        sys.stderr.write(msg + '\n')
+        response = flask.jsonify({'error': msg})
+        response.status_code = 403
+        return complete(response)
+
     message = flask.request.get_json(force=True, silent=True)
     if message and not isinstance(message, dict):
         flask.abort(404)
@@ -228,6 +238,7 @@ def init():
         status = False
 
     if status is True:
+        proxy.initialized = True
         return ('OK', 200)
     else:
         response = flask.jsonify({'error': 'The action failed to generate or locate a binary. See logs for details.'})
diff --git a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
index 20a9ee5..52022ee 100644
--- a/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
+++ b/tests/src/test/scala/runtime/actionContainers/ActionProxyContainerTests.scala
@@ -245,4 +245,5 @@ class ActionProxyContainerTests extends BasicActionRunnerTests with WskActorSyst
   testUnicode(stdUnicodeSamples)
   testEnv(stdEnvSamples)
   testLargeInput(stdLargeInputSamples)
+  testInitCannotBeCalledMoreThanOnce(codeNotReturningJson) // any code sample will do
 }