Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <[email protected]>
  • Loading branch information
octonawish-akcodes committed Jul 2, 2024
1 parent fca8fa2 commit 68b7d33
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 424 deletions.
4 changes: 3 additions & 1 deletion config/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@
"handler.py",
"storage.py"
],
"packages": []
"packages": {
"parliament-functions": "0.1.0"
}
}
},
"nodejs": {
Expand Down
30 changes: 0 additions & 30 deletions sebs/knative/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
from typing import cast, Optional


class KnativeCredentials(Credentials):
@staticmethod
def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Credentials:
return KnativeCredentials()

def serialize(self) -> dict:
return {}


class KnativeResources(Resources):
def __init__(
self,
Expand Down Expand Up @@ -164,24 +155,14 @@ def serialize(self) -> dict:

class KnativeConfig(Config):
name: str
shutdownStorage: bool
cache: Cache

def __init__(self, config: dict, cache: Cache):
super().__init__(name="knative")
self._credentials = KnativeCredentials()
self._resources = KnativeResources()
self.shutdownStorage = config["shutdownStorage"]
self.removeCluster = config["removeCluster"]
self.knative_exec = config["knativeExec"]
self.knative_bypass_security = config["knativeBypassSecurity"]
self.experimentalManifest = config["experimentalManifest"]
self.cache = cache

@property
def credentials(self) -> KnativeCredentials:
return self._credentials

@property
def resources(self) -> KnativeResources:
return self._resources
Expand All @@ -194,12 +175,7 @@ def serialize(self) -> dict:
return {
"name": self._name,
"region": self._region,
"shutdownStorage": self.shutdownStorage,
"removeCluster": self.removeCluster,
"knativeExec": self.knative_exec,
"knativeBypassSecurity": self.knative_bypass_security,
"experimentalManifest": self.experimentalManifest,
"credentials": self._credentials.serialize(),
"resources": self._resources.serialize(),
}

Expand All @@ -216,11 +192,5 @@ def deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) -> Config
return res

def update_cache(self, cache: Cache):
cache.update_config(val=self.shutdownStorage, keys=["knative", "shutdownStorage"])
cache.update_config(val=self.removeCluster, keys=["knative", "removeCluster"])
cache.update_config(val=self.knative_exec, keys=["knative", "knativeExec"])
cache.update_config(val=self.knative_bypass_security, keys=["knative", "knativeBypassSecurity"])
cache.update_config(
val=self.experimentalManifest, keys=["knative", "experimentalManifest"]
)
self.resources.update_cache(cache)
93 changes: 6 additions & 87 deletions sebs/knative/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,142 +6,61 @@
from sebs.benchmark import Benchmark
from sebs.faas.function import Function, FunctionConfig, Runtime
from sebs.storage.config import MinioConfig
from sebs.knative.trigger import LibraryTrigger, HTTPTrigger


@dataclass
class KnativeFunctionConfig(FunctionConfig):
"""
Configuration class for Knative function specific configurations.
Attributes:
docker_image (str): Docker image for the function.
namespace (str): Kubernetes namespace where the function is deployed (default is 'default').
storage (Optional[MinioConfig]): Optional MinioConfig object for storage configuration.
"""

docker_image: str = ""
namespace: str = "default"
storage: Optional[MinioConfig] = None
url: str = ""

@staticmethod
def deserialize(data: dict) -> KnativeFunctionConfig:
"""
Deserialize data from dictionary into KnativeFunctionConfig object.
Args:
data (dict): Dictionary containing serialized data.
Returns:
KnativeFunctionConfig: Deserialized KnativeFunctionConfig object.
"""
keys = list(KnativeFunctionConfig.__dataclass_fields__.keys())
data = {k: v for k, v in data.items() if k in keys}
data["runtime"] = Runtime.deserialize(data["runtime"])
if "storage" in data:
data["storage"] = MinioConfig.deserialize(data["storage"])
data["storage"] = MinioConfig.deserialize(data["storage"])
return KnativeFunctionConfig(**data)

def serialize(self) -> dict:
"""
Serialize KnativeFunctionConfig object into dictionary.
Returns:
dict: Dictionary containing serialized data.
"""
return self.__dict__

@staticmethod
def from_benchmark(benchmark: Benchmark) -> KnativeFunctionConfig:
"""
Create KnativeFunctionConfig object from a benchmark.
Args:
benchmark (Benchmark): Benchmark object.
Returns:
KnativeFunctionConfig: Initialized KnativeFunctionConfig object.
"""
return super(KnativeFunctionConfig, KnativeFunctionConfig)._from_benchmark(
benchmark, KnativeFunctionConfig
)


class KnativeFunction(Function):
"""
Class representing a Knative function.
Attributes:
name (str): Name of the function.
benchmark (str): Benchmark associated with the function.
code_package_hash (str): Hash of the code package associated with the function.
cfg (KnativeFunctionConfig): Configuration object for the function.
"""

def __init__(
self, name: str, benchmark: str, code_package_hash: str, cfg: KnativeFunctionConfig
):
"""
Initialize KnativeFunction object.
Args:
name (str): Name of the function.
benchmark (str): Benchmark associated with the function.
code_package_hash (str): Hash of the code package associated with the function.
cfg (KnativeFunctionConfig): Configuration object for the function.
"""
super().__init__(benchmark, name, code_package_hash, cfg)

@property
def config(self) -> KnativeFunctionConfig:
"""
Get the configuration object of the function.
Returns:
KnativeFunctionConfig: Configuration object of the function.
"""
return cast(KnativeFunctionConfig, self._cfg)

@staticmethod
def typename() -> str:
"""
Return the typename of the KnativeFunction class.
Returns:
str: Typename of the KnativeFunction class.
"""
return "Knative.Function"

def serialize(self) -> dict:
"""
Serialize KnativeFunction object into dictionary.
Returns:
dict: Dictionary containing serialized data.
"""
serialized_data = super().serialize()
serialized_data["config"] = self._cfg.serialize()
return serialized_data
return {**super().serialize(), "config": self._cfg.serialize()}

@staticmethod
def deserialize(cached_config: dict) -> KnativeFunction:
"""
Deserialize dictionary into KnativeFunction object.
Args:
cached_config (dict): Dictionary containing serialized data.
from sebs.faas.function import Trigger
from sebs.knative.triggers import KnativeLibraryTrigger, KnativeHTTPTrigger

Returns:
KnativeFunction: Deserialized KnativeFunction object.
"""
cfg = KnativeFunctionConfig.deserialize(cached_config["config"])
ret = KnativeFunction(
cached_config["name"], cached_config["benchmark"], cached_config["hash"], cfg
)
for trigger in cached_config["triggers"]:
trigger_type = cast(
Trigger,
{"Library": LibraryTrigger, "HTTP": HTTPTrigger}.get(trigger["type"]),
{"Library": KnativeLibraryTrigger, "HTTP": KnativeHTTPTrigger}.get(trigger["type"]),
)
assert trigger_type, "Unknown trigger type {}".format(trigger["type"])
ret.add_trigger(trigger_type.deserialize(trigger))
Expand Down
Loading

0 comments on commit 68b7d33

Please sign in to comment.