1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.miloss.fgsms.sla.rules;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.concurrent.atomic.AtomicReference;
27 import org.miloss.fgsms.common.Utility;
28 import org.miloss.fgsms.plugins.sla.AlertType;
29 import org.miloss.fgsms.plugins.sla.SLARuleInterface;
30 import org.miloss.fgsms.services.interfaces.common.MachinePerformanceData;
31 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
32 import org.miloss.fgsms.services.interfaces.common.PolicyType;
33 import org.miloss.fgsms.services.interfaces.common.ProcessPerformanceData;
34 import org.miloss.fgsms.services.interfaces.datacollector.AddDataRequestMsg;
35 import org.miloss.fgsms.services.interfaces.datacollector.BrokerData;
36 import org.miloss.fgsms.services.interfaces.policyconfiguration.ServicePolicy;
37 import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
38 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
39
40
41
42
43
44 public class ResponseTimeLessThan 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 if (nullableFaultMsg == null) {
64 nullableFaultMsg = new AtomicReference<String>();
65 }
66 NameValuePair GetNameValuePairByName = Utility.getNameValuePairByName(params, "value");
67 long val = 0;
68 String item = GetNameValuePairByName.getValue();
69 if (GetNameValuePairByName.isEncrypted()) {
70 item = Utility.DE(GetNameValuePairByName.getValue());
71 }
72 val = Long.parseLong(item);
73 if (req.getResponseTime() < val) {
74 nullableFaultMsg.set("The response time size, " + req.getResponseTime() + ", is less that the value " + val + ", " + nullableFaultMsg.get());
75 }
76 return false;
77 }
78
79 @Override
80 public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
81 return false;
82 }
83
84 @Override
85 public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
86 return false;
87 }
88
89 @Override
90 public String GetDisplayName() {
91 return "Response time is less than value";
92 }
93
94 @Override
95 public String GetHtmlFormattedHelp() {
96 return "If a transaction's response time is less than the specified value, then this rule will trigger.<Br>"
97 + "Applies to transactional service policies only.<br><br>"
98 + "Required parameters:"
99 + "<ul>"
100 + "<li>value - a positive integer to compare against (ms)</li>"
101 + "</ul>";
102 }
103
104 @Override
105 public List<NameValuePair> GetRequiredParameters() {
106 ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
107 arrayList.add(Utility.newNameValuePair("value", null, false, false));
108 return arrayList;
109 }
110
111 @Override
112 public List<NameValuePair> GetOptionalParameters() {
113 return new ArrayList<NameValuePair>();
114 }
115
116 @Override
117 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError, ServicePolicy policy) {
118 if (outError == null) {
119 outError = new AtomicReference<String>();
120 }
121 if (params == null || params.isEmpty()) {
122 outError.set("The parameter 'value' is required. " + outError.get());
123 }
124 if (!(policy instanceof TransactionalWebServicePolicy)) {
125 outError.set("This rule only applies to Transactional Service Policies. " + outError.get());
126 }
127 boolean foundLogger = false;
128 for (int i = 0; i < params.size(); i++) {
129 if (params.get(i).getName().equals("value")) {
130 foundLogger = true;
131 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
132 outError.set("A value must be specified for the parameter 'value'. " + outError.get());
133 }
134 }
135 try {
136 long x = Long.parseLong(params.get(i).getValue());
137 if (x <= 0) {
138 outError.set("The parameter 'value' must be greater than zero. " + outError.get());
139 }
140 } catch (Exception ex) {
141 outError.set("Bad value for parameter 'value'. It must be a integer or long. Message:" + ex.getMessage() + ". " + outError.get());
142 }
143 }
144 if (!foundLogger) {
145 outError.set("The parameter 'value' is required. " + outError.get());
146 }
147 if (Utility.stringIsNullOrEmpty(outError.get())) {
148 return true;
149 } else {
150 return false;
151 }
152
153 }
154
155 @Override
156 public AlertType GetType() {
157 return AlertType.Performance;
158 }
159
160 @Override
161 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
162 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
163 String item = UNDEFINED_VALUE;
164 if (mc != null) {
165 item = mc.getValue();
166 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
167 item = ENCRYPTED_MASK;
168 }
169 }
170 return Utility.encodeHTML(GetDisplayName() + " " + item+"ms");
171 }
172
173 @Override
174 public List<PolicyType> GetAppliesTo() {
175 List<PolicyType> ret = new ArrayList<PolicyType>();
176 ret.add(PolicyType.TRANSACTIONAL);
177 return ret;
178 }
179 }