From 92fbb704f5c90b638dc18072e9c2956dacb6afba Mon Sep 17 00:00:00 2001 From: vitor-aignosi Date: Fri, 18 Jul 2025 09:45:42 -0300 Subject: [PATCH] SIENTIAPDE-1151 refactor: enhance error handling in build_tag_config and slot processing to include notifications for missing servers --- orchestrator/activities/formatters.py | 27 +++++++++++++++++--- orchestrator/utils/orchestrator_functions.py | 4 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/orchestrator/activities/formatters.py b/orchestrator/activities/formatters.py index a5c8053..7b1fc8a 100644 --- a/orchestrator/activities/formatters.py +++ b/orchestrator/activities/formatters.py @@ -118,14 +118,33 @@ class Formatters(BaseActivity): for i in range(1, number_of_slots): slot_config[f"{i}"] = {} for tag in tags[last_index:last_index + tags_per_slot]: - slot_config = build_tag_config( - tag, slot_config.copy(), opc_servers, i) + try: + slot_config = build_tag_config( + tag, slot_config.copy(), opc_servers, i) + except ValueError as e: + self.send_notification( + metadata=metadata, + notification_id="ORCHESTRATOR_BUILD_TAG_CONFIG_ERROR", + message=e, + block="orchestrator", + level=NotificationLevel.ERROR + ) + last_index += tags_per_slot slot_config[f"{number_of_slots}"] = {} for tag in tags[last_index:]: - slot_config = build_tag_config( - tag, slot_config.copy(), opc_servers, number_of_slots) + try: + slot_config = build_tag_config( + tag, slot_config.copy(), opc_servers, number_of_slots) + except ValueError as e: + self.send_notification( + metadata=metadata, + notification_id="ORCHESTRATOR_BUILD_TAG_CONFIG_ERROR", + message=e, + block="orchestrator", + level=NotificationLevel.ERROR + ) self.info("Processed slots", metadata=metadata) self.debug(json.dumps( diff --git a/orchestrator/utils/orchestrator_functions.py b/orchestrator/utils/orchestrator_functions.py index 270273a..f1d6510 100644 --- a/orchestrator/utils/orchestrator_functions.py +++ b/orchestrator/utils/orchestrator_functions.py @@ -146,6 +146,10 @@ def gather_read_tags(pipelines: list[dict[str, Any]]) -> dict[str, Any]: def build_tag_config(tag: dict[str, Any], slot_config: dict[str, Any], opc_servers: dict[str, Any], i: int): server_id = tag['server_id'] + + if server_id not in opc_servers: + raise ValueError(f"Server {server_id} not found in opc_servers") + server_name = opc_servers[server_id]['server_name'] if server_name not in slot_config[f"{i}"]: slot_config[f"{i}"][server_name] = {