1 | #!/usr/bin/python
|
---|
2 |
|
---|
3 | # policies.py
|
---|
4 | #
|
---|
5 | # Author: M. Shankar, Jan 31, 2012
|
---|
6 | # Modification History
|
---|
7 | # Jan 31, 2012, Shankar: Initial version of policies.py with comments.
|
---|
8 | # May 14, 2012, Li, Shankar: Added support for archiving extra fields into policy file.
|
---|
9 | #
|
---|
10 | # This is the policies.py used to enforce policies for archiving PVs
|
---|
11 | # At a very high level, when users request PVs to be archived, the mgmt web app samples the PV to determine event rate and other parameters.
|
---|
12 | # In addition, various fields of the PV like .NAME, .ADEL, .MDEL, .RTYP etc are also obtained
|
---|
13 | # These are passed to this python script as a dictionary argument to a method called determinePolicy
|
---|
14 | # The variable name in the python environment for this information is 'pvInfo' (so use other variable names etc.).
|
---|
15 | # The method is expected to use this information to make decisions on various archiving parameters.
|
---|
16 | # The result is expected to be another dictionary that is placed into the variable called "pvPolicy".
|
---|
17 | # Optionally, fields in addition to the VAL field that are to be archived with the PV are passed in as a property of pvPolicy called 'archiveFields'
|
---|
18 | # If the user overrides the policy, this is communicated in the pvinfo as a property called 'policyName'
|
---|
19 | #
|
---|
20 | # In addition, this script must communicate the list of available policies to the JVM as another method called getPolicyList which takes no arguments.
|
---|
21 | # The results of this method is placed into a variable called called 'pvPolicies'.
|
---|
22 | # The dictionary is a name to description mapping - the description is used in the UI; the name is what is communicated to determinePolicy as a user override
|
---|
23 | #
|
---|
24 | # In addition, this script must communicate the list of fields that are to be archived as part of the stream in a method called getFieldsArchivedAsPartOfStream.
|
---|
25 | # The results of this method is placed into a list variable called called 'pvStandardFields'.
|
---|
26 |
|
---|
27 |
|
---|
28 | import sys
|
---|
29 | import os
|
---|
30 |
|
---|
31 | # Generate a list of policy names. This is used to feed the dropdown in the UI.
|
---|
32 | def getPolicyList():
|
---|
33 | pvPoliciesDict = {}
|
---|
34 | pvPoliciesDict['Default'] = 'The default policy'
|
---|
35 | pvPoliciesDict['VAC'] = 'MR Vacuum'
|
---|
36 | pvPoliciesDict['test - BPMS'] = 'test - BPMS that generate more than 1GB a year'
|
---|
37 | pvPoliciesDict['test - 2HzPVs'] = 'test - PVs with an event rate more than 2Hz'
|
---|
38 | pvPoliciesDict['test - 3DaysMTSOnly'] = 'test -Store data for 3 days upto the MTS only.'
|
---|
39 | return pvPoliciesDict
|
---|
40 |
|
---|
41 | # Define a list of fields that will be archived as part of every PV.
|
---|
42 | # The data for these fields will included in the stream for the PV.
|
---|
43 | # We also make an assumption that the data type for these fields is the same as that of the .VAL field
|
---|
44 | def getFieldsArchivedAsPartOfStream():
|
---|
45 | return ['HIHI','HIGH','LOW','LOLO','LOPR','HOPR','DRVH','DRVL'];
|
---|
46 |
|
---|
47 |
|
---|
48 | # We use the environment variables ARCHAPPL_SHORT_TERM_FOLDER and ARCHAPPL_MEDIUM_TERM_FOLDER to determine the location of the STS and the MTS in the appliance
|
---|
49 | # PARTITION_5MIN / PARTITION_15MIN / PARTITION_30MIN / PARTITION_HOUR / PARTITION_DAY / PARTITION_MONTH / PARTITION_YEAR
|
---|
50 | #shorttermstore_plugin_url = 'pb://localhost?name=STS&rootFolder=${ARCHAPPL_SHORT_TERM_FOLDER}&partitionGranularity=PARTITION_5MIN'
|
---|
51 | #mediumtermstore_plugin_url = 'pb://localhost?name=MTS&rootFolder=${ARCHAPPL_MEDIUM_TERM_FOLDER}&partitionGranularity=PARTITION_15MIN'
|
---|
52 | shorttermstore_plugin_url = 'pb://localhost?name=STS&rootFolder=${ARCHAPPL_SHORT_TERM_FOLDER}&partitionGranularity=PARTITION_HOUR'
|
---|
53 | mediumtermstore_plugin_url = 'pb://localhost?name=MTS&rootFolder=${ARCHAPPL_MEDIUM_TERM_FOLDER}&partitionGranularity=PARTITION_DAY&hold=5&gather=1'
|
---|
54 | longtermstore_plugin_url = 'pb://localhost?name=LTS&rootFolder=${ARCHAPPL_LONG_TERM_FOLDER}&partitionGranularity=PARTITION_MONTH'
|
---|
55 | #
|
---|
56 | #shorttermstore_plugin_url = 'pb://localhost?name=STS&rootFolder=${ARCHAPPL_SHORT_TERM_FOLDER}&partitionGranularity=PARTITION_5MIN'
|
---|
57 | #shorttermstore_plugin_url = 'pb://localhost?name=STS&rootFolder=${ARCHAPPL_SHORT_TERM_FOLDER}&partitionGranularity=PARTITION_HOUR&consolidateOnShutdown=true'
|
---|
58 | #longtermstore_plugin_url = 'pb://localhost?name=LTS&rootFolder=${ARCHAPPL_LONG_TERM_FOLDER}&partitionGranularity=PARTITION_YEAR'
|
---|
59 | #longtermstore_plugin_url = 'blackhole://localhost'
|
---|
60 |
|
---|
61 | def determinePolicy(pvInfoDict):
|
---|
62 | pvPolicyDict = {}
|
---|
63 |
|
---|
64 | userPolicyOverride = ''
|
---|
65 | if 'policyName' in pvInfoDict:
|
---|
66 | userPolicyOverride = pvInfoDict['policyName']
|
---|
67 |
|
---|
68 | #
|
---|
69 | if userPolicyOverride == 'VAC' or (userPolicyOverride == '' and pvInfoDict['pvName'].startswith('MRVAC') and pvInfoDict['pvName'].startswith('PRESS')):
|
---|
70 | # We reduce sampling rate for 'MRVAC:...:PRESS' records to 2sec, while these records are scanned at 1Hz.
|
---|
71 | pvPolicyDict['samplingPeriod'] = 2.0
|
---|
72 | pvPolicyDict['samplingMethod'] = 'SCAN'
|
---|
73 | pvPolicyDict['dataStores'] = [
|
---|
74 | shorttermstore_plugin_url,
|
---|
75 | mediumtermstore_plugin_url,
|
---|
76 | longtermstore_plugin_url
|
---|
77 | ]
|
---|
78 | pvPolicyDict['policyName'] = 'VAC';
|
---|
79 | #
|
---|
80 | elif userPolicyOverride == 'test - 2HzPVs' or (userPolicyOverride == '' and pvInfoDict['eventRate'] > 2.0):
|
---|
81 | pvPolicyDict['samplingPeriod'] = 1.0
|
---|
82 | pvPolicyDict['samplingMethod'] = 'MONITOR'
|
---|
83 | pvPolicyDict['dataStores'] = [
|
---|
84 | shorttermstore_plugin_url,
|
---|
85 | mediumtermstore_plugin_url,
|
---|
86 | longtermstore_plugin_url
|
---|
87 | ]
|
---|
88 | pvPolicyDict['policyName'] = 'test - 2HzPVs';
|
---|
89 | #
|
---|
90 | #elif userPolicyOverride == 'Default' or (userPolicyOverride == '' and pvInfoDict['pvName'] == 'mshankar:arch:sine'):
|
---|
91 | elif userPolicyOverride == 'Default':
|
---|
92 | pvPolicyDict['samplingPeriod'] = 1.0
|
---|
93 | pvPolicyDict['samplingMethod'] = 'MONITOR'
|
---|
94 | pvPolicyDict['dataStores'] = [
|
---|
95 | shorttermstore_plugin_url,
|
---|
96 | mediumtermstore_plugin_url,
|
---|
97 | longtermstore_plugin_url
|
---|
98 | ]
|
---|
99 | pvPolicyDict['policyName'] = 'Default';
|
---|
100 | #
|
---|
101 | elif userPolicyOverride == 'test - BPMS' or (userPolicyOverride == '' and pvInfoDict['pvName'].startswith('BPMS') and pvInfoDict['storageRate'] > 35):
|
---|
102 | # We limit BPM PVs to 1GB/year (34 bytes/sec)
|
---|
103 | # We reduce the sampling rate (and hence increase the sampling period) to cater to this.
|
---|
104 | pvPolicyDict['samplingPeriod'] = pvInfoDict['storageRate']/(35*pvInfoDict['eventRate'])
|
---|
105 | pvPolicyDict['samplingMethod'] = 'MONITOR'
|
---|
106 | pvPolicyDict['dataStores'] = [
|
---|
107 | shorttermstore_plugin_url,
|
---|
108 | mediumtermstore_plugin_url,
|
---|
109 | longtermstore_plugin_url
|
---|
110 | ]
|
---|
111 | pvPolicyDict['policyName'] = 'test - BPMS';
|
---|
112 | #
|
---|
113 | elif userPolicyOverride == 'test - 3DaysMTSOnly':
|
---|
114 | pvPolicyDict['samplingPeriod'] = 1.0
|
---|
115 | pvPolicyDict['samplingMethod'] = 'MONITOR'
|
---|
116 | pvPolicyDict['dataStores'] = [
|
---|
117 | shorttermstore_plugin_url,
|
---|
118 | # We want to store 3 days worth of data in the MTS.
|
---|
119 | 'pb://localhost?name=MTS&rootFolder=${ARCHAPPL_MEDIUM_TERM_FOLDER}&partitionGranularity=PARTITION_DAY&hold=4&gather=1',
|
---|
120 | 'blackhole://localhost?name=LTS'
|
---|
121 | ]
|
---|
122 | pvPolicyDict['policyName'] = 'test - 2HzPVs';
|
---|
123 | #
|
---|
124 | else:
|
---|
125 | pvPolicyDict['samplingPeriod'] = 1.0
|
---|
126 | pvPolicyDict['samplingMethod'] = 'MONITOR'
|
---|
127 | pvPolicyDict['dataStores'] = [
|
---|
128 | shorttermstore_plugin_url,
|
---|
129 | mediumtermstore_plugin_url,
|
---|
130 | longtermstore_plugin_url
|
---|
131 | ]
|
---|
132 | pvPolicyDict['policyName'] = 'Default';
|
---|
133 |
|
---|
134 | archiveFields=[]
|
---|
135 |
|
---|
136 | if "RTYP" not in pvInfoDict:
|
---|
137 | pvPolicyDict["archiveFields"]=archiveFields
|
---|
138 | else:
|
---|
139 | pvRTYP=pvInfoDict["RTYP"]
|
---|
140 | if pvRTYP=="ai":
|
---|
141 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
142 | archiveFields=[]
|
---|
143 | elif pvRTYP=="ao":
|
---|
144 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR','DRVH','DRVL']
|
---|
145 | archiveFields=[]
|
---|
146 | elif pvRTYP=="calc":
|
---|
147 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
148 | archiveFields=[]
|
---|
149 | elif pvRTYP=="calcout":
|
---|
150 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
151 | archiveFields=[]
|
---|
152 | elif pvRTYP=="longin":
|
---|
153 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
154 | archiveFields=[]
|
---|
155 | elif pvRTYP=="longout":
|
---|
156 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR','DRVH','DRVL']
|
---|
157 | archiveFields=[]
|
---|
158 | elif pvRTYP=="dfanout":
|
---|
159 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
160 | archiveFields=[]
|
---|
161 | elif pvRTYP=="sub":
|
---|
162 | #archiveFields=['HIHI','HIGH','LOW','LOLO','LOPR','HOPR']
|
---|
163 | archiveFields=[]
|
---|
164 | pvPolicyDict["archiveFields"]=archiveFields
|
---|
165 |
|
---|
166 | return pvPolicyDict
|
---|