Skip to content

Commit d7d3362

Browse files
authored
Use faasmctl to interact with a Faasm cluster (#29)
* use faasmctl * gh: bump code version * fix build * cpp: bump to latest version * faasmctl: bump version and use task to upload * cpp: bump after merge * gh: bump cpp and faasmctl
1 parent 85123dc commit d7d3362

File tree

7 files changed

+20
-45
lines changed

7 files changed

+20
-45
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
if: github.event.pull_request.draft == false
2121
runs-on: ubuntu-latest
2222
container:
23-
image: faasm.azurecr.io/cpython:0.2.5
23+
image: faasm.azurecr.io/cpython:0.2.6
2424
credentials:
2525
username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }}
2626
password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }}
@@ -44,7 +44,7 @@ jobs:
4444
REDIS_QUEUE_HOST: redis
4545
REDIS_STATE_HOST: redis
4646
container:
47-
image: faasm.azurecr.io/cpython:0.2.5
47+
image: faasm.azurecr.io/cpython:0.2.6
4848
credentials:
4949
username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }}
5050
password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }}

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.5
1+
0.2.6

crossenv/tasks/modules.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@
5555
# "dulwich",
5656
"Genshi",
5757
"pyaes",
58-
"pyperf",
59-
"pyperformance",
58+
# 16/07/2023 - pyperf and pyperformance installation suddendly broken
59+
# "pyperf",
60+
# "pyperformance",
6061
"six",
6162
]
6263

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
black==22.3.0
2+
faasmctl==0.5.6
23
flake8==3.9.2
3-
invoke==1.7.1
4+
invoke>=2.0.0
45
numpy==1.22.0
5-
requests==2.25.1
6+
requests>=2.31.0

tasks/cpython.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from copy import copy as deep_copy
2+
from faasmctl.util.upload import upload_wasm
23
from faasmtools.build import (
34
FAASM_BUILD_ENV_DICT,
45
WASM_HEADER_INSTALL,
@@ -7,13 +8,11 @@
78
build_config_cmd,
89
)
910
from faasmtools.compile_util import wasm_cmake, wasm_copy_upload
10-
from faasmtools.endpoints import get_faasm_upload_host_port
1111
from faasmtools.env import WASM_DIR
1212
from invoke import task
1313
from os import environ, makedirs
1414
from os.path import join, exists
1515
from re import compile
16-
from requests import put
1716
from shutil import copy, copytree, rmtree
1817
from subprocess import run
1918
from tasks.env import (
@@ -240,18 +239,7 @@ def upload(ctx):
240239
"""
241240
Upload the CPython function
242241
"""
243-
host, port = get_faasm_upload_host_port()
244242
wasm_file = join(
245243
WASM_DIR, CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, "function.wasm"
246244
)
247-
url = "http://{}:{}/f/{}/{}".format(
248-
host, port, CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME
249-
)
250-
print(
251-
"Uploading {}/{} to {}".format(
252-
CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, url
253-
)
254-
)
255-
response = put(url, data=open(wasm_file, "rb"))
256-
257-
print("Response ({}): {}".format(response.status_code, response.text))
245+
upload_wasm(CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, wasm_file)

tasks/func.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
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
91
from 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
115
from invoke import task
126
from os import makedirs, listdir
7+
from os.path import join
138
from shutil import copy
149
from 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

Comments
 (0)