1
1
from 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
2
8
from os import makedirs , listdir
3
9
from os .path import join , exists , splitext
4
10
from shutil import rmtree
5
11
from 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
19
12
20
13
FUNC_DIR = join (PROJ_ROOT , "func" )
21
14
FUNC_BUILD_DIR = join (PROJ_ROOT , "build" , "func" )
@@ -82,12 +75,8 @@ def upload(ctx, user, func):
82
75
"""
83
76
Upload a compiled function
84
77
"""
85
- host , port = get_faasm_upload_host_port ()
86
78
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 )
91
80
92
81
93
82
@task
@@ -105,8 +94,7 @@ def invoke(ctx, user, func, input_data=None, mpi=None, graph=False):
105
94
"""
106
95
Invoke a given function
107
96
"""
108
- host , port = get_faasm_invoke_host_port ()
109
- url = "http://{}:{}" .format (host , port )
97
+ # Prepare Faasm message
110
98
data = {
111
99
"function" : func ,
112
100
"user" : user ,
@@ -124,14 +112,10 @@ def invoke(ctx, user, func, input_data=None, mpi=None, graph=False):
124
112
data ["record_exec_graph" ] = True
125
113
data ["async" ] = True
126
114
127
- headers = get_knative_headers ()
128
- response = requests . post ( url , json = data , headers = headers )
115
+ # Invoke message
116
+ response = invoke_wasm ( data )
129
117
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 ))
135
119
136
120
137
121
@task
@@ -151,14 +135,7 @@ def flush(ctx):
151
135
"""
152
136
Flush the Faasm cluster
153
137
"""
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 ()
162
139
163
140
164
141
@task
0 commit comments