1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.astrogrid.community.client.ant ;
20
21 import java.net.URL;
22
23 import org.apache.tools.ant.Task ;
24 import org.apache.tools.ant.BuildException ;
25
26 import org.astrogrid.community.common.service.data.ServiceStatusData ;
27
28 import org.astrogrid.community.common.policy.service.PolicyService ;
29 import org.astrogrid.community.common.policy.service.PolicyServiceService ;
30 import org.astrogrid.community.common.policy.service.PolicyServiceServiceLocator ;
31
32 /***
33 * An Ant task to check our service status.
34 *
35 */
36 public class ServiceStatusTask
37 extends Task
38 {
39 /***
40 * Our debug flag.
41 *
42 */
43 private static final boolean DEBUG_FLAG = true ;
44
45 /***
46 * Public constructor.
47 *
48 */
49 public ServiceStatusTask()
50 {
51
52
53 super() ;
54 }
55
56 /***
57 * Public constructor.
58 *
59 */
60 public ServiceStatusTask(Task parent)
61 {
62
63
64 super() ;
65
66
67 setProject(parent.getProject()) ;
68 }
69
70 /***
71 * Initialise our Task.
72 *
73 */
74 public void init()
75 throws BuildException
76 {
77 if (DEBUG_FLAG) log("----\"----");
78 if (DEBUG_FLAG) log("ServiceStatusTask.init()");
79 }
80
81 /***
82 * The service type to test.
83 *
84 */
85 private String type ;
86
87 /***
88 * Get the service type.
89 *
90 */
91 public String getType()
92 {
93 return this.type ;
94 }
95
96 /***
97 * Set the service type.
98 *
99 */
100 public void setType(String value)
101 {
102 this.type = value ;
103 }
104
105 /***
106 * The service endpoint address.
107 *
108 */
109 private String address ;
110
111 /***
112 * Get the service endpoint.
113 *
114 */
115 public String getAddress()
116 {
117 return this.address ;
118 }
119
120 /***
121 * Set the service endpoint address.
122 *
123 */
124 public void setAddress(String value)
125 {
126 this.address = value ;
127 }
128
129 /***
130 * Execute our Task.
131 *
132 */
133 public void execute()
134 throws BuildException
135 {
136 if (DEBUG_FLAG) log("----\"----");
137 if (DEBUG_FLAG) log("ServiceStatusTask.execute()");
138 if (DEBUG_FLAG) log(" Address : " + this.getAddress());
139
140
141 try {
142
143
144 PolicyServiceService locator = new PolicyServiceServiceLocator();
145
146
147 URL endpoint = new URL(address) ;
148
149
150 PolicyService service = locator.getPolicyService(endpoint);
151
152
153 ServiceStatusData status = service.getServiceStatus() ;
154
155
156 log("Service status") ;
157 log(" Config path : " + status.getConfigPath()) ;
158 log(" Database name : " + status.getDatabaseName()) ;
159
160
161
162
163 }
164 catch (Exception ouch)
165 {
166 throw new BuildException(ouch) ;
167 }
168 }
169 }
170