Skip to content

Commit 4590053

Browse files
authored
libfaasm: add support for general S3 API (#126)
* libfaasm: add support for general s3 API * s3: add function to get number of buckets * s3: add remaining basic functions * nits: run clang-format * gh: bump minor code version * libfaasm: remove un-implemented symbols * s3: temporarily commit the workflow functions * wc: more functions * s3: untrack wc functions * s3: build functions as part of gha * func(demo): update chain_output function for new signature * func: separate threaded/non-threaded targets
1 parent 4d9f40c commit 4590053

File tree

17 files changed

+283
-16
lines changed

17 files changed

+283
-16
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SYSROOT_VERSION=0.5.0
2-
SYSROOT_CLI_IMAGE=faasm.azurecr.io/cpp-sysroot:0.5.0
1+
SYSROOT_VERSION=0.6.0
2+
SYSROOT_CLI_IMAGE=faasm.azurecr.io/cpp-sysroot:0.6.0
33
COMPOSE_PROJECT_NAME=cpp-dev

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
if: github.event.pull_request.draft == false
1818
runs-on: ubuntu-latest
1919
container:
20-
image: faasm.azurecr.io/cpp-sysroot:0.5.0
20+
image: faasm.azurecr.io/cpp-sysroot:0.6.0
2121
steps:
2222
# --- Update code ---
2323
- name: "Checkout code"

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.0
1+
0.6.0

func/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ add_subdirectory(dynlink)
7474
add_subdirectory(errors)
7575
add_subdirectory(mpi)
7676
add_subdirectory(omp)
77+
add_subdirectory(s3)
7778
add_subdirectory(threads)

func/demo/chain_output.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,37 @@ int main(int argc, char* argv[])
2626
unsigned int callIdB = faasmChain(otherB, nullptr, 0);
2727

2828
std::string expectedA = "expected A";
29-
std::string actualA;
30-
actualA.reserve(expectedA.size());
3129

3230
std::string expectedB = "longer expected B";
33-
std::string actualB;
34-
actualB.reserve(expectedB.size());
3531

32+
std::string actualA;
33+
char* actualABuf;
34+
int actualABufSize;
3635
unsigned int resA =
37-
faasmAwaitCallOutput(callIdA, actualA.c_str(), actualA.size());
36+
faasmAwaitCallOutput(callIdA, &actualABuf, &actualABufSize);
37+
actualA.assign(actualABuf, actualABuf + actualABufSize);
38+
39+
std::string actualB;
40+
char* actualBBuf;
41+
int actualBBufSize;
3842
unsigned int resB =
39-
faasmAwaitCallOutput(callIdB, actualB.c_str(), actualB.size());
43+
faasmAwaitCallOutput(callIdB, &actualBBuf, &actualBBufSize);
44+
actualB.assign(actualBBuf, actualBBuf + actualBBufSize);
4045

4146
if (resA != 0 || resB != 0) {
4247
printf("One or more chained calls failed: %i %i\n", resA, resB);
4348
return 1;
4449
}
4550

4651
if (actualA != expectedA) {
52+
printf(
53+
"Output mismatch: %s != %s\n", actualA.c_str(), expectedA.c_str());
4754
return 1;
4855
}
4956

5057
if (actualB != expectedB) {
58+
printf(
59+
"Output mismatch: %s != %s\n", actualB.c_str(), expectedB.c_str());
5160
return 1;
5261
}
5362

func/s3/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(FAASM_USER s3)
2+
3+
function(s3_func exec_name dir_path)
4+
faasm_func(${exec_name} ${dir_path})
5+
set(ALL_DEMO_FUNCS ${ALL_DEMO_FUNCS} ${exec_name} PARENT_SCOPE)
6+
endfunction(s3_func)
7+
8+
s3_func(get_num_buckets get_num_buckets.cpp)
9+
s3_func(list_buckets list_buckets.cpp)
10+
s3_func(get_num_keys get_num_keys.cpp)
11+
s3_func(list_keys list_keys.cpp)
12+
s3_func(add_key_bytes add_key_bytes.cpp)
13+
s3_func(get_key_bytes get_key_bytes.cpp)
14+
15+
# Custom target to group all the demo functions
16+
add_custom_target(s3_all_funcs DEPENDS ${ALL_DEMO_FUNCS})

func/s3/add_key_bytes.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern "C"
2+
{
3+
#include "faasm/host_interface.h"
4+
}
5+
6+
#include <faasm/faasm.h>
7+
#include <stdio.h>
8+
9+
int main(int argc, char* argv[])
10+
{
11+
// Get bucket and key from command line
12+
if (argc != 3) {
13+
printf("error: must invoke function with two arguments: bucketName "
14+
"keyName\n");
15+
return 1;
16+
}
17+
18+
char* bucketName = argv[1];
19+
char* keyName = argv[2];
20+
21+
// Get the bytes to add as input
22+
int inputSize = faasmGetInputSize();
23+
uint8_t keyBytes[inputSize];
24+
faasmGetInput(keyBytes, inputSize);
25+
26+
int ret =
27+
__faasm_s3_add_key_bytes(bucketName, keyName, (void*)keyBytes, inputSize);
28+
29+
return ret;
30+
}

func/s3/get_key_bytes.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern "C"
2+
{
3+
#include "faasm/host_interface.h"
4+
}
5+
6+
#include <faasm/faasm.h>
7+
#include <stdio.h>
8+
9+
int main(int argc, char* argv[])
10+
{
11+
// Get bucket and key from command line
12+
if (argc != 3) {
13+
printf("error: must invoke function with two arguments: bucketName "
14+
"keyName\n");
15+
return 1;
16+
}
17+
18+
char* bucketName = argv[1];
19+
char* keyName = argv[2];
20+
21+
uint8_t* keyBytes;
22+
int keyBytesLen;
23+
24+
int ret =
25+
__faasm_s3_get_key_bytes(bucketName, keyName, &keyBytes, &keyBytesLen);
26+
printf("Got %s/%s: %s\n", bucketName, keyName, (char*)keyBytes);
27+
faasmSetOutput((char*)keyBytes, keyBytesLen);
28+
29+
return ret;
30+
}

func/s3/get_num_buckets.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extern "C"
2+
{
3+
#include "faasm/host_interface.h"
4+
}
5+
6+
#include <faasm/faasm.h>
7+
#include <stdio.h>
8+
#include <string>
9+
10+
int main(int argc, char* argv[])
11+
{
12+
int numBuckets = __faasm_s3_get_num_buckets();
13+
14+
printf("Got %i buckets!\n", numBuckets);
15+
16+
std::string numBucketsStr = std::to_string(numBuckets);
17+
faasmSetOutput(numBucketsStr.c_str(), numBucketsStr.size());
18+
19+
return 0;
20+
}

func/s3/get_num_keys.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
extern "C"
2+
{
3+
#include "faasm/host_interface.h"
4+
}
5+
6+
#include <faasm/faasm.h>
7+
#include <stdio.h>
8+
#include <string>
9+
10+
int main(int argc, char* argv[])
11+
{
12+
// Get the bucket name as an input
13+
int inputSize = faasmGetInputSize();
14+
char bucketName[inputSize];
15+
faasmGetInput((uint8_t*)bucketName, inputSize);
16+
17+
int numKeys = __faasm_s3_get_num_keys(bucketName);
18+
19+
printf("Bucket %s has %i keys!\n", bucketName, numKeys);
20+
21+
std::string numKeysStr = std::to_string(numKeys);
22+
faasmSetOutput(numKeysStr.c_str(), numKeysStr.size());
23+
24+
return 0;
25+
}

0 commit comments

Comments
 (0)