1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.astrogrid.community.install.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.client.database.manager.DatabaseManagerSoapDelegate ;
27
28 /***
29 * An Ant task to control the Community DatabaseManager service.
30 *
31 */
32 public class DatabaseManagerTask
33 extends Task
34 {
35 /***
36 * Our debug flag.
37 *
38 */
39 private static final boolean DEBUG_FLAG = true ;
40
41 /***
42 * Public constructor.
43 *
44 */
45 public DatabaseManagerTask()
46 {
47
48
49 super() ;
50 }
51
52 /***
53 * Public constructor.
54 *
55 */
56 public DatabaseManagerTask(Task parent)
57 {
58
59
60 super() ;
61
62
63 setProject(parent.getProject()) ;
64 }
65
66 /***
67 * Initialise our Task.
68 *
69 */
70 public void init()
71 throws BuildException
72 {
73 if (DEBUG_FLAG) System.out.println("----\"----");
74 if (DEBUG_FLAG) System.out.println("DatabaseManagerTask.init()");
75 }
76
77 /***
78 * Our DatabaseManager service endpoint.
79 *
80 */
81 private String endpoint ;
82
83 /***
84 * Get our DatabaseManager service endpoint.
85 *
86 */
87 public String getEndpoint()
88 {
89 return this.endpoint ;
90 }
91
92 /***
93 * Set our DatabaseManager service endpoint.
94 *
95 */
96 public void setEndpoint(String value)
97 {
98 this.endpoint = value ;
99 }
100
101 /***
102 * The action we want to perform.
103 *
104 */
105 private String action ;
106
107 /***
108 * Get the action we want to perform.
109 *
110 */
111 public String getAction()
112 {
113 return this.action ;
114 }
115
116 /***
117 * Set the action we want to perform.
118 *
119 */
120 public void setAction(String value)
121 {
122 this.action = value ;
123 }
124
125 /***
126 * Execute our Task.
127 *
128 */
129 public void execute()
130 throws BuildException
131 {
132 if (DEBUG_FLAG) System.out.println("----\"----");
133 if (DEBUG_FLAG) System.out.println("DatabaseManagerTask.execute()");
134 if (DEBUG_FLAG) System.out.println(" Action : " + this.action);
135 if (DEBUG_FLAG) System.out.println(" Endpoint : " + this.endpoint);
136
137
138 if (null == action)
139 {
140 throw new BuildException(
141 "No action specified"
142 ) ;
143 }
144
145
146 if (null == endpoint)
147 {
148 throw new BuildException(
149 "No service endpoint specified"
150 ) ;
151 }
152
153
154 try {
155
156
157 DatabaseManagerSoapDelegate delegate = new DatabaseManagerSoapDelegate(
158 new URL(this.endpoint)
159 ) ;
160
161
162 if ("debug".equals(action))
163 {
164 if (DEBUG_FLAG) System.out.println(" Database name : " + delegate.getDatabaseName());
165 if (DEBUG_FLAG) System.out.println(" Database config : " + delegate.getDatabaseConfigUrl());
166 if (DEBUG_FLAG) System.out.println(" Database script : " + delegate.getDatabaseScriptResource());
167 }
168
169
170 if ("status".equals(action))
171 {
172 boolean status = delegate.checkDatabaseTables() ;
173 if (DEBUG_FLAG) System.out.println(" Database tables healthy : " + status);
174 }
175
176
177 if ("reset".equals(action))
178 {
179 if (DEBUG_FLAG) System.out.println(" Resetting database tables ....");
180 delegate.resetDatabaseTables() ;
181 boolean status = delegate.checkDatabaseTables() ;
182 if (DEBUG_FLAG) System.out.println(" Database tables healthy : " + status);
183 }
184 }
185 catch (Exception ouch)
186 {
187 throw new BuildException(ouch) ;
188 }
189 }
190 }
191