Skip to content

Commit 3f2c574

Browse files
authored
Use faasmctl to interact with a Faasm deployment (#118)
* tasks: use faasmctl instead of faasmtools * gh: bump code version to ship packages with faasmctl installed * req: bump faasmctl version * bin: instlal faasmtools in editable mode as part of creating venvs * docker: simplify python set-up * req: bump faasmctl version
1 parent 58bad28 commit 3f2c574

File tree

7 files changed

+23
-46
lines changed

7 files changed

+23
-46
lines changed

.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SYSROOT_VERSION=0.2.7
2-
SYSROOT_CLI_IMAGE=faasm.azurecr.io/cpp-sysroot:0.2.7
1+
SYSROOT_VERSION=0.2.8
2+
SYSROOT_CLI_IMAGE=faasm.azurecr.io/cpp-sysroot:0.2.8
33
COMPOSE_PROJECT_NAME=cpp-dev

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
if: github.event.pull_request.draft == false
2020
runs-on: ubuntu-latest
2121
container:
22-
image: faasm.azurecr.io/cpp-sysroot:0.2.7
22+
image: faasm.azurecr.io/cpp-sysroot:0.2.8
2323
credentials:
2424
username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }}
2525
password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }}

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.7
1+
0.2.8

bin/create_venv.sh

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ fi
2929
pip_cmd install -U pip
3030
pip_cmd install -U setuptools wheel
3131
pip_cmd install -r requirements.txt
32+
# Install faasmtools in editable mode
33+
pip_cmd install -e .
3234

3335
touch ${VENV_PATH}/faasm_venv.BUILT
3436

docker/cpp-sysroot.dockerfile

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ RUN mkdir -p /code \
2525
&& git submodule update --init -f third-party/wasi-libc \
2626
&& git submodule update --init -f third-party/zlib
2727

28-
# Install the faasmtools Python lib
28+
# Python set-up
2929
RUN cd /code/cpp \
30-
&& ./bin/create_venv.sh \
31-
&& source venv/bin/activate \
32-
&& pip3 install -r requirements.txt \
33-
&& pip3 install .
30+
&& ./bin/create_venv.sh
3431

3532
# Build all the targets
3633
RUN cd /code/cpp \

requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
black==22.3.0
2+
faasmctl==0.3.5
23
flake8==4.0.1
3-
invoke==1.7.1
4-
requests==2.25.1
4+
invoke>=2.0.0
5+
requests>=2.31.0

tasks/func.py

+12-35
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
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
28
from os import makedirs, listdir
39
from os.path import join, exists, splitext
410
from shutil import rmtree
511
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
1912

2013
FUNC_DIR = join(PROJ_ROOT, "func")
2114
FUNC_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

Comments
 (0)