-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: centralize edge_orchestrator conf as JSON only
- Loading branch information
Baptiste O'Jeanson
committed
Aug 2, 2023
1 parent
b9748b8
commit 7ff8d49
Showing
50 changed files
with
810 additions
and
316 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
edge_orchestrator/config/station_configs/marker_classification_with_1_fake_camera.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", {}), | ||
) |
Oops, something went wrong.