Skip to content
Snippets Groups Projects
Commit 556ec813 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-550: Install archiver json config along with package, slightly simplify...

L2SS-550: Install archiver json config along with package, slightly simplify its use by merging Selector into Archiver, and do not apply by default in the constructor, making all actions explicit.
parent f384165b
Branches
No related tags found
1 merge request!202L2SS-550: Install archiver config
...@@ -57,3 +57,7 @@ console_scripts = ...@@ -57,3 +57,7 @@ console_scripts =
l2ss-random-data = tangostationcontrol.test.devices.random_data:main l2ss-random-data = tangostationcontrol.test.devices.random_data:main
l2ss-snmp = tangostationcontrol.examples.snmp.snmp:main l2ss-snmp = tangostationcontrol.examples.snmp.snmp:main
l2ss-version = tangostationcontrol.common.lofar_version:main l2ss-version = tangostationcontrol.common.lofar_version:main
[options.package_data]
* = *.json
...@@ -6,6 +6,7 @@ from tango import DeviceProxy, AttributeProxy, DevState, DevFailed ...@@ -6,6 +6,7 @@ from tango import DeviceProxy, AttributeProxy, DevState, DevFailed
import time import time
import json, os import json, os
import pkg_resources
logger = logging.getLogger() logger = logging.getLogger()
...@@ -64,7 +65,7 @@ class Archiver(): ...@@ -64,7 +65,7 @@ class Archiver():
dev_polling_time = None dev_polling_time = None
dev_archive_time = None dev_archive_time = None
def __init__(self, selector_filename:str = None, cm_name: str = 'archiving/hdbppts/confmanager01', context: str = 'RUN'): def __init__(self, cm_name: str = 'archiving/hdbppts/confmanager01', context: str = 'RUN'):
self.cm_name = cm_name self.cm_name = cm_name
self.cm = DeviceProxy(cm_name) self.cm = DeviceProxy(cm_name)
try: try:
...@@ -74,11 +75,6 @@ class Archiver(): ...@@ -74,11 +75,6 @@ class Archiver():
raise Exception(f"Connection failed with Configuration Manager {cm_name}") from e raise Exception(f"Connection failed with Configuration Manager {cm_name}") from e
self.es_list = [es_name for es_name in self.get_subscribers(from_db=False)] self.es_list = [es_name for es_name in self.get_subscribers(from_db=False)]
self.cm.write_attribute('Context',context) # Set default Context Archiving for all the subscribers self.cm.write_attribute('Context',context) # Set default Context Archiving for all the subscribers
self.selector = Selector() if selector_filename is None else Selector(selector_filename) # Create selector for customized strategies
try:
self.apply_selector()
except Exception as e:
raise Exception("Error in selecting configuration. Archiving framework will not be updated.") from e
def get_db_config(self, device_name:str) -> dict: def get_db_config(self, device_name:str) -> dict:
""" """
...@@ -131,11 +127,15 @@ class Archiver(): ...@@ -131,11 +127,15 @@ class Archiver():
min_es = min(load_dict,key=load_dict.get) min_es = min(load_dict,key=load_dict.get)
return min_es return min_es
def apply_selector(self): def get_configuration(self, resource: str = 'lofar2') -> dict:
""" Read an archiver configuration from one of the preinstalled resources in archiver_config. """
resource = pkg_resources.resource_stream(__name__, f'archiver_config/{resource}.json')
return json.load(resource)
def apply_configuration(self, config_dict: dict):
""" """
Apply the customized strategy defined by the selector Apply the customized strategy defined by the given archiver configuration.
""" """
config_dict = self.selector.get_dict()
# Set global development env variables # Set global development env variables
var_dict = config_dict.get('global_variables') var_dict = config_dict.get('global_variables')
self.dev_polling_time = int(var_dict.get('development_polling_time')) self.dev_polling_time = int(var_dict.get('development_polling_time'))
...@@ -170,7 +170,6 @@ class Archiver(): ...@@ -170,7 +170,6 @@ class Archiver():
logger.warning(f"Device {device} not defined in TangoDB") logger.warning(f"Device {device} not defined in TangoDB")
else: else:
raise Exception from e raise Exception from e
return env_dict
def add_event_subscriber(self, es_name:str=None): def add_event_subscriber(self, es_name:str=None):
""" """
...@@ -445,24 +444,3 @@ class AttributeFormatException(Exception): ...@@ -445,24 +444,3 @@ class AttributeFormatException(Exception):
def __init__(self, message="Wrong Tango attribute format! Try: domain/family/member/attribute (e.g. STAT/RECV/1/temperature)"): def __init__(self, message="Wrong Tango attribute format! Try: domain/family/member/attribute (e.g. STAT/RECV/1/temperature)"):
self.message = message self.message = message
super().__init__(self.message) super().__init__(self.message)
class Selector():
"""
The Selector class implements operations on select customized retrieval strategies
"""
def __init__(self, filename='lofar2.json'):
self.filename = filename
def get_dict(self):
"""
Create a dictionary from the JSON file
"""
try:
filepath = os.path.join(os.path.dirname(__file__),'archiver_config',self.filename)
f = open(filepath)
data = json.load(f)
f.close()
except FileNotFoundError as e:
raise
return data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment