Skip to content
Snippets Groups Projects
Commit cee9c3c8 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-375: bug fixing and add parsing methods

parent 4cce6abc
No related branches found
No related tags found
1 merge request!153Resolve L2SS-375 "Archiving load"
......@@ -16,6 +16,29 @@ from .archiver_base import *
logger = logging.getLogger()
def parse_attribute_name(attribute_name:str):
"""
Parse the attribute names since most of the archiving operations require only
Tango full-qualified names.
"""
chunk_num = len(attribute_name.split('/'))
if (chunk_num!=4):
raise AttributeFormatException
def reduce_attribute_name(attribute_name:str):
"""
For some operations Tango attribute must be transformed from the form 'tango://db:port/domain/family/name/attribute'
to canonical 'domain/family/name/attribute'
"""
chunk_num = len(attribute_name.split('/'))
if (chunk_num==7 and attribute_name.split('/')[0]=='tango:'):
return '/'.join(attribute_name.split('/')[3:])
else:
if (chunk_num!=4):
raise AttributeFormatException
else:
return attribute_name
class Archiver():
"""
The Archiver class implements the basic operations to perform attributes archiving
......@@ -91,8 +114,7 @@ class Archiver():
The ConfigurationManager and EventSubscriber devices must be already up and running.
The archiving-DBMS must be already properly configured.
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
try:
self.cm.write_attribute('SetAttributeName', attribute_name)
self.cm.write_attribute('SetArchiver', self.es_name)
......@@ -137,8 +159,7 @@ class Archiver():
"""
Stops the data archiving of the attribute passed as input, and remove it from the subscriber's list.
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
try:
self.cm.AttributeStop(attribute_name)
self.cm.AttributeRemove(attribute_name)
......@@ -165,13 +186,27 @@ class Archiver():
except Exception as e:
raise Exception from e
def remove_attributes_in_error(self,exclude:list=[],es_name:str=None):
"""
Remove from the subscriber's list all the attributes currently in error (not being archived)
"""
if es_name is not None:
es = DeviceProxy(es_name)
else:
es = self.es
attributes_nok = es.AttributeNokList or []
exclude_list = [a.lower() for a in exclude]
attrs_list = [a.lower() for a in list(attributes_nok) if a.lower() not in exclude_list]
for a in attrs_list:
attr_fullname = reduce_attribute_name(a)
self.remove_attribute_from_archiver(attr_fullname)
def start_archiving_attribute(self, attribute_name:str):
"""
Starts the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
try:
self.cm.AttributeStart(attribute_name)
except Exception as e:
......@@ -185,8 +220,7 @@ class Archiver():
Stops the archiving of the attribute passed as input.
The attribute must be already present in the subscriber's list
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
try:
self.cm.AttributeStop(attribute_name)
except Exception as e:
......@@ -199,8 +233,7 @@ class Archiver():
"""
Check if an attribute is in the archiving list
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
attributes = self.cm.AttributeSearch(attribute_name.lower())
if len(attributes)>1:
# Handle case same attribute_name r/rw
......@@ -222,7 +255,7 @@ class Archiver():
self.add_attribute_to_archiver(attribute_name,polling_period,event_period,strategy)
time.sleep(3.)
self.start_archiving_attribute(attribute_name)
logger.warning(f"Attribute {attribute_name} successfully updated!")
logger.info(f"Attribute {attribute_name} successfully updated!")
def get_subscriber_attributes(self,es_name:str = None):
"""
......@@ -251,8 +284,7 @@ class Archiver():
"""
Return the error related to the attribute
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
errs_dict = self.get_subscriber_errors()
for e in errs_dict:
if attribute_name in e:
......@@ -277,8 +309,7 @@ class Archiver():
"""
Return the attribute archiving frequency in events/minute
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
if self.is_attribute_archived(attribute_name):
freq_dict = dict((a,r) for a,r in zip(self.es.AttributeList,self.es.AttributeRecordFreqList))
for f in freq_dict:
......@@ -291,8 +322,7 @@ class Archiver():
"""
Return the attribute failure archiving frequency in events/minute
"""
if (len(attribute_name.split('/'))!=4):
raise AttributeFormatException
parse_attribute_name(attribute_name)
if self.is_attribute_archived(attribute_name):
fail_dict = dict((a,r) for a,r in zip(self.es.AttributeList,self.es.AttributeFailureFreqList))
for f in fail_dict:
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment