Loading edge_cloud_management_api/controllers/app_controllers.py +55 −44 Original line number Diff line number Diff line Loading @@ -248,17 +248,24 @@ def create_app_instance(): else first_zone ) edge_cloud_zone_id = None edge_cloud_provider = None if isinstance(zone_payload, dict): edge_cloud_zone_id = zone_payload.get("edgeCloudZoneId") or zone_payload.get("zoneId") edge_cloud_provider = zone_payload.get("edgeCloudProvider") zone = get_zone(edge_cloud_zone_id) if edge_cloud_zone_id else None zone = get_zone(edge_cloud_zone_id, edge_cloud_provider) if edge_cloud_zone_id else None if not zone and edge_cloud_zone_id: try: zones = pi_edge_client.edge_cloud_zones() if isinstance(zones, list): for z in zones: if isinstance(z, dict) and z.get("edgeCloudZoneId") == edge_cloud_zone_id: z["_id"] = edge_cloud_zone_id if not isinstance(z, dict): continue if z.get("edgeCloudZoneId") != edge_cloud_zone_id: continue if edge_cloud_provider and z.get("edgeCloudProvider") != edge_cloud_provider: continue if z.get("edgeCloudProvider") == edge_cloud_provider or not edge_cloud_provider: z["isLocal"] = "true" insert_zones([z]) zone = z Loading @@ -268,10 +275,9 @@ def create_app_instance(): if not zone and edge_cloud_zone_id and isinstance(zone_payload, dict): zone_payload = dict(zone_payload) zone_payload["_id"] = edge_cloud_zone_id zone_payload.setdefault("isLocal", "true") insert_zones([zone_payload]) zone = zone_payload zone = get_zone(edge_cloud_zone_id, edge_cloud_provider) or zone_payload if not zone: return jsonify({ Loading Loading @@ -302,7 +308,7 @@ def create_app_instance(): # Step 2: Compose GSMA artefact payload # artefactId == appId (INTENTIONAL) # ============================================================ artefact_id = app_id artefact_id = None app_provider_id = appData.get("appProvider") or appData.get("appProviderId") app_name = appData.get("name") or appData.get("appName") or app_id app_version = appData.get("version") or "v1" Loading @@ -312,10 +318,15 @@ def create_app_instance(): image_path = app_repo.get("imagePath") repo_type = app_repo.get("type", "PUBLICREPO") component_specs = appData.get("componentSpec", []) app_component_specs = appData.get("appComponentSpecs", []) if isinstance(app_component_specs, list) and app_component_specs: artefact_id = app_component_specs[0].get("artefactId") component_name = None if component_specs and isinstance(component_specs, list): component_name = component_specs[0].get("componentName") component_name = component_name or app_name if not artefact_id: artefact_id = str(uuid.uuid5(uuid.NAMESPACE_URL, str(app_id))) service_name_nb = _ensure_service_name( (component_specs[0].get("serviceNameNB") if component_specs else None), Loading edge_cloud_management_api/controllers/edge_cloud_controller.py +15 −8 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ try: api_client = pi_edge_factory.create_pi_edge_api_client() zones = api_client.edge_cloud_zones() for zone in zones: zone['_id'] = zone.get('edgeCloudZoneId') zone['isLocal'] = 'true' insert_zones(zones) except Exception as e: Loading Loading @@ -77,15 +76,23 @@ def get_cached_zones() -> list[dict]: except Exception as e: logger.warning("Failed to read cached zones: %s", e) merged = list(cached or []) existing_ids = { zone.get("edgeCloudZoneId") for zone in merged if isinstance(zone, dict) } merged = [] existing_zone_keys = set() for zone in cached or []: if not isinstance(zone, dict): continue zone_key = (zone.get("edgeCloudProvider"), zone.get("edgeCloudZoneId")) if zone_key in existing_zone_keys: continue merged.append(zone) existing_zone_keys.add(zone_key) for zone in get_local_zones(): zone_id = zone.get("edgeCloudZoneId") if isinstance(zone, dict) else None if zone_id and zone_id not in existing_ids: zone_key = None if isinstance(zone, dict): zone_key = (zone.get("edgeCloudProvider"), zone.get("edgeCloudZoneId")) if zone_key and zone_key not in existing_zone_keys: merged.append(zone) existing_ids.add(zone_id) existing_zone_keys.add(zone_key) return merged def get_all_cloud_zones() -> List[EdgeCloudZone]: Loading edge_cloud_management_api/controllers/federation_manager_controller.py +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ def create_federation(): accepted_availability_zones = [] for zone in av_zones or []: if isinstance(zone, dict) and zone.get("zoneId"): accepted_availability_zones.append({"zoneId": zone.get("zoneId")}) accepted_availability_zones.append(zone.get("zoneId")) if accepted_availability_zones: zone_response, zone_code = federation_client.subscribe_to_zones( response.get("federationContextId"), Loading edge_cloud_management_api/services/storage_service.py +25 −3 Original line number Diff line number Diff line Loading @@ -4,18 +4,40 @@ import pymongo storage_url = mongo_host = config.MONGO_URI mydb_mongo = 'oeg_storage' def _zone_storage_id(zone: dict): provider = zone.get('edgeCloudProvider') or 'unknown' zone_id = zone.get('edgeCloudZoneId') or zone.get('zoneId') if not zone_id: return zone.get('_id') return f"{provider}::{zone_id}" def insert_zones(zone_list: list): collection = "zones" myclient = pymongo.MongoClient(storage_url) mydbmongo = myclient[mydb_mongo] col = mydbmongo[collection] col.insert_many(zone_list) for zone in zone_list: normalized_zone = dict(zone) normalized_zone['_id'] = _zone_storage_id(normalized_zone) col.replace_one({'_id': normalized_zone['_id']}, normalized_zone, upsert=True) def get_zone(zone_id: str): def get_zone(zone_id: str, provider: str | None = None): collection = "zones" myclient = pymongo.MongoClient(storage_url) mydbmongo = myclient[mydb_mongo] col = mydbmongo[collection] query = {'edgeCloudZoneId': zone_id} if provider: query['edgeCloudProvider'] = provider zone = col.find_one(query) else: zone = col.find_one({**query, 'isLocal': 'true'}) if zone is None: zone = col.find_one(query) if zone is None and provider: zone = col.find_one({'_id': f"{provider}::{zone_id}"}) if zone is None and not provider: zone = col.find_one({'_id': zone_id}) return zone Loading Loading
edge_cloud_management_api/controllers/app_controllers.py +55 −44 Original line number Diff line number Diff line Loading @@ -248,17 +248,24 @@ def create_app_instance(): else first_zone ) edge_cloud_zone_id = None edge_cloud_provider = None if isinstance(zone_payload, dict): edge_cloud_zone_id = zone_payload.get("edgeCloudZoneId") or zone_payload.get("zoneId") edge_cloud_provider = zone_payload.get("edgeCloudProvider") zone = get_zone(edge_cloud_zone_id) if edge_cloud_zone_id else None zone = get_zone(edge_cloud_zone_id, edge_cloud_provider) if edge_cloud_zone_id else None if not zone and edge_cloud_zone_id: try: zones = pi_edge_client.edge_cloud_zones() if isinstance(zones, list): for z in zones: if isinstance(z, dict) and z.get("edgeCloudZoneId") == edge_cloud_zone_id: z["_id"] = edge_cloud_zone_id if not isinstance(z, dict): continue if z.get("edgeCloudZoneId") != edge_cloud_zone_id: continue if edge_cloud_provider and z.get("edgeCloudProvider") != edge_cloud_provider: continue if z.get("edgeCloudProvider") == edge_cloud_provider or not edge_cloud_provider: z["isLocal"] = "true" insert_zones([z]) zone = z Loading @@ -268,10 +275,9 @@ def create_app_instance(): if not zone and edge_cloud_zone_id and isinstance(zone_payload, dict): zone_payload = dict(zone_payload) zone_payload["_id"] = edge_cloud_zone_id zone_payload.setdefault("isLocal", "true") insert_zones([zone_payload]) zone = zone_payload zone = get_zone(edge_cloud_zone_id, edge_cloud_provider) or zone_payload if not zone: return jsonify({ Loading Loading @@ -302,7 +308,7 @@ def create_app_instance(): # Step 2: Compose GSMA artefact payload # artefactId == appId (INTENTIONAL) # ============================================================ artefact_id = app_id artefact_id = None app_provider_id = appData.get("appProvider") or appData.get("appProviderId") app_name = appData.get("name") or appData.get("appName") or app_id app_version = appData.get("version") or "v1" Loading @@ -312,10 +318,15 @@ def create_app_instance(): image_path = app_repo.get("imagePath") repo_type = app_repo.get("type", "PUBLICREPO") component_specs = appData.get("componentSpec", []) app_component_specs = appData.get("appComponentSpecs", []) if isinstance(app_component_specs, list) and app_component_specs: artefact_id = app_component_specs[0].get("artefactId") component_name = None if component_specs and isinstance(component_specs, list): component_name = component_specs[0].get("componentName") component_name = component_name or app_name if not artefact_id: artefact_id = str(uuid.uuid5(uuid.NAMESPACE_URL, str(app_id))) service_name_nb = _ensure_service_name( (component_specs[0].get("serviceNameNB") if component_specs else None), Loading
edge_cloud_management_api/controllers/edge_cloud_controller.py +15 −8 Original line number Diff line number Diff line Loading @@ -13,7 +13,6 @@ try: api_client = pi_edge_factory.create_pi_edge_api_client() zones = api_client.edge_cloud_zones() for zone in zones: zone['_id'] = zone.get('edgeCloudZoneId') zone['isLocal'] = 'true' insert_zones(zones) except Exception as e: Loading Loading @@ -77,15 +76,23 @@ def get_cached_zones() -> list[dict]: except Exception as e: logger.warning("Failed to read cached zones: %s", e) merged = list(cached or []) existing_ids = { zone.get("edgeCloudZoneId") for zone in merged if isinstance(zone, dict) } merged = [] existing_zone_keys = set() for zone in cached or []: if not isinstance(zone, dict): continue zone_key = (zone.get("edgeCloudProvider"), zone.get("edgeCloudZoneId")) if zone_key in existing_zone_keys: continue merged.append(zone) existing_zone_keys.add(zone_key) for zone in get_local_zones(): zone_id = zone.get("edgeCloudZoneId") if isinstance(zone, dict) else None if zone_id and zone_id not in existing_ids: zone_key = None if isinstance(zone, dict): zone_key = (zone.get("edgeCloudProvider"), zone.get("edgeCloudZoneId")) if zone_key and zone_key not in existing_zone_keys: merged.append(zone) existing_ids.add(zone_id) existing_zone_keys.add(zone_key) return merged def get_all_cloud_zones() -> List[EdgeCloudZone]: Loading
edge_cloud_management_api/controllers/federation_manager_controller.py +1 −1 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ def create_federation(): accepted_availability_zones = [] for zone in av_zones or []: if isinstance(zone, dict) and zone.get("zoneId"): accepted_availability_zones.append({"zoneId": zone.get("zoneId")}) accepted_availability_zones.append(zone.get("zoneId")) if accepted_availability_zones: zone_response, zone_code = federation_client.subscribe_to_zones( response.get("federationContextId"), Loading
edge_cloud_management_api/services/storage_service.py +25 −3 Original line number Diff line number Diff line Loading @@ -4,18 +4,40 @@ import pymongo storage_url = mongo_host = config.MONGO_URI mydb_mongo = 'oeg_storage' def _zone_storage_id(zone: dict): provider = zone.get('edgeCloudProvider') or 'unknown' zone_id = zone.get('edgeCloudZoneId') or zone.get('zoneId') if not zone_id: return zone.get('_id') return f"{provider}::{zone_id}" def insert_zones(zone_list: list): collection = "zones" myclient = pymongo.MongoClient(storage_url) mydbmongo = myclient[mydb_mongo] col = mydbmongo[collection] col.insert_many(zone_list) for zone in zone_list: normalized_zone = dict(zone) normalized_zone['_id'] = _zone_storage_id(normalized_zone) col.replace_one({'_id': normalized_zone['_id']}, normalized_zone, upsert=True) def get_zone(zone_id: str): def get_zone(zone_id: str, provider: str | None = None): collection = "zones" myclient = pymongo.MongoClient(storage_url) mydbmongo = myclient[mydb_mongo] col = mydbmongo[collection] query = {'edgeCloudZoneId': zone_id} if provider: query['edgeCloudProvider'] = provider zone = col.find_one(query) else: zone = col.find_one({**query, 'isLocal': 'true'}) if zone is None: zone = col.find_one(query) if zone is None and provider: zone = col.find_one({'_id': f"{provider}::{zone_id}"}) if zone is None and not provider: zone = col.find_one({'_id': zone_id}) return zone Loading