Skip to content

Commit

Permalink
Merge pull request #328 from atlanticwave-sdx/add-topo-when-initializ…
Browse files Browse the repository at this point in the history
…e-te-manager

Use topology from database when initialize te manager
  • Loading branch information
congwang09 authored Oct 1, 2024
2 parents a6b251d + 7c9b358 commit df7f6f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
# MongoDB logs can drown out everything else, so we'll write
# them to a file. To watch the log messages, use: `docker exec
# -it <container> tail -f /var/log/mongodb/mongod.log`.
- '--quiet'
- '--logpath'
- '/var/log/mongodb/mongod.log'
healthcheck:
Expand Down
9 changes: 8 additions & 1 deletion sdx_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import os
import threading
Expand Down Expand Up @@ -64,8 +65,14 @@ def create_app(run_listener: bool = True):
app.db_instance = DbUtils()
app.db_instance.initialize_db()

topo_val = app.db_instance.read_from_db("topologies", "latest_topo")

# Get a handle to PCE.
app.te_manager = TEManager(topology_data=None)
app.te_manager = (
TEManager(topology_data=json.loads(topo_val["latest_topo"]))
if topo_val
else TEManager(topology_data=None)
)

# TODO: This is a hack, until we find a better way to get a handle
# to TEManager from Flask current_app, which are typically
Expand Down
9 changes: 4 additions & 5 deletions sdx_controller/handlers/lc_message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def process_lc_json_msg(
"domains", "domain_list", domain_list
)

logger.info("Adding topo")
logger.info("Adding topology to TE manager")
self.te_manager.add_topology(msg_json)

if self.db_instance.read_from_db("topologies", "num_domain_topos") is None:
Expand All @@ -63,15 +63,14 @@ def process_lc_json_msg(
)
else:
num_domain_topos = len(domain_list)
num_domain_topos = int(num_domain_topos) + 1
self.db_instance.add_key_value_pair_to_db(
"topologies", "num_domain_topos", num_domain_topos
)

logger.info("Adding topo to db.")
db_key = "LC-" + str(num_domain_topos)
logger.info("Adding topology to db: " + domain_name)

self.db_instance.add_key_value_pair_to_db(
"topologies", db_key, json.dumps(msg_json)
"topologies", domain_name, json.dumps(msg_json)
)

# TODO: use TEManager API directly; but TEManager does not
Expand Down
10 changes: 5 additions & 5 deletions sdx_controller/messaging/rpc_queue_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 topo in range(1, num_domain_topos + 2):
db_key = f"LC-{topo}"
topology = db_instance.read_from_db("topologies", db_key)

for domain in domain_list:
topology = db_instance.read_from_db("topologies", domain)

if topology:
# Get the actual thing minus the Mongo ObjectID.
topology = topology[db_key]
topology = topology[domain]
topo_json = json.loads(topology)
self.te_manager.add_topology(topo_json)
logger.debug(f"Read {db_key}: {topology}")
logger.debug(f"Read {domain}: {topology}")

while not self._exit_event.is_set():
# Queue.get() will block until there's an item in the queue.
Expand Down

0 comments on commit df7f6f4

Please sign in to comment.