Skip to content

Commit 5409e67

Browse files
added wrappers and updated knative functions
Signed-off-by: Abhishek Kumar <abhishek22512@gmail.com>
1 parent f74a2df commit 5409e67

File tree

8 files changed

+231
-42
lines changed

8 files changed

+231
-42
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import logging
2+
import datetime
3+
from flask import jsonify
4+
from parliament import Context
5+
from function import handler
6+
7+
8+
def main(context: Context):
9+
logging.getLogger().setLevel(logging.INFO)
10+
begin = datetime.datetime.now()
11+
12+
try:
13+
# Extract JSON data from the request
14+
event = context.request.json
15+
print(f"Received event: {event}")
16+
17+
# Pass the extracted JSON data to the handler function
18+
ret = handler(event)
19+
end = datetime.datetime.now()
20+
logging.info(f"Function result: {ret}")
21+
results_time = (end - begin) / datetime.timedelta(microseconds=1)
22+
23+
response = {
24+
"begin": begin.strftime("%s.%f"),
25+
"end": end.strftime("%s.%f"),
26+
"results_time": results_time,
27+
"result": ret,
28+
}
29+
30+
return jsonify(response), 200
31+
32+
except Exception as e:
33+
end = datetime.datetime.now()
34+
results_time = (end - begin) / datetime.timedelta(microseconds=1)
35+
logging.error(f"Error - invocation failed! Reason: {e}")
36+
response = {
37+
"begin": begin.strftime("%s.%f"),
38+
"end": end.strftime("%s.%f"),
39+
"results_time": results_time,
40+
"result": f"Error - invocation failed! Reason: {e}",
41+
}
42+
return jsonify(response), 500

benchmarks/wrappers/knative/python/storage.py

Whitespace-only changes.

config/systems.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
"username": "docker_user",
250250
"deployment": {
251251
"files": [
252-
"handler.py",
252+
"func.py",
253253
"storage.py"
254254
],
255255
"packages": {
@@ -269,8 +269,8 @@
269269
"username": "docker_user",
270270
"deployment": {
271271
"files": [
272-
"handler.js",
273-
"storage.js"
272+
"",
273+
""
274274
],
275275
"packages": []
276276
}

sebs/knative/config.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Resour
101101
# Check for new config
102102
if "storage" in config:
103103
ret._storage = MinioConfig.deserialize(config["storage"])
104-
ret.logging.info("Using user-provided configuration of storage for Knative.")
104+
ret.logging.info(
105+
"Using user-provided configuration of storage for Knative."
106+
)
105107

106108
# check if there has been an update
107109
if not (
@@ -122,21 +124,26 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Resour
122124
and "resources" in cached_config
123125
and "storage" in cached_config["resources"]
124126
):
125-
ret._storage = MinioConfig.deserialize(cached_config["resources"]["storage"])
127+
ret._storage = MinioConfig.deserialize(
128+
cached_config["resources"]["storage"]
129+
)
126130
ret.logging.info("Using cached configuration of storage for Knative.")
127131

128132
return ret
129133

130134
def update_cache(self, cache: Cache):
131135
super().update_cache(cache)
132136
cache.update_config(
133-
val=self.docker_registry, keys=["knative", "resources", "docker", "registry"]
137+
val=self.docker_registry,
138+
keys=["knative", "resources", "docker", "registry"],
134139
)
135140
cache.update_config(
136-
val=self.docker_username, keys=["knative", "resources", "docker", "username"]
141+
val=self.docker_username,
142+
keys=["knative", "resources", "docker", "username"],
137143
)
138144
cache.update_config(
139-
val=self.docker_password, keys=["knative", "resources", "docker", "password"]
145+
val=self.docker_password,
146+
keys=["knative", "resources", "docker", "password"],
140147
)
141148
if self._storage:
142149
self._storage.update_cache(["knative", "resources", "storage"], cache)

sebs/knative/function.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sebs.faas.function import Function, FunctionConfig, Runtime
88
from sebs.storage.config import MinioConfig
99

10+
1011
@dataclass
1112
class KnativeFunctionConfig(FunctionConfig):
1213
docker_image: str = ""
@@ -31,9 +32,14 @@ def from_benchmark(benchmark: Benchmark) -> KnativeFunctionConfig:
3132
benchmark, KnativeFunctionConfig
3233
)
3334

35+
3436
class KnativeFunction(Function):
3537
def __init__(
36-
self, name: str, benchmark: str, code_package_hash: str, cfg: KnativeFunctionConfig
38+
self,
39+
name: str,
40+
benchmark: str,
41+
code_package_hash: str,
42+
cfg: KnativeFunctionConfig,
3743
):
3844
super().__init__(benchmark, name, code_package_hash, cfg)
3945

@@ -55,12 +61,17 @@ def deserialize(cached_config: dict) -> KnativeFunction:
5561

5662
cfg = KnativeFunctionConfig.deserialize(cached_config["config"])
5763
ret = KnativeFunction(
58-
cached_config["name"], cached_config["benchmark"], cached_config["hash"], cfg
64+
cached_config["name"],
65+
cached_config["benchmark"],
66+
cached_config["hash"],
67+
cfg,
5968
)
6069
for trigger in cached_config["triggers"]:
6170
trigger_type = cast(
6271
Trigger,
63-
{"Library": KnativeLibraryTrigger, "HTTP": KnativeHTTPTrigger}.get(trigger["type"]),
72+
{"Library": KnativeLibraryTrigger, "HTTP": KnativeHTTPTrigger}.get(
73+
trigger["type"]
74+
),
6475
)
6576
assert trigger_type, "Unknown trigger type {}".format(trigger["type"])
6677
ret.add_trigger(trigger_type.deserialize(trigger))

0 commit comments

Comments
 (0)