11from base64 import b64encode
2+ from faasmctl .util .flush import flush_workers
3+ from faasmctl .util .invoke import invoke_wasm
4+ from faasmctl .util .upload import upload_wasm
5+ from faasmtools .env import PROJ_ROOT
6+ from faasmtools .compile_util import wasm_cmake , wasm_copy_upload
7+ from invoke import task
28from os import makedirs , listdir
39from os .path import join , exists , splitext
410from shutil import rmtree
511from subprocess import run
6- import requests
7- from invoke import task
8-
9- from faasmtools .env import PROJ_ROOT
10- from faasmtools .endpoints import (
11- get_faasm_invoke_host_port ,
12- get_faasm_planner_host_port ,
13- get_faasm_upload_host_port ,
14- get_knative_headers ,
15- )
16- from faasmtools .compile_util import wasm_cmake , wasm_copy_upload
17-
18- FAABRIC_MSG_TYPE_FLUSH = 3
1912
2013FUNC_DIR = join (PROJ_ROOT , "func" )
2114FUNC_BUILD_DIR = join (PROJ_ROOT , "build" , "func" )
@@ -82,12 +75,8 @@ def upload(ctx, user, func):
8275 """
8376 Upload a compiled function
8477 """
85- host , port = get_faasm_upload_host_port ()
8678 func_file = join (FUNC_BUILD_DIR , user , "{}.wasm" .format (func ))
87- url = "http://{}:{}/f/{}/{}" .format (host , port , user , func )
88- response = requests .put (url , data = open (func_file , "rb" ))
89-
90- print ("Response {}: {}" .format (response .status_code , response .text ))
79+ upload_wasm (user , func , func_file )
9180
9281
9382@task
@@ -105,8 +94,7 @@ def invoke(ctx, user, func, input_data=None, mpi=None, graph=False):
10594 """
10695 Invoke a given function
10796 """
108- host , port = get_faasm_invoke_host_port ()
109- url = "http://{}:{}" .format (host , port )
97+ # Prepare Faasm message
11098 data = {
11199 "function" : func ,
112100 "user" : user ,
@@ -124,14 +112,10 @@ def invoke(ctx, user, func, input_data=None, mpi=None, graph=False):
124112 data ["record_exec_graph" ] = True
125113 data ["async" ] = True
126114
127- headers = get_knative_headers ()
128- response = requests . post ( url , json = data , headers = headers )
115+ # Invoke message
116+ response = invoke_wasm ( data )
129117
130- if response .status_code != 200 :
131- print ("Error ({}):\n {}" .format (response .status_code , response .text ))
132- exit (1 )
133-
134- print ("Success:\n {}" .format (response .text ))
118+ print ("Success:\n {}" .format (response .messageResults [0 ].outputData ))
135119
136120
137121@task
@@ -151,14 +135,7 @@ def flush(ctx):
151135 """
152136 Flush the Faasm cluster
153137 """
154- headers = get_knative_headers ()
155- host , port = get_faasm_planner_host_port ()
156-
157- url = "http://{}:{}" .format (host , port )
158- data = {"type" : FAABRIC_MSG_TYPE_FLUSH }
159- response = requests .post (url , json = data , headers = headers )
160-
161- print ("Flush response {}: {}" .format (response .status_code , response .text ))
138+ flush_workers ()
162139
163140
164141@task
0 commit comments