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,24 +1,23 @@
|
||||
import json
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
from asyncua.crypto.security_policies import SecurityPolicyBasic256
|
||||
from asyncua.sync import Client
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
from sientia_do.notifications.handlers import NotificationHandler
|
||||
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
||||
from sientia_do.temporal.activities.base import BaseActivity
|
||||
from sientia_do.temporal.utils.logger import Logger
|
||||
from ingestor.managers.data_manager import DataManager
|
||||
import ingestor.metrics as metrics
|
||||
|
||||
|
||||
class OpcManager():
|
||||
class OpcManager(BaseActivity):
|
||||
def __init__(self, name: str, url: str, data_manager: DataManager,
|
||||
logger: Logger, server_uri: str, notification_handler: NotificationHandler, pod_id: str,
|
||||
logger: Logger, server_uri: str, notification_handler: NotificationHandler, pod_id: str, metadata: dict,
|
||||
cert_path: str = None, private_key_path: str = None, server_cert_path: str = None):
|
||||
self.url = url
|
||||
self.name = name
|
||||
self.server_uri = server_uri
|
||||
self.data_queue = {}
|
||||
self.logger = logger
|
||||
self.non_receive_count = 0
|
||||
self.client = None
|
||||
self.cert_path = cert_path
|
||||
@@ -27,13 +26,17 @@ class OpcManager():
|
||||
self.nodes = {}
|
||||
self.subscriptions = {}
|
||||
self.data_manager = data_manager
|
||||
self.notification_handler = notification_handler
|
||||
self.pod_id = pod_id
|
||||
self.metadata = metadata
|
||||
|
||||
metrics.OPC_CONNECTION_STATUS.labels(
|
||||
pod_id=self.pod_id, server_name=self.name, server_url=self.url).set(0)
|
||||
metrics.OPC_TAGS_SUBSCRIBED.labels(
|
||||
pod_id=self.pod_id, server_name=self.name).set(0)
|
||||
|
||||
BaseActivity.__init__(self, logger=logger,
|
||||
notification_handler=notification_handler)
|
||||
|
||||
def __str__(self):
|
||||
return f"OpcManager(name={self.name}, url={self.url}, server_uri={self.server_uri})\n" \
|
||||
f"nodes={self.nodes}, subscriptions={self.subscriptions}"
|
||||
@@ -296,7 +299,8 @@ class OpcManager():
|
||||
if self.nodes[node]['cycle_rule']['cycle_count'] >= 5:
|
||||
name = config['tag_name']
|
||||
cycles = self.nodes[node]['cycle_rule']['cycle_count']
|
||||
self.notification_handler.build_and_send_notification(
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'TAG_{node}:{name}_LISTENNING_STOPPED',
|
||||
message=f'{cycles} cycles without receive from {node}:{name}',
|
||||
block="opc_manager",
|
||||
@@ -314,7 +318,8 @@ class OpcManager():
|
||||
metrics.OPC_CYCLES_WITHOUT_DATA.labels(
|
||||
pod_id=self.pod_id, server_name=self.name).set(self.non_receive_count)
|
||||
if self.non_receive_count >= 5:
|
||||
self.notification_handler.build_and_send_notification(
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'OPC_LISTENNING_STOPPED__{self.name}',
|
||||
message=f'{self.non_receive_count} cycles without '
|
||||
f'receive from OPC {self.name}. Tags: {json.dumps(self.nodes)}',
|
||||
@@ -324,7 +329,8 @@ class OpcManager():
|
||||
if self.non_receive_count >= 15:
|
||||
metrics.OPC_RECONNECTIONS_TOTAL.labels(
|
||||
pod_id=self.pod_id, server_name=self.name).inc()
|
||||
self.notification_handler.build_and_send_notification(
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'OPC_CONNECTION_RETRY__{self.name}',
|
||||
message=f'Retrying to connect to server {self.name}',
|
||||
block="opc_manager",
|
||||
|
||||
Reference in New Issue
Block a user