Loading edge_cloud_management_api/configs/env_config.py +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ class Configuration(BaseSettings): PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME") PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD") HTTP_PROXY: str = os.getenv("HTTP_PROXY") FEDERATION_MANAGER_HOST=os.getenv("FEDERATION_MANAGER_HOST") config = Configuration() edge_cloud_management_api/controllers/app_controllers.py +86 −7 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ def delete_app(appId, x_correlator=None): # noqa: E501 pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_app(appId=appId) return response.json() return response # with MongoManager() as db: # number_of_deleted_documents = db.delete_document("apps", {"_id": appId}) # if number_of_deleted_documents == 0: Loading @@ -124,6 +124,80 @@ def delete_app(appId, x_correlator=None): # noqa: E501 ) #def create_app_instance(): # logger.info("Received request to create app instance") # try: # Step 1: Get request body # body = request.get_json() # logger.debug(f"Request body: {body}") # Step 2: Validate body format # app_id = body.get('appId') # app_zones = body.get('appZones') # if not app_id or not app_zones: # return jsonify({"error": "Missing required fields: appId or appZones"}), 400 # Step 3: Connect to Mongo and check if app exists # with MongoManager() as mongo_manager: # app_data = mongo_manager.find_document("apps", {"_id": app_id}) # pi_edge_client_factory = PiEdgeAPIClientFactory() # pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() # app_data = pi_edge_client.get_app(app_id) # if len(app_data)<1: # logger.warning(f"No application found with ID {app_id}") # return jsonify({"error": "App not found", "details": f"No application found with ID {app_id}"}), 404 # logger.info(f"Application {app_id} found in database") # Step 4: Deploy app instance using Pi-Edge client #logger.info(f"Preparing to send deployment request to SRM for appId={app_id}") # deployment_payload = { # "appId": app_id, # "appZones": app_zones #} #Print everything before sending # print("\n=== Preparing Deployment Request ===") # print(f"Endpoint: {pi_edge_client.base_url}/deployedServiceFunction") # print(f"Headers: {pi_edge_client._get_headers()}") # print(f"Payload: {deployment_payload}") # print("=== End of Deployment Request ===\n") #Try sending to Pi-Edge, catch connection errors separately # try: # response = pi_edge_client.deploy_service_function(data=deployment_payload) # if isinstance(response, dict) and "error" in response: # logger.warning(f"Failed to deploy service function: {response}") # return jsonify({ # "warning": "Deployment not completed (SRM service unreachable)", # "details": response # }), 202 # Still accept the request but warn # logger.info(f"Deployment response from SRM: {response}") # except Exception as inner_error: # logger.error(f"Exception while trying to deploy to SRM: {inner_error}") # return jsonify({ # "warning": "SRM backend unavailable. Deployment request was built correctly.", # "details": str(inner_error) # }), 202 # Still accept it (because your backend worked) # return jsonify({"message": f"Application {app_id} instantiation accepted"}), 202 # except ValidationError as e: # logger.error(f"Validation error: {str(e)}") # return jsonify({"error": "Validation error", "details": str(e)}), 400 #except Exception as e: # logger.error(f"Unexpected error in create_app_instance: {str(e)}") # return jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500 def create_app_instance(): logger.info("Received request to create app instance") Loading @@ -136,12 +210,12 @@ def create_app_instance(): edge_zone_id = body.get("edgeCloudZoneId") k8s_ref = body.get("kubernetesClusterRef") if not app_id or not edge_zone_id or not k8s_ref: return jsonify({"error": "Missing required fields: appId, edgeCloudZoneId, or kubernetesCLusterRef"}), 400 # if not app_id or not edge_zone_id: # return jsonify({"error": "Missing required fields: appId or edgeCloudZoneId"}), 400 logger.info(f"Preparing to send deployment request to SRM for appId={app_id}") pi_edge_client_factory = PiEdgeAPICLientFactory() pi_edge_client_factory = PiEdgeAPIClientFactory() pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() print("\n === Preparing Deployment Request ===") Loading @@ -151,7 +225,7 @@ def create_app_instance(): print("=== End of Deployment Request ===\n") try: response = pi_edge_client_deploy_service_function(data=body) response = pi_edge_client.deploy_service_function(data=body) if isinstance(response, dict) and "error" in response: logger.warning(f"Failed to deploy service function: {response}") Loading @@ -169,7 +243,7 @@ def create_app_instance(): "details": str(inner_error) }),202 return jsonify({"message": f"Application {app_id} instantiation accepted"}), 202 return response except ValidationError as e: logger.error(f"Validation error: {str(e)}") return jsonify({"error": "Validation error", "details": str(e)}), 400 Loading Loading @@ -219,7 +293,12 @@ def get_app_instance(app_id=None, x_correlator=None, app_instance_id=None, regio def delete_app_instance(appInstanceId: str, x_correlator=None): """ Terminate an Application Instance - Removes a specific app instance from the database. - Returns 204 if deleted, 404 if not found. """ try: pi_edge_client_factory = PiEdgeAPIClientFactory() pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() Loading edge_cloud_management_api/controllers/edge_cloud_controller.py +3 −0 Original line number Diff line number Diff line Loading @@ -119,3 +119,6 @@ def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=No "message": f"An error occurred: {str(e)}", } return jsonify(error_info), 500 def get_zone_details(zoneId:str): pass edge_cloud_management_api/controllers/federation_manager_controller.py 0 → 100644 +53 −0 Original line number Diff line number Diff line from flask import request, jsonify from edge_cloud_management_api.services.federation_services import FederationManagerClientFactory factory = FederationManagerClientFactory() federation_client = factory.create_federation_client() def create_federation(): """ POST /partner Forwards the federation creation request to Federation Manager. """ try: body = request.get_json() result = federation_client.post_partner(body) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def get_federation(federationContextId): """ GET /{federationContextId}/partner Forwards the GET federation info request. """ try: result = federation_client.get_partner(federationContextId) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def delete_federation(federationContextId): """ DELETE /{federationContextId}/partner Forwards the DELETE federation request. """ try: result = federation_client.delete_partner(federationContextId) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def get_federation_context_ids(): """ GET /fed-context-id Forwards the request to fetch federation context IDs. """ try: result = federation_client.get_federation_context_ids() return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 500 edge_cloud_management_api/controllers/network_functions_controller.py 0 → 100644 +155 −0 Original line number Diff line number Diff line from flask import jsonify from pydantic import BaseModel, Field, ValidationError from typing import List from edge_cloud_management_api.managers.log_manager import logger from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory def create_qod_session(body: dict): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.create_qod_session(body) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def delete_qod_session(sessionId: str): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_qod_session(sessionId=sessionId) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response.json() except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_qod_session(sessionId: str): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_qod_session(sessionId=sessionId) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response.json() except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def create_traffic_influence_resource(body: dict): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.create_traffic_influence_resource(body) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_traffic_influence_resource(id: str): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_traffic_influence_resource(id) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def delete_traffic_influence_resource(id: str): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_traffic_influence_resource(id) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_all_traffic_influence_resources(): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_all_traffic_influence_resources() return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) No newline at end of file Loading
edge_cloud_management_api/configs/env_config.py +1 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ class Configuration(BaseSettings): PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME") PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD") HTTP_PROXY: str = os.getenv("HTTP_PROXY") FEDERATION_MANAGER_HOST=os.getenv("FEDERATION_MANAGER_HOST") config = Configuration()
edge_cloud_management_api/controllers/app_controllers.py +86 −7 Original line number Diff line number Diff line Loading @@ -101,7 +101,7 @@ def delete_app(appId, x_correlator=None): # noqa: E501 pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_app(appId=appId) return response.json() return response # with MongoManager() as db: # number_of_deleted_documents = db.delete_document("apps", {"_id": appId}) # if number_of_deleted_documents == 0: Loading @@ -124,6 +124,80 @@ def delete_app(appId, x_correlator=None): # noqa: E501 ) #def create_app_instance(): # logger.info("Received request to create app instance") # try: # Step 1: Get request body # body = request.get_json() # logger.debug(f"Request body: {body}") # Step 2: Validate body format # app_id = body.get('appId') # app_zones = body.get('appZones') # if not app_id or not app_zones: # return jsonify({"error": "Missing required fields: appId or appZones"}), 400 # Step 3: Connect to Mongo and check if app exists # with MongoManager() as mongo_manager: # app_data = mongo_manager.find_document("apps", {"_id": app_id}) # pi_edge_client_factory = PiEdgeAPIClientFactory() # pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() # app_data = pi_edge_client.get_app(app_id) # if len(app_data)<1: # logger.warning(f"No application found with ID {app_id}") # return jsonify({"error": "App not found", "details": f"No application found with ID {app_id}"}), 404 # logger.info(f"Application {app_id} found in database") # Step 4: Deploy app instance using Pi-Edge client #logger.info(f"Preparing to send deployment request to SRM for appId={app_id}") # deployment_payload = { # "appId": app_id, # "appZones": app_zones #} #Print everything before sending # print("\n=== Preparing Deployment Request ===") # print(f"Endpoint: {pi_edge_client.base_url}/deployedServiceFunction") # print(f"Headers: {pi_edge_client._get_headers()}") # print(f"Payload: {deployment_payload}") # print("=== End of Deployment Request ===\n") #Try sending to Pi-Edge, catch connection errors separately # try: # response = pi_edge_client.deploy_service_function(data=deployment_payload) # if isinstance(response, dict) and "error" in response: # logger.warning(f"Failed to deploy service function: {response}") # return jsonify({ # "warning": "Deployment not completed (SRM service unreachable)", # "details": response # }), 202 # Still accept the request but warn # logger.info(f"Deployment response from SRM: {response}") # except Exception as inner_error: # logger.error(f"Exception while trying to deploy to SRM: {inner_error}") # return jsonify({ # "warning": "SRM backend unavailable. Deployment request was built correctly.", # "details": str(inner_error) # }), 202 # Still accept it (because your backend worked) # return jsonify({"message": f"Application {app_id} instantiation accepted"}), 202 # except ValidationError as e: # logger.error(f"Validation error: {str(e)}") # return jsonify({"error": "Validation error", "details": str(e)}), 400 #except Exception as e: # logger.error(f"Unexpected error in create_app_instance: {str(e)}") # return jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500 def create_app_instance(): logger.info("Received request to create app instance") Loading @@ -136,12 +210,12 @@ def create_app_instance(): edge_zone_id = body.get("edgeCloudZoneId") k8s_ref = body.get("kubernetesClusterRef") if not app_id or not edge_zone_id or not k8s_ref: return jsonify({"error": "Missing required fields: appId, edgeCloudZoneId, or kubernetesCLusterRef"}), 400 # if not app_id or not edge_zone_id: # return jsonify({"error": "Missing required fields: appId or edgeCloudZoneId"}), 400 logger.info(f"Preparing to send deployment request to SRM for appId={app_id}") pi_edge_client_factory = PiEdgeAPICLientFactory() pi_edge_client_factory = PiEdgeAPIClientFactory() pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() print("\n === Preparing Deployment Request ===") Loading @@ -151,7 +225,7 @@ def create_app_instance(): print("=== End of Deployment Request ===\n") try: response = pi_edge_client_deploy_service_function(data=body) response = pi_edge_client.deploy_service_function(data=body) if isinstance(response, dict) and "error" in response: logger.warning(f"Failed to deploy service function: {response}") Loading @@ -169,7 +243,7 @@ def create_app_instance(): "details": str(inner_error) }),202 return jsonify({"message": f"Application {app_id} instantiation accepted"}), 202 return response except ValidationError as e: logger.error(f"Validation error: {str(e)}") return jsonify({"error": "Validation error", "details": str(e)}), 400 Loading Loading @@ -219,7 +293,12 @@ def get_app_instance(app_id=None, x_correlator=None, app_instance_id=None, regio def delete_app_instance(appInstanceId: str, x_correlator=None): """ Terminate an Application Instance - Removes a specific app instance from the database. - Returns 204 if deleted, 404 if not found. """ try: pi_edge_client_factory = PiEdgeAPIClientFactory() pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client() Loading
edge_cloud_management_api/controllers/edge_cloud_controller.py +3 −0 Original line number Diff line number Diff line Loading @@ -119,3 +119,6 @@ def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=No "message": f"An error occurred: {str(e)}", } return jsonify(error_info), 500 def get_zone_details(zoneId:str): pass
edge_cloud_management_api/controllers/federation_manager_controller.py 0 → 100644 +53 −0 Original line number Diff line number Diff line from flask import request, jsonify from edge_cloud_management_api.services.federation_services import FederationManagerClientFactory factory = FederationManagerClientFactory() federation_client = factory.create_federation_client() def create_federation(): """ POST /partner Forwards the federation creation request to Federation Manager. """ try: body = request.get_json() result = federation_client.post_partner(body) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def get_federation(federationContextId): """ GET /{federationContextId}/partner Forwards the GET federation info request. """ try: result = federation_client.get_partner(federationContextId) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def delete_federation(federationContextId): """ DELETE /{federationContextId}/partner Forwards the DELETE federation request. """ try: result = federation_client.delete_partner(federationContextId) return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 400 def get_federation_context_ids(): """ GET /fed-context-id Forwards the request to fetch federation context IDs. """ try: result = federation_client.get_federation_context_ids() return jsonify(result), 200 if "error" not in result else 502 except Exception as e: return jsonify({"error": str(e)}), 500
edge_cloud_management_api/controllers/network_functions_controller.py 0 → 100644 +155 −0 Original line number Diff line number Diff line from flask import jsonify from pydantic import BaseModel, Field, ValidationError from typing import List from edge_cloud_management_api.managers.log_manager import logger from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory def create_qod_session(body: dict): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.create_qod_session(body) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def delete_qod_session(sessionId: str): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_qod_session(sessionId=sessionId) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response.json() except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_qod_session(sessionId: str): """ Creates a new QoD session """ try: # Validate the input data using Pydantic # validated_data = AppManifest(**body) # validated_data_dict = validated_data.model_dump(mode="json") # validated_data_dict["_id"] = str(uuid.uuid4()) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_qod_session(sessionId=sessionId) # Insert into MongoDB # with MongoManager() as db: # document_id = db.insert_document("apps", validated_data_dict) # return ( # jsonify({"appId": str(document_id)}), # 201, # ) return response.json() except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def create_traffic_influence_resource(body: dict): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.create_traffic_influence_resource(body) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_traffic_influence_resource(id: str): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_traffic_influence_resource(id) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def delete_traffic_influence_resource(id: str): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.delete_traffic_influence_resource(id) return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) def get_all_traffic_influence_resources(): try: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_all_traffic_influence_resources() return response except ValidationError as e: return jsonify({"error": "Invalid input", "details": e.errors()}), 400 except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), 500, ) No newline at end of file