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.common;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.InputStream;
26 import java.io.StringWriter;
27 import java.util.GregorianCalendar;
28 import javax.xml.bind.JAXBContext;
29 import javax.xml.bind.JAXBException;
30 import javax.xml.bind.Marshaller;
31 import javax.xml.parsers.DocumentBuilder;
32 import javax.xml.parsers.DocumentBuilderFactory;
33 import org.apache.log4j.Level;
34
35 import org.miloss.fgsms.plugins.sla.AlertContainer;
36 import org.oasis_open.docs.wsdm.mows_2.AnyXmlContentsType;
37 import org.oasis_open.docs.wsdm.mows_2.BusyState;
38 import org.oasis_open.docs.wsdm.mows_2.CrashedState;
39 import org.oasis_open.docs.wsdm.mows_2.DownState;
40 import org.oasis_open.docs.wsdm.mows_2.DurationMetric;
41 import org.oasis_open.docs.wsdm.mows_2.EndpointDescriptions;
42 import org.oasis_open.docs.wsdm.mows_2.GetManageabilityReferencesResponse;
43 import org.oasis_open.docs.wsdm.mows_2.IdleState;
44 import org.oasis_open.docs.wsdm.mows_2.IntegerCounter;
45 import org.oasis_open.docs.wsdm.mows_2.MessageContentNotIncludedFlag;
46 import org.oasis_open.docs.wsdm.mows_2.MessageContentSizeType;
47 import org.oasis_open.docs.wsdm.mows_2.MessageContentType;
48 import org.oasis_open.docs.wsdm.mows_2.MessageInformationType;
49 import org.oasis_open.docs.wsdm.mows_2.MessageSizeUnitType;
50 import org.oasis_open.docs.wsdm.mows_2.OperationDurationMetric;
51 import org.oasis_open.docs.wsdm.mows_2.OperationIntegerCounter;
52 import org.oasis_open.docs.wsdm.mows_2.OperationMetricType;
53 import org.oasis_open.docs.wsdm.mows_2.OperationOperationalStatusType;
54 import org.oasis_open.docs.wsdm.mows_2.OperationalStateType;
55 import org.oasis_open.docs.wsdm.mows_2.RequestCompletedState;
56 import org.oasis_open.docs.wsdm.mows_2.RequestFailedState;
57 import org.oasis_open.docs.wsdm.mows_2.RequestProcessingNotification;
58 import org.oasis_open.docs.wsdm.mows_2.RequestProcessingState;
59 import org.oasis_open.docs.wsdm.mows_2.RequestProcessingStateInformationType;
60 import org.oasis_open.docs.wsdm.mows_2.RequestProcessingStateType;
61 import org.oasis_open.docs.wsdm.mows_2.RequestReceivedState;
62 import org.oasis_open.docs.wsdm.mows_2.SaturatedState;
63 import org.oasis_open.docs.wsdm.mows_2.StoppedState;
64 import org.oasis_open.docs.wsdm.mows_2.TcpIpDirectionType;
65 import org.oasis_open.docs.wsdm.mows_2.TcpIpInfo;
66 import org.oasis_open.docs.wsdm.mows_2.TcpIpProtocolType;
67 import org.oasis_open.docs.wsdm.mows_2.UpState;
68 import org.oasis_open.docs.wsdm.muws1_2.ComponentAddressType;
69 import org.oasis_open.docs.wsdm.muws1_2.ComponentType;
70 import org.oasis_open.docs.wsdm.muws1_2.CorrelatablePropertiesType;
71 import org.oasis_open.docs.wsdm.muws1_2.ManagementEventType;
72 import org.oasis_open.docs.wsdm.muws2_2.AbortInitiated;
73 import org.oasis_open.docs.wsdm.muws2_2.AvailabilitySituation;
74 import org.oasis_open.docs.wsdm.muws2_2.CapabilitySituation;
75 import org.oasis_open.docs.wsdm.muws2_2.CategoryType;
76 import org.oasis_open.docs.wsdm.muws2_2.ConfigureSituation;
77 import org.oasis_open.docs.wsdm.muws2_2.ConnectCompleted;
78 import org.oasis_open.docs.wsdm.muws2_2.ConnectInitiated;
79 import org.oasis_open.docs.wsdm.muws2_2.ConnectSituation;
80 import org.oasis_open.docs.wsdm.muws2_2.CreateCompleted;
81 import org.oasis_open.docs.wsdm.muws2_2.CreateInitiated;
82 import org.oasis_open.docs.wsdm.muws2_2.CreateSituation;
83 import org.oasis_open.docs.wsdm.muws2_2.CreationNotification;
84 import org.oasis_open.docs.wsdm.muws2_2.DebugReport;
85 import org.oasis_open.docs.wsdm.muws2_2.DestroyCompleted;
86 import org.oasis_open.docs.wsdm.muws2_2.DestroyInitiated;
87 import org.oasis_open.docs.wsdm.muws2_2.DestroySituation;
88 import org.oasis_open.docs.wsdm.muws2_2.DestructionNotification;
89 import org.oasis_open.docs.wsdm.muws2_2.DialectableExpressionType;
90 import org.oasis_open.docs.wsdm.muws2_2.EventCorrelationPropertiesType;
91 import org.oasis_open.docs.wsdm.muws2_2.HeartbeatReport;
92 import org.oasis_open.docs.wsdm.muws2_2.LangString;
93 import org.oasis_open.docs.wsdm.muws2_2.LogReport;
94 import org.oasis_open.docs.wsdm.muws2_2.MsgCatalogInformationType;
95 import org.oasis_open.docs.wsdm.muws2_2.OtherSituation;
96 import org.oasis_open.docs.wsdm.muws2_2.PauseInitiated;
97 import org.oasis_open.docs.wsdm.muws2_2.PerformanceReport;
98 import org.oasis_open.docs.wsdm.muws2_2.QueryRelationshipsByType;
99 import org.oasis_open.docs.wsdm.muws2_2.QueryRelationshipsByTypeResponse;
100 import org.oasis_open.docs.wsdm.muws2_2.ReconnectInitiated;
101 import org.oasis_open.docs.wsdm.muws2_2.RelationshipCreatedNotification;
102 import org.oasis_open.docs.wsdm.muws2_2.RelationshipDeletedNotification;
103 import org.oasis_open.docs.wsdm.muws2_2.RelationshipParticipantType;
104 import org.oasis_open.docs.wsdm.muws2_2.RelationshipType;
105 import org.oasis_open.docs.wsdm.muws2_2.RelationshipTypeType;
106 import org.oasis_open.docs.wsdm.muws2_2.ReportSituation;
107 import org.oasis_open.docs.wsdm.muws2_2.RequestCompleted;
108 import org.oasis_open.docs.wsdm.muws2_2.RequestInitiated;
109 import org.oasis_open.docs.wsdm.muws2_2.RequestSituation;
110 import org.oasis_open.docs.wsdm.muws2_2.RestartInitiated;
111 import org.oasis_open.docs.wsdm.muws2_2.SecurityReport;
112 import org.oasis_open.docs.wsdm.muws2_2.Self;
113 import org.oasis_open.docs.wsdm.muws2_2.SituationCategoryType;
114 import org.oasis_open.docs.wsdm.muws2_2.SituationType;
115 import org.oasis_open.docs.wsdm.muws2_2.StartCompleted;
116 import org.oasis_open.docs.wsdm.muws2_2.StartInitiated;
117 import org.oasis_open.docs.wsdm.muws2_2.StartSituation;
118 import org.oasis_open.docs.wsdm.muws2_2.StateTransitionType;
119 import org.oasis_open.docs.wsdm.muws2_2.StateType;
120 import org.oasis_open.docs.wsdm.muws2_2.StatusReport;
121 import org.oasis_open.docs.wsdm.muws2_2.StopCompleted;
122 import org.oasis_open.docs.wsdm.muws2_2.StopInitiated;
123 import org.oasis_open.docs.wsdm.muws2_2.StopSituation;
124 import org.oasis_open.docs.wsdm.muws2_2.SubstitutableMsgType;
125 import org.oasis_open.docs.wsdm.muws2_2.TraceReport;
126 import org.oasis_open.docs.wsrf.bf_2.BaseFaultType;
127 import org.oasis_open.docs.wsrf.rp_2.DeleteResourceProperties;
128 import org.oasis_open.docs.wsrf.rp_2.DeleteResourcePropertiesRequestFailedFaultType;
129 import org.oasis_open.docs.wsrf.rp_2.DeleteResourcePropertiesResponse;
130 import org.oasis_open.docs.wsrf.rp_2.DeleteType;
131 import org.oasis_open.docs.wsrf.rp_2.GetMultipleResourceProperties;
132 import org.oasis_open.docs.wsrf.rp_2.GetResourcePropertyDocument;
133 import org.oasis_open.docs.wsrf.rp_2.GetResourcePropertyDocumentResponse;
134 import org.oasis_open.docs.wsrf.rp_2.GetResourcePropertyResponse;
135 import org.oasis_open.docs.wsrf.rp_2.InsertResourceProperties;
136 import org.oasis_open.docs.wsrf.rp_2.InsertResourcePropertiesRequestFailedFaultType;
137 import org.oasis_open.docs.wsrf.rp_2.InsertResourcePropertiesResponse;
138 import org.oasis_open.docs.wsrf.rp_2.InsertType;
139 import org.oasis_open.docs.wsrf.rp_2.InvalidModificationFaultType;
140 import org.oasis_open.docs.wsrf.rp_2.InvalidQueryExpressionFaultType;
141 import org.oasis_open.docs.wsrf.rp_2.InvalidResourcePropertyQNameFaultType;
142 import org.oasis_open.docs.wsrf.rp_2.PutResourcePropertyDocument;
143 import org.oasis_open.docs.wsrf.rp_2.PutResourcePropertyDocumentResponse;
144 import org.oasis_open.docs.wsrf.rp_2.QueryEvaluationErrorFaultType;
145 import org.oasis_open.docs.wsrf.rp_2.QueryExpressionRPDocument;
146 import org.oasis_open.docs.wsrf.rp_2.QueryExpressionType;
147 import org.oasis_open.docs.wsrf.rp_2.QueryResourceProperties;
148 import org.oasis_open.docs.wsrf.rp_2.QueryResourcePropertiesResponse;
149 import org.oasis_open.docs.wsrf.rp_2.ResourcePropertyChangeFailureType;
150 import org.oasis_open.docs.wsrf.rp_2.ResourcePropertyValueChangeNotificationType;
151 import org.oasis_open.docs.wsrf.rp_2.SetResourceProperties;
152 import org.oasis_open.docs.wsrf.rp_2.SetResourcePropertiesResponse;
153 import org.oasis_open.docs.wsrf.rp_2.SetResourcePropertyRequestFailedFaultType;
154 import org.oasis_open.docs.wsrf.rp_2.UnableToModifyResourcePropertyFaultType;
155 import org.oasis_open.docs.wsrf.rp_2.UnableToPutResourcePropertyDocumentFaultType;
156 import org.oasis_open.docs.wsrf.rp_2.UnknownQueryExpressionDialectFaultType;
157 import org.oasis_open.docs.wsrf.rp_2.UpdateResourceProperties;
158 import org.oasis_open.docs.wsrf.rp_2.UpdateResourcePropertiesRequestFailedFaultType;
159 import org.oasis_open.docs.wsrf.rp_2.UpdateResourcePropertiesResponse;
160 import org.oasis_open.docs.wsrf.rp_2.UpdateType;
161 import org.w3c.dom.Document;
162 import us.gov.ic.ism.v2.ClassificationType;
163
164
165
166
167
168 public class SLAUtils {
169
170 private static Logger log = Logger.getLogger("fgsms.SLAUtils");
171
172
173
174
175
176
177
178 public static org.w3c.dom.Element WSDMAlertToDomElement(ManagementEventType alert) {
179 try {
180 InputStream is = new ByteArrayInputStream(WSDMtoXmlString(alert).getBytes(Constants.CHARSET));
181 DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
182 fac.setNamespaceAware(true);
183 DocumentBuilder newDocumentBuilder = fac.newDocumentBuilder();
184 Document xmlDocument = newDocumentBuilder.parse(is);
185 xmlDocument.getDocumentElement().normalize();
186 return xmlDocument.getDocumentElement();
187 } catch (Exception ex) {
188 log.log(Level.FATAL, BundleLoader.getBundleString("ErrorWSDMCreateDomElement"), ex);
189 }
190 return null;
191
192 }
193
194
195
196
197
198
199
200 public static String WSDMtoXmlString(ManagementEventType e) {
201 try {
202 JAXBContext jc = JAXBContext.newInstance(
203
204
205 AnyXmlContentsType.class,
206 BusyState.class,
207 CrashedState.class,
208 DownState.class,
209 DurationMetric.class,
210 EndpointDescriptions.class,
211 GetManageabilityReferencesResponse.class,
212 IdleState.class,
213 IntegerCounter.class,
214 MessageContentNotIncludedFlag.class,
215 MessageContentSizeType.class,
216 MessageContentType.class,
217 MessageInformationType.class,
218 MessageSizeUnitType.class,
219 OperationalStateType.class,
220 OperationDurationMetric.class,
221 OperationIntegerCounter.class,
222 OperationMetricType.class,
223 OperationOperationalStatusType.class,
224 RequestCompletedState.class,
225 RequestFailedState.class,
226 RequestProcessingNotification.class,
227 RequestProcessingState.class,
228 RequestProcessingStateInformationType.class,
229 RequestProcessingStateType.class,
230 RequestReceivedState.class,
231 SaturatedState.class,
232 StoppedState.class,
233 TcpIpDirectionType.class,
234 TcpIpInfo.class,
235 TcpIpProtocolType.class,
236 UpState.class,
237 ComponentAddressType.class,
238 ComponentType.class,
239 CorrelatablePropertiesType.class,
240 ManagementEventType.class,
241 AbortInitiated.class,
242 AvailabilitySituation.class,
243 CapabilitySituation.class,
244 CategoryType.class,
245 ConfigureSituation.class,
246 ConnectCompleted.class,
247 ConnectInitiated.class,
248 ConnectSituation.class,
249 CreateCompleted.class,
250 CreateInitiated.class,
251 CreateSituation.class,
252 CreationNotification.class,
253 DebugReport.class,
254 DestroyCompleted.class,
255 DestroyInitiated.class,
256 DestroySituation.class,
257 DestructionNotification.class,
258 DialectableExpressionType.class,
259 EventCorrelationPropertiesType.class,
260 HeartbeatReport.class,
261 LangString.class,
262 LogReport.class,
263 MsgCatalogInformationType.class,
264 OtherSituation.class,
265 PauseInitiated.class,
266 PerformanceReport.class,
267 QueryRelationshipsByType.class,
268 QueryRelationshipsByTypeResponse.class,
269 ReconnectInitiated.class,
270 RelationshipCreatedNotification.class,
271 RelationshipDeletedNotification.class,
272 RelationshipParticipantType.class,
273 RelationshipType.class,
274 RelationshipTypeType.class,
275 ReportSituation.class,
276 RequestCompleted.class,
277 RequestInitiated.class,
278 RequestSituation.class,
279 RestartInitiated.class,
280 SecurityReport.class,
281 Self.class,
282 SituationCategoryType.class,
283 SituationType.class,
284 StartCompleted.class,
285 StartInitiated.class,
286 StartSituation.class,
287 StateTransitionType.class,
288 StateType.class,
289 StatusReport.class,
290 StopCompleted.class,
291 StopInitiated.class,
292 StopSituation.class,
293 SubstitutableMsgType.class,
294 TraceReport.class,
295 BaseFaultType.class,
296 DeleteResourceProperties.class,
297 DeleteResourcePropertiesRequestFailedFaultType.class,
298 DeleteResourcePropertiesResponse.class,
299 DeleteType.class,
300 GetMultipleResourceProperties.class,
301 GetResourcePropertyDocument.class,
302 GetResourcePropertyDocumentResponse.class,
303 GetResourcePropertyResponse.class,
304 InsertResourceProperties.class,
305 InsertResourcePropertiesRequestFailedFaultType.class,
306 InsertResourcePropertiesResponse.class,
307 InsertType.class,
308 InvalidModificationFaultType.class,
309 InvalidQueryExpressionFaultType.class,
310 InvalidResourcePropertyQNameFaultType.class,
311 PutResourcePropertyDocument.class,
312 PutResourcePropertyDocumentResponse.class,
313 QueryEvaluationErrorFaultType.class,
314 QueryExpressionRPDocument.class,
315 QueryExpressionType.class,
316 QueryResourceProperties.class,
317 QueryResourcePropertiesResponse.class,
318 ResourcePropertyChangeFailureType.class,
319 ResourcePropertyValueChangeNotificationType.class,
320 SetResourceProperties.class,
321 SetResourcePropertiesResponse.class,
322 SetResourcePropertyRequestFailedFaultType.class,
323 UnableToModifyResourcePropertyFaultType.class,
324 UnableToPutResourcePropertyDocumentFaultType.class,
325 UnknownQueryExpressionDialectFaultType.class,
326 UpdateResourceProperties.class,
327 UpdateResourcePropertiesRequestFailedFaultType.class,
328 UpdateResourcePropertiesResponse.class,
329 UpdateType.class,
330 ClassificationType.class);
331 Marshaller um = jc.createMarshaller();
332 StringWriter sw = new StringWriter();
333 um.marshal(e, sw);
334 return sw.toString();
335 } catch (JAXBException ex) {
336 log.log(Level.WARN, BundleLoader.getBundleString("ErrorWSDMMarshalling"), ex);
337 }
338 return null;
339 }
340
341
342
343
344
345
346
347
348 public static org.oasis_open.docs.wsdm.muws1_2.ManagementEventType createWSDMEvent(AlertContainer alert) throws IllegalArgumentException {
349 if (alert == null) {
350 throw new IllegalArgumentException("alert");
351 }
352
353 ManagementEventType m = new ManagementEventType();
354
355 GregorianCalendar gcal = new GregorianCalendar();
356 gcal.setTimeInMillis(System.currentTimeMillis());
357
358 m.setEventId(BundleLoader.getBundleString("WSDMEventIdPrefix") + alert.getSLAID());
359 ComponentType c = new ComponentType();
360 c.setResourceId(alert.getModifiedurl());
361 m.setSourceComponent(c);
362 SituationType sit = new SituationType();
363 LangString l = new LangString();
364 l.setLang(BundleLoader.getBundleString("WSDMLangauge"));
365 l.setValue(alert.getFaultMsg());
366 sit.setMessage(l);
367
368 sit.setSituationCategory(alert.getAlerttype());
369 short severity = 4;
370 sit.setSeverity(severity);
371 m.setSituation(sit);
372 try {
373
374 m.setReportTime((gcal));
375 sit.setSituationTime((gcal));
376 } catch (Exception ex) {
377 log.log(Level.WARN, BundleLoader.getBundleString("ErrorDataTypeFactorLoad"), ex);
378 }
379 return m;
380
381 }
382 }