Revision 584
Added by berkley about 24 years ago
lib/metacat.properties | ||
---|---|---|
5 | 5 |
# |
6 | 6 |
user=@user@ |
7 | 7 |
password=@password@ |
8 |
defaultDB=jdbc:oracle:thin:@dev.nceas.ucsb.edu:1521:exp
|
|
8 |
defaultDB=jdbc:oracle:thin:@alpha.nceas.ucsb.edu:1521:oralin
|
|
9 | 9 |
dbDriver=oracle.jdbc.driver.OracleDriver |
10 | 10 |
initialConnections=5 |
11 | 11 |
incrementConnections=5 |
... | ... | |
20 | 20 |
servletpath=@servlet-path@ |
21 | 21 |
htmlpath=@html-path@ |
22 | 22 |
packagedoctype=-//NCEAS//package1.0//EN |
23 |
server=dev.nceas.ucsb.edu
|
|
23 |
server=alpha.nceas.ucsb.edu:8080
|
|
24 | 24 |
authclass=edu.ucsb.nceas.metacat.AuthLdap |
25 | 25 |
ldapurl=ldap://ldap.nceas.ucsb.edu:389/ |
26 | 26 |
ldapbase=o=NCEAS,c=US |
27 | 27 |
deltaT=60 |
28 | 28 |
replicationpath=@replication-path@ |
29 |
replicationlog=metacatreplication.log |
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
87 | 87 |
replicationDaemon.cancel(); |
88 | 88 |
out.println("Replication Handler Stopped"); |
89 | 89 |
System.out.println("Replication Handler Stopped"); |
90 |
MetacatReplication.replLog("deltaT handler stopped"); |
|
90 | 91 |
} |
91 | 92 |
else if(((String[])params.get("action"))[0].equals("start")) |
92 | 93 |
{ //start the replication server |
... | ... | |
112 | 113 |
replicationDaemon = new Timer(true); |
113 | 114 |
replicationDaemon.scheduleAtFixedRate(new ReplicationHandler(out), 0, |
114 | 115 |
rate * 1000); |
116 |
MetacatReplication.replLog("deltaT handler started with rate=" + |
|
117 |
rate + " seconds"); |
|
115 | 118 |
out.println("Replication Handler Started"); |
116 | 119 |
System.out.println("Replication Handler Started"); |
117 | 120 |
} |
... | ... | |
171 | 174 |
} |
172 | 175 |
//System.out.println("action in forcereplicate is: " + dbaction); |
173 | 176 |
//System.out.println("serverCode in forcereplicate is: " + serverCode); |
177 |
MetacatReplication.replLog("force replication request from " + server); |
|
174 | 178 |
|
175 | 179 |
int serverCheckCode = MetacatReplication.getServerCode(server); |
176 | 180 |
URL u = new URL("http://" + server + "?action=read&docid=" + docid); |
... | ... | |
195 | 199 |
Connection conn = util.openDBConnection(); |
196 | 200 |
DocumentImpl.write(conn, new StringReader(xmldoc), null, dbaction, docid, |
197 | 201 |
user, group, serverCode, override); |
202 |
MetacatReplication.replLog("document " + docid + " added to DB with " + |
|
203 |
"action " + dbaction); |
|
198 | 204 |
conn.close(); |
199 | 205 |
} |
200 | 206 |
catch(Exception e) |
... | ... | |
214 | 220 |
private void handleGetLockRequest(PrintWriter out, Hashtable params, |
215 | 221 |
HttpServletResponse response) |
216 | 222 |
{ |
217 |
System.out.println("in handlegetlockrequest"); |
|
218 | 223 |
try |
219 | 224 |
{ |
220 | 225 |
Connection conn = util.openDBConnection(); |
221 | 226 |
String docid = ((String[])params.get("docid"))[0]; |
222 | 227 |
String remoteRev = ((String[])params.get("updaterev"))[0]; |
223 | 228 |
DocumentImpl requestDoc = new DocumentImpl(conn, docid); |
229 |
MetacatReplication.replLog("lock request for " + docid); |
|
224 | 230 |
int localRevInt = requestDoc.getRev(); |
225 | 231 |
int remoteRevInt = Integer.parseInt(remoteRev); |
226 | 232 |
|
... | ... | |
234 | 240 |
lockThread = new Thread(this); |
235 | 241 |
lockThread.setPriority(Thread.MIN_PRIORITY); |
236 | 242 |
lockThread.start(); |
243 |
MetacatReplication.replLog("lock granted for " + docid); |
|
237 | 244 |
} |
238 | 245 |
else |
239 | 246 |
{ //deny the lock |
240 | 247 |
out.println("<filelocked><docid>" + docid + "</docid></filelocked>"); |
248 |
MetacatReplication.replLog("lock denied for " + docid + |
|
249 |
"reason: file already locked"); |
|
241 | 250 |
} |
242 | 251 |
} |
243 | 252 |
else |
244 | 253 |
{//deny the lock. |
245 | 254 |
out.println("<outdatedfile><docid>" + docid + "</docid></filelocked>"); |
255 |
MetacatReplication.replLog("lock denied for " + docid + |
|
256 |
"reason: client has outdated file"); |
|
246 | 257 |
} |
247 | 258 |
conn.close(); |
248 | 259 |
} |
... | ... | |
299 | 310 |
try |
300 | 311 |
{ |
301 | 312 |
String docid = ((String[])(params.get("docid")))[0]; |
302 |
System.out.println("incoming get request for document: " + |
|
303 |
docid); |
|
313 |
//System.out.println("incoming get request for document: " + docid); |
|
304 | 314 |
Connection conn = util.openDBConnection(); |
305 | 315 |
DocumentImpl di = new DocumentImpl(conn, docid); |
306 | 316 |
response.setContentType("text/xml"); |
307 | 317 |
out.print(di.toString()); |
308 | 318 |
conn.close(); |
319 |
MetacatReplication.replLog("document " + docid + " sent"); |
|
309 | 320 |
} |
310 | 321 |
catch(Exception e) |
311 | 322 |
{ |
... | ... | |
331 | 342 |
private void handleUpdateRequest(PrintWriter out, Hashtable params, |
332 | 343 |
HttpServletResponse response) |
333 | 344 |
{ |
334 |
System.out.println("in handleUpdateRequest2"); |
|
335 | 345 |
try |
336 | 346 |
{ |
337 |
System.out.println("received update request"); |
|
347 |
//System.out.println("received update request");
|
|
338 | 348 |
StringBuffer docsql = new StringBuffer(); |
339 | 349 |
StringBuffer doclist = new StringBuffer(); |
340 | 350 |
|
... | ... | |
385 | 395 |
conn.close(); |
386 | 396 |
response.setContentType("text/xml"); |
387 | 397 |
out.println(doclist.toString()); |
398 |
MetacatReplication.replLog("update request handled"); |
|
388 | 399 |
} |
389 | 400 |
catch(Exception e) |
390 | 401 |
{ |
... | ... | |
525 | 536 |
|
526 | 537 |
return serverResponse.toString(); |
527 | 538 |
} |
539 |
|
|
540 |
/** |
|
541 |
* Method for writing replication messages to a log file specified in |
|
542 |
* metacat.properties |
|
543 |
*/ |
|
544 |
public static void replLog(String message) |
|
545 |
{ |
|
546 |
try |
|
547 |
{ |
|
548 |
FileOutputStream fos = new FileOutputStream( |
|
549 |
util.getOption("replicationlog"), true); |
|
550 |
PrintWriter pw = new PrintWriter(fos); |
|
551 |
SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss"); |
|
552 |
java.util.Date localtime = new java.util.Date(); |
|
553 |
String dateString = formatter.format(localtime); |
|
554 |
dateString += " :: " + message; |
|
555 |
//time stamp each entry |
|
556 |
pw.println(dateString); |
|
557 |
pw.flush(); |
|
558 |
} |
|
559 |
catch(Exception e) |
|
560 |
{ |
|
561 |
System.out.println("error writing to replication log"); |
|
562 |
e.printStackTrace(System.out); |
|
563 |
} |
|
564 |
} |
|
528 | 565 |
} |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
762 | 762 |
String group, int serverCode, boolean override) |
763 | 763 |
throws Exception |
764 | 764 |
{ |
765 |
System.out.println("in write"); |
|
766 | 765 |
MetaCatUtil util = new MetaCatUtil(); |
767 | 766 |
// Determine if the docid is OK for INSERT or UPDATE |
768 | 767 |
AccessionNumber ac = new AccessionNumber(conn); |
769 | 768 |
String newdocid = ac.generate(docid, action); |
770 | 769 |
|
771 |
System.out.println("action: " + action + " servercode: " + |
|
772 |
serverCode + " override: " + override); |
|
770 |
//System.out.println("action: " + action + " servercode: " +
|
|
771 |
// serverCode + " override: " + override);
|
|
773 | 772 |
|
774 | 773 |
if((serverCode != 1 && action.equals("UPDATE")) && !override) |
775 | 774 |
{ //if this document being written is not a resident of this server then |
... | ... | |
782 | 781 |
DocumentImpl newdoc = new DocumentImpl(conn, docid); |
783 | 782 |
int updaterev = newdoc.getRev(); |
784 | 783 |
String server = MetacatReplication.getServer(serverCode); |
784 |
MetacatReplication.replLog("attempting to lock " + docid); |
|
785 | 785 |
URL u = new URL("http://" + server + "?action=getlock&updaterev=" + |
786 | 786 |
updaterev + "&docid=" + docid); |
787 | 787 |
System.out.println("sending message: " + u.toString()); |
... | ... | |
792 | 792 |
{//the lock was granted go ahead with the insert |
793 | 793 |
try |
794 | 794 |
{ |
795 |
MetacatReplication.replLog("lock granted for " + docid + " from " + |
|
796 |
server); |
|
795 | 797 |
XMLReader parser = initializeParser(conn,action,newdocid,user, |
796 | 798 |
serverCode); |
797 | 799 |
conn.setAutoCommit(false); |
... | ... | |
842 | 844 |
{//the file is currently locked by another user |
843 | 845 |
//notify our user to wait a few minutes, check out a new copy and try |
844 | 846 |
//again. |
845 |
System.out.println("file locked"); |
|
847 |
//System.out.println("file locked"); |
|
848 |
MetacatReplication.replLog("lock denied for " + docid + " on " + |
|
849 |
server + " reason: file already locked"); |
|
846 | 850 |
throw new Exception("The file specified is already locked by another " + |
847 | 851 |
"user. Please wait 30 seconds, checkout the " + |
848 | 852 |
"newer document, merge your changes and try " + |
... | ... | |
851 | 855 |
else if(openingtag.equals("<outdatedfile>")) |
852 | 856 |
{//our file is outdated. notify our user to check out a new copy of the |
853 | 857 |
//file and merge his version with the new version. |
854 |
System.out.println("outdated file"); |
|
858 |
//System.out.println("outdated file"); |
|
859 |
MetacatReplication.replLog("lock denied for " + docid + " on " + |
|
860 |
server + " reason: local file outdated"); |
|
855 | 861 |
throw new Exception("The file you are trying to update is an outdated" + |
856 | 862 |
" version. Please checkout the newest document, " + |
857 | 863 |
"merge your changes and try again."); |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
121 | 121 |
{ |
122 | 122 |
//System.out.println("get responses"); |
123 | 123 |
server = (String)(keys.nextElement()); |
124 |
MetacatReplication.replLog("full update started to: " + server); |
|
124 | 125 |
u = new URL("http://" + server + "?action=update"); |
125 | 126 |
//System.out.println(u.toString()); |
126 | 127 |
String result = MetacatReplication.getURLContent(u); |
127 |
System.out.println(result); |
|
128 |
//System.out.println(result);
|
|
128 | 129 |
responses.add(result); |
129 | 130 |
} |
130 | 131 |
|
... | ... | |
181 | 182 |
{ //if the document needs to be updated or inserted, this is executed |
182 | 183 |
u = new URL("http://" + docServer + "?action=read&docid=" + |
183 | 184 |
docid); |
185 |
MetacatReplication.replLog("reading doc " + docid + " from " + |
|
186 |
docServer); |
|
184 | 187 |
//System.out.println(u.toString()); |
185 | 188 |
String newxmldoc = MetacatReplication.getURLContent(u); |
186 | 189 |
DocInfoHandler dih = new DocInfoHandler(); |
... | ... | |
193 | 196 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
194 | 197 |
Hashtable docinfoHash = dih.getDocInfo(); |
195 | 198 |
int serverCode = MetacatReplication.getServerCode(docServer); |
196 |
System.out.println("updating doc: " + docid + " action: "+ action); |
|
199 |
//System.out.println("updating doc: " + docid + " action: "+ action);
|
|
197 | 200 |
String newDocid = DocumentImpl.write(conn, |
198 | 201 |
new StringReader(newxmldoc), |
199 | 202 |
null, |
... | ... | |
203 | 206 |
(String)docinfoHash.get("user_owner"), |
204 | 207 |
serverCode, |
205 | 208 |
true); |
209 |
MetacatReplication.replLog("wrote doc " + docid + " from " + |
|
210 |
docServer); |
|
206 | 211 |
} |
207 | 212 |
} |
208 | 213 |
|
... | ... | |
213 | 218 |
if(!alreadyDeleted(docid, conn)) |
214 | 219 |
{ |
215 | 220 |
DocumentImpl.delete(conn, docid, null, null); |
216 |
System.out.println("Document " + docid + " deleted."); |
|
221 |
//System.out.println("Document " + docid + " deleted."); |
|
222 |
MetacatReplication.replLog("doc " + docid + " deleted"); |
|
217 | 223 |
} |
218 | 224 |
} |
219 | 225 |
|
... | ... | |
232 | 238 |
pstmt = conn.prepareStatement(sql.toString()); |
233 | 239 |
pstmt.executeUpdate(); |
234 | 240 |
//conn.commit(); |
235 |
System.out.println("last_checked updated to " + datestr + " on " + |
|
236 |
server); |
|
241 |
//System.out.println("last_checked updated to " + datestr + " on " +
|
|
242 |
// server);
|
|
237 | 243 |
} |
238 | 244 |
} |
239 | 245 |
} |
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java | ||
---|---|---|
77 | 77 |
String server = (String)(keys.nextElement()); |
78 | 78 |
if(dbactionFlag) |
79 | 79 |
{ |
80 |
MetacatReplication.replLog("force replicating to " + server); |
|
80 | 81 |
comeAndGetIt = new URL("http://" + server + |
81 | 82 |
"?action=forcereplicate&server=" + |
82 | 83 |
util.getOption("server") + |
... | ... | |
86 | 87 |
} |
87 | 88 |
else |
88 | 89 |
{ |
90 |
MetacatReplication.replLog("force replicating (default action) to )" + |
|
91 |
server); |
|
89 | 92 |
comeAndGetIt = new URL("http://" + server + |
90 | 93 |
"?action=forcereplicate&server=" + |
91 | 94 |
util.getOption("server") + |
Also available in: Unified diff
added a logging system for replication. The log file location is set in metacat.properties