1- from faasmtools .build import FAASM_LOCAL_DIR
2- from faasmtools .endpoints import (
3- get_faasm_invoke_host_port ,
4- get_faasm_upload_host_port ,
5- get_knative_headers ,
6- )
7-
8- import requests
91from base64 import b64encode
10- from os .path import join
2+ from faasmctl .util .invoke import invoke_wasm
3+ from faasmctl .util .upload import upload_python
4+ from faasmtools .build import FAASM_LOCAL_DIR
115from invoke import task
126from os import makedirs , listdir
7+ from os .path import join
138from shutil import copy
149from tasks .env import CPYTHON_FUNC_USER , CPYTHON_FUNC_NAME , PROJ_ROOT
1510
@@ -23,7 +18,6 @@ def uploadpy(ctx, func, local=False):
2318 """
2419 Upload the given Python function
2520 """
26- host , port = get_faasm_upload_host_port ()
2721 src_file = join (PY_FUNC_DIR , "{}.py" .format (func ))
2822
2923 if local :
@@ -35,10 +29,7 @@ def uploadpy(ctx, func, local=False):
3529 print ("Copying function {} {} -> {}" .format (func , src_file , dest_file ))
3630 copy (src_file , dest_file )
3731 else :
38- url = "http://{}:{}/p/{}/{}" .format (host , port , "python" , func )
39- response = requests .put (url , data = open (src_file , "rb" ))
40-
41- print ("Response ({}): {}" .format (response .status_code , response .text ))
32+ upload_python (func , src_file )
4233
4334
4435@task
@@ -59,8 +50,6 @@ def invoke(ctx, user, func, input_data=None):
5950 """
6051 Invoke a python function on a Faasm cluster
6152 """
62- host , port = get_faasm_invoke_host_port ()
63- url = "http://{}:{}" .format (host , port )
6453 data = {
6554 "user" : CPYTHON_FUNC_USER ,
6655 "function" : CPYTHON_FUNC_NAME ,
@@ -74,11 +63,7 @@ def invoke(ctx, user, func, input_data=None):
7463 "utf-8"
7564 )
7665
77- headers = get_knative_headers ()
78- response = requests .post (url , json = data , headers = headers )
79-
80- if response .status_code != 200 :
81- print ("Error ({}):\n {}" .format (response .status_code , response .text ))
82- exit (1 )
66+ # Invoke message
67+ response = invoke_wasm (data )
8368
84- print ("Success:\n {}" .format (response .text ))
69+ print ("Success:\n {}" .format (response .messageResults [ 0 ]. outputData ))
0 commit comments