3 #########################
8 from archi_utils
import sort_by_archiModes
9 ##############################################
13 def archiving(attrs_archiModes
, action
, db
= 'Tdb'):
14 ##############################################################################################
16 if action
!= 'start' and action
!= 'stop' and action
!= 'check':
17 print "\nCorrect use: " + "archving_* start/stop/check BEAM_MONITOR_ID/DEV_FULLNAME/ATTR_FULlNAME [tdb/hdb]\n"
20 if db
!= 'Tdb' and action
!= 'Hdb': # TODO: case-indifferent check
21 print "Invalid db argument passed to the function 'archiving'"
24 check_command
= "IsArchived" + db
25 if action
in ['start', 'stop']:
26 action_command
= "Archiving" + action
[:1].upper()+action
[1:] + db
27 #print "DEBUG: action_command = " + action_command
30 ac_byModes
= sort_by_archiModes(attrs_archiModes
)
31 #print ac_byModes # debug
33 #sys.exit(0) ###########################################
35 all_startArchivingArgs
= []
37 for m
in range (len(ac_byModes
)):
39 startArchivingArgs_m
= []
41 startArchivingArgs_m
.append('0') # are all attrs archived in the same HdbArchivier device
43 m_attrsNb
= len(ac_byModes
[m
][1])
44 startArchivingArgs_m
.append( m_attrsNb
) # num of attrs to archive
45 for a
in range (m_attrsNb
):
46 startArchivingArgs_m
.append( ac_byModes
[m
][1][a
] ) # list of the archived attrs
47 #print startArchivingArgs_m # debug
48 for p
in range ( len(ac_byModes
[m
][0]) ):
49 startArchivingArgs_m
.append( ac_byModes
[m
][0][p
] ) # archiving mode parameters
50 #print ac_byModes[m][0] # debug
53 startArchivingArgs_m
.append('TDB_SPEC') # supplimentary params for the temporary archiving
54 startArchivingArgs_m
.append('1800000') # bo
55 startArchivingArgs_m
.append('21600000') # bo
57 #print "\nArchiving configuration " + str(m+1) # debug
58 #print startArchivingArgs_m # debug
60 all_startArchivingArgs
.append(startArchivingArgs_m
)
62 all_attrLists
.append(startArchivingArgs_m
[2:m_attrsNb
+2])
63 #print all_attrLists[m] # debug
66 actionCommand_args
= all_startArchivingArgs
68 actionCommand_args
= all_attrLists
69 #print "DEBUG: len(actionCommand_args) = " + str(len(actionCommand_args))
71 #sys.exit(0) ##################################################################
74 archivingmanager
= DeviceProxy('archiving/archivingmanager/archivingmanager.1')
75 archivingmanager
.set_timeout_millis(30000)
78 for m
in range (len(all_startArchivingArgs
)):
80 #mode = extractor.GetArchivingMode( blSteadiness_attrNames[a] )
82 print "\nArchiving configuration " + str(m
+1) # debug
83 print all_startArchivingArgs
[m
] # debug
84 loggingStatus_list
= archivingmanager
.command_inout(check_command
, all_attrLists
[m
])
85 print "\nArchiving configuration " + str(m
+1) + " status: " + str(loggingStatus_list
)
88 extractor
= DeviceProxy('archiving/tdb/tdbextractor.1')
89 for a
in range (len(all_attrLists
[m
])):
90 if loggingStatus_list
[a
] == 0:
91 print all_attrLists
[m
][a
], " is not being archived"
93 actual_archiMode
= extractor
.GetArchivingMode(all_attrLists
[m
][a
])
94 print actual_archiMode
# debug
95 model_archiMode
= attrs_archiModes
[all_attrLists
[m
][a
]]
96 #print model_archiMode # debug
99 if len(actual_archiMode
) < len(model_archiMode
):
102 for i
in range (len(model_archiMode
)):
103 if actual_archiMode
[i
] != model_archiMode
[i
]:
104 if '.' in model_archiMode
[i
]:
105 if float(actual_archiMode
[i
]) != float(model_archiMode
[i
]):
106 print float(actual_archiMode
[i
])
107 print float(model_archiMode
[i
])
114 print all_attrLists
[m
][a
], " is being archived with the following archiving mode:"
115 print actual_archiMode
119 if action
== 'start':
120 print "\n" + str( time
.strftime("%Y-%m-%d %H:%M:%S", time
.localtime()) ) + '\t' + "Starting archiving"
122 print "\n" + str( time
.strftime("%Y-%m-%d %H:%M:%S", time
.localtime()) ) + '\t' + "Stopping archiving"
125 if action
in ['start', 'stop']:
127 for m
in range (len(actionCommand_args
)):
131 print actionCommand_args
[m
]
132 archivingmanager
.command_inout(action_command
, actionCommand_args
[m
])
134 loggingStatus_list
= archivingmanager
.command_inout(check_command
, all_attrLists
[m
])
136 if(action
== 'start' and sum(loggingStatus_list
) != len(loggingStatus_list
)):
138 print '\nWARNING: Archiving has not been correctly started'
139 print "Archiving configuration " + str(m
+1)
140 print actionCommand_args
[m
]
142 if(action
== 'stop' and sum(loggingStatus_list
) != 0):
144 print '\nWARNING: Archiving has not been correctly stopped'
145 print "\nArchiving configuration " + str(m
+1)
146 print actionCommand_args
[m
]
148 print "\nArchiving configuration " + str(m
+1) + " status: " + str(loggingStatus_list
)