Commit 36f99f95 authored by George Papathanail's avatar George Papathanail
Browse files

feat: add build_app_deployment_staus_change_events mapper

parent 0b9a58b3
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ from open_exposure_gateway.api.camara.edge_application_management.vwip.schemas i
    NetworkInterface as CamaraNetworkInterface,
)
from open_exposure_gateway.domain.edge_application_management import (
    AppDeploymentStatusChangeCloudEvent,
    AppDeploymentStatusChangeData,
    AppDeploymentTranslation,
    AppInstanceStatusChangeCloudEvent,
    AppInstanceStatusChangeData,
@@ -821,3 +823,29 @@ def build_app_instance_status_change_event(
            status=to_app_instance_status(app_instance.state).value,
        ),
    )


def build_app_deployment_status_change_events(
    app_deployment_id: UUID,
    app_instances: list[AppInstance],
    app_id: UUID,
    occurred_at: str,
) -> list[AppDeploymentStatusChangeCloudEvent]:
    """One CloudEvent per changed instance for the onAppDeploymentStatusChange
    callback array (ADR-0008). All instances of a deployment share one
    app_registration_id, hence one resolved app_id."""
    return [
        AppDeploymentStatusChangeCloudEvent(
            id=str(uuid4()),
            source=_CALLBACK_EVENT_SOURCE,
            time=occurred_at,
            data=AppDeploymentStatusChangeData(
                appDeploymentId=app_deployment_id,
                appInstanceId=app_instance.app_instance_id,
                appId=app_id,
                edgeCloudZoneId=app_instance.edge_cloud_zone_id,
                status=to_app_instance_status(app_instance.state).value,
            ),
        )
        for app_instance in app_instances
    ]