SIENTIAPDE-1163
Refactor Ingestor and Manager classes to use CoreNotificationHandler and improve metadata handling - Updated Ingestor class to initialize logger using get_logger and replaced notification handler initialization with metadata dictionary. - Refactored DataManager, IngestorManager, OpcManager, and ResourceManager classes to inherit from BaseActivity, allowing for consistent logger and notification handler usage. - Enhanced notification handling by integrating metadata into notification methods across various managers. - Added .vscode/ to .gitignore to exclude VSCode configuration files.
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
from logging import Logger
|
||||
import traceback
|
||||
from typing import Dict, List
|
||||
from copy import deepcopy
|
||||
from sientia_do.notifications.handlers import NotificationHandler
|
||||
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
from sientia_do.temporal.activities.base import BaseActivity
|
||||
from sientia_do.temporal.utils.logger import Logger
|
||||
from ingestor.managers.data_manager import DataManager
|
||||
from ingestor.managers.opc_manager import OpcManager
|
||||
from ingestor.managers.resource_manager import ResourceManager
|
||||
import ingestor.metrics as metrics
|
||||
|
||||
|
||||
class IngestorManager():
|
||||
class IngestorManager(BaseActivity):
|
||||
def __init__(self,
|
||||
kafka_servers: str, redis_data: dict,
|
||||
lease_ttl: int, heartbeat_ttl: int, pod_id: str,
|
||||
poll_interval: int, mongo_connection_string: str, mongo_database: str,
|
||||
metadata: dict,
|
||||
logger: Logger, notification_handler: NotificationHandler,
|
||||
export_to_kafka: bool = False):
|
||||
|
||||
@@ -24,23 +26,39 @@ class IngestorManager():
|
||||
redis_password = redis_data.get('password', None)
|
||||
|
||||
self.data_manager = DataManager(
|
||||
kafka_servers, mongo_connection_string, mongo_database,
|
||||
export_to_kafka, logger, notification_handler)
|
||||
kafka_servers=kafka_servers,
|
||||
mongo_connection_string=mongo_connection_string,
|
||||
mongo_database=mongo_database,
|
||||
export_to_kafka=export_to_kafka,
|
||||
metadata=metadata,
|
||||
logger=logger,
|
||||
notification_handler=notification_handler
|
||||
)
|
||||
self.opc_managers = {}
|
||||
self.resource_manager = ResourceManager(
|
||||
redis_host, redis_port, lease_ttl, heartbeat_ttl, pod_id, redis_username, redis_password
|
||||
host=redis_host,
|
||||
port=redis_port,
|
||||
lease_ttl=lease_ttl,
|
||||
heartbeat_ttl=heartbeat_ttl,
|
||||
pod_id=pod_id,
|
||||
metadata=metadata,
|
||||
logger=logger,
|
||||
notification_handler=notification_handler,
|
||||
username=redis_username,
|
||||
password=redis_password,
|
||||
)
|
||||
self.number_of_slots = 0
|
||||
self.poll_interval = poll_interval
|
||||
self.logger = logger
|
||||
self.managed_tags = {}
|
||||
self.opc_servers = {}
|
||||
|
||||
self.notification_handler = notification_handler
|
||||
self.pod_id = pod_id
|
||||
self.metadata = metadata
|
||||
|
||||
def initialize_opc_from_config(self, server_config: dict,
|
||||
data_manager: DataManager, logger: Logger) -> OpcManager | None:
|
||||
BaseActivity.__init__(self, logger=logger,
|
||||
notification_handler=notification_handler)
|
||||
|
||||
def initialize_opc_from_config(self, server_config: dict) -> OpcManager | None:
|
||||
"""
|
||||
Initializes an OPC Manager instance using the provided server configuration.
|
||||
Args:
|
||||
@@ -63,12 +81,17 @@ class IngestorManager():
|
||||
self.logger.info(
|
||||
f"Initializing OpcManager at {server_config['url']}")
|
||||
manager = OpcManager(
|
||||
server_config['name'], server_config['url'],
|
||||
data_manager, logger, server_config['server_uri'],
|
||||
self.notification_handler, self.pod_id, server_config.get(
|
||||
'cert_path'),
|
||||
server_config.get('private_key_path'),
|
||||
server_config.get('server_cert_path')
|
||||
name=server_config['name'],
|
||||
url=server_config['url'],
|
||||
data_manager=self.data_manager,
|
||||
logger=self.logger,
|
||||
server_uri=server_config['server_uri'],
|
||||
notification_handler=self.notification_handler,
|
||||
pod_id=self.pod_id,
|
||||
metadata=self.metadata,
|
||||
cert_path=server_config.get('cert_path'),
|
||||
private_key_path=server_config.get('private_key_path'),
|
||||
server_cert_path=server_config.get('server_cert_path')
|
||||
)
|
||||
|
||||
manager.config = server_config
|
||||
@@ -76,7 +99,8 @@ class IngestorManager():
|
||||
except Exception as e:
|
||||
|
||||
trace = traceback.format_exc()
|
||||
self.notification_handler.build_and_send_notification(
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'OPC_CONNECTION_ERROR_{server_config["name"]}',
|
||||
message=f'Error initializing OPC manager: {e}',
|
||||
block="opc_manager",
|
||||
@@ -135,7 +159,7 @@ class IngestorManager():
|
||||
f"Initializing OPC manager for server {server}"
|
||||
)
|
||||
server_instance = self.initialize_opc_from_config(
|
||||
server_config, self.data_manager, self.logger
|
||||
server_config
|
||||
)
|
||||
|
||||
elif server_instance.config != server_config:
|
||||
@@ -145,7 +169,7 @@ class IngestorManager():
|
||||
server_instance.disconnect()
|
||||
del self.opc_managers[server]
|
||||
server_instance = self.initialize_opc_from_config(
|
||||
server_config, self.data_manager, self.logger
|
||||
server_config
|
||||
)
|
||||
else:
|
||||
self.logger.debug(
|
||||
@@ -416,7 +440,8 @@ class IngestorManager():
|
||||
metrics.OPC_SUBSCRIPTION_ERRORS.labels(
|
||||
pod_id=self.pod_id, server=server, slot=slot).inc()
|
||||
trace = traceback.format_exc()
|
||||
self.notification_handler.build_and_send_notification(
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'OPC_SUBSCRIPTION_ERROR_{slot}:{server}',
|
||||
message=f'Failed to subscribe to tags from {slot}:{server}\n{tags}: {e}',
|
||||
block="opc_manager",
|
||||
|
||||
Reference in New Issue
Block a user