Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
congwang09 committed Sep 5, 2024
1 parent 86e5acb commit d96bf15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions sdx_controller/handlers/connection_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,24 @@ def archive_connection(self, service_id) -> None:
connection_request = self.db_instance.read_from_db("connections", service_id)
if not connection_request:
return

connection_request_str = connection_request[service_id]
self.db_instance.delete_one_entry("connections", service_id)

historical_connections = self.db_instance.read_from_db("historical_connections", service_id)
historical_connections = self.db_instance.read_from_db(
"historical_connections", service_id
)

if historical_connections:
historical_connections_list = historical_connections[service_id]
historical_connections_list.append(connection_request_str)
self.db_instance.add_key_value_pair_to_db("historical_connections", service_id, historical_connections_list)
self.db_instance.add_key_value_pair_to_db(
"historical_connections", service_id, historical_connections_list
)
else:
self.db_instance.add_key_value_pair_to_db("historical_connections", service_id, [connection_request_str])
self.db_instance.add_key_value_pair_to_db(
"historical_connections", service_id, [connection_request_str]
)
logger.debug(f"Archived connection: {service_id}")

def remove_connection(self, te_manager, service_id) -> Tuple[str, int]:
Expand Down
11 changes: 9 additions & 2 deletions sdx_controller/utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

import pymongo

COLLECTION_NAMES = ["topologies", "connections", "breakdowns", "domains", "links", "historical_connections"]
COLLECTION_NAMES = [
"topologies",
"connections",
"breakdowns",
"domains",
"links",
"historical_connections",
]

pymongo_logger = logging.getLogger("pymongo")
pymongo_logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -105,4 +112,4 @@ def mark_deleted(self, collection, key):
def delete_one_entry(self, collection, key):
key = str(key)
db_collection = self.sdxdb[collection]
db_collection.delete_one({key: {"$exists": True}})
db_collection.delete_one({key: {"$exists": True}})

0 comments on commit d96bf15

Please sign in to comment.