Loading edge_cloud_management_api/__init__.pydeleted 100644 → 0 +0 −0 Empty file deleted. edge_cloud_management_api/controllers/app_controllers.py +39 −27 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from edge_cloud_management_api.managers.db_manager import MongoManager from edge_cloud_management_api.managers.log_manager import logger from edge_cloud_management_api.models.application_models import AppManifest, AppZones, AppInstance from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClient class NotFound404Exception(Exception): Loading @@ -17,16 +18,20 @@ def submit_app(body: dict): """ 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()) # 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.submit_app(body) # Insert into MongoDB with MongoManager() as db: document_id = db.insert_document("apps", validated_data_dict) return ( jsonify({"appId": str(document_id)}), 201, ) # 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 Loading @@ -41,16 +46,19 @@ def submit_app(body: dict): def get_apps(x_correlator=None): # noqa: E501 """Retrieve metadata information of all applications""" try: with MongoManager() as db: documents_cursor = db.find_documents("apps", {}) response_apps = list() for document in documents_cursor: document["appId"] = document["_id"] del document["_id"] response_apps.append(document) return (jsonify(response_apps), 200) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() registered_apps = api_client.get_service_functions_catalogue() return registered_apps # with MongoManager() as db: # documents_cursor = db.find_documents("apps", {}) # response_apps = list() # for document in documents_cursor: # document["appId"] = document["_id"] # del document["_id"] # response_apps.append(document) # return (jsonify(response_apps), 200) except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), Loading @@ -61,14 +69,18 @@ def get_apps(x_correlator=None): # noqa: E501 def get_app(appId, x_correlator=None): # noqa: E501 """Retrieve the information of an Application""" try: with MongoManager() as db: document = db.find_document("apps", {"_id": appId}) if document is None: raise NotFound404Exception() document["appId"] = document["_id"] del document["_id"] return (jsonify(document), 200) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_app(appId) return response # with MongoManager() as db: # document = db.find_document("apps", {"_id": appId}) # if document is None: # raise NotFound404Exception() # document["appId"] = document["_id"] # del document["_id"] # return (jsonify(document), 200) except NotFound404Exception: return ( Loading edge_cloud_management_api/models/application_models.py +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class AppManifest(BaseModel): packageType: PackageType operatingSystem: Optional[OperatingSystem] appRepo: AppRepo requiredResources: Any # Could be KubernetesResources, ContainerResources, etc. requiredResources: Optional[Any] # Could be KubernetesResources, ContainerResources, etc. componentSpec: List[ComponentSpec] Loading edge_cloud_management_api/services/pi_edge_services.py +46 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,52 @@ class PiEdgeAPIClient: except Exception as err: return {"error": f"An unexpected error occurred: {err}"} def submit_app(self, body): """ Register app metadata to SRM """ url = f"{self.base_url}/serviceFunction" try: request_headers = self._get_headers() response = requests.post(url, headers=request_headers, verify=False, json=body) response.raise_for_status() return response.json() except Timeout: return {"error": "The request to the external API timed out. Please try again later."} except ConnectionError: return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { "error": f"HTTP error occurred: {http_err}.", "status_code": response.status_code, } def get_app(self, appId): """ Get app metadata from SRM """ url = f"{self.base_url}/serviceFunction/"+appId try: request_headers = self._get_headers() response = requests.get(url, headers=request_headers, verify=False) response.raise_for_status() return response.json() except Timeout: return {"error": "The request to the external API timed out. Please try again later."} except ConnectionError: return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { "error": f"HTTP error occurred: {http_err}.", "status_code": response.status_code, } def deploy_service_function(self, data: list): """ Post data to the /deployedServiceFunction endpoint. Loading edge_cloud_management_api/specification/openapi.yaml +2 −2 Original line number Diff line number Diff line Loading @@ -969,10 +969,10 @@ components: required: - name - version - appProvider # - appProvider - packageType - appRepo - requiredResources # - requiredResources - componentSpec AppProvider: Loading Loading
edge_cloud_management_api/controllers/app_controllers.py +39 −27 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ from edge_cloud_management_api.managers.db_manager import MongoManager from edge_cloud_management_api.managers.log_manager import logger from edge_cloud_management_api.models.application_models import AppManifest, AppZones, AppInstance from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClientFactory from edge_cloud_management_api.services.pi_edge_services import PiEdgeAPIClient class NotFound404Exception(Exception): Loading @@ -17,16 +18,20 @@ def submit_app(body: dict): """ 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()) # 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.submit_app(body) # Insert into MongoDB with MongoManager() as db: document_id = db.insert_document("apps", validated_data_dict) return ( jsonify({"appId": str(document_id)}), 201, ) # 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 Loading @@ -41,16 +46,19 @@ def submit_app(body: dict): def get_apps(x_correlator=None): # noqa: E501 """Retrieve metadata information of all applications""" try: with MongoManager() as db: documents_cursor = db.find_documents("apps", {}) response_apps = list() for document in documents_cursor: document["appId"] = document["_id"] del document["_id"] response_apps.append(document) return (jsonify(response_apps), 200) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() registered_apps = api_client.get_service_functions_catalogue() return registered_apps # with MongoManager() as db: # documents_cursor = db.find_documents("apps", {}) # response_apps = list() # for document in documents_cursor: # document["appId"] = document["_id"] # del document["_id"] # response_apps.append(document) # return (jsonify(response_apps), 200) except Exception as e: return ( jsonify({"error": "An unexpected error occurred", "details": str(e)}), Loading @@ -61,14 +69,18 @@ def get_apps(x_correlator=None): # noqa: E501 def get_app(appId, x_correlator=None): # noqa: E501 """Retrieve the information of an Application""" try: with MongoManager() as db: document = db.find_document("apps", {"_id": appId}) if document is None: raise NotFound404Exception() document["appId"] = document["_id"] del document["_id"] return (jsonify(document), 200) pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() response = api_client.get_app(appId) return response # with MongoManager() as db: # document = db.find_document("apps", {"_id": appId}) # if document is None: # raise NotFound404Exception() # document["appId"] = document["_id"] # del document["_id"] # return (jsonify(document), 200) except NotFound404Exception: return ( Loading
edge_cloud_management_api/models/application_models.py +1 −1 Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ class AppManifest(BaseModel): packageType: PackageType operatingSystem: Optional[OperatingSystem] appRepo: AppRepo requiredResources: Any # Could be KubernetesResources, ContainerResources, etc. requiredResources: Optional[Any] # Could be KubernetesResources, ContainerResources, etc. componentSpec: List[ComponentSpec] Loading
edge_cloud_management_api/services/pi_edge_services.py +46 −0 Original line number Diff line number Diff line Loading @@ -94,6 +94,52 @@ class PiEdgeAPIClient: except Exception as err: return {"error": f"An unexpected error occurred: {err}"} def submit_app(self, body): """ Register app metadata to SRM """ url = f"{self.base_url}/serviceFunction" try: request_headers = self._get_headers() response = requests.post(url, headers=request_headers, verify=False, json=body) response.raise_for_status() return response.json() except Timeout: return {"error": "The request to the external API timed out. Please try again later."} except ConnectionError: return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { "error": f"HTTP error occurred: {http_err}.", "status_code": response.status_code, } def get_app(self, appId): """ Get app metadata from SRM """ url = f"{self.base_url}/serviceFunction/"+appId try: request_headers = self._get_headers() response = requests.get(url, headers=request_headers, verify=False) response.raise_for_status() return response.json() except Timeout: return {"error": "The request to the external API timed out. Please try again later."} except ConnectionError: return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { "error": f"HTTP error occurred: {http_err}.", "status_code": response.status_code, } def deploy_service_function(self, data: list): """ Post data to the /deployedServiceFunction endpoint. Loading
edge_cloud_management_api/specification/openapi.yaml +2 −2 Original line number Diff line number Diff line Loading @@ -969,10 +969,10 @@ components: required: - name - version - appProvider # - appProvider - packageType - appRepo - requiredResources # - requiredResources - componentSpec AppProvider: Loading