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.plugins;
22
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.GregorianCalendar;
26 import java.util.List;
27 import java.util.concurrent.atomic.AtomicReference;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30 import javax.xml.datatype.DatatypeFactory;
31 import javax.xml.ws.BindingProvider;
32 import javax.xml.ws.WebServiceFeature;
33 import org.miloss.fgsms.plugins.sla.alertservice.AlertRecieverPortType;
34 import org.miloss.fgsms.plugins.sla.alertservice.AlertRecieverService;
35 import org.miloss.fgsms.common.DBSettingsLoader;
36 import org.miloss.fgsms.common.Utility;
37 import org.miloss.fgsms.plugins.sla.AlertContainer;
38 import org.miloss.fgsms.plugins.sla.SLAActionInterface;
39 import org.miloss.fgsms.services.interfaces.common.NameValuePair;
40 import org.miloss.fgsms.services.interfaces.common.PolicyType;
41 import org.miloss.fgsms.services.interfaces.policyconfiguration.KeyNameValueEnc;
42
43
44
45
46
47
48 public class CustomSLAAction implements SLAActionInterface {
49
50
51
52 private URL LoadWSDL() {
53 URL wsdl = null;
54 try {
55 wsdl = Thread.currentThread().getContextClassLoader().getResource("META-INF/SLAPluginWebService.wsdl");
56 } catch (Exception ex) {
57 }
58 try {
59 wsdl = Thread.currentThread().getContextClassLoader().getResource("/META-INF/SLAPluginWebService.wsdl");
60 } catch (Exception ex) {
61 }
62 try {
63 wsdl = this.getClass().getClassLoader().getResource("/META-INF/SLAPluginWebService.wsdl");
64 } catch (Exception ex) {
65 }
66 try {
67 wsdl = this.getClass().getClassLoader().getResource("META-INF/SLAPluginWebService.wsdl");
68 } catch (Exception ex) {
69 }
70
71 return wsdl;
72 }
73
74
75 @Override
76 public List<NameValuePair> GetRequiredParameters() {
77 return new ArrayList<NameValuePair>();
78 }
79
80 @Override
81 public List<NameValuePair> GetOptionalParameters() {
82 return new ArrayList<NameValuePair>();
83 }
84
85 @Override
86 public boolean ValidateConfiguration(List<NameValuePair> params, AtomicReference<String> outError) {
87 return true;
88 }
89
90 @Override
91 public String GetHtmlFormattedHelp() {
92 return "Hello World";
93 }
94
95 @Override
96 public String GetDisplayName() {
97 return "Custom SLA Action Example";
98 }
99
100 @Override
101 public void ProcessAction(AlertContainer alert, List<NameValuePair> params) {
102 try {
103 KeyNameValueEnc settings = DBSettingsLoader.GetPropertiesFromDB(true, "SDK.Samples.AlertRecieverService", "URL");
104 if (settings != null && settings.getKeyNameValue() != null && settings.getKeyNameValue().getPropertyValue() != null) {
105 AlertRecieverService svc = new AlertRecieverService(LoadWSDL());
106
107 AlertRecieverPortType port = svc.getAlertRecieverPort();
108 BindingProvider bp = (BindingProvider) port;
109 bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, settings.getKeyNameValue().getPropertyValue());
110 DatatypeFactory fac = DatatypeFactory.newInstance();
111 GregorianCalendar gcal = new GregorianCalendar();
112 gcal.setTimeInMillis(System.currentTimeMillis());
113
114 port.recieveServiceAlert(gcal, alert.getSLAID() + " " + alert.getFaultMsg() + " " + alert.getModifiedurl());
115 } else {
116 Logger.getLogger("SDK.Samples.AlertRecieverService").log(Level.WARNING, "Plugin SDK.Samples.AlertRecieverService is not configured, add the general setting SDK.Samples.AlertRecieverService, URL");
117 }
118 } catch (Exception ex) {
119 ex.printStackTrace();
120 }
121 }
122
123 @Override
124 public List<PolicyType> GetAppliesTo() {
125 return Utility.getAllPolicyTypes();
126 }
127 }