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