diff --git a/sdx_controller/controllers/l2vpn_controller.py b/sdx_controller/controllers/l2vpn_controller.py index 3335e2d..4006d68 100644 --- a/sdx_controller/controllers/l2vpn_controller.py +++ b/sdx_controller/controllers/l2vpn_controller.py @@ -70,7 +70,7 @@ def delete_connection(service_id): return "OK", 200 -def getconnection_by_id(service_id): +def get_connection_by_id(service_id): """ Find connection by ID. @@ -88,7 +88,7 @@ def getconnection_by_id(service_id): return json.loads(value[service_id]) -def getconnections(): # noqa: E501 +def get_connections(): # noqa: E501 """List all connections connection details # noqa: E501 @@ -218,3 +218,21 @@ def patch_connection(service_id, body=None): # noqa: E501 return f"Failed, reason: {e}", 500 return response, code + + +def get_archived_connections_by_id(service_id): + """ + List archived connection by ID. + + :param service_id: ID of connection that needs to be fetched + :type service_id: str + + :rtype: Connection + """ + + value = get_connection_status(db_instance, service_id) + + if not value: + return "Connection not found", 404 + + return value diff --git a/sdx_controller/handlers/connection_handler.py b/sdx_controller/handlers/connection_handler.py index fff74c7..b644794 100644 --- a/sdx_controller/handlers/connection_handler.py +++ b/sdx_controller/handlers/connection_handler.py @@ -271,6 +271,14 @@ def handle_link_failure(self, te_manager, failed_links): logger.debug(connection) self.place_connection(te_manager, connection) + def get_archived_connections(self, service_id: str): + historical_connections = self.db_instance.read_from_db( + "historical_connections", service_id + ) + if not historical_connections: + return None + return historical_connections[service_id] + def get_connection_status(db, service_id: str): """ diff --git a/sdx_controller/handlers/lc_message_handler.py b/sdx_controller/handlers/lc_message_handler.py index d58e878..aa69b84 100644 --- a/sdx_controller/handlers/lc_message_handler.py +++ b/sdx_controller/handlers/lc_message_handler.py @@ -63,14 +63,11 @@ def process_lc_json_msg( ) else: num_domain_topos = len(domain_list) - self.db_instance.add_key_value_pair_to_db( - "topologies", "num_domain_topos", num_domain_topos - ) - - logger.info("Adding topology to db: " + domain_name) + db_key = "LC-" + str(num_domain_topos) + logger.info(f"Adding topology {db_key} to db.") self.db_instance.add_key_value_pair_to_db( - "topologies", domain_name, json.dumps(msg_json) + "topologies", db_key, json.dumps(msg_json) ) # TODO: use TEManager API directly; but TEManager does not diff --git a/sdx_controller/messaging/rpc_queue_consumer.py b/sdx_controller/messaging/rpc_queue_consumer.py index 379cf96..3356b72 100644 --- a/sdx_controller/messaging/rpc_queue_consumer.py +++ b/sdx_controller/messaging/rpc_queue_consumer.py @@ -111,16 +111,16 @@ def start_sdx_consumer(self, thread_queue, db_instance): num_domain_topos = num_domain_topos_from_db["num_domain_topos"] logger.debug("Read num_domain_topos from db: ") logger.debug(num_domain_topos) - - for domain in domain_list: - topology = db_instance.read_from_db("topologies", domain) + for topo in range(1, num_domain_topos + 1): + db_key = f"LC-{topo}" + topology = db_instance.read_from_db("topologies", db_key) if topology: # Get the actual thing minus the Mongo ObjectID. - topology = topology[domain] + topology = topology[db_key] topo_json = json.loads(topology) self.te_manager.add_topology(topo_json) - logger.debug(f"Read {domain}: {topology}") + logger.debug(f"Read {db_key}: {topology}") while not self._exit_event.is_set(): # Queue.get() will block until there's an item in the queue. diff --git a/sdx_controller/swagger/swagger.yaml b/sdx_controller/swagger/swagger.yaml index d40c2de..016e1aa 100644 --- a/sdx_controller/swagger/swagger.yaml +++ b/sdx_controller/swagger/swagger.yaml @@ -159,7 +159,7 @@ paths: - l2vpn summary: List all l2vpn connections description: connection details - operationId: getconnections + operationId: get_connections responses: "200": description: successful operation @@ -204,7 +204,7 @@ paths: - l2vpn summary: Find l2vpn connection by ID description: connection details - operationId: getconnection_by_id + operationId: get_connection_by_id parameters: - name: service_id in: path @@ -284,6 +284,38 @@ paths: "400": description: Invalid Connection x-openapi-router-controller: sdx_controller.controllers.l2vpn_controller + /l2vpn/1.0/{service_id}/archived: + get: + tags: + - l2vpn + summary: Get list of l2vpn connection historical events by ID + description: connection historical events + operationId: get_archived_connections_by_id + parameters: + - name: service_id + in: path + description: ID of l2vpn connection for querying history + required: true + style: simple + explode: false + schema: + type: string + format: uuid + responses: + "200": + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/connection' + application/xml: + schema: + $ref: '#/components/schemas/connection' + "400": + description: Invalid ID supplied + "404": + description: connection not found + x-openapi-router-controller: sdx_controller.controllers.l2vpn_controller /user: post: tags: