Commit a0d5c0b0 authored by George Papathanail's avatar George Papathanail
Browse files

Merge branch 'fix/payloads-to-deploy-on-partner' into 'main'

update federation_controller and federation_service - add zone subscription logic

See merge request !12
parents 58181d28 8bc81148
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -46,6 +46,18 @@ def create_federation():
            zones_to_insert.append(inserted_item)
        insert_zones(zones_to_insert)    
        insert_federation(fed)

        zone_ids = [zone.get('zoneId') for zone in av_zones]
        callback_url = body.get('availZoneNotifLink')  # Optional from request
        zone_response, zone_code = federation_client.subscribe_to_zones(
            response.get('federationContextId'),
            zone_ids,
            token,
            callback_url
        )
        if zone_code != 200:
            logger.warning(f"Zone subscription returned non-200: {zone_code} - {zone_response}")

    return response, code

def get_federation(federationContextId):
+32 −0
Original line number Diff line number Diff line
@@ -253,6 +253,38 @@ class FederationManagerClient:
            logger.error(f"Zone synchronization unexpected error: {e}")
            return {"error": str(e), "status_code": 500}

    def subscribe_to_zones(self, federation_context_id: str, accepted_zone_ids: list, token: str,
                           callback_url: str = None):

        url = f"{self.base_url}/{federation_context_id}/zones"

        body = {
            'acceptedAvailabilityZones': accepted_zone_ids
        }

        if callback_url:
            body['availZoneNotifLink'] = callback_url

        try:
            response = requests.post(url, headers=self._get_headers(token), json=body, timeout=10)
            try:
                response_body = response.json()
            except ValueError:
                response_body = response.text
            return response_body, response.status_code
        except Timeout:
            logger.error("Subscribe to zones timed out")
            return {"error": "Request timed out"}, 408
        except ConnectionError:
            logger.error("Subscribe to zones connection error")
            return {"error": "Connection error"}, 503
        except requests.exceptions.HTTPError as http_err:
            logger.error(f"Subscribe to zones HTTP error: {http_err}")
            return {"error": str(http_err)}, response.status_code
        except Exception as e:
            logger.error(f"Subscribe to zones unexpected error: {e}")
            return {"error": str(e)}, 500

    def get_zone_resource_info(self, federation_context_id: str, zone_id: str, token: str):

        url = f"{self.base_url}/{federation_context_id}/zones/{zone_id}"