You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/02/21 13:03:07 UTC

[GitHub] rabbah closed pull request #6: Use actionproxy from dockerSkeleton do not clown and own is the motto FTW!

rabbah closed pull request #6: Use actionproxy from dockerSkeleton do not clown and own is the motto FTW!
URL: https://github.com/apache/incubator-openwhisk-runtime-python/pull/6
 
 
   

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/.travis.yml b/.travis.yml
index 746b1a5..d0c9442 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,3 +20,9 @@ env:
   global:
   - secure: Ac7MlWUpsLwmbcjCigDf+vftiXAEJbf78FVm2QCd4IeFqlRiNbQm3bWRXOOW3Zqh4R4o/wSFpFq0qKPrI9WJjOcxD0GxFboq2iGWTegddfDbENV/IBmjurl6NzYY6dUB7GUSmHYy6tdKnxMhjHzZCn2m4OVWltcMtnOV0G+uYvbnre7vXfb67duzJF+mYpJJ7rC0wGh+N50bYvm0BTtPcQMYJibq6sDTY8Lr1b74QGdM/sODre69CbuiwAA7Ed0hajEcMkv8YnwY0De/PL7hthUyCWSD+i1AhtD+3odA64yX/pAbBzfCcqPoI0Nt5ZmAAUKLJ9pAHCc74dlmYzj9wj1z5TS0nLOE2l++vNvgsA3/c+lqrBv6hc9FmSKx4yfNdFCakVLEfdRJw/45ibIRN5dCW5tDdIx8aciBV8c0CyYgSLRvtVuvw5IX7fbwhHOZ8ftTRzCHS0Nd9zs4x3za+1aucWFQEyrkPtXZIiqeuV7yI4S7yYhGeJy/3KmuN7ljDiTElZb/W9W22ryw/UwCyyZBGnvhomAwInS3E51Jv8GuOU9FVliGzGs2yLuVQ1FjIZ25Au5W4TLTor/jE+dxOlH4u25neqsKBxzG4iyJs3AfJnycD8op7JbTG64OqpVvaB8A4N3P416IxGALSFVv2BWSLY4qW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94TCGf0lMyaag/JOETdDgC9hAbh4aSx1cj4hGXiuGrNMbYblMBsjvujqFp2nraw/DE93pHGRY9lbBZIjEVhj/jBmOv1I3yRdXHj4VybZc4JGnfQVGz/RYDOEmKGoLoVWFp+hGAHDqVos9ZvEBByMAAmgVD2/D5cBER3oskp/JJjKmFLk614FcNh4D7/+bYAFhxbCgnoLHH5GeSo0q73O3JSi5pZggEIN9xis7SVQgPl+MUDTe5N3X3J3bQc7cMYGLzh0VNSyYaHuW2P02vWBNE/FAkL8UGrfGsXnDyGRRxo8fYHTXpIjhIkE7tY5eZQ=
+    on_pull_requests: false
+    on_success: change
+    on_failure: always
\ No newline at end of file
diff --git a/README.md b/README.md
index 2696688..04a2e3d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Apache OpenWhisk runtimes for swift
+# Apache OpenWhisk runtimes for Python
 [![Build Status](https://travis-ci.org/apache/incubator-openwhisk-runtime-python.svg?branch=master)](https://travis-ci.org/apache/incubator-openwhisk-runtime-python)
 
 
@@ -13,7 +13,7 @@ Replace `python3action` with `python2action` to use python 2.
 ### To use on deployment that contains the rutime as a kind
 To use as a kind action using python 3
 ```
-wsk action update myAction myAction.swift --kind python:3
+wsk action update myAction myAction.py --kind python:3
 ```
 Replace `python:3` with `python:2` to use python 2.
 
diff --git a/ansible/environments/local/group_vars/all b/ansible/environments/local/group_vars/all
index 2b82ecd..63e2846 100755
--- a/ansible/environments/local/group_vars/all
+++ b/ansible/environments/local/group_vars/all
@@ -1,8 +1,9 @@
 whisk_version_name: local
-config_root_dir: /tmp
+config_root_dir: /tmp/wskconf
 whisk_logs_dir: /tmp/wsklogs
 docker_registry: ""
 docker_dns: ""
+bypass_pull_for_local_images: true
 
 db_prefix: whisk_local_
 
@@ -19,11 +20,10 @@ apigw_auth_user: ""
 apigw_auth_pwd: ""
 apigw_host_v2: "http://{{ groups['apigateway']|first }}:{{apigateway.port.api}}/v2"
 
-controller_arguments: '-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1098'
-invoker_arguments: "{{ controller_arguments }}"
-
 invoker_allow_multiple_instances: true
 
+env_hosts_dir: "{{ playbook_dir }}/environments/local"
+
 runtimes_manifest:
   defaultImagePrefix: "openwhisk"
   defaultImageTag: "latest"
diff --git a/ansible/environments/local/hosts b/ansible/environments/local/hosts
index c99f195..4715e55 100644
--- a/ansible/environments/local/hosts
+++ b/ansible/environments/local/hosts
@@ -9,8 +9,11 @@ ansible ansible_connection=local
 [controllers]
 controller0         ansible_host=172.17.0.1 ansible_connection=local
 
-[kafka]
-172.17.0.1          ansible_host=172.17.0.1 ansible_connection=local
+[kafkas]
+kafka0              ansible_host=172.17.0.1 ansible_connection=local
+
+[zookeepers:children]
+kafkas
 
 [invokers]
 invoker0            ansible_host=172.17.0.1 ansible_connection=local
diff --git a/core/python2Action/Dockerfile b/core/python2Action/Dockerfile
index 95ff655..0d84504 100644
--- a/core/python2Action/Dockerfile
+++ b/core/python2Action/Dockerfile
@@ -32,8 +32,9 @@ RUN pip install --no-cache-dir --upgrade pip setuptools six \
 
 ENV FLASK_PROXY_PORT 8080
 
-RUN mkdir -p /pythonAction
-ADD actionproxy.py /pythonAction/
+# Add the action proxy
+ADD https://raw.githubusercontent.com/apache/incubator-openwhisk-runtime-docker/dockerskeleton%401.1.0/core/actionProxy/actionproxy.py /actionProxy/actionproxy.py
+
 ADD pythonrunner.py /pythonAction/
 
 CMD ["/bin/bash", "-c", "cd pythonAction && python -u pythonrunner.py"]
diff --git a/core/python2Action/actionproxy.py b/core/python2Action/actionproxy.py
deleted file mode 100644
index c68231f..0000000
--- a/core/python2Action/actionproxy.py
+++ /dev/null
@@ -1,271 +0,0 @@
-"""Executable Python script for a proxy service to dockerSkeleton.
-
-Provides a proxy service (using Flask, a Python web microframework)
-that implements the required /init and /run routes to interact with
-the OpenWhisk invoker service.
-
-The implementation of these routes is encapsulated in a class named
-ActionRunner which provides a basic framework for receiving code
-from an invoker, preparing it for execution, and then running the
-code when required.
-
-/*
- * 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 sys
-import os
-import json
-import subprocess
-import codecs
-import flask
-from gevent.wsgi import WSGIServer
-import zipfile
-import io
-import base64
-
-
-class ActionRunner:
-    """ActionRunner."""
-    LOG_SENTINEL = 'XXX_THE_END_OF_A_WHISK_ACTIVATION_XXX'
-
-    # initializes the runner
-    # @param source the path where the source code will be located (if any)
-    # @param binary the path where the binary will be located (may be the
-    # same as source code path)
-    def __init__(self, source=None, binary=None):
-        defaultBinary = '/action/exec'
-        self.source = source if source else defaultBinary
-        self.binary = binary if binary else defaultBinary
-
-    def preinit(self):
-        return
-
-    # extracts from the JSON object message a 'code' property and
-    # writes it to the <source> path. The source code may have an
-    # an optional <epilogue>. The source code is subsequently built
-    # to produce the <binary> that is executed during <run>.
-    # @param message is a JSON object, should contain 'code'
-    # @return True iff binary exists and is executable
-    def init(self, message):
-        def prep():
-            self.preinit()
-            if 'code' in message and message['code'] is not None:
-                binary = message['binary'] if 'binary' in message else False
-                if not binary:
-                    return self.initCodeFromString(message)
-                else:
-                    return self.initCodeFromZip(message)
-            else:
-                return False
-
-        if prep():
-            try:
-                # write source epilogue if any
-                # the message is passed along as it may contain other
-                # fields relevant to a specific container.
-                if self.epilogue(message) is False:
-                    return False
-                # build the source
-                if self.build(message) is False:
-                    return False
-            except Exception:
-                return False
-        # verify the binary exists and is executable
-        return self.verify()
-
-    # optionally appends source to the loaded code during <init>
-    def epilogue(self, init_arguments):
-        return
-
-    # optionally builds the source code loaded during <init> into an executable
-    def build(self, init_arguments):
-        return
-
-    # @return True iff binary exists and is executable, False otherwise
-    def verify(self):
-        return (os.path.isfile(self.binary) and
-                os.access(self.binary, os.X_OK))
-
-    # constructs an environment for the action to run in
-    # @param message is a JSON object received from invoker (should
-    # contain 'value' and 'api_key' and other metadata)
-    # @return an environment dictionary for the action process
-    def env(self, message):
-        # make sure to include all the env vars passed in by the invoker
-        env = os.environ
-        for p in ['api_key', 'namespace', 'action_name', 'activation_id', 'deadline']:
-            if p in message:
-                env['__OW_%s' % p.upper()] = message[p]
-        return env
-
-    # runs the action, called iff self.verify() is True.
-    # @param args is a JSON object representing the input to the action
-    # @param env is the environment for the action to run in (defined edge
-    # host, auth key)
-    # return JSON object result of running the action or an error dictionary
-    # if action failed
-    def run(self, args, env):
-        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.'})
-
-        try:
-            input = json.dumps(args)
-            p = subprocess.Popen(
-                [self.binary, input],
-                stdout=subprocess.PIPE,
-                stderr=subprocess.PIPE,
-                env=env)
-        except Exception as e:
-            return error(e)
-
-        # run the process and wait until it completes.
-        # stdout/stderr will always be set because we passed PIPEs to Popen
-        (o, e) = p.communicate()
-
-        # stdout/stderr may be either text or bytes, depending on Python
-        # version, so if bytes, decode to text. Note that in Python 2
-        # a string will match both types; so also skip decoding in that case
-        if isinstance(o, bytes) and not isinstance(o, str):
-            o = o.decode('utf-8')
-        if isinstance(e, bytes) and not isinstance(e, str):
-            e = e.decode('utf-8')
-
-        # get the last line of stdout, even if empty
-        lastNewLine = o.rfind('\n', 0, len(o)-1)
-        if lastNewLine != -1:
-            # this is the result string to JSON parse
-            lastLine = o[lastNewLine+1:].strip()
-            # emit the rest as logs to stdout (including last new line)
-            sys.stdout.write(o[:lastNewLine+1])
-        else:
-            # either o is empty or it is the result string
-            lastLine = o.strip()
-
-        if e:
-            sys.stderr.write(e)
-
-        try:
-            json_output = json.loads(lastLine)
-            if isinstance(json_output, dict):
-                return (200, json_output)
-            else:
-                return error(lastLine)
-        except Exception:
-            return error(lastLine)
-
-    # initialize code from inlined string
-    def initCodeFromString(self, message):
-        with codecs.open(self.source, 'w', 'utf-8') as fp:
-            fp.write(message['code'])
-        return True
-
-    # initialize code from base64 encoded archive
-    def initCodeFromZip(self, message):
-        try:
-            bytes = base64.b64decode(message['code'])
-            bytes = io.BytesIO(bytes)
-            archive = zipfile.ZipFile(bytes)
-            archive.extractall(os.path.dirname(self.source))
-            archive.close()
-            return True
-        except Exception as e:
-            print('err', str(e))
-            return False
-
-proxy = flask.Flask(__name__)
-proxy.debug = False
-runner = None
-
-
-def setRunner(r):
-    global runner
-    runner = r
-
-
-@proxy.route('/init', methods=['POST'])
-def init():
-    message = flask.request.get_json(force=True, silent=True)
-    if message and not isinstance(message, dict):
-        flask.abort(404)
-    else:
-        value = message.get('value', {}) if message else {}
-
-    if not isinstance(value, dict):
-        flask.abort(404)
-
-    try:
-        status = runner.init(value)
-    except Exception as e:
-        status = False
-
-    if status is True:
-        return ('OK', 200)
-    else:
-        response = flask.jsonify({'error': 'The action failed to generate or locate a binary. See logs for details.'})
-        response.status_code = 502
-        return complete(response)
-
-
-@proxy.route('/run', methods=['POST'])
-def run():
-    def error():
-        response = flask.jsonify({'error': 'The action did not receive a dictionary as an argument.'})
-        response.status_code = 404
-        return complete(response)
-
-    message = flask.request.get_json(force=True, silent=True)
-    if message and not isinstance(message, dict):
-        return error()
-    else:
-        args = message.get('value', {}) if message else {}
-        if not isinstance(args, dict):
-            return error()
-
-    if runner.verify():
-        try:
-            code, result = runner.run(args, runner.env(message or {}))
-            response = flask.jsonify(result)
-            response.status_code = code
-        except Exception as e:
-            response = flask.jsonify({'error': 'Internal error. {}'.format(e)})
-            response.status_code = 500
-    else:
-        response = flask.jsonify({'error': 'The action failed to locate a binary. See logs for details.'})
-        response.status_code = 502
-    return complete(response)
-
-
-def complete(response):
-    # Add sentinel to stdout/stderr
-    sys.stdout.write('%s\n' % ActionRunner.LOG_SENTINEL)
-    sys.stdout.flush()
-    sys.stderr.write('%s\n' % ActionRunner.LOG_SENTINEL)
-    sys.stderr.flush()
-    return response
-
-
-def main():
-    port = int(os.getenv('FLASK_PROXY_PORT', 8080))
-    server = WSGIServer(('', port), proxy, log=None)
-    server.serve_forever()
-
-if __name__ == '__main__':
-    setRunner(ActionRunner())
-    main()


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services