Commit 5c06d78b authored by George Papathanail's avatar George Papathanail
Browse files

add federation manager service

parent bc1f66d5
Loading
Loading
Loading
Loading
+6 −5
Original line number Original line Diff line number Diff line
@@ -6,11 +6,12 @@ load_dotenv()




class Configuration(BaseSettings):
class Configuration(BaseSettings):
    MONGO_URI: str = os.getenv("MONGO_URI")
    MONGO_URI: str = os.getenv("MONGO_URI") or ""
    SRM_HOST: str = os.getenv("SRM_HOST")
    SRM_HOST: str = os.getenv("SRM_HOST") or ""
    PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME")
    PI_EDGE_USERNAME: str = os.getenv("PI_EDGE_USERNAME") or ""
    PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD")
    PI_EDGE_PASSWORD: str = os.getenv("PI_EDGE_PASSWORD") or ""
    HTTP_PROXY: str = os.getenv("HTTP_PROXY")
    HTTP_PROXY: str = os.getenv("HTTP_PROXY") or ""
    FEDERATION_MANAGER_HOST: str = os.getenv("FEDERATION_MANAGER_HOST") or ""




config = Configuration()
config = Configuration()
+13 −77
Original line number Original line Diff line number Diff line
@@ -17,20 +17,9 @@ def submit_app(body: dict):
    Controller for submitting application metadata.
    Controller for submitting application metadata.
    """
    """
    try:
    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()
        pi_edge_factory = PiEdgeAPIClientFactory()
        api_client = pi_edge_factory.create_pi_edge_api_client()
        api_client = pi_edge_factory.create_pi_edge_api_client()
        response = api_client.submit_app(body)
        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,
        #     )
        return response
        return response


    except ValidationError as e:
    except ValidationError as e:
@@ -50,15 +39,6 @@ def get_apps(x_correlator=None): # noqa: E501
        api_client = pi_edge_factory.create_pi_edge_api_client()
        api_client = pi_edge_factory.create_pi_edge_api_client()
        registered_apps = api_client.get_service_functions_catalogue()
        registered_apps = api_client.get_service_functions_catalogue()
        return registered_apps
        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:
    except Exception as e:
        return (
        return (
            jsonify({"error": "An unexpected error occurred", "details": str(e)}),
            jsonify({"error": "An unexpected error occurred", "details": str(e)}),
@@ -73,14 +53,6 @@ def get_app(appId, x_correlator=None): # noqa: E501
        api_client = pi_edge_factory.create_pi_edge_api_client()
        api_client = pi_edge_factory.create_pi_edge_api_client()
        response = api_client.get_app(appId)
        response = api_client.get_app(appId)
        return response
        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:
    except NotFound404Exception:
        return (
        return (
@@ -102,14 +74,6 @@ def delete_app(appId, x_correlator=None): # noqa: E501
        api_client = pi_edge_factory.create_pi_edge_api_client()
        api_client = pi_edge_factory.create_pi_edge_api_client()
        response = api_client.delete_app(appId=appId)
        response = api_client.delete_app(appId=appId)
        return response.json()
        return response.json()
        # with MongoManager() as db:
        #     number_of_deleted_documents = db.delete_document("apps", {"_id": appId})
        #     if number_of_deleted_documents == 0:
        #         raise NotFound404Exception()
        #     elif number_of_deleted_documents == 1:
        #         return ("", 204)
        #     else:
        #         raise Exception(f"deleted {number_of_deleted_documents} documents")


    except NotFound404Exception:
    except NotFound404Exception:
        return (
        return (
@@ -183,16 +147,6 @@ def get_app_instance(app_id=None, x_correlator=None, app_instance_id=None, regio
    Supports filtering by app_id, app_instance_id, and region.
    Supports filtering by app_id, app_instance_id, and region.
    """
    """
    try:
    try:
        # query = {}
        # if app_id:
        #     query["appId"] = app_id
        # if app_instance_id:
        #     query["appInstanceId"] = app_instance_id
        # if region:
        #     query["edgeCloudZone.edgeCloudRegion"] = region

        # with MongoManager() as db:
        #     instances = list(db.find_documents("appinstances", query))
        instances = None
        instances = None
        pi_edge_client_factory = PiEdgeAPIClientFactory()
        pi_edge_client_factory = PiEdgeAPIClientFactory()
        pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client()
        pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client()
@@ -225,24 +179,6 @@ def delete_app_instance(appInstanceId: str, x_correlator=None):
        pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client()
        pi_edge_client = pi_edge_client_factory.create_pi_edge_api_client()
        response = pi_edge_client.delete_app_instance(appInstanceId)
        response = pi_edge_client.delete_app_instance(appInstanceId)
        return jsonify({'result': response.text, 'status': response.status_code})
        return jsonify({'result': response.text, 'status': response.status_code})
        # with MongoManager() as db:
        #     query = {
        #         "appInstanceId": app_instance_id,
        #         "appId": app_id
        #     }
        #     deleted_count = db.delete_document("appinstances", query)

        #     if deleted_count == 0:
        #         return (
        #             jsonify({
        #                 "status": 404,
        #                 "code": "NOT_FOUND",
        #                 "message": "App instance not found"
        #             }),
        #             404,
        #         )

        #     return "", 204  # Successfully deleted


    except Exception as e:
    except Exception as e:
        return (
        return (
+3 −17
Original line number Original line Diff line number Diff line
@@ -41,20 +41,6 @@ def get_local_zones() -> list[dict]:
            logger.error(f"SRM error: {result['error']}")
            logger.error(f"SRM error: {result['error']}")
            return []
            return []


        # zones = []
        # for node in result:
        #     try:
        #         zone = EdgeCloudZone(
        #             edgeCloudZoneId=node["id"],
        #             edgeCloudZoneName=node.get("name", "unknown"),
        #             edgeCloudZoneStatus=node.get("status", "unknown"),
        #             edgeCloudProvider=node.get("provider", "local-provider"),
        #             edgeCloudRegion=node.get("region", "default-region")
        #         )
        #         zones.append(zone.model_dump())
        #     except Exception as e:
        #         logger.warning(f"Failed to parse node into EdgeCloudZone: {e}")

        return result
        return result


    except Exception as e:
    except Exception as e:
@@ -72,10 +58,10 @@ def get_all_cloud_zones() -> List[EdgeCloudZone]:
    return get_local_zones() + get_federated_zones()
    return get_local_zones() + get_federated_zones()




def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=None):  # noqa: E501
def get_edge_cloud_zones(x_correlator: str | None = None, region=None, status=None):
    """Retrieve a list of the operators Edge Cloud Zones and their status
    """Retrieve a list of the operators Edge Cloud Zones and their status


    List of the operators Edge Cloud Zones and their status, ordering the results by location and filtering by status (active/inactive/unknown)  # noqa: E501
    List of the operators Edge Cloud Zones and their status, ordering the results by location and filtering by status (active/inactive/unknown)


    :param x_correlator: Correlation id for the different services
    :param x_correlator: Correlation id for the different services
    :type x_correlator: str
    :type x_correlator: str
+53 −0
Original line number Original line 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)}), 400
+52 −0
Original line number Original line Diff line number Diff line
from pydantic import BaseModel
from typing import List, Optional


class MobileNetworkIds(BaseModel):
    mncs: List[str]
    mcc: str


class FixedNetworkIds(BaseModel):
    __root__: List[str]


class CallbackCredentials(BaseModel):
    tokenUrl: str
    clientId: str
    clientSecret: str


class ServiceEndpoint(BaseModel):
    ipv4Addresses: Optional[List[str]] = None
    ipv6Addresses: Optional[List[str]] = None
    port: Optional[int] = None
    fqdn: Optional[str] = None


class ZoneDetails(BaseModel):
    geographyDetails: str
    zoneId: str
    geolocation: str


class FederationRequestData(BaseModel):
    origOPFederationId: str
    origOPCountryCode: Optional[str]
    origOPMobileNetworkCodes: Optional[MobileNetworkIds]
    origOPFixedNetworkCodes: Optional[List[str]]
    initialDate: str
    partnerStatusLink: str
    partnerCallbackCredentials: Optional[CallbackCredentials]


class FederationResponseData(BaseModel):
    federationContextId: str
    partnerOPFederationId: str
    partnerOPCountryCode: Optional[str]
    partnerOPMobileNetworkCodes: Optional[MobileNetworkIds]
    partnerOPFixedNetworkCodes: Optional[List[str]]
    offeredAvailabilityZones: Optional[List[ZoneDetails]]
    platformCaps: List[str]
    edgeDiscoveryServiceEndPoint: Optional[ServiceEndpoint]
    lcmServiceEndPoint: Optional[ServiceEndpoint]
Loading