Skip to content

Commit

Permalink
refactor: centralize edge_orchestrator conf as JSON only
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste O'Jeanson committed Aug 2, 2023
1 parent b9748b8 commit 7ff8d49
Show file tree
Hide file tree
Showing 50 changed files with 810 additions and 316 deletions.
Empty file.
23 changes: 22 additions & 1 deletion edge_orchestrator/config/inventory.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
{
"binary_storages": [
"azure_container",
"filesystem",
"gcp_bucket",
"in_memory"
],
"cameras": [
"fake",
"pi_camera",
"usb_camera"
],
"metadata_storages": [
"azure_container",
"filesystem",
"gcp_bucket",
"in_memory",
"mongo_db"
],
"model_forwards": [
"fake",
"tf_serving"
],
"telemetry_sinks": [
"azure_iot_hub",
"fake",
"postgresql"
],
"models": {
"inception": {
"category": "classification",
Expand Down Expand Up @@ -56,7 +78,6 @@
640
],
"objectness_threshold": 0.5

},
"mobilenet_ssd_v2_coco": {
"category": "object_detection",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{
"binary_storage": {
"type": "filesystem",
"params": {
"src_directory": "/tmp/vio/edge_orchestrator/data/storage"
}
},
"metadata_storage": {
"type": "filesystem"
},
"model_forward": {
"type": "fake"
},
"telemetry_sink": {
"type": "fake"
},
"cameras": {
"camera_id4": {
"camera_#1": {
"type": "fake",
"source": "marker_images",
"position": "back",
"exposition": 100,
"models_graph": {
"model_id4": {
"model_#4": {
"metadata": "marker_quality_control",
"depends_on": []
}
},
"camera_rule": {
"name": "expected_label_rule",
"parameters": {
"expected_label": ["OK"]
"expected_label": [
"OK"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
{
"binary_storage": {
"type": "filesystem",
"params": {
"src_directory": "/tmp/vio/edge_orchestrator/data/storage"
}
},
"metadata_storage": {
"type": "filesystem"
},
"model_forward": {
"type": "fake"
},
"telemetry_sink": {
"type": "fake"
},
"cameras": {
"camera_id3": {
"camera_#1": {
"type": "fake",
"source": "marker_images",
"position": "back",
Expand All @@ -14,11 +29,13 @@
"camera_rule": {
"name": "expected_label_rule",
"parameters": {
"expected_label": ["OK"]
"expected_label": [
"OK"
]
}
}
},
"camera_id4": {
"camera_#4": {
"type": "fake",
"source": "marker_images",
"position": "back",
Expand All @@ -32,7 +49,9 @@
"camera_rule": {
"name": "expected_label_rule",
"parameters": {
"expected_label": ["OK"]
"expected_label": [
"OK"
]
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion edge_orchestrator/edge_orchestrator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from edge_orchestrator.application.server import server

if __name__ == "__main__":

def main():
orchestrator_app = server()
uvicorn.run(orchestrator_app, host="0.0.0.0", port=8000, log_level="info")


if __name__ == "__main__":
main()
185 changes: 113 additions & 72 deletions edge_orchestrator/edge_orchestrator/api_config.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,126 @@
import os

from edge_orchestrator import logger


def load_config():
configuration = os.environ.get("API_CONFIG", "default")
logger.info(f"App running with configuration: {configuration}")

available_configurations = [
"test",
"docker",
"default",
"edge",
"edge-lite",
"upload-gcp",
]
if configuration not in available_configurations:
raise ValueError(
f"Unknown configuration '{configuration}'. "
f"Valid configurations are {available_configurations}."
from functools import lru_cache
from pathlib import Path

from application.config import get_settings
from edge_orchestrator.domain.models.edge_station import EdgeStation
from edge_orchestrator.domain.ports.binary_storage import BinaryStorage
from edge_orchestrator.domain.ports.inventory import Inventory
from edge_orchestrator.domain.ports.metadata_storage import MetadataStorage
from edge_orchestrator.domain.ports.model_forward import ModelForward
from edge_orchestrator.domain.ports.station_config import StationConfig
from edge_orchestrator.domain.ports.telemetry_sink import TelemetrySink
from edge_orchestrator.domain.use_cases.supervisor import Supervisor
from edge_orchestrator.domain.use_cases.uploader import Uploader
from edge_orchestrator.infrastructure.binary_storage.binary_storage_factory import (
BinaryStorageFactory,
)
from edge_orchestrator.infrastructure.inventory.json_inventory import JsonInventory
from edge_orchestrator.infrastructure.metadata_storage.metadata_storage_factory import (
MetadataStorageFactory,
)
from edge_orchestrator.infrastructure.model_forward.model_forward_factory import (
ModelForwardFactory,
)
from edge_orchestrator.infrastructure.station_config.json_station_config import (
JsonStationConfig,
)
from edge_orchestrator.infrastructure.telemetry_sink.telemetry_sink_factory import (
TelemetrySinkFactory,
)


@lru_cache()
def get_supervisor() -> Supervisor:
return Supervisor(
get_binary_storage(),
get_edge_station(),
get_metadata_storage(),
get_model_forward(),
get_station_config(),
get_telemetry_sink(),
)


@lru_cache()
def get_uploader() -> Uploader:
return Uploader(
get_metadata_storage(),
get_binary_storage(),
)


def _get_active_config_name(active_config_path: Path) -> str:
if active_config_path.exists():
with open(active_config_path, "r") as active_config:
return active_config.read().strip()
else:
return "no_active_configuration"


@lru_cache()
def get_inventory() -> Inventory:
return JsonInventory(get_settings().inventory_path)


@lru_cache()
def get_station_config(
try_setting_station_config_from_file: bool = True,
) -> StationConfig:
settings = get_settings()
station_config = JsonStationConfig(
settings.station_configs_folder, get_inventory(), settings.data_folder
)
if try_setting_station_config_from_file:
station_config = set_station_config_from_file(
station_config, settings.active_config_path
)
elif configuration == "test":
from edge_orchestrator.environment.test import Test
return station_config

configuration_class = Test
elif configuration == "docker":
from edge_orchestrator.environment.docker import Docker

configuration_class = Docker
elif configuration == "default":
from edge_orchestrator.environment.default import Default

configuration_class = Default
elif configuration == "edge":
from edge_orchestrator.environment.edge_with_mongo_db_metadata_storage import (
EdgeWithMongoDbMetadataStorage,
)

configuration_class = EdgeWithMongoDbMetadataStorage
elif configuration == "edge-lite":
from edge_orchestrator.environment.edge_with_azure_container_storage import (
EdgeWithAzureContainerStorage,
)

configuration_class = EdgeWithAzureContainerStorage
elif configuration == "upload-gcp":
from edge_orchestrator.environment.upload_with_gcp_bucket import (
UploadWithGCPBucket,
)

configuration_class = UploadWithGCPBucket

return configuration_class()


config = load_config()


def get_metadata_storage():
return config.get_metadata_storage()


def get_binary_storage():
return config.get_binary_storage()
def set_station_config_from_file(
station_config: StationConfig, active_config_path: Path
) -> StationConfig:
active_config_name = _get_active_config_name(active_config_path)
station_config.set_station_config(active_config_name)
return station_config


def get_model_forward():
return config.get_model_forward()
@lru_cache()
def get_binary_storage() -> BinaryStorage:
station_config = get_station_config()
return BinaryStorageFactory.get_binary_storage(
station_config.active_config["binary_storage"].get("type"),
**station_config.active_config["binary_storage"].get("params", {}),
)


def get_inventory():
return config.get_inventory()
@lru_cache()
def get_metadata_storage() -> MetadataStorage:
station_config = get_station_config()
return MetadataStorageFactory.get_metadata_storage(
station_config.active_config["metadata_storage"]["type"],
**station_config.active_config["metadata_storage"].get("params", {}),
)


def get_station_config():
return config.get_station_config()
@lru_cache()
def get_edge_station() -> EdgeStation:
return EdgeStation(get_station_config())


def get_edge_station():
return config.get_edge_station()
@lru_cache()
def get_model_forward() -> ModelForward:
station_config = get_station_config()
return ModelForwardFactory.get_model_forward(
station_config.active_config["model_forward"]["type"],
**station_config.active_config["model_forward"].get("params", {}),
)


def get_telemetry_sink():
return config.get_telemetry_sink()
@lru_cache()
def get_telemetry_sink() -> TelemetrySink:
station_config = get_station_config()
return TelemetrySinkFactory.get_telemetry_sink(
station_config.active_config["telemetry_sink"]["type"],
**station_config.active_config["telemetry_sink"].get("params", {}),
)
Loading

0 comments on commit 7ff8d49

Please sign in to comment.