From d7d3362fb6542aa633a7aeec74121c7b54896106 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 18 Jul 2023 12:14:09 +0100 Subject: [PATCH] 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 --- .github/workflows/tests.yml | 4 ++-- VERSION | 2 +- crossenv/tasks/modules.py | 5 +++-- requirements.txt | 5 +++-- tasks/cpython.py | 16 ++-------------- tasks/func.py | 31 ++++++++----------------------- third-party/cpp | 2 +- 7 files changed, 20 insertions(+), 45 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1429717..1ff44b0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,7 +20,7 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest container: - image: faasm.azurecr.io/cpython:0.2.5 + image: faasm.azurecr.io/cpython:0.2.6 credentials: username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }} password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }} @@ -44,7 +44,7 @@ jobs: REDIS_QUEUE_HOST: redis REDIS_STATE_HOST: redis container: - image: faasm.azurecr.io/cpython:0.2.5 + image: faasm.azurecr.io/cpython:0.2.6 credentials: username: ${{ secrets.ACR_SERVICE_PRINCIPAL_ID }} password: ${{ secrets.ACR_SERVICE_PRINCIPAL_PASSWORD }} diff --git a/VERSION b/VERSION index 3a4036f..53a75d6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.5 +0.2.6 diff --git a/crossenv/tasks/modules.py b/crossenv/tasks/modules.py index 1e3ae21..561cc71 100644 --- a/crossenv/tasks/modules.py +++ b/crossenv/tasks/modules.py @@ -55,8 +55,9 @@ # "dulwich", "Genshi", "pyaes", - "pyperf", - "pyperformance", + # 16/07/2023 - pyperf and pyperformance installation suddendly broken + # "pyperf", + # "pyperformance", "six", ] diff --git a/requirements.txt b/requirements.txt index 8be08ed..62ac458 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ black==22.3.0 +faasmctl==0.5.6 flake8==3.9.2 -invoke==1.7.1 +invoke>=2.0.0 numpy==1.22.0 -requests==2.25.1 +requests>=2.31.0 diff --git a/tasks/cpython.py b/tasks/cpython.py index 61c8373..fa4b3f6 100644 --- a/tasks/cpython.py +++ b/tasks/cpython.py @@ -1,4 +1,5 @@ from copy import copy as deep_copy +from faasmctl.util.upload import upload_wasm from faasmtools.build import ( FAASM_BUILD_ENV_DICT, WASM_HEADER_INSTALL, @@ -7,13 +8,11 @@ build_config_cmd, ) from faasmtools.compile_util import wasm_cmake, wasm_copy_upload -from faasmtools.endpoints import get_faasm_upload_host_port from faasmtools.env import WASM_DIR from invoke import task from os import environ, makedirs from os.path import join, exists from re import compile -from requests import put from shutil import copy, copytree, rmtree from subprocess import run from tasks.env import ( @@ -240,18 +239,7 @@ def upload(ctx): """ Upload the CPython function """ - host, port = get_faasm_upload_host_port() wasm_file = join( WASM_DIR, CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, "function.wasm" ) - url = "http://{}:{}/f/{}/{}".format( - host, port, CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME - ) - print( - "Uploading {}/{} to {}".format( - CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, url - ) - ) - response = put(url, data=open(wasm_file, "rb")) - - print("Response ({}): {}".format(response.status_code, response.text)) + upload_wasm(CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, wasm_file) diff --git a/tasks/func.py b/tasks/func.py index 1077cd6..f309726 100644 --- a/tasks/func.py +++ b/tasks/func.py @@ -1,15 +1,10 @@ -from faasmtools.build import FAASM_LOCAL_DIR -from faasmtools.endpoints import ( - get_faasm_invoke_host_port, - get_faasm_upload_host_port, - get_knative_headers, -) - -import requests from base64 import b64encode -from os.path import join +from faasmctl.util.invoke import invoke_wasm +from faasmctl.util.upload import upload_python +from faasmtools.build import FAASM_LOCAL_DIR from invoke import task from os import makedirs, listdir +from os.path import join from shutil import copy from tasks.env import CPYTHON_FUNC_USER, CPYTHON_FUNC_NAME, PROJ_ROOT @@ -23,7 +18,6 @@ def uploadpy(ctx, func, local=False): """ Upload the given Python function """ - host, port = get_faasm_upload_host_port() src_file = join(PY_FUNC_DIR, "{}.py".format(func)) if local: @@ -35,10 +29,7 @@ def uploadpy(ctx, func, local=False): print("Copying function {} {} -> {}".format(func, src_file, dest_file)) copy(src_file, dest_file) else: - url = "http://{}:{}/p/{}/{}".format(host, port, "python", func) - response = requests.put(url, data=open(src_file, "rb")) - - print("Response ({}): {}".format(response.status_code, response.text)) + upload_python(func, src_file) @task @@ -59,8 +50,6 @@ def invoke(ctx, user, func, input_data=None): """ Invoke a python function on a Faasm cluster """ - host, port = get_faasm_invoke_host_port() - url = "http://{}:{}".format(host, port) data = { "user": CPYTHON_FUNC_USER, "function": CPYTHON_FUNC_NAME, @@ -74,11 +63,7 @@ def invoke(ctx, user, func, input_data=None): "utf-8" ) - headers = get_knative_headers() - response = requests.post(url, json=data, headers=headers) - - if response.status_code != 200: - print("Error ({}):\n{}".format(response.status_code, response.text)) - exit(1) + # Invoke message + response = invoke_wasm(data) - print("Success:\n{}".format(response.text)) + print("Success:\n{}".format(response.messageResults[0].outputData)) diff --git a/third-party/cpp b/third-party/cpp index b556c29..16102b1 160000 --- a/third-party/cpp +++ b/third-party/cpp @@ -1 +1 @@ -Subproject commit b556c29b46869d0f07d55c53b1b6819e6c4c72f1 +Subproject commit 16102b14075c61491bf4a46f79672ea687413d53