Commit 46a0ca2d authored by Adrian Pino's avatar Adrian Pino Committed by GitHub
Browse files

Merge pull request #153 from SunriseOpenOperatorPlatform/feature/make-i2edge-fully-camara-compliant

Feature/make i2edge fully camara compliant
parents 6f726f7e a270f3ae
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@ import uuid
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional


import yaml
import yaml
from requests import Response


from sunrise6g_opensdk.edgecloud.adapters.aeros import config
from sunrise6g_opensdk.edgecloud.adapters.aeros import config
from sunrise6g_opensdk.edgecloud.adapters.aeros.continuum_client import ContinuumClient
from sunrise6g_opensdk.edgecloud.adapters.aeros.continuum_client import ContinuumClient
@@ -223,6 +224,21 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                deployed.append({"appId": stored_app_id, "appInstanceId": instance_id})
                deployed.append({"appId": stored_app_id, "appInstanceId": instance_id})
        return deployed
        return deployed


    def get_deployed_app(
        self, app_instance_id: str, app_id: Optional[str] = None, region: Optional[str] = None
    ) -> Response:
        """
        Placeholder implementation for CAMARA compliance.
        Retrieves information of a specific application instance.

        :param app_instance_id: Unique identifier of the application instance
        :param app_id: Optional filter by application ID
        :param region: Optional filter by Edge Cloud region
        :return: Response with application instance details
        """
        # TODO: Implement actual aeros-specific logic for retrieving a specific deployed app
        raise NotImplementedError("get_deployed_app is not yet implemented for aeros adapter")

    def _purge_deployed_app_from_continuum(self, app_id: str) -> None:
    def _purge_deployed_app_from_continuum(self, app_id: str) -> None:
        aeros_client = ContinuumClient(self.base_url)
        aeros_client = ContinuumClient(self.base_url)
        response = aeros_client.purge_service(app_id)
        response = aeros_client.purge_service(app_id)
+271 −141

File changed.

Preview size limit exceeded, changes collapsed.

+37 −9
Original line number Original line Diff line number Diff line
@@ -37,16 +37,28 @@ def get_error_message_from(response: requests.Response) -> str:
        return response.text
        return response.text




def i2edge_post(url: str, model_payload: BaseModel) -> dict:
def i2edge_post(url: str, model_payload: BaseModel, expected_status: int = 201) -> dict:
    headers = {
    headers = {
        "Content-Type": "application/json",
        "Content-Type": "application/json",
        "accept": "application/json",
        "accept": "application/json",
    }
    }
    json_payload = json.dumps(model_payload.model_dump(mode="json", exclude_none=True))
    json_payload = json.dumps(model_payload.model_dump(mode="json", exclude_none=True))

    # Debug: Log the payload being sent to i2Edge
    log.debug(f"Sending payload to i2Edge: {json_payload}")

    try:
    try:
        response = requests.post(url, data=json_payload, headers=headers)
        response = requests.post(url, data=json_payload, headers=headers)
        response.raise_for_status()
        if response.status_code == expected_status:
            return response
            return response
        else:
            # Raise an error with meaningful message about status code mismatch
            i2edge_err_msg = get_error_message_from(response)
            err_msg = "Failed to post: Expected status {}, got {}. Detail: {}".format(
                expected_status, response.status_code, i2edge_err_msg
            )
            log.error(err_msg)
            raise I2EdgeError(err_msg)
    except requests.exceptions.HTTPError as e:
    except requests.exceptions.HTTPError as e:
        i2edge_err_msg = get_error_message_from(response)
        i2edge_err_msg = get_error_message_from(response)
        err_msg = "Failed to deploy app: {}. Detail: {}".format(i2edge_err_msg, e)
        err_msg = "Failed to deploy app: {}. Detail: {}".format(i2edge_err_msg, e)
@@ -88,13 +100,21 @@ def i2edge_post_multiform_data(url: str, model_payload: BaseModel) -> dict:
        raise I2EdgeError(err_msg)
        raise I2EdgeError(err_msg)




def i2edge_delete(url: str, id: str) -> dict:
def i2edge_delete(url: str, id: str, expected_status: int = 200) -> dict:
    headers = {"accept": "application/json"}
    headers = {"accept": "application/json"}
    try:
    try:
        query = "{}/{}".format(url, id)
        query = "{}/{}".format(url, id)
        response = requests.delete(query, headers=headers)
        response = requests.delete(query, headers=headers)
        response.raise_for_status()
        if response.status_code == expected_status:
            return response
            return response
        else:
            # Raise an error with meaningful message about status code mismatch
            i2edge_err_msg = get_error_message_from(response)
            err_msg = "Failed to delete: Expected status {}, got {}. Detail: {}".format(
                expected_status, response.status_code, i2edge_err_msg
            )
            log.error(err_msg)
            raise I2EdgeError(err_msg)
    except requests.exceptions.HTTPError as e:
    except requests.exceptions.HTTPError as e:
        i2edge_err_msg = get_error_message_from(response)
        i2edge_err_msg = get_error_message_from(response)
        err_msg = "Failed to undeploy app: {}. Detail: {}".format(i2edge_err_msg, e)
        err_msg = "Failed to undeploy app: {}. Detail: {}".format(i2edge_err_msg, e)
@@ -102,12 +122,20 @@ def i2edge_delete(url: str, id: str) -> dict:
        raise I2EdgeError(err_msg)
        raise I2EdgeError(err_msg)




def i2edge_get(url: str, params: Optional[dict]):
def i2edge_get(url: str, params: Optional[dict], expected_status: int = 200):
    headers = {"accept": "application/json"}
    headers = {"accept": "application/json"}
    try:
    try:
        response = requests.get(url, params=params, headers=headers)
        response = requests.get(url, params=params, headers=headers)
        response.raise_for_status()
        if response.status_code == expected_status:
            return response
            return response
        else:
            # Raise an error with meaningful message about status code mismatch
            i2edge_err_msg = get_error_message_from(response)
            err_msg = "Failed to get: Expected status {}, got {}. Detail: {}".format(
                expected_status, response.status_code, i2edge_err_msg
            )
            log.error(err_msg)
            raise I2EdgeError(err_msg)
    except requests.exceptions.HTTPError as e:
    except requests.exceptions.HTTPError as e:
        i2edge_err_msg = get_error_message_from(response)
        i2edge_err_msg = get_error_message_from(response)
        err_msg = "Failed to get apps: {}. Detail: {}".format(i2edge_err_msg, e)
        err_msg = "Failed to get apps: {}. Detail: {}".format(i2edge_err_msg, e)
+6 −6

File changed.

Preview size limit exceeded, changes collapsed.

+16 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading