diff --git a/tangostationcontrol/setup.cfg b/tangostationcontrol/setup.cfg index 31662e40d639c2af2de417e734e794dc5679d4a4..ccbd782a1cfacbd44ebef9c3c57446b56dfd293d 100644 --- a/tangostationcontrol/setup.cfg +++ b/tangostationcontrol/setup.cfg @@ -57,3 +57,7 @@ console_scripts = l2ss-random-data = tangostationcontrol.test.devices.random_data:main l2ss-snmp = tangostationcontrol.examples.snmp.snmp:main l2ss-version = tangostationcontrol.common.lofar_version:main + +[options.package_data] +* = *.json + diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py index 715ca039db4aaf03121f3b1c15815de7746a133e..434d60556bd4ccfdc9e91e95033f5e0f38acf025 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py @@ -6,6 +6,7 @@ from tango import DeviceProxy, AttributeProxy, DevState, DevFailed import time import json, os +import pkg_resources logger = logging.getLogger() @@ -82,10 +83,10 @@ class Archiver(): """ # Global 'DEVELOPMENT' environment variables set by configuration file - dev_polling_time = None - dev_archive_time = None + dev_polling_time = 600 + dev_archive_time = 3600 - 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 = DeviceProxy(cm_name) try: @@ -95,11 +96,6 @@ class Archiver(): 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.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: """ @@ -150,13 +146,17 @@ class Archiver(): load_dict[es_name]=float(es.AttributeRecordFreq or 0) # Return the subscriber's name with min load min_es = min(load_dict,key=load_dict.get) - return min_es - - def apply_selector(self): + return min_es + + 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 var_dict = config_dict.get('global_variables') self.dev_polling_time = int(var_dict.get('development_polling_time')) @@ -191,7 +191,6 @@ class Archiver(): logger.warning(f"Device {device} not defined in TangoDB") else: raise Exception from e - return env_dict def add_event_subscriber(self, es_name:str=None): """ @@ -446,7 +445,7 @@ class Archiver(): return fail_dict[f] else: logger.warning(f"Attribute {attribute_name} not found!") - + class AttributeFormatException(Exception): """ Exception that handles wrong attribute naming @@ -454,24 +453,3 @@ class AttributeFormatException(Exception): def __init__(self, message="Wrong Tango attribute format! Try: domain/family/member/attribute (e.g. STAT/RECV/1/temperature)"): self.message = 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