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

Merge branch 'L2SS-550-fix-archiver-config-install' into 'master'

L2SS-550: Install archiver config

Closes L2SS-550

See merge request !202
parents b547c733 5847e826
Branches
Tags
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()
...@@ -82,10 +83,10 @@ class Archiver(): ...@@ -82,10 +83,10 @@ class Archiver():
""" """
# Global 'DEVELOPMENT' environment variables set by configuration file # Global 'DEVELOPMENT' environment variables set by configuration file
dev_polling_time = None dev_polling_time = 600
dev_archive_time = None 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_name = cm_name
self.cm = DeviceProxy(cm_name) self.cm = DeviceProxy(cm_name)
try: try:
...@@ -95,11 +96,6 @@ class Archiver(): ...@@ -95,11 +96,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:
""" """
...@@ -152,11 +148,15 @@ class Archiver(): ...@@ -152,11 +148,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'))
...@@ -191,7 +191,6 @@ class Archiver(): ...@@ -191,7 +191,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):
""" """
...@@ -454,24 +453,3 @@ class AttributeFormatException(Exception): ...@@ -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)"): 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