Revision 629
Added by berkley about 24 years ago
lib/replControl.html | ||
---|---|---|
70 | 70 |
<input type="radio" name="subaction" value="delete"> Remove this server<br> |
71 | 71 |
<input type="radio" name="subaction" value="add"> Add this server<br> |
72 | 72 |
<input type="radio" name="subaction" value="list"> List the current servers<br> |
73 |
<input size="30" name="server" > |
|
73 |
<input size="30" name="server" > <br>Replicate To (1 or 0)?: |
|
74 |
<input size="2" name="replicate"> |
|
74 | 75 |
<br><br> |
75 | 76 |
<input type="submit" value="Submit"> |
76 | 77 |
</form> |
src/xmltables.sql | ||
---|---|---|
47 | 47 |
serverid NUMBER(20), |
48 | 48 |
server VARCHAR2(512), |
49 | 49 |
last_checked DATE, |
50 |
replicate NUMBER(1), |
|
50 | 51 |
CONSTRAINT xml_replication_pk PRIMARY KEY (serverid) |
51 | 52 |
); |
52 | 53 |
|
... | ... | |
60 | 61 |
END; |
61 | 62 |
/ |
62 | 63 |
|
63 |
INSERT INTO xml_replication (serverid, server) VALUES ('1', 'localhost');
|
|
64 |
INSERT INTO xml_replication (serverid, server, replicate) VALUES ('1', 'localhost', '0');
|
|
64 | 65 |
|
65 | 66 |
/* |
66 | 67 |
* Nodes -- table to store XML Nodes (both elements and attributes) |
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
180 | 180 |
PreparedStatement pstmt; |
181 | 181 |
if(subaction.equals("add")) |
182 | 182 |
{ |
183 |
String replicate = ((String[])params.get("replicate"))[0]; |
|
183 | 184 |
String server = ((String[])params.get("server"))[0]; |
184 | 185 |
pstmt = conn.prepareStatement("insert into xml_replication (server, " + |
185 |
"last_checked) values ('" + server + "', to_date(" + |
|
186 |
"'01/01/00', 'MM/DD/YY'))"); |
|
186 |
"last_checked, replicate) values ('" + server + "', to_date(" +
|
|
187 |
"'01/01/00', 'MM/DD/YY'), '" + replicate + "')");
|
|
187 | 188 |
pstmt.execute(); |
188 |
out.println("server " + server + " added"); |
|
189 |
out.println("server " + server + " added");
|
|
189 | 190 |
} |
190 | 191 |
else if(subaction.equals("delete")) |
191 | 192 |
{ |
... | ... | |
199 | 200 |
{ |
200 | 201 |
response.setContentType("text/html"); |
201 | 202 |
out.println("<html><body><table border=\"1\">"); |
202 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td></tr>"); |
|
203 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td><td>"); |
|
204 |
out.println("<b>replicate</b></td></tr>"); |
|
203 | 205 |
pstmt = conn.prepareStatement("select * from xml_replication"); |
204 | 206 |
pstmt.execute(); |
205 | 207 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
207 | 209 |
while(tablehasrows) |
208 | 210 |
{ |
209 | 211 |
out.println("<tr><td>" + rs.getString(2) + "</td><td>"); |
210 |
out.println(rs.getString(3) + "</td></tr>"); |
|
212 |
out.println(rs.getString(3) + "</td><td>"); |
|
213 |
out.println(rs.getString(4) + "</td></tr>"); |
|
211 | 214 |
tablehasrows = rs.next(); |
212 | 215 |
} |
213 | 216 |
out.println("</table></body></html>"); |
... | ... | |
231 | 234 |
{ |
232 | 235 |
//System.out.println("in handleforcereplicaterequest"); |
233 | 236 |
String server = ((String[])params.get("server"))[0]; |
237 |
if(!(replToServer(server))) |
|
238 |
{ //do not get the server's new document if we are not replicating from there |
|
239 |
return; |
|
240 |
} |
|
241 |
|
|
234 | 242 |
//the server that the request came from |
235 | 243 |
String docid = ((String[])params.get("docid"))[0]; |
236 | 244 |
//the docid of the document to get |
... | ... | |
734 | 742 |
//e.printStackTrace(System.out); |
735 | 743 |
} |
736 | 744 |
} |
745 |
|
|
746 |
/** |
|
747 |
* Returns true if the replicate field for server in xml_replication is 1. |
|
748 |
* Returns false otherwise |
|
749 |
*/ |
|
750 |
public static boolean replToServer(String server) |
|
751 |
{ |
|
752 |
try |
|
753 |
{ |
|
754 |
Connection conn = util.openDBConnection(); |
|
755 |
PreparedStatement pstmt = conn.prepareStatement("select replicate from " + |
|
756 |
"xml_replication where server like '" + |
|
757 |
server + "'"); |
|
758 |
pstmt.execute(); |
|
759 |
ResultSet rs = pstmt.getResultSet(); |
|
760 |
boolean tablehasrows = rs.next(); |
|
761 |
if(tablehasrows) |
|
762 |
{ |
|
763 |
int i = rs.getInt(1); |
|
764 |
if(i == 1) |
|
765 |
{ |
|
766 |
return true; |
|
767 |
} |
|
768 |
else |
|
769 |
{ |
|
770 |
return false; |
|
771 |
} |
|
772 |
} |
|
773 |
} |
|
774 |
catch(Exception e) |
|
775 |
{ |
|
776 |
System.out.println("error in replToServer: " + e.getMessage()); |
|
777 |
} |
|
778 |
return false; |
|
779 |
//the default if this server does not exist is to not replicate to it. |
|
780 |
} |
|
737 | 781 |
} |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
446 | 446 |
PreparedStatement pstmt; |
447 | 447 |
try |
448 | 448 |
{ |
449 |
pstmt = conn.prepareStatement("select server, last_checked from " +
|
|
450 |
"xml_replication"); |
|
449 |
pstmt = conn.prepareStatement("select server, last_checked, replicate " +
|
|
450 |
"from xml_replication");
|
|
451 | 451 |
pstmt.execute(); |
452 | 452 |
ResultSet rs = pstmt.getResultSet(); |
453 | 453 |
boolean tableHasRows = rs.next(); |
454 | 454 |
while(tableHasRows) |
455 | 455 |
{ |
456 |
String server = rs.getString(1); |
|
457 |
String last_checked = rs.getString(2); |
|
458 |
if(!server.equals("localhost")) |
|
459 |
{ |
|
460 |
sl.put(server, last_checked); |
|
456 |
if(rs.getInt(3) == 1) |
|
457 |
{//only put the server in the list if the replicate flag is true |
|
458 |
String server = rs.getString(1); |
|
459 |
String last_checked = rs.getString(2); |
|
460 |
if(!server.equals("localhost")) |
|
461 |
{ |
|
462 |
sl.put(server, last_checked); |
|
463 |
} |
|
461 | 464 |
} |
462 |
tableHasRows = rs.next(); |
|
465 |
tableHasRows = rs.next();
|
|
463 | 466 |
} |
464 | 467 |
} |
465 | 468 |
catch(Exception e) |
Also available in: Unified diff
added support for one way replication