Revision 1292
Added by Jing Tao over 22 years ago
test/dtdxml.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!DOCTYPE PARENT [ |
|
3 |
<!ELEMENT PARENT (CHILD*)> |
|
4 |
<!ELEMENT CHILD (MARK?,NAME+)> |
|
5 |
<!ELEMENT MARK EMPTY> |
|
6 |
<!ELEMENT NAME (LASTNAME+,FIRSTNAME+)*> |
|
7 |
<!ELEMENT LASTNAME (#PCDATA)> |
|
8 |
<!ELEMENT FIRSTNAME (#PCDATA)> |
|
9 |
<!ATTLIST MARK |
|
10 |
NUMBER ID #REQUIRED |
|
11 |
LISTED CDATA #FIXED "yes" |
|
12 |
TYPE (natural|adopted) "natural"> |
|
13 |
<!ENTITY STATEMENT "This is well-formed XML"> |
|
14 |
]> |
|
15 |
<PARENT> |
|
16 |
&STATEMENT; |
|
17 |
<CHILD> |
|
18 |
<MARK NUMBER="1" LISTED="yes" TYPE="natural"/> |
|
19 |
<NAME> |
|
20 |
<LASTNAME>child</LASTNAME> |
|
21 |
<FIRSTNAME>second</FIRSTNAME> |
|
22 |
</NAME> |
|
23 |
</CHILD> |
|
24 |
</PARENT> |
|
25 |
|
|
0 | 26 |
test/edu/ucsb/nceas/metacattest/ReplicationServerListTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Copyright: 2000 Regents of the University of California and the |
|
4 |
* National Center for Ecological Analysis and Synthesis |
|
5 |
* Purpose: To test the ReplicationServerList class by JUnit |
|
6 |
* Authors: @Jing Tao@ |
|
7 |
* Release: @release@ |
|
8 |
* |
|
9 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
12 |
* |
|
13 |
* This program is free software; you can redistribute it and/or modify |
|
14 |
* it under the terms of the GNU General Public License as published by |
|
15 |
* the Free Software Foundation; either version 2 of the License, or |
|
16 |
* (at your option) any later version. |
|
17 |
* |
|
18 |
* This program is distributed in the hope that it will be useful, |
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
* GNU General Public License for more details. |
|
22 |
* |
|
23 |
* You should have received a copy of the GNU General Public License |
|
24 |
* along with this program; if not, write to the Free Software |
|
25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
*/ |
|
27 |
|
|
28 |
package edu.ucsb.nceas.metacattest; |
|
29 |
|
|
30 |
import edu.ucsb.nceas.metacat.*; |
|
31 |
//import edu.ucsb.nceas.morpho.framework.*; |
|
32 |
import junit.framework.Test; |
|
33 |
import junit.framework.TestCase; |
|
34 |
import junit.framework.TestResult; |
|
35 |
import junit.framework.TestSuite; |
|
36 |
|
|
37 |
import java.io.*; |
|
38 |
import java.net.*; |
|
39 |
import java.util.*; |
|
40 |
|
|
41 |
|
|
42 |
/** |
|
43 |
* A JUnit test for testing Step class processing |
|
44 |
*/ |
|
45 |
public class ReplicationServerListTest extends TestCase |
|
46 |
{ |
|
47 |
private static String metacatReplicationURL= |
|
48 |
MetaCatUtil.getOption("junitreplicationurl"); |
|
49 |
private ReplicationServerList serverList = null; |
|
50 |
/** |
|
51 |
* Constructor to build the test |
|
52 |
* |
|
53 |
* @param name the name of the test method |
|
54 |
*/ |
|
55 |
public ReplicationServerListTest(String name) |
|
56 |
{ |
|
57 |
super(name); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Constructor to build the test |
|
62 |
* |
|
63 |
* @param name the name of the test method |
|
64 |
* @param list the ReplicationServerList will be passed int |
|
65 |
*/ |
|
66 |
public ReplicationServerListTest(String name, ReplicationServerList list) |
|
67 |
{ |
|
68 |
super(name); |
|
69 |
serverList=list; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Establish a testing framework by initializing appropriate objects |
|
74 |
*/ |
|
75 |
public void setUp() |
|
76 |
{ |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Release any objects after tests are complete |
|
82 |
*/ |
|
83 |
public void tearDown() |
|
84 |
{ |
|
85 |
//DBConnectionPool will be release |
|
86 |
DBConnectionPool.release(); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Create a suite of tests to be run together |
|
91 |
*/ |
|
92 |
public static Test suite() |
|
93 |
{ |
|
94 |
//Get DBConnection pool, this is only for junit test. |
|
95 |
//Because DBConnection is singleton class. So there is only one DBConnection |
|
96 |
//pool in the program |
|
97 |
try |
|
98 |
{ |
|
99 |
DBConnectionPool pool = DBConnectionPool.getInstance(); |
|
100 |
}//try |
|
101 |
catch (Exception e) |
|
102 |
{ |
|
103 |
MetaCatUtil.debugMessage("Error in ReplicationServerList() to get" + |
|
104 |
" DBConnection pool"+e.getMessage(), 30); |
|
105 |
}//catch |
|
106 |
|
|
107 |
TestSuite suite = new TestSuite(); |
|
108 |
suite.addTest(new ReplicationServerListTest("initialize")); |
|
109 |
|
|
110 |
try |
|
111 |
{ |
|
112 |
|
|
113 |
//Add two server into xml_replication table |
|
114 |
URL dev = new URL(metacatReplicationURL+"?action=servercontrol&server=dev"+ |
|
115 |
"&subaction=add&replicate=1&datareplicate=1&hub=1"); |
|
116 |
URL epsilon = new URL(metacatReplicationURL+"?action=servercontrol"+ |
|
117 |
"&server=epsilon&subaction=add&replicate=0&datareplicate=1&hub=0"); |
|
118 |
InputStream input = dev.openStream(); |
|
119 |
input.close(); |
|
120 |
input = epsilon.openStream(); |
|
121 |
input.close(); |
|
122 |
|
|
123 |
//create a new server list |
|
124 |
ReplicationServerList list = new ReplicationServerList(); |
|
125 |
|
|
126 |
//Doing test test cases |
|
127 |
suite.addTest(new ReplicationServerListTest("testSize", list)); |
|
128 |
|
|
129 |
suite.addTest(new ReplicationServerListTest("testServerAt0", list)); |
|
130 |
suite.addTest(new ReplicationServerListTest("testServerAt1", list)); |
|
131 |
|
|
132 |
suite.addTest(new ReplicationServerListTest |
|
133 |
("testNonEmptyServerList", list)); |
|
134 |
|
|
135 |
suite.addTest(new ReplicationServerListTest("testServerIsNotInList", list)); |
|
136 |
suite.addTest(new ReplicationServerListTest("testServerIsInList", list)); |
|
137 |
|
|
138 |
suite.addTest(new ReplicationServerListTest |
|
139 |
("testGetLastCheckedDate", list)); |
|
140 |
|
|
141 |
suite.addTest(new ReplicationServerListTest |
|
142 |
("testGetReplicationValueFalse", list)); |
|
143 |
|
|
144 |
suite.addTest(new ReplicationServerListTest |
|
145 |
("testGetReplicationValueTrue", list)); |
|
146 |
suite.addTest(new ReplicationServerListTest |
|
147 |
("testGetDataReplicationValueFalse", list)); |
|
148 |
|
|
149 |
suite.addTest(new ReplicationServerListTest("testGetHubValueTrue", list)); |
|
150 |
suite.addTest(new ReplicationServerListTest("testGetHubValueFalse", list)); |
|
151 |
|
|
152 |
//Delete this two server |
|
153 |
URL deleteDev = new URL(metacatReplicationURL+"?action=servercontrol" + |
|
154 |
"&server=dev&subaction=delete"); |
|
155 |
URL deleteEpsilon = new URL(metacatReplicationURL+"?action=servercontrol" + |
|
156 |
"&server=epsilon&subaction=delete"); |
|
157 |
input = deleteDev.openStream(); |
|
158 |
input.close(); |
|
159 |
input = deleteEpsilon.openStream(); |
|
160 |
input.close(); |
|
161 |
}//try |
|
162 |
catch (Exception e) |
|
163 |
{ |
|
164 |
MetaCatUtil.debugMessage("Error in ReplicationServerListTest.suite: "+ |
|
165 |
e.getMessage(), 10); |
|
166 |
}//catch |
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
return suite; |
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
/** |
|
177 |
* Run an initial test that always passes to check that the test |
|
178 |
* harness is working. |
|
179 |
*/ |
|
180 |
public void initialize() |
|
181 |
{ |
|
182 |
assert(1 == 1); |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
/** |
|
187 |
* Test the a empty server list is empty |
|
188 |
*/ |
|
189 |
public void testEmptyServerList() |
|
190 |
{ |
|
191 |
|
|
192 |
assert(serverList.isEmpty()); |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* Test the a non-empty server list is non-empty |
|
197 |
*/ |
|
198 |
public void testNonEmptyServerList() |
|
199 |
{ |
|
200 |
|
|
201 |
assert(!serverList.isEmpty()); |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* Test the size() method |
|
206 |
*/ |
|
207 |
public void testSize() |
|
208 |
{ |
|
209 |
int size = serverList.size(); |
|
210 |
assert(size ==2); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Test the method serverAt(0) |
|
215 |
*/ |
|
216 |
public void testServerAt0() |
|
217 |
{ |
|
218 |
ReplicationServer server = serverList.serverAt(0); |
|
219 |
String serverName = server.getServerName(); |
|
220 |
assert(serverName.equals("dev")); |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Test the method serverAt(1) |
|
225 |
*/ |
|
226 |
public void testServerAt1() |
|
227 |
{ |
|
228 |
ReplicationServer server = serverList.serverAt(1); |
|
229 |
String serverName = server.getServerName(); |
|
230 |
assert(serverName.equals("epsilon")); |
|
231 |
} |
|
232 |
|
|
233 |
|
|
234 |
/** |
|
235 |
* Test the a given server is not in the server list |
|
236 |
*/ |
|
237 |
public void testServerIsNotInList() |
|
238 |
{ |
|
239 |
assert(!serverList.isGivenServerInList("localhost")); |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Test the a given server is in the server list |
|
244 |
*/ |
|
245 |
public void testServerIsInList() |
|
246 |
{ |
|
247 |
assert(serverList.isGivenServerInList("dev")); |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* Test the method getLastCheckedDate |
|
252 |
*/ |
|
253 |
public void testGetLastCheckedDate() |
|
254 |
{ |
|
255 |
String lastCheckedDate = serverList.getLastCheckedDate("dev"); |
|
256 |
assert(lastCheckedDate.equals("0001-01-01 BC")); |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* Test the method getReplicationValue(resulst is true) |
|
261 |
*/ |
|
262 |
public void testGetReplicationValueTrue() |
|
263 |
{ |
|
264 |
assert(serverList.getReplicationValue("dev")); |
|
265 |
} |
|
266 |
|
|
267 |
/** |
|
268 |
* Test the method getReplicationValue(result is false) |
|
269 |
*/ |
|
270 |
public void testGetReplicationValueFalse() |
|
271 |
{ |
|
272 |
assert(!serverList.getReplicationValue("epsilon")); |
|
273 |
} |
|
274 |
|
|
275 |
/** |
|
276 |
* Test the method getDataReplicationValue(result is true) |
|
277 |
*/ |
|
278 |
public void testGetDataReplicationValueTrue() |
|
279 |
{ |
|
280 |
assert(serverList.getDataReplicationValue("dev")); |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* Test the method getDataReplicationValue(result is false) |
|
285 |
*/ |
|
286 |
public void testGetDataReplicationValueFalse() |
|
287 |
{ |
|
288 |
assert(!serverList.getDataReplicationValue("epsilon")); |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* Test the method getHubValue(result is true) |
|
293 |
*/ |
|
294 |
public void testGetHubValueTrue() |
|
295 |
{ |
|
296 |
assert(serverList.getHubValue("dev")); |
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* Test the method getHubValue(result is false) |
|
301 |
*/ |
|
302 |
public void testGetHubValueFalse() |
|
303 |
{ |
|
304 |
assert(!serverList.getHubValue("epsilon")); |
|
305 |
} |
|
306 |
|
|
307 |
|
|
308 |
}//ReplicationServerListTest |
|
0 | 309 |
lib/replControl.html | ||
---|---|---|
32 | 32 |
</HEAD> |
33 | 33 |
<FRAMESET COLS="*" FRAMEBORDER=0 BORDER=0> |
34 | 34 |
|
35 |
<FRAMESET ROWS="*,200" FRAMEBORDER=0 BORDER=0>
|
|
35 |
<FRAMESET ROWS="*,150" FRAMEBORDER=0 BORDER=0>
|
|
36 | 36 |
|
37 | 37 |
<FRAME SRC="replMain.html" BORDER=0 NAME="top"> |
38 | 38 |
|
lib/metacat.properties | ||
---|---|---|
14 | 14 |
maximumConnectionAge=120000 |
15 | 15 |
maximumConnectionTime=60000 |
16 | 16 |
maximumUsageNumber=100 |
17 |
runDBConnectionRecycleThread=on
|
|
17 |
runDBConnectionRecycleThread=off
|
|
18 | 18 |
cycleTimeOfDBConnection=30000 |
19 |
forcereplicationwaitingtime=@forcereplicationwaitingtime@ |
|
19 | 20 |
config-dir=@config-dir@ |
20 | 21 |
default-style=@default-style@ |
21 | 22 |
xmlcatalogfile=/opt/tomcat/webapps/xmltodb/catalog.txt |
... | ... | |
39 | 40 |
deltaT=60 |
40 | 41 |
replicationpath=@replication-path@ |
41 | 42 |
replicationlog=@replication-log@ |
42 |
replication=@replication@ |
|
43 |
replicationsenddata=@replicationsenddata@ |
|
44 |
replicationacceptdata=@replicationacceptdata@ |
|
45 | 43 |
dtdPath=@config-dir@/dtd/ |
46 | 44 |
dtdURL=@server@@html-path@/dtd/ |
47 | 45 |
datafilepath=@datafilepath@ |
48 | 46 |
certPath=@install-dir@/ |
49 | 47 |
context=@context@ |
50 |
hub=super1 |
|
51 | 48 |
debuglevel=@debuglevel@ |
52 | 49 |
datafileflag=datafile |
lib/replMain.html | ||
---|---|---|
97 | 97 |
<input type="radio" name="subaction" value="delete"> Remove this server<br> |
98 | 98 |
<input type="radio" name="subaction" value="add"> Add this server<br> |
99 | 99 |
<input size="30" name="server" > <br> |
100 |
Replicate To server (1 or 0)?: <input size="2" name="replicate"> <br> |
|
100 |
Replicate xml doc To server (1 or 0)?: <input size="2" name="replicate"> <br> |
|
101 |
Replicate data file To server (1 or 0)?: <input size="2" name="datareplicate"> <br> |
|
102 |
Localhost is a hub to server (1 or 0)?: <input size="2" name="hub"> <br> |
|
101 | 103 |
Download certificate from<br> |
102 | 104 |
<input type="text" size="30" name="certificate"> |
103 | 105 |
<br><br> |
src/xmltables_postgres.sql | ||
---|---|---|
48 | 48 |
serverid INT8 default nextval('xml_replication_id_seq'), |
49 | 49 |
server VARCHAR(512), |
50 | 50 |
last_checked DATE, |
51 |
replicate INT8, |
|
51 |
replicate INT8, |
|
52 |
datareplicate INT8, |
|
53 |
hub INT8, |
|
52 | 54 |
CONSTRAINT xml_replication_pk PRIMARY KEY (serverid) |
53 | 55 |
); |
54 | 56 |
|
55 |
INSERT INTO xml_replication (serverid, server, replicate) VALUES ('1', 'localhost', '0');
|
|
57 |
INSERT INTO xml_replication (server, replicate, datareplicate, hub) VALUES ('localhost', '0', '0', '0');
|
|
56 | 58 |
|
57 | 59 |
/* |
58 | 60 |
* Nodes -- table to store XML Nodes (both elements and attributes) |
src/xmltables.sql | ||
---|---|---|
52 | 52 |
serverid NUMBER(20), |
53 | 53 |
server VARCHAR2(512), |
54 | 54 |
last_checked DATE, |
55 |
replicate NUMBER(1), |
|
55 |
replicate NUMBER(1), |
|
56 |
datareplicate NUMBER(1), |
|
57 |
hub NUMBER(1), |
|
56 | 58 |
CONSTRAINT xml_replication_pk PRIMARY KEY (serverid) |
57 | 59 |
); |
58 | 60 |
|
... | ... | |
66 | 68 |
END; |
67 | 69 |
/ |
68 | 70 |
|
69 |
INSERT INTO xml_replication (serverid, server, replicate)
|
|
70 |
VALUES ('1', 'localhost', '0');
|
|
71 |
INSERT INTO xml_replication (server, replicate, datareplicate, hub)
|
|
72 |
VALUES ('localhost', '0', '0', '0');
|
|
71 | 73 |
|
72 | 74 |
/* |
73 | 75 |
* Nodes -- table to store XML Nodes (both elements and attributes) |
src/edu/ucsb/nceas/metacat/ReplicationServer.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class represent a server in xml_replcation table |
|
4 |
* Copyright: 2000 Regents of the University of California and the |
|
5 |
* National Center for Ecological Analysis and Synthesis |
|
6 |
* Authors: Jing Tao |
|
7 |
* Release: @release@ |
|
8 |
* |
|
9 |
* '$Author$' |
|
10 |
* '$Date$' |
|
11 |
* '$Revision$' |
|
12 |
* |
|
13 |
* This program is free software; you can redistribute it and/or modify |
|
14 |
* it under the terms of the GNU General Public License as published by |
|
15 |
* the Free Software Foundation; either version 2 of the License, or |
|
16 |
* (at your option) any later version. |
|
17 |
* |
|
18 |
* This program is distributed in the hope that it will be useful, |
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 |
* GNU General Public License for more details. |
|
22 |
* |
|
23 |
* You should have received a copy of the GNU General Public License |
|
24 |
* along with this program; if not, write to the Free Software |
|
25 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
26 |
*/ |
|
27 |
|
|
28 |
package edu.ucsb.nceas.metacat; |
|
29 |
|
|
30 |
/** |
|
31 |
* A class express a entry in xml_replication. It include server name, |
|
32 |
* lastChechedDate, replication or not, dataReplication or not, hub or not |
|
33 |
*/ |
|
34 |
|
|
35 |
public class ReplicationServer |
|
36 |
{ |
|
37 |
private String serverName = null; //server name |
|
38 |
private String lastCheckedDate = null; //string of last |
|
39 |
private boolean replication = false; //replciate xml document or not |
|
40 |
private boolean dataReplication = false; //replciate data file or not |
|
41 |
//it is relative to replcation |
|
42 |
//if replication is false, it should |
|
43 |
//be false |
|
44 |
private boolean hub = false; //it is hub or not. Hub means the localhost can |
|
45 |
//replcate documents to the server if the |
|
46 |
//document's home server is not localhost |
|
47 |
/** |
|
48 |
* Consturctor of ReplicationServer |
|
49 |
*/ |
|
50 |
public ReplicationServer() |
|
51 |
{ |
|
52 |
this.serverName = null; |
|
53 |
this.lastCheckedDate = null; |
|
54 |
this.replication = false; |
|
55 |
this.dataReplication = false; |
|
56 |
this.hub = false; |
|
57 |
}//constructor |
|
58 |
|
|
59 |
/** |
|
60 |
* Get server name |
|
61 |
*/ |
|
62 |
public String getServerName() |
|
63 |
{ |
|
64 |
return this.serverName; |
|
65 |
}//getServerName |
|
66 |
|
|
67 |
/** |
|
68 |
* Set a sting as server name |
|
69 |
* @param myServerName, the string will set to object's serverName |
|
70 |
*/ |
|
71 |
public void setServerName(String myServerName) |
|
72 |
{ |
|
73 |
this.serverName = myServerName; |
|
74 |
}//setServerName |
|
75 |
|
|
76 |
/** |
|
77 |
* Get last checked date |
|
78 |
*/ |
|
79 |
public String getLastCheckedDate() |
|
80 |
{ |
|
81 |
return this.lastCheckedDate; |
|
82 |
}//getLastCheckedDate |
|
83 |
|
|
84 |
/** |
|
85 |
* Set a string as last checked date |
|
86 |
* @Param myLastCheckedDate, the string will set to object's lastCheckedDate |
|
87 |
*/ |
|
88 |
public void setLastCheckedDate(String myLastCheckedDate) |
|
89 |
{ |
|
90 |
this.lastCheckedDate = myLastCheckedDate; |
|
91 |
}//setLastCheckedDate |
|
92 |
|
|
93 |
/** |
|
94 |
* Get replication xml or not option |
|
95 |
*/ |
|
96 |
public boolean getReplication() |
|
97 |
{ |
|
98 |
return this.replication; |
|
99 |
}//getReplication |
|
100 |
|
|
101 |
/** |
|
102 |
* Set replication option |
|
103 |
* @param myReplication, the option will set to object's replication |
|
104 |
*/ |
|
105 |
public void setReplication(boolean myReplication) |
|
106 |
{ |
|
107 |
this.replication = myReplication; |
|
108 |
}//setReplication |
|
109 |
|
|
110 |
/** |
|
111 |
* Get datareplication xml or not option |
|
112 |
*/ |
|
113 |
public boolean getDataReplication() |
|
114 |
{ |
|
115 |
return this.dataReplication; |
|
116 |
}//getDataReplication |
|
117 |
|
|
118 |
/** |
|
119 |
* Set data replication option |
|
120 |
* @param myDataReplication, the option will set to object's datareplication |
|
121 |
*/ |
|
122 |
public void setDataReplication(boolean myDataReplication) |
|
123 |
{ |
|
124 |
this.dataReplication = myDataReplication; |
|
125 |
}//setDataReplication |
|
126 |
|
|
127 |
/** |
|
128 |
* Get hub option |
|
129 |
*/ |
|
130 |
public boolean getHub() |
|
131 |
{ |
|
132 |
return this.hub; |
|
133 |
}//getHub |
|
134 |
|
|
135 |
/** |
|
136 |
* Set hub option |
|
137 |
* @param myHub, the option will set to object's hub option |
|
138 |
*/ |
|
139 |
public void setHub(boolean myHub) |
|
140 |
{ |
|
141 |
this.hub = myHub; |
|
142 |
}//setHub |
|
143 |
|
|
144 |
}//class ReplicationServer |
|
145 |
|
|
0 | 146 |
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
88 | 88 |
Hashtable params = new Hashtable(); |
89 | 89 |
Enumeration paramlist = request.getParameterNames(); |
90 | 90 |
|
91 |
//First check if administrate conifgure the replcation feature on |
|
92 |
//This configuration is set in build.xml file |
|
93 |
//If it is not on, reject any request. |
|
94 |
if (!(util.getOption("replication")).equals("on")) |
|
95 |
{ |
|
96 |
(response.getWriter()).println("MetaCat is not set to handle replication"); |
|
97 |
(response.getWriter()).close(); |
|
98 |
return; |
|
99 |
} |
|
91 |
|
|
100 | 92 |
|
101 | 93 |
// NOT NEEDED - doesn't provide enough security because of possible IP spoofing |
102 | 94 |
// REPLACED with running replication comminications over HTTPS |
... | ... | |
121 | 113 |
!action.equals("getall") ) { |
122 | 114 |
|
123 | 115 |
server = ((String[])params.get("server"))[0]; |
124 |
if ( getServerCode(server) == 0 ) { |
|
116 |
if ( getServerCodeForServerName(server) == 0 ) {
|
|
125 | 117 |
System.out.println("Action \"" + action + |
126 | 118 |
"\" rejected for server: " + server); |
127 | 119 |
return; |
... | ... | |
144 | 136 |
} |
145 | 137 |
else if ( action.equals("forcereplicatedatafile") ) |
146 | 138 |
{ |
147 |
|
|
148 |
//OutputStream out=response.getOutputStream(); |
|
149 | 139 |
//read a specific docid from remote host, and store it into local host |
150 | 140 |
handleForceReplicateDataFileRequest(params); |
151 |
//out.close(); |
|
141 |
|
|
152 | 142 |
} |
153 | 143 |
else |
154 | 144 |
{ |
... | ... | |
244 | 234 |
DBConnection dbConn = null; |
245 | 235 |
int serialNumber = -1; |
246 | 236 |
PreparedStatement pstmt = null; |
247 |
|
|
237 |
String replicate =null; |
|
238 |
String server = null; |
|
239 |
String dataReplicate = null; |
|
240 |
String hub = null; |
|
248 | 241 |
try { |
249 | 242 |
//conn = util.openDBConnection(); |
250 | 243 |
dbConn=DBConnectionPool. |
... | ... | |
253 | 246 |
|
254 | 247 |
// add server to server list |
255 | 248 |
if ( subaction.equals("add") ) { |
256 |
String replicate = ((String[])params.get("replicate"))[0]; |
|
257 |
String server = ((String[])params.get("server"))[0]; |
|
249 |
replicate = ((String[])params.get("replicate"))[0]; |
|
250 |
server = ((String[])params.get("server"))[0]; |
|
251 |
//Get data replication value |
|
252 |
dataReplicate = ((String[])params.get("datareplicate"))[0]; |
|
253 |
//Get hub value |
|
254 |
hub = ((String[])params.get("hub"))[0]; |
|
255 |
|
|
258 | 256 |
pstmt = dbConn.prepareStatement("INSERT INTO xml_replication " + |
259 |
"(server, last_checked, replicate) " +
|
|
257 |
"(server, last_checked, replicate, datareplicate, hub) " +
|
|
260 | 258 |
"VALUES ('" + server + "', to_date(" + |
261 | 259 |
"'01/01/00', 'MM/DD/YY'), '" + |
262 |
replicate + "')"); |
|
260 |
replicate +"', '" +dataReplicate+"', '" |
|
261 |
+ hub +"')"); |
|
263 | 262 |
pstmt.execute(); |
264 | 263 |
pstmt.close(); |
265 | 264 |
dbConn.commit(); |
... | ... | |
267 | 266 |
response.setContentType("text/html"); |
268 | 267 |
out.println("<html><body><table border=\"1\">"); |
269 | 268 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td><td>"); |
270 |
out.println("<b>replicate</b></td></tr>"); |
|
269 |
out.println("<b>replicate</b></td>"); |
|
270 |
out.println("<td><b>datareplicate</b></td>"); |
|
271 |
out.println("<td><b>hub</b></td></tr>"); |
|
271 | 272 |
pstmt = dbConn.prepareStatement("SELECT * FROM xml_replication"); |
272 | 273 |
//increase dbconnection usage |
273 | 274 |
dbConn.increaseUsageCount(1); |
... | ... | |
278 | 279 |
while(tablehasrows) { |
279 | 280 |
out.println("<tr><td>" + rs.getString(2) + "</td><td>"); |
280 | 281 |
out.println(rs.getString(3) + "</td><td>"); |
281 |
out.println(rs.getString(4) + "</td></tr>"); |
|
282 |
out.println(rs.getString(4) + "</td><td>"); |
|
283 |
out.println(rs.getString(5) + "</td><td>"); |
|
284 |
out.println(rs.getString(6) + "</td></tr>"); |
|
285 |
|
|
282 | 286 |
tablehasrows = rs.next(); |
283 | 287 |
} |
284 | 288 |
out.println("</table></body></html>"); |
... | ... | |
290 | 294 |
|
291 | 295 |
// delete server from server list |
292 | 296 |
} else if ( subaction.equals("delete") ) { |
293 |
String server = ((String[])params.get("server"))[0];
|
|
297 |
server = ((String[])params.get("server"))[0]; |
|
294 | 298 |
pstmt = dbConn.prepareStatement("DELETE FROM xml_replication " + |
295 | 299 |
"WHERE server LIKE '" + server + "'"); |
296 | 300 |
pstmt.execute(); |
... | ... | |
300 | 304 |
response.setContentType("text/html"); |
301 | 305 |
out.println("<html><body><table border=\"1\">"); |
302 | 306 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td><td>"); |
303 |
out.println("<b>replicate</b></td></tr>"); |
|
307 |
out.println("<b>replicate</b></td>"); |
|
308 |
out.println("<td><b>datareplicate</b></td>"); |
|
309 |
out.println("<td><b>hub</b></td></tr>"); |
|
310 |
|
|
304 | 311 |
pstmt = dbConn.prepareStatement("SELECT * FROM xml_replication"); |
305 | 312 |
//increase dbconnection usage |
306 | 313 |
dbConn.increaseUsageCount(1); |
... | ... | |
311 | 318 |
{ |
312 | 319 |
out.println("<tr><td>" + rs.getString(2) + "</td><td>"); |
313 | 320 |
out.println(rs.getString(3) + "</td><td>"); |
314 |
out.println(rs.getString(4) + "</td></tr>"); |
|
321 |
out.println(rs.getString(4) + "</td><td>"); |
|
322 |
out.println(rs.getString(5) + "</td><td>"); |
|
323 |
out.println(rs.getString(6) + "</td></tr>"); |
|
315 | 324 |
tablehasrows = rs.next(); |
316 | 325 |
} |
317 | 326 |
out.println("</table></body></html>"); |
... | ... | |
321 | 330 |
response.setContentType("text/html"); |
322 | 331 |
out.println("<html><body><table border=\"1\">"); |
323 | 332 |
out.println("<tr><td><b>server</b></td><td><b>last_checked</b></td><td>"); |
324 |
out.println("<b>replicate</b></td></tr>"); |
|
333 |
out.println("<b>replicate</b></td>"); |
|
334 |
out.println("<td><b>datareplicate</b></td>"); |
|
335 |
out.println("<td><b>hub</b></td></tr>"); |
|
325 | 336 |
pstmt = dbConn.prepareStatement("SELECT * FROM xml_replication"); |
326 | 337 |
pstmt.execute(); |
327 | 338 |
ResultSet rs = pstmt.getResultSet(); |
... | ... | |
329 | 340 |
while(tablehasrows) { |
330 | 341 |
out.println("<tr><td>" + rs.getString(2) + "</td><td>"); |
331 | 342 |
out.println(rs.getString(3) + "</td><td>"); |
332 |
out.println(rs.getString(4) + "</td></tr>"); |
|
343 |
out.println(rs.getString(4) + "</td><td>"); |
|
344 |
out.println(rs.getString(5) + "</td><td>"); |
|
345 |
out.println(rs.getString(6) + "</td></tr>"); |
|
333 | 346 |
tablehasrows = rs.next(); |
334 | 347 |
} |
335 | 348 |
out.println("</table></body></html>"); |
349 |
} |
|
350 |
else |
|
351 |
{ |
|
352 |
|
|
353 |
out.println("<error>Unkonwn subaction</error>"); |
|
354 |
|
|
336 | 355 |
} |
337 | 356 |
pstmt.close(); |
338 | 357 |
//conn.close(); |
... | ... | |
445 | 464 |
//serverCode = MetacatReplication.getServerCode(server); |
446 | 465 |
//override = true; //we are now overriding the default action |
447 | 466 |
} |
448 |
MetacatReplication.replLog("force replication request from " + server);
|
|
449 |
util.debugMessage("Force replication docid: "+docid, 20);
|
|
450 |
util.debugMessage("Force replication action: "+dbaction, 20);
|
|
451 |
// sending back read request to server
|
|
452 |
|
|
467 |
MetacatReplication.replLog("force replication request from " + server); |
|
468 |
MetaCatUtil.debugMessage("Force replication request from: "+ server, 34);
|
|
469 |
MetaCatUtil.debugMessage("Force replication docid: "+docid, 34);
|
|
470 |
MetaCatUtil.debugMessage("Force replication action: "+dbaction, 34);
|
|
471 |
// sending back read request to remote server |
|
453 | 472 |
URL u = new URL("https://" + server + "?server=" |
454 | 473 |
+util.getLocalReplicationServerName() |
455 | 474 |
+"&action=read&docid=" + docid); |
... | ... | |
467 | 486 |
XMLReader docinfoParser = ReplicationHandler.initParser(dih); |
468 | 487 |
docinfoParser.parse(new InputSource(new StringReader(docInfoStr))); |
469 | 488 |
Hashtable docinfoHash = dih.getDocInfo(); |
489 |
|
|
490 |
// Get user owner of this docid |
|
470 | 491 |
String user = (String)docinfoHash.get("user_owner"); |
471 |
|
|
492 |
// Get home server of this docid |
|
472 | 493 |
String homeServer=(String)docinfoHash.get("home_server"); |
473 |
util.debugMessage("homeServer: "+homeServer,20);
|
|
474 |
// write the document here |
|
475 |
//Connection conn = util.openDBConnection();
|
|
494 |
MetaCatUtil.debugMessage("homeServer: "+homeServer, 34);
|
|
495 |
|
|
496 |
// Get DBConnection from pool
|
|
476 | 497 |
dbConn=DBConnectionPool. |
477 | 498 |
getDBConnection("MetacatReplication.handleForceReplicateRequest"); |
478 | 499 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
500 |
// write the document to local database |
|
479 | 501 |
DocumentImpl.writeReplication(dbConn, |
480 | 502 |
new StringReader(xmldoc), null, null, dbaction, docid, user, |
481 |
null, homeServer, false); |
|
503 |
null, homeServer, false, server);
|
|
482 | 504 |
|
483 |
|
|
484 |
//conn.close(); |
|
485 |
|
|
486 | 505 |
MetacatReplication.replLog("document " + docid + " added to DB with " + |
487 | 506 |
"action " + dbaction); |
488 |
} catch(Exception e) { |
|
507 |
}//try |
|
508 |
catch(Exception e) |
|
509 |
{ |
|
489 | 510 |
|
490 | 511 |
System.out.println("ERROR in MetacatReplication.handleForceReplicate" + |
491 | 512 |
"Request(): " + e.getMessage()); |
492 | 513 |
e.printStackTrace(); |
493 |
} |
|
514 |
}//catch
|
|
494 | 515 |
finally |
495 | 516 |
{ |
517 |
// Return the checked out DBConnection |
|
496 | 518 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
497 | 519 |
}//finally |
498 | 520 |
} |
... | ... | |
504 | 526 |
*/ |
505 | 527 |
private void handleForceReplicateDataFileRequest(Hashtable params) |
506 | 528 |
{ |
507 |
//check if the metacat was configured to handle replication |
|
508 |
if (!(util.getOption("replicationacceptdata")).equals("on")) |
|
509 |
{ |
|
510 |
return; |
|
511 |
} |
|
529 |
|
|
512 | 530 |
//make sure there is some parameters |
513 | 531 |
if(params.isEmpty()) |
514 | 532 |
{ |
515 | 533 |
return; |
516 | 534 |
} |
517 |
String server = ((String[])params.get("server"))[0]; // the server that |
|
518 |
//docid should include rev number |
|
519 |
String docid = ((String[])params.get("docid"))[0]; // sent the document |
|
520 |
if (docid==null) |
|
535 |
// Get remote server |
|
536 |
String server = ((String[])params.get("server"))[0]; |
|
537 |
// the docid should include rev number |
|
538 |
String docid = ((String[])params.get("docid"))[0]; |
|
539 |
// Make sure there is a docid and server |
|
540 |
if (docid==null || server==null || server.equals("")) |
|
521 | 541 |
{ |
522 |
util.debugMessage("Didn't specify docid for replication", 20); |
|
542 |
MetaCatUtil.debugMessage("Didn't specify docid or server for replication" |
|
543 |
, 20); |
|
523 | 544 |
return; |
524 | 545 |
} |
525 |
//docid was switch to two parts |
|
546 |
|
|
547 |
// Overide or not |
|
526 | 548 |
boolean override = false; |
527 |
int serverCode = 1;
|
|
549 |
// dbaction - update or insert
|
|
528 | 550 |
String dbaction=null; |
529 |
//Connection conn=null; |
|
530 |
|
|
551 |
|
|
531 | 552 |
try |
532 | 553 |
{ |
533 |
//docid was switch to two parts |
|
554 |
//docid was switch to two parts uinque code and rev
|
|
534 | 555 |
String uniqueCode=MetaCatUtil.getDocIdFromString(docid); |
535 | 556 |
int rev=MetaCatUtil.getVersionFromString(docid); |
536 | 557 |
if(params.containsKey("dbaction")) |
... | ... | |
541 | 562 |
{ |
542 | 563 |
dbaction = "update"; |
543 | 564 |
} |
544 |
//serverCode = MetacatReplication.getServerCode(server); |
|
565 |
|
|
545 | 566 |
MetacatReplication.replLog("force replication request from " + server); |
546 |
|
|
567 |
MetaCatUtil.debugMessage("Force replication request from: "+ server, 34); |
|
568 |
MetaCatUtil.debugMessage("Force replication docid: "+docid, 34); |
|
569 |
MetaCatUtil.debugMessage("Force replication action: "+dbaction, 34); |
|
547 | 570 |
// get the document info from server |
548 | 571 |
URL docinfourl = new URL("https://" + server + |
549 | 572 |
"?server="+util.getLocalReplicationServerName() |
... | ... | |
563 | 586 |
String docType = (String)docinfoHash.get("doctype"); |
564 | 587 |
|
565 | 588 |
String docHomeServer= (String)docinfoHash.get("home_server"); |
566 |
MetaCatUtil.debugMessage("docHomeServer of data file: "+docHomeServer);
|
|
589 |
MetaCatUtil.debugMessage("docHomeServer of datafile: "+docHomeServer, 34);
|
|
567 | 590 |
|
568 | 591 |
|
569 | 592 |
|
... | ... | |
586 | 609 |
String datafilePath = util.getOption("datafilepath"); |
587 | 610 |
//register data file into xml_documents table and wite data file |
588 | 611 |
//into file system |
589 |
DocumentImpl.writeDataFile(url.openStream(), datafilePath, docName,
|
|
590 |
docType, docid, user,docHomeServer);
|
|
612 |
DocumentImpl.writeDataFileInReplication(url.openStream(), datafilePath,
|
|
613 |
docName, docType, docid, user,docHomeServer,server);
|
|
591 | 614 |
} |
592 | 615 |
|
593 | 616 |
|
... | ... | |
598 | 621 |
{ |
599 | 622 |
|
600 | 623 |
//util.returnConnection(conn); |
601 |
util.debugMessage("ERROR in MetacatReplication.handleForceReplicate" + |
|
624 |
util.debugMessage |
|
625 |
("ERROR in MetacatReplication.handleForceDataFileReplicate" + |
|
602 | 626 |
"Request(): " + e.getMessage(), 30); |
603 | 627 |
} |
604 | 628 |
} |
... | ... | |
612 | 636 |
private void handleGetLockRequest(PrintWriter out, Hashtable params, |
613 | 637 |
HttpServletResponse response) |
614 | 638 |
{ |
615 |
//Connection conn = null; |
|
639 |
|
|
616 | 640 |
try |
617 | 641 |
{ |
618 |
/*conn = MetacatReplication.getDBConnection("MetacatReplication." + |
|
619 |
"handleGetLockRequest");*/ |
|
642 |
|
|
620 | 643 |
String docid = ((String[])params.get("docid"))[0]; |
621 | 644 |
String remoteRev = ((String[])params.get("updaterev"))[0]; |
622 | 645 |
DocumentImpl requestDoc = new DocumentImpl(docid); |
... | ... | |
671 | 694 |
{ |
672 | 695 |
String docid = ((String[])(params.get("docid")))[0]; |
673 | 696 |
StringBuffer sb = new StringBuffer(); |
674 |
//Connection conn = null; |
|
697 |
|
|
675 | 698 |
try |
676 | 699 |
{ |
677 |
/*conn = MetacatReplication.getDBConnection("MetacatReplication." + |
|
678 |
"handleGetDocumentInfoRequest");*/ |
|
700 |
|
|
679 | 701 |
DocumentImpl doc = new DocumentImpl(docid); |
680 | 702 |
sb.append("<documentinfo><docid>").append(docid); |
681 | 703 |
sb.append("</docid><docname>").append(doc.getDocname()); |
... | ... | |
692 | 714 |
sb.append("</rev></documentinfo>"); |
693 | 715 |
response.setContentType("text/xml"); |
694 | 716 |
out.println(sb.toString()); |
695 |
//conn.close(); |
|
717 |
|
|
696 | 718 |
} |
697 | 719 |
catch (Exception e) |
698 | 720 |
{ |
... | ... | |
710 | 732 |
Hashtable params, HttpServletResponse response) |
711 | 733 |
|
712 | 734 |
{ |
713 |
//check the metacat was configured to handle data replication |
|
714 |
if (!(util.getOption("replicationsenddata")).equals("on")) |
|
715 |
{ |
|
716 |
return; |
|
717 |
} |
|
718 |
|
|
735 |
// File path for data file |
|
719 | 736 |
String filepath = util.getOption("datafilepath"); |
737 |
// Request docid |
|
720 | 738 |
String docId = ((String[])(params.get("docid")))[0]; |
721 | 739 |
//check if the doicd is null |
722 | 740 |
if (docId==null) |
... | ... | |
752 | 770 |
{ |
753 | 771 |
filepath += "/"; |
754 | 772 |
} |
755 |
String filename = filepath + docId; //MIME type |
|
773 |
// Get file aboslute file name |
|
774 |
String filename = filepath + docId; |
|
756 | 775 |
|
757 |
String contentType = null;//getServletContext().getMimeType(filename); |
|
776 |
//MIME type |
|
777 |
String contentType = null; |
|
778 |
if (filename.endsWith(".xml")) |
|
779 |
{ |
|
780 |
contentType="text/xml"; |
|
781 |
} |
|
782 |
else if (filename.endsWith(".css")) |
|
783 |
{ |
|
784 |
contentType="text/css"; |
|
785 |
} |
|
786 |
else if (filename.endsWith(".dtd")) |
|
787 |
{ |
|
788 |
contentType="text/plain"; |
|
789 |
} |
|
790 |
else if (filename.endsWith(".xsd")) |
|
791 |
{ |
|
792 |
contentType="text/xml"; |
|
793 |
} |
|
794 |
else if (filename.endsWith("/")) |
|
795 |
{ |
|
796 |
contentType="text/html"; |
|
797 |
} |
|
798 |
else |
|
799 |
{ |
|
800 |
File f = new File(filename); |
|
801 |
if ( f.isDirectory() ) |
|
802 |
{ |
|
803 |
contentType="text/html"; |
|
804 |
} |
|
805 |
else |
|
806 |
{ |
|
807 |
contentType="application/octet-stream"; |
|
808 |
} |
|
809 |
} |
|
758 | 810 |
|
759 |
if (contentType == null) |
|
760 |
{ |
|
761 |
if (filename.endsWith(".xml")) |
|
762 |
{ |
|
763 |
contentType="text/xml"; |
|
764 |
} |
|
765 |
else if (filename.endsWith(".css")) |
|
766 |
{ |
|
767 |
contentType="text/css"; |
|
768 |
} |
|
769 |
else if (filename.endsWith(".dtd")) |
|
770 |
{ |
|
771 |
contentType="text/plain"; |
|
772 |
} |
|
773 |
else if (filename.endsWith(".xsd")) |
|
774 |
{ |
|
775 |
contentType="text/xml"; |
|
776 |
} |
|
777 |
else if (filename.endsWith("/")) |
|
778 |
{ |
|
779 |
contentType="text/html"; |
|
780 |
} |
|
781 |
else |
|
782 |
{ |
|
783 |
File f = new File(filename); |
|
784 |
if ( f.isDirectory() ) |
|
785 |
{ |
|
786 |
contentType="text/html"; |
|
787 |
} |
|
788 |
else |
|
789 |
{ |
|
790 |
contentType="application/octet-stream"; |
|
791 |
} |
|
792 |
} |
|
793 |
} |
|
794 |
|
|
811 |
// Set the mime type |
|
795 | 812 |
response.setContentType(contentType); |
796 |
// if we decide to use "application/octet-stream" for all data returns |
|
797 |
// response.setContentType("application/octet-stream");
|
|
813 |
|
|
814 |
// Get the content of the file
|
|
798 | 815 |
FileInputStream fin = null; |
799 | 816 |
try |
800 | 817 |
{ |
801 |
|
|
818 |
// FileInputStream to metacat |
|
802 | 819 |
fin = new FileInputStream(filename); |
803 |
|
|
804 |
byte[] buf = new byte[4 * 1024]; // 4K buffer |
|
820 |
// 4K buffer |
|
821 |
byte[] buf = new byte[4 * 1024]; |
|
822 |
// Read data from file input stream to byte array |
|
805 | 823 |
int b = fin.read(buf); |
824 |
// Write to outStream from byte array |
|
806 | 825 |
while (b != -1) |
807 | 826 |
{ |
808 |
|
|
809 | 827 |
outPut.write(buf, 0, b); |
810 | 828 |
b = fin.read(buf); |
811 | 829 |
} |
812 |
|
|
830 |
// close file input stream |
|
813 | 831 |
fin.close(); |
814 | 832 |
|
815 |
}
|
|
833 |
}//try
|
|
816 | 834 |
catch(Exception e) |
817 | 835 |
{ |
818 | 836 |
System.out.println("error getting data file from MetacatReplication." + |
819 | 837 |
"handlGetDataFileRequest " + e.getMessage()); |
820 | 838 |
e.printStackTrace(System.out); |
821 |
} |
|
839 |
}//catch
|
|
822 | 840 |
|
823 | 841 |
} |
824 | 842 |
|
... | ... | |
829 | 847 |
private void handleGetDocumentRequest(PrintWriter out, Hashtable params, |
830 | 848 |
HttpServletResponse response) |
831 | 849 |
{ |
832 |
//Connection dbConn = null; |
|
850 |
|
|
833 | 851 |
try |
834 | 852 |
{ |
835 | 853 |
//try to open a https stream to test if the request server's public key |
... | ... | |
844 | 862 |
{ |
845 | 863 |
response.setContentType("text/xml"); |
846 | 864 |
out.println("<error>Couldn't pass the trust test</error>"); |
865 |
out.close(); |
|
847 | 866 |
return; |
848 | 867 |
} |
849 | 868 |
|
850 | 869 |
String docid = ((String[])(params.get("docid")))[0]; |
851 |
/*conn = MetacatReplication.getDBConnection("MetacatReplication." + |
|
852 |
"handleGetDocumentRequest");*/ |
|
870 |
|
|
853 | 871 |
DocumentImpl di = new DocumentImpl(docid); |
854 | 872 |
response.setContentType("text/xml"); |
855 | 873 |
out.print(di.toString()); |
856 |
//conn.close(); |
|
874 |
|
|
857 | 875 |
MetacatReplication.replLog("document " + docid + " sent"); |
858 | 876 |
|
859 | 877 |
} |
... | ... | |
863 | 881 |
+"handlGetDocumentRequest " + e.getMessage(), 30); |
864 | 882 |
//e.printStackTrace(System.out); |
865 | 883 |
response.setContentType("text/xml"); |
866 |
out.println("<error>e.getMessage()</error>");
|
|
884 |
out.println("<error>"+e.getMessage()+"</error>");
|
|
867 | 885 |
} |
868 | 886 |
|
869 | 887 |
} |
... | ... | |
886 | 904 |
private void handleUpdateRequest(PrintWriter out, Hashtable params, |
887 | 905 |
HttpServletResponse response) |
888 | 906 |
{ |
907 |
// Checked out DBConnection |
|
889 | 908 |
DBConnection dbConn = null; |
909 |
// DBConenction serial number when checked it out |
|
890 | 910 |
int serialNumber = -1; |
891 | 911 |
PreparedStatement pstmt = null; |
912 |
// Server list to store server info of xml_replication table |
|
913 |
ReplicationServerList serverList = null; |
|
914 |
|
|
892 | 915 |
try |
893 | 916 |
{ |
917 |
// Check out a DBConnection from pool |
|
918 |
dbConn=DBConnectionPool. |
|
919 |
getDBConnection("MetacatReplication.handleUpdateRequest"); |
|
920 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
921 |
// Create a server list from xml_replication table |
|
922 |
serverList = new ReplicationServerList(); |
|
923 |
|
|
924 |
// Get remote server name from param |
|
925 |
String server = ((String[])params.get("server"))[0]; |
|
926 |
// If no servr name in param, return a error |
|
927 |
if ( server == null || server.equals("")) |
|
928 |
{ |
|
929 |
response.setContentType("text/xml"); |
|
930 |
out.println("<error>Request didn't specify server name</error>"); |
|
931 |
out.close(); |
|
932 |
return; |
|
933 |
}//if |
|
934 |
|
|
894 | 935 |
//try to open a https stream to test if the request server's public key |
895 | 936 |
//in the key store, this is security issue |
896 |
String server = ((String[])params.get("server"))[0]; |
|
897 | 937 |
URL u = new URL("https://" + server + "?server=" |
898 | 938 |
+util.getLocalReplicationServerName() |
899 | 939 |
+"&action=test"); |
... | ... | |
903 | 943 |
{ |
904 | 944 |
response.setContentType("text/xml"); |
905 | 945 |
out.println("<error>Couldn't pass the trust test</error>"); |
946 |
out.close(); |
|
906 | 947 |
return; |
907 | 948 |
} |
908 | 949 |
|
950 |
|
|
951 |
// Check if local host configure to replicate xml documents to remote |
|
952 |
// server. If not send back a error message |
|
953 |
if (!serverList.getReplicationValue(server)) |
|
954 |
{ |
|
955 |
response.setContentType("text/xml"); |
|
956 |
out.println |
|
957 |
("<error>Configuration not allow to replicate document to you</error>"); |
|
958 |
out.close(); |
|
959 |
return; |
|
960 |
}//if |
|
961 |
|
|
962 |
// Store the sql command |
|
909 | 963 |
StringBuffer docsql = new StringBuffer(); |
964 |
// Stroe the docid list |
|
910 | 965 |
StringBuffer doclist = new StringBuffer(); |
966 |
// Store the deleted docid list |
|
967 |
StringBuffer delsql = new StringBuffer(); |
|
968 |
// Store the data set file |
|
911 | 969 |
Vector packageFiles = new Vector(); |
912 | 970 |
|
913 |
//get all docs that reside on this server
|
|
971 |
// Append local server's name and replication servlet to doclist
|
|
914 | 972 |
doclist.append("<?xml version=\"1.0\"?><replication>"); |
915 | 973 |
doclist.append("<server>").append(util.getOption("server")); |
916 | 974 |
doclist.append(util.getOption("replicationpath")); |
917 | 975 |
doclist.append("</server><updates>"); |
918 | 976 |
|
977 |
// Get correct docid that reside on this server according the requesting |
|
978 |
// server's replicate and data replicate value in xml_replication table |
|
919 | 979 |
docsql.append("select docid, rev, doctype from xml_documents "); |
920 |
if (!(util.getOption("hub")).equals("super")) |
|
980 |
// If the localhost is not a hub to the remote server, only replicate |
|
981 |
// the docid' which home server is local host (server_location =1) |
|
982 |
if (!serverList.getHubValue(server)) |
|
921 | 983 |
{ |
922 | 984 |
docsql.append("where server_location = 1"); |
923 | 985 |
} |
986 |
MetaCatUtil.debugMessage("Doc sql: "+docsql.toString(), 30); |
|
924 | 987 |
|
925 |
//get any deleted documents |
|
926 |
StringBuffer delsql = new StringBuffer(); |
|
988 |
// Get any deleted documents |
|
927 | 989 |
delsql.append("select distinct docid from "); |
928 | 990 |
delsql.append("xml_revisions where docid not in (select docid from "); |
929 | 991 |
delsql.append("xml_documents) "); |
930 |
if (!(util.getOption("hub")).equals("super")) |
|
992 |
// If the localhost is not a hub to the remote server, only replicate |
|
993 |
// the docid' which home server is local host (server_location =1) |
|
994 |
if (!serverList.getHubValue(server)) |
|
931 | 995 |
{ |
932 | 996 |
delsql.append("and server_location = 1"); |
933 | 997 |
} |
934 |
|
|
935 |
/*conn = MetacatReplication.getDBConnection("MetacatReplication." + |
|
936 |
"handleUpdateRequest");*/ |
|
937 |
dbConn=DBConnectionPool. |
|
938 |
getDBConnection("MetacatReplication.handleUpdateRequest"); |
|
939 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
998 |
MetaCatUtil.debugMessage("Deleted sql: "+delsql.toString(), 30); |
|
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
// Get docid list of local host |
|
940 | 1003 |
pstmt = dbConn.prepareStatement(docsql.toString()); |
941 | 1004 |
pstmt.execute(); |
942 | 1005 |
ResultSet rs = pstmt.getResultSet(); |
943 | 1006 |
boolean tablehasrows = rs.next(); |
944 | 1007 |
//If metacat configed to replicate data file |
945 |
if ((util.getOption("replicationsenddata")).equals("on")) |
|
1008 |
//if ((util.getOption("replicationsenddata")).equals("on")) |
|
1009 |
if (serverList.getDataReplicationValue(server)) |
|
946 | 1010 |
{ |
947 | 1011 |
while(tablehasrows) |
948 | 1012 |
{ |
949 | 1013 |
String recordDoctype = rs.getString(3); |
950 | 1014 |
Vector packagedoctypes = MetaCatUtil.getOptionList( |
951 | 1015 |
MetaCatUtil.getOption("packagedoctype")); |
1016 |
//if this is a package file, put it at the end |
|
1017 |
//because if a package file is read before all of the files it |
|
1018 |
//refers to are loaded then there is an error |
|
952 | 1019 |
if(!packagedoctypes.contains(recordDoctype)) |
953 |
{ //if this is a package file, put it at the end |
|
954 |
//because if a package file is read before all of the files it |
|
955 |
//refers to are loaded then there is an error |
|
1020 |
{ |
|
1021 |
//If this is not data file |
|
956 | 1022 |
if (!recordDoctype.equals("BIN")) |
957 | 1023 |
{ |
958 | 1024 |
//for non-data file document |
... | ... | |
961 | 1027 |
doclist.append("</docid><rev>").append(rs.getInt(2)); |
962 | 1028 |
doclist.append("</rev>"); |
963 | 1029 |
doclist.append("</updatedDocument>"); |
964 |
} |
|
1030 |
}//if
|
|
965 | 1031 |
else |
966 | 1032 |
{ |
967 | 1033 |
//for data file document, in datafile attributes |
... | ... | |
974 | 1040 |
doclist.append(MetaCatUtil.getOption("datafileflag")); |
975 | 1041 |
doclist.append("</datafile>"); |
976 | 1042 |
doclist.append("</updatedDocument>"); |
977 |
} |
|
978 |
} |
|
1043 |
}//else
|
|
1044 |
}//if packagedoctpes
|
|
979 | 1045 |
else |
980 | 1046 |
{ //the package files are saved to be put into the xml later. |
981 | 1047 |
Vector v = new Vector(); |
982 | 1048 |
v.add(new String(rs.getString(1))); |
983 | 1049 |
v.add(new Integer(rs.getInt(2))); |
984 | 1050 |
packageFiles.add(new Vector(v)); |
985 |
} |
|
1051 |
}//esle
|
|
986 | 1052 |
tablehasrows = rs.next(); |
987 | 1053 |
}//while |
988 | 1054 |
}//if |
... | ... | |
1058 | 1124 |
"handleupdaterequest: " + e.getMessage(), 30); |
1059 | 1125 |
//e.printStackTrace(System.out); |
1060 | 1126 |
response.setContentType("text/xml"); |
1061 |
out.println("<error>e.getMessage()</error>");
|
|
1127 |
out.println("<error>"+e.getMessage()+"</error>");
|
|
1062 | 1128 |
} |
1063 | 1129 |
finally |
1064 | 1130 |
{ |
... | ... | |
1076 | 1142 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
1077 | 1143 |
}//finally |
1078 | 1144 |
}//finally |
1079 |
|
|
1080 |
|
|
1081 |
|
|
1082 |
|
|
1083 |
} |
|
1145 |
|
|
1146 |
}//handlUpdateRequest |
|
1084 | 1147 |
|
1085 | 1148 |
/** |
1086 | 1149 |
* Returns the xml_catalog table encoded in xml |
... | ... | |
1150 | 1213 |
System.out.println("error in MetacatReplication.handleGetCatalogRequest:"+ |
1151 | 1214 |
e.getMessage()); |
1152 | 1215 |
e.printStackTrace(System.out); |
1216 |
if(printFlag) |
|
1217 |
{ |
|
1218 |
out.println("<error>"+e.getMessage()+"</error>"); |
|
1219 |
} |
|
1153 | 1220 |
} |
1154 | 1221 |
finally |
1155 | 1222 |
{ |
... | ... | |
1222 | 1289 |
* @return the servername or null if the specified serverCode does not |
1223 | 1290 |
* exist. |
1224 | 1291 |
*/ |
1225 |
public static String getServer(int serverCode) |
|
1292 |
public static String getServerNameForServerCode(int serverCode)
|
|
1226 | 1293 |
{ |
1227 | 1294 |
//System.out.println("serverid: " + serverCode); |
1228 | 1295 |
DBConnection dbConn = null; |
... | ... | |
1283 | 1350 |
* @return integer > 0 representing the code of the server, 0 if the server |
1284 | 1351 |
* does not exist. |
1285 | 1352 |
*/ |
1286 |
public static int getServerCode(String server) throws Exception |
|
1353 |
public static int getServerCodeForServerName(String server) throws Exception
|
|
1287 | 1354 |
{ |
1288 | 1355 |
DBConnection dbConn = null; |
1289 | 1356 |
int serialNumber = -1; |
... | ... | |
1333 | 1400 |
} |
1334 | 1401 |
|
1335 | 1402 |
/** |
1403 |
* Method to get a host server information for given docid |
|
1404 |
* @param conn a connection to the database |
|
1405 |
*/ |
|
1406 |
public static Hashtable getHomeServerInfoForDocId(String docId) |
|
1407 |
{ |
|
1408 |
Hashtable sl = new Hashtable(); |
|
1409 |
DBConnection dbConn = null; |
|
1410 |
int serialNumber = -1; |
|
1411 |
//MetaCatUtil ut=new MetaCatUtil(); |
|
1412 |
docId=MetaCatUtil.getDocIdFromString(docId); |
|
1413 |
PreparedStatement pstmt=null; |
|
1414 |
int serverLocation; |
|
1415 |
try |
|
1416 |
{ |
|
1417 |
//get conection |
|
1418 |
dbConn=DBConnectionPool. |
|
1419 |
getDBConnection("ReplicationHandler.getHomeServer"); |
|
1420 |
serialNumber=dbConn.getCheckOutSerialNumber(); |
|
1421 |
//get a server location from xml_document table |
|
1422 |
pstmt=dbConn.prepareStatement("select server_location from xml_documents " |
|
1423 |
+"where docid = ?"); |
|
1424 |
pstmt.setString(1, docId); |
|
1425 |
pstmt.execute(); |
|
1426 |
ResultSet serverName = pstmt.getResultSet(); |
|
1427 |
//get a server location |
|
1428 |
if(serverName.next()) |
|
1429 |
{ |
|
1430 |
serverLocation=serverName.getInt(1); |
|
1431 |
pstmt.close(); |
|
1432 |
} |
|
1433 |
else |
|
1434 |
{ |
|
1435 |
pstmt.close(); |
|
1436 |
//ut.returnConnection(conn); |
|
1437 |
return null; |
|
1438 |
} |
|
1439 |
pstmt=dbConn.prepareStatement("select server, last_checked, replicate " + |
|
1440 |
"from xml_replication where serverid = ?"); |
|
1441 |
//increase usage count |
|
1442 |
dbConn.increaseUsageCount(1); |
|
1443 |
pstmt.setInt(1, serverLocation); |
|
1444 |
pstmt.execute(); |
|
1445 |
ResultSet rs = pstmt.getResultSet(); |
|
1446 |
boolean tableHasRows = rs.next(); |
|
1447 |
if (tableHasRows) |
|
1448 |
{ |
|
1449 |
|
|
1450 |
String server = rs.getString(1); |
|
1451 |
String last_checked = rs.getString(2); |
|
1452 |
if(!server.equals("localhost")) |
|
1453 |
{ |
|
1454 |
sl.put(server, last_checked); |
|
1455 |
} |
|
1456 |
|
|
1457 |
} |
|
1458 |
else |
|
1459 |
{ |
|
1460 |
pstmt.close(); |
|
1461 |
//ut.returnConnection(conn); |
|
1462 |
return null; |
|
1463 |
} |
|
1464 |
pstmt.close(); |
|
1465 |
} |
|
1466 |
catch(Exception e) |
|
1467 |
{ |
|
1468 |
System.out.println("error in replicationHandler.getHomeServer(): " + |
|
1469 |
e.getMessage()); |
|
1470 |
} |
|
1471 |
finally |
|
1472 |
{ |
|
1473 |
try |
|
1474 |
{ |
|
1475 |
pstmt.close(); |
|
1476 |
//ut.returnConnection(conn); |
|
1477 |
} |
|
1478 |
catch (Exception ee) |
|
1479 |
{ |
|
1480 |
MetaCatUtil.debugMessage("Eror irn rplicationHandler.getHomeServer() "+ |
|
1481 |
"to close pstmt: "+ee.getMessage(), 30); |
|
1482 |
} |
|
1483 |
finally |
|
1484 |
{ |
|
1485 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
1486 |
} |
|
1487 |
|
|
1488 |
}//finally |
|
1489 |
return sl; |
|
1490 |
} |
|
1491 |
|
|
1492 |
/** |
|
1493 |
* Returns a home server location given a accnum |
|
1494 |
* @param accNum , given accNum for a document |
|
1495 |
* |
|
1496 |
*/ |
|
1497 |
public static int getHomeServerCodeForDocId(String accNum) throws Exception |
|
1498 |
{ |
|
1499 |
DBConnection dbConn = null; |
|
1500 |
int serialNumber = -1; |
|
1501 |
PreparedStatement pstmt = null; |
|
1502 |
int serverCode = 1; |
|
1503 |
//MetaCatUtil ut = new MetaCatUtil(); |
|
1504 |
String docId=MetaCatUtil.getDocIdFromString(accNum); |
|
1505 |
|
|
1506 |
try |
|
1507 |
{ |
Also available in: Unified diff
Merge cvs branch replication to cvs head.