Skip to content

Commit

Permalink
Merge pull request #145 from atlanticwave-sdx/delete-connection
Browse files Browse the repository at this point in the history
Delete connection
  • Loading branch information
congwang09 committed Jun 12, 2024
2 parents 20a74e8 + 23b8496 commit 3fdd855
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
- MQ_USER=${MQ_USER}
- MQ_PASS=${MQ_PASS}
# OXP settings.
- OXP_CONNECTION_URL=${OXP_CONNECTION_URL}
- OXP_PROVISION_URL=${OXP_PROVISION_URL}
- OXP_PULL_URL=${OXP_PULL_URL}
- OXP_PULL_INTERVAL=${OXP_PULL_INTERVAL}
- OXP_CONNECTION_URL=${OXP_CONNECTION_URL}
Expand Down
37 changes: 26 additions & 11 deletions sdx_lc/messaging/topic_queue_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,37 @@ def handle_mq_msg(self, msg_body):
if is_json(msg_body):
self.logger.info("JSON message")
msg_json = json.loads(msg_body)
if "uni_a" in msg_json and "uni_z" in msg_json:
if (
"link" in msg_json
and "uni_a" in msg_json["link"]
and "uni_z" in msg_json["link"]
):
connection = msg_json["link"]
self.logger.info("Got connection message.")
self.db_instance.add_key_value_pair_to_db(self.message_id, msg_body)
self.db_instance.add_key_value_pair_to_db(self.message_id, connection)
self.logger.info("Save to database complete.")
self.logger.info("Message ID:" + str(self.message_id))
self.message_id += 1
self.logger.info("Sending connection info to OXP.")
# Uncomment lines below to send connection info to OXP
try:
r = requests.post(str(OXP_CONNECTION_URL), json=msg_json)
self.logger.info(f"Status from OXP: {r}")
except Exception as e:
self.logger.error(f"Error on POST to {OXP_CONNECTION_URL}: {e}")
self.logger.info(
"Check your configuration and make sure OXP service is running."
)
# send connection info to OXP
if msg_json.get("operation") == "post":
try:
r = requests.post(str(OXP_CONNECTION_URL), json=connection)
self.logger.info(f"Status from OXP: {r}")
except Exception as e:
self.logger.error(f"Error on POST to {OXP_CONNECTION_URL}: {e}")
self.logger.info(
"Check your configuration and make sure OXP service is running."
)
elif msg_json.get("operation") == "delete":
try:
r = requests.delete(str(OXP_CONNECTION_URL), json=connection)
self.logger.info(f"Status from OXP: {r}")
except Exception as e:
self.logger.error(f"Error on DELETE {OXP_CONNECTION_URL}: {e}")
self.logger.info(
"Check your configuration and make sure OXP service is running."
)
elif "version" in msg_json:
msg_id = msg_json["id"]
lc_name = msg_json["name"]
Expand Down

0 comments on commit 3fdd855

Please sign in to comment.