1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.miloss.fgsms.sla.rules;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.concurrent.atomic.AtomicReference;
26 import org.miloss.fgsms.common.Utility;
27 import org.miloss.fgsms.plugins.sla.AlertType;
28 import org.miloss.fgsms.plugins.sla.SLARuleInterface;
29 import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
30 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
31 import org.miloss.fgsms.services.interfaces.common.PolicyType;
32 import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
33 import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
34 import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
35 import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
36 import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
37 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
38 import org.miloss.fgsms.sla.NonTransactionalSLAProcessor;
39
40
41
42
43
44 public class MeanTimeBetweenFailureGreatThan implements SLARuleInterface {
45
46 @Override
47 public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
48 return false;
49 }
50
51 @Override
52 public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
53 return false;
54 }
55
56 @Override
57 public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
58 return false;
59 }
60
61 @Override
62 public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
63 return false;
64 }
65
66 @Override
67 public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
68 return false;
69 }
70
71 @Override
72 public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
73 if (nullableFaultMsg == null) {
74 nullableFaultMsg = new AtomicReference<String>();
75 }
76
77 NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "duration");
78 long duration = Long.parseLong(GetNameValuePairByName.getValue());
79 NameValuePair rater = Utility.getNameValuePairByName(params, "value");
80 long rate = Long.parseLong(rater.getValue());
81
82 long faultrate = NonTransactionalSLAProcessor.GrabMTBF(duration, pol.getURL());
83 if (faultrate > duration) {
84 nullableFaultMsg.set("MTBF measured value of " + faultrate + " is greater than " + rate + ", " + nullableFaultMsg.get());
85 return true;
86 }
87 return false;
88 }
89
90 @Override
91 public String GetDisplayName() {
92 return "MTBF greater than (value)";
93 }
94
95 @Override
96 public String GetHtmlFormattedHelp() {
97 return "This rule will trigger when the Mean Time Between Failure is greater than the specified duration."
98 + "This rule is processed periodically as part of the Non-Transactional SLA Processor, who execution cycle is controled by the administrator. "
99 + "This rule applies to transactional service policies only.<Br><br>"
100 + "Required parameters:"
101 + "<ul>"
102 + "<li>value - must be a positive integer. This is the threshold</li>"
103 + "<li>duration - must be a positive integer or long. This represents time in milliseconds for the duration to search through. It must be one of the values from which"
104 + "statistics are aggregated. By default, the following durations are calculated 5 minutes (300000ms), 15 minutes (900000ms), 1 hour (3600000ms),"
105 + "and 24 hours (1440000ms). Administrators can add additional time periods for aggregation via General Settings."
106 + "</il>"
107 + "</ul>";
108 }
109
110 @Override
111 public List<NameValuePair> GetRequiredParameters() {
112 ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
113
114 arrayList.add(Utility.newNameValuePair("duration", null, false, false));
115
116 return arrayList;
117 }
118
119 @Override
120 public List<NameValuePair> GetOptionalParameters() {
121 return new ArrayList<NameValuePair>();
122 }
123
124 @Override
125 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
126 if (outError == null) {
127 outError = new AtomicReference<String>();
128 }
129 if (params == null || params.isEmpty()) {
130 outError.set("The parameter 'value' is required. " + outError.get());
131 }
132 if (!(policy instanceof TransactionalWebServicePolicy)) {
133 outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
134 }
135
136 boolean foundduration = false;
137 for (int i = 0; i < params.size(); i++) {
138
139 if (params.get(i).getName().equals("duration")) {
140 foundduration = true;
141 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
142 outError.set("A value must be specified for the parameter 'duration'. " + outError.get());
143 }
144 try {
145 long x = Long.parseLong(params.get(i).getValue());
146 if (x <= 0) {
147 outError.set("The parameter 'duration' must be greater than zero. " + outError.get());
148 }
149 } catch (Exception ex) {
150 outError.set("Bad value for parameter 'duration'. It must be an integer or long. Message:" + ex.getMessage() + ". " + outError.get());
151 }
152 }
153 }
154
155 if (!foundduration) {
156 outError.set("The parameter 'duration' is required. " + outError.get());
157 }
158 if (Utility.stringIsNullOrEmpty(outError.get())) {
159 return true;
160 } else {
161 return false;
162 }
163 }
164
165 @Override
166 public AlertType GetType() {
167 return AlertType.Performance;
168 }
169
170 @Override
171 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
172 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
173 String item = UNDEFINED_VALUE;
174 if (mc != null) {
175 item = mc.getValue();
176 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
177 item = ENCRYPTED_MASK;
178 }
179 }
180 return Utility.encodeHTML(GetDisplayName() + " " + item + " ms");
181 }
182
183 @Override
184 public List<PolicyType> GetAppliesTo() {
185 List<PolicyType> x = new ArrayList<PolicyType>();
186 x.add(PolicyType.TRANSACTIONAL);
187
188
189 return x;
190 }
191 }