Loading edge_cloud_management_api/configs/env_config.py +6 −6 Original line number Diff line number Diff line Loading @@ -6,12 +6,12 @@ load_dotenv() class Configuration(BaseSettings): MONGO_URI: str = os.getenv("MONGO_URI") or "" SRM_HOST: str = os.getenv("SRM_HOST") or "" PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME") or "" PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD") or "" HTTP_PROXY: str = os.getenv("HTTP_PROXY") or "" FEDERATION_MANAGER_HOST: str = os.getenv("FEDERATION_MANAGER_HOST") or "" MONGO_URI: str = os.getenv("MONGO_URI") SRM_HOST: str = os.getenv("SRM_HOST") 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 +80 −1 Original line number Diff line number Diff line Loading @@ -85,6 +85,80 @@ def delete_app(appId, x_correlator=None): ) #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 Loading @@ -170,7 +244,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 +5 −0 Original line number Diff line number Diff line Loading @@ -111,9 +111,14 @@ def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=No } return jsonify(error_info), 500 <<<<<<< HEAD def edge_cloud_zone_details(zoneId: str) -> dict: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() result = api_client.edge_cloud_zone_details(zone_id=zoneId) return result ======= def get_zone_details(zoneId:str): pass >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 edge_cloud_management_api/controllers/federation_manager_controller.py +2 −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(): """ Loading edge_cloud_management_api/services/federation_services.py +12 −0 Original line number Diff line number Diff line <<<<<<< HEAD import os ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 import requests from requests.exceptions import Timeout, ConnectionError from edge_cloud_management_api.configs.env_config import config from edge_cloud_management_api.managers.log_manager import logger <<<<<<< HEAD from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 class FederationManagerClient: def __init__(self, base_url=None): Loading Loading @@ -94,6 +100,7 @@ class FederationManagerClient: logger.error(f"GET /fed-context-id unexpected error: {e}") return {"error": str(e)} <<<<<<< HEAD def onboard_application(self, federation_context_id: str, body: dict): url = f"{self.base_url}/{federation_context_id}/application/onboarding" try: Loading Loading @@ -153,6 +160,8 @@ class FederationManagerClient: return {"error": str(e), "status_code": 500} ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 class FederationManagerClientFactory: def __init__(self): Loading @@ -162,6 +171,7 @@ class FederationManagerClientFactory: base_url = base_url or self.default_base_url return FederationManagerClient(base_url=base_url) <<<<<<< HEAD def onboard_application_to_partners(app_id, zones): SOURCE_OP = os.getenv("SOURCE_OP_ID") federation_context_id = os.getenv("FEDERATION_CONTEXT_ID") Loading Loading @@ -209,6 +219,8 @@ class FederationManagerClientFactory: return {"onboardingResults": results}, 202 ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 if __name__ == "__main__": factory = FederationManagerClientFactory() Loading Loading
edge_cloud_management_api/configs/env_config.py +6 −6 Original line number Diff line number Diff line Loading @@ -6,12 +6,12 @@ load_dotenv() class Configuration(BaseSettings): MONGO_URI: str = os.getenv("MONGO_URI") or "" SRM_HOST: str = os.getenv("SRM_HOST") or "" PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME") or "" PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD") or "" HTTP_PROXY: str = os.getenv("HTTP_PROXY") or "" FEDERATION_MANAGER_HOST: str = os.getenv("FEDERATION_MANAGER_HOST") or "" MONGO_URI: str = os.getenv("MONGO_URI") SRM_HOST: str = os.getenv("SRM_HOST") 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 +80 −1 Original line number Diff line number Diff line Loading @@ -85,6 +85,80 @@ def delete_app(appId, x_correlator=None): ) #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 Loading @@ -170,7 +244,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 +5 −0 Original line number Diff line number Diff line Loading @@ -111,9 +111,14 @@ def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=No } return jsonify(error_info), 500 <<<<<<< HEAD def edge_cloud_zone_details(zoneId: str) -> dict: pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() result = api_client.edge_cloud_zone_details(zone_id=zoneId) return result ======= def get_zone_details(zoneId:str): pass >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270
edge_cloud_management_api/controllers/federation_manager_controller.py +2 −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(): """ Loading
edge_cloud_management_api/services/federation_services.py +12 −0 Original line number Diff line number Diff line <<<<<<< HEAD import os ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 import requests from requests.exceptions import Timeout, ConnectionError from edge_cloud_management_api.configs.env_config import config from edge_cloud_management_api.managers.log_manager import logger <<<<<<< HEAD from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 class FederationManagerClient: def __init__(self, base_url=None): Loading Loading @@ -94,6 +100,7 @@ class FederationManagerClient: logger.error(f"GET /fed-context-id unexpected error: {e}") return {"error": str(e)} <<<<<<< HEAD def onboard_application(self, federation_context_id: str, body: dict): url = f"{self.base_url}/{federation_context_id}/application/onboarding" try: Loading Loading @@ -153,6 +160,8 @@ class FederationManagerClient: return {"error": str(e), "status_code": 500} ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 class FederationManagerClientFactory: def __init__(self): Loading @@ -162,6 +171,7 @@ class FederationManagerClientFactory: base_url = base_url or self.default_base_url return FederationManagerClient(base_url=base_url) <<<<<<< HEAD def onboard_application_to_partners(app_id, zones): SOURCE_OP = os.getenv("SOURCE_OP_ID") federation_context_id = os.getenv("FEDERATION_CONTEXT_ID") Loading Loading @@ -209,6 +219,8 @@ class FederationManagerClientFactory: return {"onboardingResults": results}, 202 ======= >>>>>>> 1c306f8dd595452cbe7804c3473f2f4b77a0b270 if __name__ == "__main__": factory = FederationManagerClientFactory() Loading