Skip to content
Commits on Source (2)
......@@ -6,12 +6,16 @@ from edge_cloud_management_api.managers.log_manager import logger
from edge_cloud_management_api.services.edge_cloud_services import PiEdgeAPIClientFactory
from edge_cloud_management_api.services.storage_service import insert_zones
try:
pi_edge_factory = PiEdgeAPIClientFactory()
api_client = pi_edge_factory.create_pi_edge_api_client()
zones = api_client.edge_cloud_zones()
for zone in zones:
zone['_id'] = zone.get('edgeCloudZoneId')
insert_zones(zones)
except Exception as e:
logger.error(e.args)
class EdgeCloudZone(BaseModel):
edgeCloudZoneId: str = Field(..., description="Unique identifier of the Edge Cloud Zone")
......@@ -47,8 +51,6 @@ def get_local_zones() -> list[dict]:
if isinstance(result, dict) and "error" in result:
logger.error(f"SRM error: {result['error']}")
return []
return result
except Exception as e:
......
......@@ -17,28 +17,28 @@ def create_federation():
body = request.get_json()
token = __get_token()
response = federation_client.post_partner(body, token)
return jsonify(response)
response, code = federation_client.post_partner(body, token)
return response, code
def get_federation(federationContextId):
"""GET /{federationContextId}/partner - Get federation info."""
token = __get_token()
result = federation_client.get_partner(federationContextId, token)
return jsonify(result)
response, code = federation_client.get_partner(federationContextId, token)
return response, code
def delete_federation(federationContextId):
"""DELETE /{federationContextId}/partner - Delete federation."""
token = __get_token()
result = federation_client.delete_partner(federationContextId, token)
return jsonify(result)
response, code = federation_client.delete_partner(federationContextId, token)
return response, code
def get_federation_context_ids():
"""GET /fed-context-id - Fetch federationContextId(s)."""
token = __get_token()
response = federation_client.get_federation_context_ids(token)
return jsonify(response)
response, code = federation_client.get_federation_context_ids(token)
return response, code
def onboard_application_to_partner(federationContextId):
......@@ -64,6 +64,23 @@ def delete_onboarded_app(federationContextId, appId):
result = federation_client.delete_onboarded_app(federationContextId, appId, token)
return jsonify(result)
'''---AVAILABILITY ZONE INFO SYNCHRONIZATION---'''
def request_zone_synch(federationContextId):
token = __get_token()
body = request.get_json()
response = federation_client.request_zone_sync(federation_context_id=federationContextId, body=body, token=token)
return jsonify(response)
def get_zone_resource_info(federationContextId, zoneId):
token = __get_token()
response = federation_client.get_zone_resource_info(federation_context_id=federationContextId, zone_id=zoneId, token=token)
return jsonify(response)
def remove_zone_sync(federationContextId, zoneId):
token = __get_token()
response = federation_client.remove_zone_sync(federation_context_id=federationContextId, zone_id=zoneId, token=token)
return jsonify(response)
def __get_token():
bearer = connexion.request.headers['Authorization']
......
......@@ -18,83 +18,86 @@ class FederationManagerClient:
headers['Accept'] = 'application/json'
return headers
'''---FEDERATION ESTABLISHMENT---'''
def post_partner(self, data: dict, token: str):
url = f"{self.base_url}/partner"
try:
response = requests.post(url, json=data, headers=self._get_headers(token), timeout=10)
response.raise_for_status()
return response.json()
return response.json(), 200
except Timeout:
logger.error("POST /partner timed out")
return {"error": "Request timed out"}, 408
except ConnectionError:
logger.error("POST /partner connection error")
return {"error": "Connection error"}
return {"error": "Connection error"}, 504
except requests.exceptions.HTTPError as http_err:
logger.error(f"POST /partner HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
return {'Error': http_err.response.json().get('detail')}, response.status_code
except Exception as e:
logger.error(f"POST /partner unexpected error: {e}")
return {"error": str(e)}
return {"error": str(e)}, 500
def get_partner(self, federation_context_id: str, token: str):
url = f"{self.base_url}/{federation_context_id}/partner"
try:
response = requests.get(url, headers=self._get_headers(token), timeout=10)
response.raise_for_status()
return response.json()
return response.json(), 200
except Timeout:
logger.error("GET /{id}/partner timed out")
return {"error": "Request timed out"}
return {"error": "Request timed out"}, 408
except ConnectionError:
logger.error("GET /{id}/partner connection error")
return {"error": "Connection error"}
return {"error": "Connection error"}, 504
except requests.exceptions.HTTPError as http_err:
logger.error(f"GET /{id}/partner HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
return {'Error': http_err.response.json().get('detail')}, response.status_code
except Exception as e:
logger.error(f"GET /{id}/partner unexpected error: {e}")
return {"error": str(e)}
return {"error": str(e)}, 500
def delete_partner(self, federation_context_id: str, token: str):
url = f"{self.base_url}/{federation_context_id}/partner"
try:
response = requests.delete(url, headers=self._get_headers(token), timeout=10)
if response.content:
return response.json()
return response.json(), 200
return {"status": response.status_code}
except Timeout:
logger.error("DELETE /{id}/partner timed out")
return {"error": "Request timed out"}
return {"error": "Request timed out"}, 408
except ConnectionError:
logger.error("DELETE /{id}/partner connection error")
return {"error": "Connection error"}
return {"error": "Connection error"}, 504
except requests.exceptions.HTTPError as http_err:
logger.error(f"DELETE /{id}/partner HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
return {'Error': http_err.response.json().get('detail')}, response.status_code
except Exception as e:
logger.error(f"DELETE /{id}/partner unexpected error: {e}")
return {"error": str(e)}
return {"error": str(e)}, 500
def get_federation_context_ids(self, token: str):
url = f"{self.base_url}/fed-context-id"
try:
response = requests.get(url, headers=self._get_headers(token), timeout=10)
response.raise_for_status()
return response.json()
return response.json(), 200
except Timeout:
logger.error("GET /fed-context-id timed out")
return {"error": "Request timed out"}
return {"error": "Request timed out"}, 408
except ConnectionError:
logger.error("GET /fed-context-id connection error")
return {"error": "Connection error"}
return {"error": "Connection error"}, 504
except requests.exceptions.HTTPError as http_err:
logger.error(f"GET /fed-context-id HTTP error: {http_err}")
if response.status_code==404:
return {'erorr': http_err}, 404
return {'Error': http_err.response.json().get('detail')}, response.status_code
except Exception as e:
logger.error(f"GET /fed-context-id unexpected error: {e}")
return {"error": str(e)}
return {"error": str(e)}, 500
'''---PARTNER APP ONBOARDING---'''
def onboard_application(self, federation_context_id: str, body: dict, token: str):
url = f"{self.base_url}/{federation_context_id}/application/onboarding"
......@@ -138,12 +141,12 @@ class FederationManagerClient:
def delete_onboarded_app(self, federation_context_id: str, app_id: str, token: str):
url = f"{self.base_url}/{federation_context_id}/application/onboarding/app/{app_id}"
try:
response = requests.delete(url, headers=self._get_headers(), timeout=10)
response = requests.delete(url, headers=self._get_headers(token), timeout=10)
response.raise_for_status()
return {"message": "Deleted successfully", "status_code": response.status_code}
except Timeout:
logger.error("DELETE onboarding app timed out")
return {"error": "Request timed out", "status_code": 504}
return {"error": "Request timed out", "status_code": 408}
except ConnectionError:
logger.error("DELETE onboarding app connection error")
return {"error": "Connection error", "status_code": 503}
......@@ -154,6 +157,67 @@ class FederationManagerClient:
logger.error(f"DELETE onboarding app unexpected error: {e}")
return {"error": str(e), "status_code": 500}
'''---PARTNER APP DEPLOYMENT---'''
'''---AVAILABILITY ZONE INFO SYNCHRONIZATION---'''
def request_zone_sync(self, federation_context_id: str, body: dict, token: str):
url = f"{self.base_url}/{federation_context_id}/zones"
try:
response = requests.post(url, headers=self._get_headers(token), json=body, timeout=10)
return response.json()
except Timeout:
logger.error("Zone synchronization timed out")
return {"error": "Request timed out", "status_code": 408}
except ConnectionError:
logger.error("Zone synchronization connection error")
return {"error": "Connection error", "status_code": 503}
except requests.exceptions.HTTPError as http_err:
logger.error(f"Zone synchronization HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
except Exception as e:
logger.error(f"Zone synchronization unexpected error: {e}")
return {"error": str(e), "status_code": 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}"
try:
response = requests.get(url, headers=self._get_headers(token), timeout=10)
return response.json()
except Timeout:
logger.error("Zone resource info timed out")
return {"error": "Request timed out", "status_code": 408}
except ConnectionError:
logger.error("Zone resource info connection error")
return {"error": "Connection error", "status_code": 503}
except requests.exceptions.HTTPError as http_err:
logger.error(f"Zone resource info HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
except Exception as e:
logger.error(f"Zone resource info unexpected error: {e}")
return {"error": str(e), "status_code": 500}
def remove_zone_sync(self, federation_context_id: str, zone_id: str, token: str):
url = f"{self.base_url}/{federation_context_id}/zones/{zone_id}"
try:
response = requests.delete(url, headers=self._get_headers(token), timeout=10)
return response.json()
except Timeout:
logger.error("Remove Zone sync timed out")
return {"error": "Request timed out", "status_code": 408}
except ConnectionError:
logger.error("Remove Zone sync connection error")
return {"error": "Connection error", "status_code": 503}
except requests.exceptions.HTTPError as http_err:
logger.error(f"Remove Zone sync HTTP error: {http_err}")
return {"error": str(http_err), "status_code": response.status_code}
except Exception as e:
logger.error(f"Remove Zone sync unexpected error: {e}")
return {"error": str(e), "status_code": 500}
class FederationManagerClientFactory:
......
......@@ -854,189 +854,189 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/FederationResponseData'
"400":
description: Bad request
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"404":
description: Unauthorized
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"408":
description: Timeout
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"409":
description: Conflict
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"500":
description: Internal Server Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
callbacks:
onPartnerStatusEvent:
'{$request.body#/partnerStatusLink }':
post:
requestBody:
description: |
OP uses this callback api to notify partner OP about change in federation status, federation metadata or offered zone details. Allowed combinations of objectType and operationType are
- FEDERATION - STATUS: Status specified by parameter 'federationStatus'.
- ZONES - STATUS: Status specified by parameter 'zoneStatus'.
- ZONES - ADD: Use parameter 'addZones' to define add new zones
- ZONES - REMOVE: Use parameter 'removeZones' to define remove zones.
- EDGE_DISCOVERY_SERVICE - UPDATE: Use parameter 'edgeDiscoverySvcEndPoint' to specify new endpoints
- LCM_SERVICE - UPDATE: Use parameter 'lcmSvcEndPoint' to specify new endpoints
- MOBILE_NETWORK_CODES - ADD: Use parameter 'addMobileNetworkIds' to define new mobile network codes.
- MOBILE_NETWORK_CODES - REMOVE: Use parameter 'removeMobileNetworkIds' to remove mobile network codes.
- FIXED_NETWORK_CODES - ADD: Use parameter 'addFixedNetworkIds' to define new fixed network codes.
- FIXED_NETWORK_CODES - REMOVE: Use parameter 'removeFixedNetworkIds' to remove fixed network codes.
- SERVICE_APIS - ADD/REMOVE: Parameter Usage 'addServiceAPIs / removeServiceAPIs' to add or remove Service APIs support.
content:
application/json:
schema:
required:
- federationContextId
- modificationDate
- objectType
- operationType
type: object
properties:
federationContextId:
$ref: '#/components/schemas/FederationIdentifier'
objectType:
type: string
enum:
- FEDERATION
- ZONES
- EDGE_DISCOVERY_SERVICE
- LCM_SERVICE
- MOBILE_NETWORK_CODES
- FIXED_NETWORK_CODES
- SERVICE_APIS
operationType:
type: string
enum:
- STATUS
- UPDATE
- ADD
- REMOVE
edgeDiscoverySvcEndPoint:
$ref: '#/components/schemas/ServiceEndpoint'
lcmSvcEndPoint:
$ref: '#/components/schemas/ServiceEndpoint'
addMobileNetworkIds:
$ref: '#/components/schemas/MobileNetworkIds'
removeMobileNetworkIds:
$ref: '#/components/schemas/MobileNetworkIds'
addFixedNetworkIds:
$ref: '#/components/schemas/FixedNetworkIds'
removeFixedNetworkIds:
$ref: '#/components/schemas/FixedNetworkIds'
addZones:
minItems: 1
type: array
description: "List of zones, which the operator platform\
\ wishes to make available to developers/ISVs of requesting\
\ operator platform."
items:
$ref: '#/components/schemas/ZoneDetails'
removeZones:
minItems: 1
type: array
description: "List of zones, which the operator platform\
\ no longer wishes to share."
items:
$ref: '#/components/schemas/ZoneIdentifier'
addServiceAPIs:
$ref: '#/components/schemas/serviceAPINames'
removeServiceAPIs:
$ref: '#/components/schemas/serviceAPINames'
zoneStatus:
minItems: 1
type: array
items:
required:
- status
- zoneId
type: object
properties:
zoneId:
$ref: '#/components/schemas/ZoneIdentifier'
status:
$ref: '#/components/schemas/Status'
federationStatus:
$ref: '#/components/schemas/Status'
modificationDate:
type: string
description: Date and time of the federation modification
by the originating partner OP
format: date-time
responses:
"204":
description: Expected response to a successful call back processing
"400":
description: Bad request
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"401":
description: Unauthorized
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"409":
description: Conflict
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"422":
description: Unprocessable Entity
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"500":
description: Internal Server Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"503":
description: Service Unavailable
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"520":
description: Web Server Returned an Unknown Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
default:
description: Generic Error
# "400":
# description: Bad request
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "404":
# description: Unauthorized
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "408":
# description: Timeout
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "409":
# description: Conflict
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "500":
# description: Internal Server Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# callbacks:
# onPartnerStatusEvent:
# '{$request.body#/partnerStatusLink }':
# post:
# requestBody:
# description: |
# OP uses this callback api to notify partner OP about change in federation status, federation metadata or offered zone details. Allowed combinations of objectType and operationType are
# - FEDERATION - STATUS: Status specified by parameter 'federationStatus'.
# - ZONES - STATUS: Status specified by parameter 'zoneStatus'.
# - ZONES - ADD: Use parameter 'addZones' to define add new zones
# - ZONES - REMOVE: Use parameter 'removeZones' to define remove zones.
# - EDGE_DISCOVERY_SERVICE - UPDATE: Use parameter 'edgeDiscoverySvcEndPoint' to specify new endpoints
# - LCM_SERVICE - UPDATE: Use parameter 'lcmSvcEndPoint' to specify new endpoints
# - MOBILE_NETWORK_CODES - ADD: Use parameter 'addMobileNetworkIds' to define new mobile network codes.
# - MOBILE_NETWORK_CODES - REMOVE: Use parameter 'removeMobileNetworkIds' to remove mobile network codes.
# - FIXED_NETWORK_CODES - ADD: Use parameter 'addFixedNetworkIds' to define new fixed network codes.
# - FIXED_NETWORK_CODES - REMOVE: Use parameter 'removeFixedNetworkIds' to remove fixed network codes.
# - SERVICE_APIS - ADD/REMOVE: Parameter Usage 'addServiceAPIs / removeServiceAPIs' to add or remove Service APIs support.
# content:
# application/json:
# schema:
# required:
# - federationContextId
# - modificationDate
# - objectType
# - operationType
# type: object
# properties:
# federationContextId:
# $ref: '#/components/schemas/FederationIdentifier'
# objectType:
# type: string
# enum:
# - FEDERATION
# - ZONES
# - EDGE_DISCOVERY_SERVICE
# - LCM_SERVICE
# - MOBILE_NETWORK_CODES
# - FIXED_NETWORK_CODES
# - SERVICE_APIS
# operationType:
# type: string
# enum:
# - STATUS
# - UPDATE
# - ADD
# - REMOVE
# edgeDiscoverySvcEndPoint:
# $ref: '#/components/schemas/ServiceEndpoint'
# lcmSvcEndPoint:
# $ref: '#/components/schemas/ServiceEndpoint'
# addMobileNetworkIds:
# $ref: '#/components/schemas/MobileNetworkIds'
# removeMobileNetworkIds:
# $ref: '#/components/schemas/MobileNetworkIds'
# addFixedNetworkIds:
# $ref: '#/components/schemas/FixedNetworkIds'
# removeFixedNetworkIds:
# $ref: '#/components/schemas/FixedNetworkIds'
# addZones:
# minItems: 1
# type: array
# description: "List of zones, which the operator platform\
# \ wishes to make available to developers/ISVs of requesting\
# \ operator platform."
# items:
# $ref: '#/components/schemas/ZoneDetails'
# removeZones:
# minItems: 1
# type: array
# description: "List of zones, which the operator platform\
# \ no longer wishes to share."
# items:
# $ref: '#/components/schemas/ZoneIdentifier'
# addServiceAPIs:
# $ref: '#/components/schemas/serviceAPINames'
# removeServiceAPIs:
# $ref: '#/components/schemas/serviceAPINames'
# zoneStatus:
# minItems: 1
# type: array
# items:
# required:
# - status
# - zoneId
# type: object
# properties:
# zoneId:
# $ref: '#/components/schemas/ZoneIdentifier'
# status:
# $ref: '#/components/schemas/Status'
# federationStatus:
# $ref: '#/components/schemas/Status'
# modificationDate:
# type: string
# description: Date and time of the federation modification
# by the originating partner OP
# format: date-time
# responses:
# "204":
# description: Expected response to a successful call back processing
# "400":
# description: Bad request
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "401":
# description: Unauthorized
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "404":
# description: Not Found
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "409":
# description: Conflict
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "422":
# description: Unprocessable Entity
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "500":
# description: Internal Server Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "503":
# description: Service Unavailable
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "520":
# description: Web Server Returned an Unknown Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# default:
# description: Generic Error
/{federationContextId}/partner:
get:
......@@ -1065,24 +1065,24 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/inline_response_200_1'
"401":
description: Unauthorized
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"500":
description: Internal Server Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
# "401":
# description: Unauthorized
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "404":
# description: Not Found
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "500":
# description: Internal Server Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
delete:
tags:
- FederationManagement
......@@ -1102,24 +1102,24 @@ paths:
responses:
"200":
description: Federation removed successfully
"401":
description: Unauthorized
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"500":
description: Internal Server Error
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
# "401":
# description: Unauthorized
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "404":
# description: Not Found
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "500":
# description: Internal Server Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
/fed-context-id:
get:
tags:
......@@ -1132,43 +1132,41 @@ paths:
responses:
"200":
description: Federation context identifier retrieval request accepted
headers:
Location:
description: "Contains the URI of the existing resource, according to\
\ the structure: {apiRoot}/operatorplatform/federation/v1/partner/{federationContextId}"
required: true
style: simple
explode: false
schema:
type: string
Accept-Encoding:
description: "Accept-Encoding, described in IETF RFC 7694"
style: simple
explode: false
schema:
type: string
Content-Encoding:
description: "Content-Encoding, described in IETF RFC 7231"
style: simple
explode: false
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/inline_response_200_2'
"401":
description: Unauthorized
content:
application:/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
"404":
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/ProblemDetails'
# "401":
# description: Unauthorized
# content:
# application:/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "404":
# description: Not Found
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "408":
# description: Request timed out
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "504":
# description: Connection Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
# "500":
# description: Interal Server Error
# content:
# application/problem+json:
# schema:
# $ref: '#/components/schemas/ProblemDetails'
components:
# securitySchemes:
......