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.StatisticalServicePolicy;
38 import org.miloss.fgsms.services.interfaces.policyconfiguration.TransactionalWebServicePolicy;
39 import org.miloss.fgsms.services.interfaces.status.SetStatusRequestMsg;
40
41
42
43
44
45 public class QueueOrTopicDoesNotExist implements SLARuleInterface {
46
47 @Override
48 public boolean CheckTransactionalRule(SetStatusRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
49 return false;
50 }
51
52 @Override
53 public boolean CheckTransactionalRule(ProcessPerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
54 return false;
55 }
56
57 @Override
58 public boolean CheckTransactionalRule(MachinePerformanceData req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
59 return false;
60 }
61
62 @Override
63 public boolean CheckTransactionalRule(AddDataRequestMsg req, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
64 return false;
65 }
66
67 @Override
68 public boolean CheckTransactionalRule(String url, List<BrokerData> data, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg) {
69 if (nullableFaultMsg == null) {
70 nullableFaultMsg = new AtomicReference<String>();
71 }
72 NameValuePair val = Utility.getNameValuePairByName(params, "value");
73 String value = null;
74 if (val.isEncrypted()) {
75 value = (Utility.DE(val.getValue()));
76 } else {
77 value = (val.getValue());
78 }
79 StringBuilder msg = new StringBuilder();
80 for (int i = 0; i < data.size(); i++) {
81 if (data.get(i).getQueueOrTopicCanonicalName().equalsIgnoreCase(value))
82 {
83 return false;
84 }
85 }
86 msg.append("The queue or topic named ").append(value).append(" does not exist!");
87
88 String s = msg.toString();
89 if (Utility.stringIsNullOrEmpty(s)) {
90 return false;
91 } else {
92 nullableFaultMsg.set(s + "," + nullableFaultMsg.get());
93 return true;
94 }
95 }
96
97 @Override
98 public boolean CheckNonTransactionalRule(ServicePolicy pol, List<NameValuePair> params, AtomicReference<String> nullableFaultMsg, boolean pooled) {
99 return false;
100 }
101
102 @Override
103 public String GetDisplayName() {
104 return "Message Broker Queue Size";
105 }
106
107 @Override
108 public String GetHtmlFormattedHelp() {
109 return "This rule will trigger if the specified queue or topic canonical name size does not exist in the policies statical message broker. "
110 + "Applies to statistical message broker policies only.<br><br>"
111 + "Required parameters:"
112 + "<ul>"
113 + "<li>value - the exact name, ignoring case of the queue or topic canonical name</li>"
114 + "</ul>";
115 }
116
117 @Override
118 public List<NameValuePair> GetRequiredParameters() {
119 ArrayList<NameValuePair> arrayList = new ArrayList<NameValuePair>();
120 arrayList.add(Utility.newNameValuePair("value", null, false, false));
121 return arrayList;
122 }
123
124
125 @Override
126 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError,ServicePolicy policy) {
127 if (outError == null) {
128 outError = new AtomicReference<String>();
129 }
130 if (params == null || params.isEmpty()) {
131 outError.set("The parameter 'value' is required. " + outError.get());
132 }
133 if (!(policy instanceof StatisticalServicePolicy)) {
134 outError.set("This rule only applies to Statistical Service Policies. " + outError.get());
135 }
136 boolean foundLogger = false;
137 for (int i = 0; i < params.size(); i++) {
138 if (params.get(i).getName().equals("value")) {
139 foundLogger = true;
140 if (Utility.stringIsNullOrEmpty(params.get(i).getValue())) {
141 outError.set("A value must be specified for the parameter 'value'. " + outError.get());
142 }
143
144 }
145
146 }
147 if (!foundLogger) {
148 outError.set("The parameter 'value' is required. " + outError.get());
149 }
150 if (Utility.stringIsNullOrEmpty(outError.get())) {
151 return true;
152 } else {
153 return false;
154 }
155
156 }
157
158 @Override
159 public List<NameValuePair> GetOptionalParameters() {
160 return new ArrayList<NameValuePair>();
161 }
162
163 @Override
164 public AlertType GetType() {
165 return AlertType.Performance;
166 }
167
168
169 @Override
170 public String GetHtmlFormattedDisplay(List<NameValuePair> params) {
171 NameValuePair mc = Utility.getNameValuePairByName(params, "value");
172 String item = UNDEFINED_VALUE;
173 if (mc != null) {
174 item = mc.getValue();
175 if (mc.isEncrypted() || mc.isEncryptOnSave()) {
176 item = ENCRYPTED_MASK;
177 }
178 }
179
180 return Utility.encodeHTML(GetDisplayName() + " " + item );
181 }
182
183 @Override
184 public List<PolicyType> GetAppliesTo() {
185 List<PolicyType> x = new ArrayList<PolicyType>();
186 x.add(PolicyType.STATISTICAL);
187
188
189 return x;
190 }
191 }
192