Loading edge_cloud_management_api/controllers/app_controllers.py +2 −6 Original line number Diff line number Diff line Loading @@ -17,9 +17,7 @@ def submit_app(body: dict): # app_id = mongo.db.applications.insert_one(validated_data.dict()).inserted_id app_id = 3 return ( jsonify( {"message": "Application submitted successfully!", "appId": str(app_id)} ), jsonify({"message": "Application submitted successfully!", "appId": str(app_id)}), 201, ) Loading Loading @@ -107,9 +105,7 @@ def create_app_instance(body, app_id, x_correlator=None): # noqa: E501 return error, 500 def get_app_instance( app_id, x_correlator=None, app_instance_id=None, region=None ): # noqa: E501 def get_app_instance(app_id, x_correlator=None, app_instance_id=None, region=None): # noqa: E501 """Retrieve the information of Application Instances for a given App Ask the Edge Cloud Provider the information of the instances for a given application # noqa: E501 Loading edge_cloud_management_api/controllers/edge_cloud_controller.py +2 −11 Original line number Diff line number Diff line Loading @@ -4,9 +4,7 @@ from typing import List class EdgeCloudZone(BaseModel): edgeCloudZoneId: str = Field( ..., description="Unique identifier of the Edge Cloud Zone" ) edgeCloudZoneId: str = Field(..., description="Unique identifier of the Edge Cloud Zone") edgeCloudZoneName: str = Field(..., description="Name of the Edge Cloud Zone") edgeCloudZoneStatus: str = Field( ..., Loading Loading @@ -66,14 +64,7 @@ def get_edge_cloud_zones(x_correlator=None, region=None, status=None): # noqa: filtered_zones = [ zone for zone in get_all_cloud_zones() if ( (query_params.region is None) or (zone["edgeCloudRegion"] == query_params.region) ) and ( (query_params.status is None) or (zone["edgeCloudZoneStatus"] == query_params.status) ) if ((query_params.region is None) or (zone["edgeCloudRegion"] == query_params.region)) and ((query_params.status is None) or (zone["edgeCloudZoneStatus"] == query_params.status)) ] response = [EdgeCloudZone(**zone).model_dump() for zone in filtered_zones] return jsonify(response), 200 Loading edge_cloud_management_api/models/application_models.py +8 −24 Original line number Diff line number Diff line Loading @@ -65,9 +65,7 @@ class ComponentEndpointInfo(BaseModel): class AppInstanceInfo(BaseModel): appInstanceId: UUID4 # str = Field(..., regex=r"^[0-9a-fA-F-]{36}$") status: AppInstanceStatus = ( AppInstanceStatus.unknown ) # [ ready, instantiating, failed, terminating, unknown ] status: AppInstanceStatus = AppInstanceStatus.unknown # [ ready, instantiating, failed, terminating, unknown ] componentEndpointInfo: List[ComponentEndpointInfo] kubernetesClusterRef: Optional[UUID4] edgeCloudZone: EdgeCloudZone Loading @@ -91,9 +89,7 @@ class AppRepo(BaseModel): userName: Optional[str] credentials: Optional[str] # maxLength: 128 authType: Optional[AppRepoAuthType] checksum: Optional[ str ] # MD5 checksum for VM and file-based images, sha256 digest for containers checksum: Optional[str] # MD5 checksum for VM and file-based images, sha256 digest for containers class RequiredResources(BaseModel): Loading Loading @@ -233,9 +229,7 @@ class RequiredResources(BaseModel): addons: Optional[K8sAddons] class VmResources(BaseModel): infraKind: str = Field( ..., description="Type of infrastructure: Virtual Machine" ) infraKind: str = Field(..., description="Type of infrastructure: Virtual Machine") numCPU: int memory: int # in MB additionalStorages: Optional[List[AdditionalStorage]] Loading @@ -249,17 +243,13 @@ class RequiredResources(BaseModel): gpu: Optional[GpuInfo] class DockerComposeResources(BaseModel): infraKind: str = Field( ..., description="Type of infrastructure: Docker Compose" ) infraKind: str = Field(..., description="Type of infrastructure: Docker Compose") numCPU: int memory: int # in MB storage: Optional[AdditionalStorage] gpu: Optional[GpuInfo] __root__: Union[ KubernetesResources, VmResources, ContainerResources, DockerComposeResources ] __root__: Union[KubernetesResources, VmResources, ContainerResources, DockerComposeResources] # class ComponentSpec(BaseModel): Loading Loading @@ -298,18 +288,12 @@ class NetworkInterface(BaseModel): description="Unique identifier for the network interface.", ) protocol: Protocol = Field(..., description="IP transport communication protocol.") port: int = Field( ..., ge=1, le=65535, description="Port number exposed by the component." ) visibilityType: VisibilityType = Field( ..., description="Defines whether the interface is external or internal." ) port: int = Field(..., ge=1, le=65535, description="Port number exposed by the component.") visibilityType: VisibilityType = Field(..., description="Defines whether the interface is external or internal.") class ComponentSpec(BaseModel): componentName: str = Field( ..., description="Unique name for the component within the application." ) componentName: str = Field(..., description="Unique name for the component within the application.") networkInterfaces: List[NetworkInterface] = Field( ..., min_items=1, Loading edge_cloud_management_api/services/pi_edge_services.py +7 −22 Original line number Diff line number Diff line Loading @@ -81,14 +81,10 @@ class PiEdgeAPIClient: raise ValueError("Unexpected response from Pi Edge Server") except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading @@ -108,19 +104,13 @@ class PiEdgeAPIClient: """ url = f"{self.base_url}/deployedServiceFunction" try: response = self.requests_session.post( url, json=data, headers=self._get_headers() ) response = self.requests_session.post(url, json=data, headers=self._get_headers()) response.raise_for_status() except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading @@ -146,14 +136,10 @@ class PiEdgeAPIClient: return nodes except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading Loading @@ -201,7 +187,6 @@ class PiEdgeAPIClientFactory: if __name__ == "__main__": pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() Loading tests/unit/controllers/test_app_controllers.py +7 −5 Original line number Diff line number Diff line Loading @@ -3,14 +3,16 @@ import pytest from edge_cloud_management_api.controllers.app_controllers import get_app @pytest.mark.parametrize("app_id, x_correlator, expected", [ @pytest.mark.parametrize( "app_id, x_correlator, expected", [ (1, None, "do some magic!"), (2, "123", "do some magic!"), ]) ], ) def test_get_app(app_id, x_correlator, expected): """ Test the get_app controller. """ result = get_app(app_id, x_correlator) assert result == expected Loading
edge_cloud_management_api/controllers/app_controllers.py +2 −6 Original line number Diff line number Diff line Loading @@ -17,9 +17,7 @@ def submit_app(body: dict): # app_id = mongo.db.applications.insert_one(validated_data.dict()).inserted_id app_id = 3 return ( jsonify( {"message": "Application submitted successfully!", "appId": str(app_id)} ), jsonify({"message": "Application submitted successfully!", "appId": str(app_id)}), 201, ) Loading Loading @@ -107,9 +105,7 @@ def create_app_instance(body, app_id, x_correlator=None): # noqa: E501 return error, 500 def get_app_instance( app_id, x_correlator=None, app_instance_id=None, region=None ): # noqa: E501 def get_app_instance(app_id, x_correlator=None, app_instance_id=None, region=None): # noqa: E501 """Retrieve the information of Application Instances for a given App Ask the Edge Cloud Provider the information of the instances for a given application # noqa: E501 Loading
edge_cloud_management_api/controllers/edge_cloud_controller.py +2 −11 Original line number Diff line number Diff line Loading @@ -4,9 +4,7 @@ from typing import List class EdgeCloudZone(BaseModel): edgeCloudZoneId: str = Field( ..., description="Unique identifier of the Edge Cloud Zone" ) edgeCloudZoneId: str = Field(..., description="Unique identifier of the Edge Cloud Zone") edgeCloudZoneName: str = Field(..., description="Name of the Edge Cloud Zone") edgeCloudZoneStatus: str = Field( ..., Loading Loading @@ -66,14 +64,7 @@ def get_edge_cloud_zones(x_correlator=None, region=None, status=None): # noqa: filtered_zones = [ zone for zone in get_all_cloud_zones() if ( (query_params.region is None) or (zone["edgeCloudRegion"] == query_params.region) ) and ( (query_params.status is None) or (zone["edgeCloudZoneStatus"] == query_params.status) ) if ((query_params.region is None) or (zone["edgeCloudRegion"] == query_params.region)) and ((query_params.status is None) or (zone["edgeCloudZoneStatus"] == query_params.status)) ] response = [EdgeCloudZone(**zone).model_dump() for zone in filtered_zones] return jsonify(response), 200 Loading
edge_cloud_management_api/models/application_models.py +8 −24 Original line number Diff line number Diff line Loading @@ -65,9 +65,7 @@ class ComponentEndpointInfo(BaseModel): class AppInstanceInfo(BaseModel): appInstanceId: UUID4 # str = Field(..., regex=r"^[0-9a-fA-F-]{36}$") status: AppInstanceStatus = ( AppInstanceStatus.unknown ) # [ ready, instantiating, failed, terminating, unknown ] status: AppInstanceStatus = AppInstanceStatus.unknown # [ ready, instantiating, failed, terminating, unknown ] componentEndpointInfo: List[ComponentEndpointInfo] kubernetesClusterRef: Optional[UUID4] edgeCloudZone: EdgeCloudZone Loading @@ -91,9 +89,7 @@ class AppRepo(BaseModel): userName: Optional[str] credentials: Optional[str] # maxLength: 128 authType: Optional[AppRepoAuthType] checksum: Optional[ str ] # MD5 checksum for VM and file-based images, sha256 digest for containers checksum: Optional[str] # MD5 checksum for VM and file-based images, sha256 digest for containers class RequiredResources(BaseModel): Loading Loading @@ -233,9 +229,7 @@ class RequiredResources(BaseModel): addons: Optional[K8sAddons] class VmResources(BaseModel): infraKind: str = Field( ..., description="Type of infrastructure: Virtual Machine" ) infraKind: str = Field(..., description="Type of infrastructure: Virtual Machine") numCPU: int memory: int # in MB additionalStorages: Optional[List[AdditionalStorage]] Loading @@ -249,17 +243,13 @@ class RequiredResources(BaseModel): gpu: Optional[GpuInfo] class DockerComposeResources(BaseModel): infraKind: str = Field( ..., description="Type of infrastructure: Docker Compose" ) infraKind: str = Field(..., description="Type of infrastructure: Docker Compose") numCPU: int memory: int # in MB storage: Optional[AdditionalStorage] gpu: Optional[GpuInfo] __root__: Union[ KubernetesResources, VmResources, ContainerResources, DockerComposeResources ] __root__: Union[KubernetesResources, VmResources, ContainerResources, DockerComposeResources] # class ComponentSpec(BaseModel): Loading Loading @@ -298,18 +288,12 @@ class NetworkInterface(BaseModel): description="Unique identifier for the network interface.", ) protocol: Protocol = Field(..., description="IP transport communication protocol.") port: int = Field( ..., ge=1, le=65535, description="Port number exposed by the component." ) visibilityType: VisibilityType = Field( ..., description="Defines whether the interface is external or internal." ) port: int = Field(..., ge=1, le=65535, description="Port number exposed by the component.") visibilityType: VisibilityType = Field(..., description="Defines whether the interface is external or internal.") class ComponentSpec(BaseModel): componentName: str = Field( ..., description="Unique name for the component within the application." ) componentName: str = Field(..., description="Unique name for the component within the application.") networkInterfaces: List[NetworkInterface] = Field( ..., min_items=1, Loading
edge_cloud_management_api/services/pi_edge_services.py +7 −22 Original line number Diff line number Diff line Loading @@ -81,14 +81,10 @@ class PiEdgeAPIClient: raise ValueError("Unexpected response from Pi Edge Server") except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading @@ -108,19 +104,13 @@ class PiEdgeAPIClient: """ url = f"{self.base_url}/deployedServiceFunction" try: response = self.requests_session.post( url, json=data, headers=self._get_headers() ) response = self.requests_session.post(url, json=data, headers=self._get_headers()) response.raise_for_status() except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading @@ -146,14 +136,10 @@ class PiEdgeAPIClient: return nodes except Timeout: return { "error": "The request to the external API timed out. Please try again later." } 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." } return {"error": "Failed to connect to the external API service. Service might be unavailable."} except requests.exceptions.HTTPError as http_err: return { Loading Loading @@ -201,7 +187,6 @@ class PiEdgeAPIClientFactory: if __name__ == "__main__": pi_edge_factory = PiEdgeAPIClientFactory() api_client = pi_edge_factory.create_pi_edge_api_client() Loading
tests/unit/controllers/test_app_controllers.py +7 −5 Original line number Diff line number Diff line Loading @@ -3,14 +3,16 @@ import pytest from edge_cloud_management_api.controllers.app_controllers import get_app @pytest.mark.parametrize("app_id, x_correlator, expected", [ @pytest.mark.parametrize( "app_id, x_correlator, expected", [ (1, None, "do some magic!"), (2, "123", "do some magic!"), ]) ], ) def test_get_app(app_id, x_correlator, expected): """ Test the get_app controller. """ result = get_app(app_id, x_correlator) assert result == expected