Support python function input

For example:
http POST http://127.0.0.1:7070/v1/executions function_id=<FUNCTION_ID> input:='{"param1": "value1"}' X-Auth-Token:<TOKEN>

Change-Id: I04ead79c22ead5720eaab58f456568a7ed9b23b4
This commit is contained in:
Lingxian Kong 2017-06-15 22:44:59 +12:00
parent 80302f534e
commit 0d3ba2f7c8
4 changed files with 18 additions and 9 deletions

View File

@ -181,7 +181,7 @@ runtime/function/execution in Qinling.
main() main()
EOF EOF
$ pip install requests -t ~/qinling_test $ pip install requests -t ~/qinling_test
$ zip ~/qinling_test/qinling_test.zip ~/qinling_test/* $ zip -r ~/qinling_test/qinling_test.zip ~/qinling_test/*
.. end .. end

View File

@ -76,11 +76,12 @@ class ExecutionsController(rest.RestController):
db_model = db_api.create_execution(params) db_model = db_api.create_execution(params)
self.engine_client.create_execution( if not func_url:
db_model.id, function_id, runtime_id, self.engine_client.create_execution(
input=params.get('input'), db_model.id, function_id, runtime_id,
is_sync=is_sync input=params.get('input'),
) is_sync=is_sync
)
if is_sync: if is_sync:
db_model = db_api.get_execution(db_model.id) db_model = db_api.get_execution(db_model.id)

View File

@ -12,7 +12,7 @@ in their function packages through Qinling API or CLI.
You'll need access to a Docker registry to push the image, by default it's You'll need access to a Docker registry to push the image, by default it's
docker hub. After modification, build a new image and upload to docker hub: docker hub. After modification, build a new image and upload to docker hub:
docker build -t USER/python-runtime. && docker push USER/python-runtime docker build -t USER/python-runtime . && docker push USER/python-runtime
## Using the image in Qinling ## Using the image in Qinling

View File

@ -33,7 +33,7 @@ file_name = ''
def download(): def download():
download_url = request.form['download_url'] download_url = request.form['download_url']
function_id = request.form['function_id'] function_id = request.form['function_id']
token = request.form['token'] token = request.form.get('token')
headers = {} headers = {}
if token: if token:
@ -67,9 +67,17 @@ def execute():
importer = zipimport.zipimporter(file_name) importer = zipimport.zipimporter(file_name)
module = importer.load_module('main') module = importer.load_module('main')
input = {}
if request.form:
# Refer to:
# http://werkzeug.pocoo.org/docs/0.12/datastructures/#werkzeug.datastructures.MultiDict
input = request.form.to_dict()
app.logger.debug('Invoking function with input: %s' % input)
start = time.time() start = time.time()
try: try:
result = module.main() result = module.main(**input)
except Exception as e: except Exception as e:
result = str(e) result = str(e)