Revision 595
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
118 | 118 |
out.println("Replication Handler Started"); |
119 | 119 |
System.out.println("Replication Handler Started"); |
120 | 120 |
} |
121 |
else if(((String[])params.get("action"))[0].equals("getall")) |
|
122 |
{ //updates this server exactly once |
|
123 |
replicationDaemon.schedule(new ReplicationHandler(out), 0); |
|
124 |
out.println("<html><body>\"Get All\" Done</body></html>"); |
|
125 |
} |
|
121 | 126 |
else if(((String[])params.get("action"))[0].equals("forcereplicate")) |
122 | 127 |
{ |
123 | 128 |
handleForceReplicateRequest(out, params, response); |
... | ... | |
148 | 153 |
{ |
149 | 154 |
handleGetCatalogRequest(out, params, response, true); |
150 | 155 |
} |
156 |
else if(((String[])params.get("action"))[0].equals("servercontrol")) |
|
157 |
{ |
|
158 |
handleServerControlRequest(out, params, response); |
|
159 |
} |
|
160 |
|
|
151 | 161 |
} |
152 | 162 |
} |
153 | 163 |
|
164 |
/** |
|
165 |
* This method can add, delete and list the servers currently included in |
|
166 |
* xml_replication. |
|
167 |
* action subaction other needed params |
|
168 |
* --------------------------------------------------------- |
|
169 |
* servercontrol add server |
|
170 |
* servercontrol delete server |
|
171 |
* servercontrol list |
|
172 |
*/ |
|
173 |
private void handleServerControlRequest(PrintWriter out, Hashtable params, |
|
174 |
HttpServletResponse response) |
|
175 |
{ |
|
176 |
String subaction = ((String[])params.get("subaction"))[0]; |
|
177 |
try |
|
178 |
{ |
|
179 |
Connection conn = util.openDBConnection(); |
|
180 |
PreparedStatement pstmt; |
|
181 |
if(subaction.equals("add")) |
|
182 |
{ |
|
183 |
String server = ((String[])params.get("server"))[0]; |
|
184 |
pstmt = conn.prepareStatement("insert into xml_replication (server, " + |
|
185 |
"last_checked) values ('" + server + "', to_date(" + |
|
186 |
"'01/01/00', 'MM/DD/YY'))"); |
|
187 |
pstmt.execute(); |
|
188 |
out.println("server " + server + " added"); |
|
189 |
} |
|
190 |
else if(subaction.equals("delete")) |
|
191 |
{ |
|
192 |
String server = ((String[])params.get("server"))[0]; |
|
193 |
pstmt = conn.prepareStatement("delete from xml_replication where " + |
|
194 |
"server like '" + server + "'"); |
|
195 |
pstmt.execute(); |
|
196 |
out.println("server " + server + " deleted"); |
|
197 |
} |
|
198 |
else if(subaction.equals("list")) |
|
199 |
{ |
|
200 |
response.setContentType("text/html"); |
|
201 |
out.println("<html><body><table border=\"1\">"); |
|
202 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td></tr>"); |
|
203 |
pstmt = conn.prepareStatement("select * from xml_replication"); |
|
204 |
pstmt.execute(); |
|
205 |
ResultSet rs = pstmt.getResultSet(); |
|
206 |
boolean tablehasrows = rs.next(); |
|
207 |
while(tablehasrows) |
|
208 |
{ |
|
209 |
out.println("<tr><td>" + rs.getString(2) + "</td><td>"); |
|
210 |
out.println(rs.getString(3) + "</td></tr>"); |
|
211 |
tablehasrows = rs.next(); |
|
212 |
} |
|
213 |
out.println("</table></body></html>"); |
|
214 |
} |
|
215 |
conn.close(); |
|
216 |
} |
|
217 |
catch(Exception e) |
|
218 |
{ |
|
219 |
System.out.println("error in handleServerControlRequest " + |
|
220 |
e.getMessage()); |
|
221 |
e.printStackTrace(System.out); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
154 | 225 |
/** |
155 | 226 |
* when a forcereplication request comes in, this method sends a read request |
156 | 227 |
* to the requesting server for the specified docid. |
... | ... | |
246 | 317 |
lockThread = new Thread(this); |
247 | 318 |
lockThread.setPriority(Thread.MIN_PRIORITY); |
248 | 319 |
lockThread.start(); |
320 |
System.out.println("lock granted for " + docid); |
|
249 | 321 |
MetacatReplication.replLog("lock granted for " + docid); |
250 | 322 |
} |
251 | 323 |
else |
... | ... | |
323 | 395 |
out.print(di.toString()); |
324 | 396 |
conn.close(); |
325 | 397 |
MetacatReplication.replLog("document " + docid + " sent"); |
398 |
System.out.println("document " + docid + " sent"); |
|
326 | 399 |
} |
327 | 400 |
catch(Exception e) |
328 | 401 |
{ |
... | ... | |
350 | 423 |
{ |
351 | 424 |
try |
352 | 425 |
{ |
353 |
MetaCatUtil.debugMessage("received update request");
|
|
426 |
System.out.println("received update request");
|
|
354 | 427 |
StringBuffer docsql = new StringBuffer(); |
355 | 428 |
StringBuffer doclist = new StringBuffer(); |
356 | 429 |
|
... | ... | |
401 | 474 |
conn.close(); |
402 | 475 |
response.setContentType("text/xml"); |
403 | 476 |
out.println(doclist.toString()); |
404 |
MetacatReplication.replLog("update request handled");
|
|
477 |
System.out.println("update request handled");
|
|
405 | 478 |
} |
406 | 479 |
catch(Exception e) |
407 | 480 |
{ |
... | ... | |
500 | 573 |
{ |
501 | 574 |
MetaCatUtil.debugMessage("thread started for docid: " + |
502 | 575 |
(String)fileLocks.elementAt(0)); |
576 |
System.out.println("thread started for docid: " + |
|
577 |
(String)fileLocks.elementAt(0)); |
|
503 | 578 |
Thread.sleep(30000); //the lock will expire in 30 seconds |
504 | 579 |
MetaCatUtil.debugMessage("thread for docid: " + |
505 |
(String)fileLocks.elementAt(fileLocks.size() - 1) + |
|
506 |
" exiting."); |
|
580 |
(String)fileLocks.elementAt(fileLocks.size() - 1) + |
|
581 |
" exiting."); |
|
582 |
System.out.println("thread for docid: " + |
|
583 |
(String)fileLocks.elementAt(fileLocks.size() - 1) + |
|
584 |
" exiting."); |
|
507 | 585 |
fileLocks.remove(fileLocks.size() - 1); |
508 | 586 |
//fileLocks is treated as a FIFO queue. If there are more than one lock |
509 | 587 |
//in the vector, the first one inserted will be removed. |
... | ... | |
627 | 705 |
catch(Exception e) |
628 | 706 |
{ |
629 | 707 |
System.out.println("error writing to replication log"); |
630 |
e.printStackTrace(System.out); |
|
708 |
//e.printStackTrace(System.out);
|
|
631 | 709 |
} |
632 | 710 |
} |
633 | 711 |
} |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
111 | 111 |
XMLReader parser; |
112 | 112 |
URL u; |
113 | 113 |
|
114 |
//System.out.println("in update2"); |
|
115 |
|
|
116 | 114 |
try |
117 | 115 |
{ |
118 | 116 |
MetaCatUtil.debugMessage("init parser"); |
... | ... | |
120 | 118 |
keys = serverList.keys(); |
121 | 119 |
while(keys.hasMoreElements()) |
122 | 120 |
{ |
123 |
MetaCatUtil.debugMessage("get responses"); |
|
124 | 121 |
server = (String)(keys.nextElement()); |
125 | 122 |
MetacatReplication.replLog("full update started to: " + server); |
126 | 123 |
u = new URL("http://" + server + "?action=update"); |
127 |
MetaCatUtil.debugMessage(u.toString());
|
|
124 |
System.out.println("Sending Message: " + u.toString());
|
|
128 | 125 |
String result = MetacatReplication.getURLContent(u); |
129 |
MetaCatUtil.debugMessage(result); |
|
130 | 126 |
responses.add(result); |
131 | 127 |
} |
132 | 128 |
|
133 |
MetaCatUtil.debugMessage("responses: " + responses.toString());
|
|
129 |
System.out.println("responses: " + responses.toString());
|
|
134 | 130 |
|
135 | 131 |
for(int i=0; i<responses.size(); i++) |
136 | 132 |
{ //check each server for updated files |
... | ... | |
183 | 179 |
{ //if the document needs to be updated or inserted, this is executed |
184 | 180 |
u = new URL("http://" + docServer + "?action=read&docid=" + |
185 | 181 |
docid); |
186 |
MetacatReplication.replLog("reading doc " + docid + " from " + |
|
187 |
docServer); |
|
188 |
//System.out.println(u.toString()); |
|
182 |
System.out.println("Sending message: " + u.toString()); |
|
189 | 183 |
String newxmldoc = MetacatReplication.getURLContent(u); |
190 | 184 |
DocInfoHandler dih = new DocInfoHandler(); |
191 | 185 |
XMLReader docinfoParser = initParser(dih); |
192 | 186 |
URL docinfoUrl = new URL("http://" + docServer + |
193 | 187 |
"?action=getdocumentinfo&docid=" + |
194 | 188 |
docid); |
195 |
//System.out.println(docinfoUrl.toString());
|
|
189 |
System.out.println("Sending message: " + docinfoUrl.toString());
|
|
196 | 190 |
String docInfoStr = MetacatReplication.getURLContent(docinfoUrl); |
197 | 191 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
198 | 192 |
Hashtable docinfoHash = dih.getDocInfo(); |
... | ... | |
209 | 203 |
true); |
210 | 204 |
MetacatReplication.replLog("wrote doc " + docid + " from " + |
211 | 205 |
docServer); |
206 |
System.out.println("wrote doc " + docid + " from " + |
|
207 |
docServer); |
|
212 | 208 |
} |
213 | 209 |
} |
214 | 210 |
|
... | ... | |
219 | 215 |
if(!alreadyDeleted(docid, conn)) |
220 | 216 |
{ |
221 | 217 |
DocumentImpl.delete(conn, docid, null, null); |
222 |
MetaCatUtil.debugMessage("Document " + docid + " deleted.");
|
|
218 |
System.out.println("Document " + docid + " deleted.");
|
|
223 | 219 |
MetacatReplication.replLog("doc " + docid + " deleted"); |
224 | 220 |
} |
225 | 221 |
} |
... | ... | |
239 | 235 |
pstmt = conn.prepareStatement(sql.toString()); |
240 | 236 |
pstmt.executeUpdate(); |
241 | 237 |
//conn.commit(); |
242 |
MetaCatUtil.debugMessage("last_checked updated to " + datestr + " on " +
|
|
238 |
System.out.println("last_checked updated to " + datestr + " on " +
|
|
243 | 239 |
server); |
244 | 240 |
} |
245 | 241 |
} |
... | ... | |
264 | 260 |
while(keys.hasMoreElements()) |
265 | 261 |
{ //go through each server |
266 | 262 |
server = (String)(keys.nextElement()); |
267 |
System.out.println("server: " + server); |
|
268 | 263 |
URL u = new URL("http://" + server + "?action=getcatalog"); |
264 |
System.out.println("sending message " + u.toString()); |
|
269 | 265 |
String catxml = MetacatReplication.getURLContent(u); |
270 |
System.out.println("catxml: " + catxml); |
|
266 |
//System.out.println("catxml: " + catxml);
|
|
271 | 267 |
CatalogMessageHandler cmh = new CatalogMessageHandler(); |
272 | 268 |
XMLReader catparser = initParser(cmh); |
273 | 269 |
catparser.parse(new InputSource(new StringReader(catxml))); |
... | ... | |
275 | 271 |
Vector remoteCatalog = cmh.getCatalogVect(); |
276 | 272 |
|
277 | 273 |
String localcatxml = MetacatReplication.getCatalogXML(); |
278 |
System.out.println("localcatxml: " + localcatxml); |
|
274 |
//System.out.println("localcatxml: " + localcatxml);
|
|
279 | 275 |
cmh = new CatalogMessageHandler(); |
280 | 276 |
catparser = initParser(cmh); |
281 | 277 |
catparser.parse(new InputSource(new StringReader(localcatxml))); |
... | ... | |
289 | 285 |
for(int i=0; i<localCatalog.size(); i++) |
290 | 286 |
{ |
291 | 287 |
Vector v = new Vector((Vector)localCatalog.elementAt(i)); |
292 |
System.out.println("v1: " + v.toString()); |
|
288 |
//System.out.println("v1: " + v.toString());
|
|
293 | 289 |
publicId.add(new String((String)v.elementAt(3))); |
294 |
System.out.println("adding " + (String)v.elementAt(3)); |
|
290 |
//System.out.println("adding " + (String)v.elementAt(3));
|
|
295 | 291 |
} |
296 | 292 |
|
297 | 293 |
for(int i=0; i<remoteCatalog.size(); i++) |
298 | 294 |
{ |
299 | 295 |
Vector v = (Vector)remoteCatalog.elementAt(i); |
300 |
System.out.println("v2: " + v.toString()); |
|
296 |
//System.out.println("v2: " + v.toString());
|
|
301 | 297 |
//System.out.println("i: " + i); |
302 | 298 |
//System.out.println("remoteCatalog.size(): " + remoteCatalog.size()); |
303 |
System.out.println("publicID: " + publicId.toString()); |
|
304 |
System.out.println("v.elementAt(3): " + (String)v.elementAt(3)); |
|
299 |
//System.out.println("publicID: " + publicId.toString());
|
|
300 |
//System.out.println("v.elementAt(3): " + (String)v.elementAt(3));
|
|
305 | 301 |
if(!publicId.contains(v.elementAt(3))) |
306 | 302 |
{ //so we don't have this public id in our local table so we need to |
307 | 303 |
//add it. |
308 |
System.out.println("in if"); |
|
304 |
//System.out.println("in if");
|
|
309 | 305 |
StringBuffer sql = new StringBuffer(); |
310 | 306 |
sql.append("insert into xml_catalog (entry_type, source_doctype, "); |
311 | 307 |
sql.append("target_doctype, public_id, system_id) values (?,?,?,"); |
312 | 308 |
sql.append("?,?)"); |
313 |
System.out.println("sql: " + sql.toString()); |
|
309 |
//System.out.println("sql: " + sql.toString());
|
|
314 | 310 |
PreparedStatement pstmt = conn.prepareStatement(sql.toString()); |
315 | 311 |
pstmt.setString(1, (String)v.elementAt(0)); |
316 | 312 |
pstmt.setString(2, (String)v.elementAt(1)); |
src/edu/ucsb/nceas/metacat/CatalogMessageHandler.java | ||
---|---|---|
70 | 70 |
|| currentTag.equals("target_doctype") || currentTag.equals("public_id") |
71 | 71 |
|| currentTag.equals("system_id")) |
72 | 72 |
{ |
73 |
System.out.println("parser adding: " + (new String(ch, start, length)).trim()); |
|
73 |
//System.out.println("parser adding: " + (new String(ch, start, length)).trim());
|
|
74 | 74 |
indivUpdate.add((new String(ch, start, length)).trim()); |
75 | 75 |
} |
76 | 76 |
} |
Also available in: Unified diff
added additional actions to facilitate a web based interface to the replication servlet.