Project

General

Profile

« Previous | Next » 

Revision 6672

replication control panel now fully implemented as an admin configuration screen
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5528

View differences:

lib/admin/replication-configuration-include.jsp
1
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0//EN">
2
<!--
3
  *  '$RCSfile$'
4
  *      Authors: Chad Berkley
5
  *    Copyright: 2000 Regents of the University of California and the
6
  *               National Center for Ecological Analysis and Synthesis
7
  *  For Details: http://www.nceas.ucsb.edu/
8
  *
9
  *   '$Author$'
10
  *     '$Date$'
11
  * '$Revision$'
12
  * 
13
  * This is an HTML document for loading an xml document into Oracle
14
  *
15
  * This program is free software; you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
17
  * the Free Software Foundation; either version 2 of the License, or
18
  * (at your option) any later version.
19
  *
20
  * This program is distributed in the hope that it will be useful,
21
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
  * GNU General Public License for more details.
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with this program; if not, write to the Free Software
27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
-->
29
<html>
30
<head>
31

  
32
<title>Replication Configuration</title>
33
<link rel="stylesheet" type="text/css"
34
	href="<%=request.getContextPath()%>/admin/admin.css"></link>
35
<script language="JavaScript" type="text/JavaScript"
36
	src="<%=request.getContextPath()%>/admin/admin.js"></script>
37

  
38
</head>
39
<body>
40
<%@ include file="./header-section.jsp"%>
41

  
42
<img src="<%=request.getContextPath()%>/metacat-logo.png"
43
	width="100px" align="right" />
44
<h2>Replication Configuration</h2>
45

  
46
<p>Manage Metacat Replication</p>
47

  
48
<h3>Timed Replication</h3>
49
<hr class="config-line">
50

  
51
<form action="<%=request.getContextPath()%>/admin" method="POST" target="bottom">
52

  
53
	<div class="form-row">
54
		<img class="question-mark" src="style/images/question-mark.gif" 
55
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
56
		<div class="textinput-label">
57
			<label for="rate" title="Rate">Delta T (milliseconds)</label>
58
		</div>
59
		<input class="textinput" 
60
			id="rate" 
61
			name="rate" 	             		    	    	           		    	             			
62
			value="172800000"/> 
63
	</div>
64
	<div class="form-row">
65
		<img class="question-mark" src="style/images/question-mark.gif" 
66
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
67
		<div class="textinput-label">
68
			<label for="firsttime" title="First Time (The format should be 10:00 AM)">First Time</label>
69
		</div>
70
		<input class="textinput" 
71
			id="firsttime" 
72
			name="firsttime" 	             		    	    	           		    	             			
73
			value="10:00 PM"/> 
74
	</div>
75
	<div class="form-row">
76
		<img class="question-mark" src="style/images/question-mark.gif" 
77
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
78
		<div class="textinput-label">
79
			<label for="action" title="Action">Timer</label>
80
		</div>
81
		<input 
82
			type= radio 
83
			class="textinput" 
84
			id="action" 
85
			name="action" 	             		    	    	           		    	             			
86
			value="start"/>Start
87
		<input 
88
			type= radio 
89
			class="textinput" 
90
			id="action" 
91
			name="action" 	             		    	    	           		    	             			
92
			value="stop"/>Stop
93
	</div>
94

  
95
	<input type="hidden" name="configureType" value="replication">
96
	<input type="submit" value="Submit" target="bottom">
97
	
98
</form>
99

  
100
<h3>Replicate Now</h3>
101
<hr class="config-line">
102

  
103
<table border="0" cellpadding="4" cellspacing="0" width="100%" class="tablepanel">
104
	<tr>
105
		<td>
106
		<form action="<%=request.getContextPath()%>/admin" method="POST" target="bottom">
107
			<input type="hidden" name="action" value="getall"> 
108
			<input type="hidden" name="configureType" value="replication">
109
			<input type="submit" value="Get All" target="bottom">
110
			bring all updated documents from remote hosts to this server
111
		</form>
112
		</td>
113
	</tr>
114
</table>
115

  
116
<h3>Servers</h3>
117
<hr class="config-line">
118

  
119
<form action="<%=request.getContextPath()%>/admin" method="POST" target="bottom">
120
	<div class="form-row">
121
		<img class="question-mark" src="style/images/question-mark.gif" 
122
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
123
		<div class="textinput-label">
124
			<label for="subaction" title="Action">&nbsp;</label>
125
		</div>
126
		<input 
127
			type= radio 
128
			class="textinput" 
129
			id="subaction" 
130
			name="subaction" 	             		    	    	           		    	             			
131
			value="add"/>Add
132
		<input 
133
			type= radio 
134
			class="textinput" 
135
			id="subaction" 
136
			name="subaction" 	             		    	    	           		    	             			
137
			value="delete"/>Remove
138
	</div>
139
	<div class="form-row">
140
		<img class="question-mark" src="style/images/question-mark.gif" 
141
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
142
		<div class="textinput-label">
143
			<label for="server" title="Server">Server</label>
144
		</div>
145
		<input class="textinput" 
146
			id="server" 
147
			name="server" 	             		    	    	           		    	             			
148
			value=""/> 
149
	</div>
150
	<div class="form-row">
151
		<img class="question-mark" src="style/images/question-mark.gif" 
152
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
153
		<div class="textinput-label">
154
			<label for="replicate" title="Replicate">Replicate metadata?</label>
155
		</div>
156
		<input 
157
			type= radio 
158
			class="textinput" 
159
			id="replicate" 
160
			name="replicate" 	             		    	    	           		    	             			
161
			value="1"/>Yes
162
		<input 
163
			type= radio 
164
			class="textinput" 
165
			id="replicate" 
166
			name="replicate" 	             		    	    	           		    	             			
167
			value="0"/>No
168
	</div>
169
	<div class="form-row">
170
		<img class="question-mark" src="style/images/question-mark.gif" 
171
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
172
		<div class="textinput-label">
173
			<label for="datareplicate" title="Replicate data">Replicate data?</label>
174
		</div>
175
		<input 
176
			type= radio 
177
			class="textinput" 
178
			id="datareplicate" 
179
			name="datareplicate" 	             		    	    	           		    	             			
180
			value="1"/>Yes
181
		<input 
182
			type= radio 
183
			class="textinput" 
184
			id="datareplicate" 
185
			name="datareplicate" 	             		    	    	           		    	             			
186
			value="0"/>No 
187
	</div>
188
	<div class="form-row">
189
		<img class="question-mark" src="style/images/question-mark.gif" 
190
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
191
		<div class="textinput-label">
192
			<label for="systemmetadatareplicate" title="Replicate System Metadata">Replicate SystemMetadata?</label>
193
		</div>
194
		<input 
195
			type= radio 
196
			class="textinput" 
197
			id="systemmetadatareplicate" 
198
			name="systemmetadatareplicate" 	             		    	    	           		    	             			
199
			value="1"/>Yes
200
		<input 
201
			type= radio 
202
			class="textinput" 
203
			id="systemmetadatareplicate" 
204
			name="systemmetadatareplicate" 	             		    	    	           		    	             			
205
			value="0"/>No 
206
	</div>
207
	<div class="form-row">
208
		<img class="question-mark" src="style/images/question-mark.gif" 
209
			onClick="helpWindow('<%= request.getContextPath() %>','metacat-configure.html#replication')"/>
210
		<div class="textinput-label">
211
			<label for="hub" title="Hub">Localhost is a hub?</label>
212
		</div>
213
		<input 
214
			type= radio 
215
			class="textinput" 
216
			id="hub" 
217
			name="hub" 	             		    	    	           		    	             			
218
			value="1"/>Yes
219
		<input 
220
			type= radio 
221
			class="textinput" 
222
			id="hub" 
223
			name="hub" 	             		    	    	           		    	             			
224
			value="0"/>No
225
	</div>
226

  
227
	<input type="hidden" name="configureType" value="replication">
228
	<input type="hidden" name="action" value="servercontrol">
229
	<input type="submit" value="Submit" target="bottom">
230

  
231
</form>
232

  
233
<br/>
234

  
235
<a
236
	href="<%=request.getContextPath()%>/admin?configureType=replication&action=servercontrol&subaction=list"
237
	target="bottom">Refresh Server List</a>
238

  
239
<br/>
240

  
241
<a href="<%=request.getContextPath()%>/admin" target="_top">Return to main configuration</a>
242

  
243
<%@ include file="./footer-section.jsp"%>
244

  
245
</body>
246
</html>
0 247

  
lib/admin/replication-configuration.jsp
1
<%@ page language="java" %>
2
<%@ page import="java.util.Set,java.util.Map,java.util.Vector,edu.ucsb.nceas.utilities.PropertiesMetaData" %>
3
<%@ page import="edu.ucsb.nceas.utilities.MetaDataGroup,edu.ucsb.nceas.utilities.MetaDataProperty" %>
4
<% 
5
/**
6
 *  '$RCSfile$'
7
 *    Copyright: 2008 Regents of the University of California and the
8
 *               National Center for Ecological Analysis and Synthesis
9
 *  For Details: http://www.nceas.ucsb.edu/
10
 *
11
 *   '$Author$'
12
 *     '$Date$'
13
 * '$Revision$'
14
 * 
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 2 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
 */
29
%>
30

  
31
<html>
32
<head>
33

  
34
<title>Replication Configuration</title>
35
<link rel="stylesheet" type="text/css" 
36
        href="<%= request.getContextPath() %>/admin/admin.css"></link>
37
<script language="JavaScript" type="text/JavaScript" src="<%= request.getContextPath() %>/admin/admin.js"></script>
38

  
39
</head>
40

  
41
<FRAMESET ROWS="*,150"  FRAMEBORDER=0 BORDER=0>
42
  
43
  <FRAME SRC="<%= request.getContextPath() %>/admin/replication-configuration-include.jsp" BORDER=0 NAME="top">
44

  
45
  <FRAME SRC="<%= request.getContextPath() %>/admin?configureType=replication&action=servercontrol&subaction=list" name="bottom">
46

  
47
</FRAMESET>
48

  
49
</html>
0 50

  
lib/admin/metacat-configuration.jsp
254 254
	}
255 255
%>
256 256

  
257
<!-- replication -->
258
   	<tr>
259
   	<td class="configured-tag">[configured] </td>  
260
   	<td class="property-title"> Replication Configuration </td>   
261
<%
262
	if (propsConfigured != null && propsConfigured) {
263
%>
264
        	
265
	<td class="configure-link"> <a href="<%= request.getContextPath() %>/admin?configureType=replication">Reconfigure Now</a> </td>			
266
        	
267
<%
268
	} else {
269
%> 
270
	<td class="configure-link"> Configure Global Properties First </td>
271
<%
272
	}
273
%>     	
274
   	</tr>
275

  
276

  
277

  
278
<!--  -->
257 279
</table>
258 280

  
259 281
<%
src/edu/ucsb/nceas/metacat/admin/ReplicationAdmin.java
43 43
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
44 44
import edu.ucsb.nceas.metacat.shared.ServiceException;
45 45
import edu.ucsb.nceas.metacat.util.AuthUtil;
46
import edu.ucsb.nceas.metacat.util.RequestUtil;
46 47
import edu.ucsb.nceas.metacat.util.SessionData;
47 48

  
48 49
/**
......
101 102
		if (!params.isEmpty() && params.get("action") != null) {
102 103
			action = ((String[]) params.get("action"))[0];
103 104
		}
104
		String server = null;
105 105
		
106 106
		// start, stop, getall and servercontrol need to check if user is administrator
107 107
		HttpSession session = request.getSession(true);
......
157 157
			out.println("<html><body>\"Get All\" Done</body></html>");
158 158
		} else if (action.equals("servercontrol")) {
159 159
			ReplicationService.handleServerControlRequest(params, response);
160
		} 
160
		} else {
161
			// Forward the request to the JSP page
162
			RequestUtil.forwardRequest(request, response, "/admin/replication-configuration.jsp", null);
163
		}
161 164
		
162
		// Forward the request to the JSP page
163
		//RequestUtil.forwardRequest(request, response, "/admin/replControl.html", null);
164
		
165 165
	}
166 166
	
167 167
	/**
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.replication;
28 28

  
29
import java.io.BufferedInputStream;
30
import java.io.BufferedOutputStream;
31 29
import java.io.ByteArrayInputStream;
32 30
import java.io.ByteArrayOutputStream;
33 31
import java.io.File;
......
376 374
				}
377 375
				out.write("</table></body></html>");
378 376

  
379
				// download certificate with the public key on this server
380
				// and import it as a trusted certificate
381
				String certURL = ((String[]) params.get("certificate"))[0];
382
				if (certURL != null && !certURL.equals("")) {
383
					downloadCertificate(certURL);
384
				}
385

  
386 377
				// delete server from server list
387 378
			} else if (subaction.equals("delete")) {
388 379
				server = ((String[]) params.get("server"))[0];
......
480 471

  
481 472
	}
482 473

  
483
	// download certificate with the public key from certURL and
484
	// upload it onto this server; it then must be imported as a
485
	// trusted certificate
486
	private static void downloadCertificate(String certURL) throws FileNotFoundException,
487
			IOException, MalformedURLException, PropertyNotFoundException {
488

  
489
		// the path to be uploaded to
490
		String certPath = SystemUtil.getContextDir();
491

  
492
		// get filename from the URL of the certificate
493
		String filename = certURL;
494
		int slash = Math.max(filename.lastIndexOf('/'), filename.lastIndexOf('\\'));
495
		if (slash > -1) {
496
			filename = filename.substring(slash + 1);
497
		}
498

  
499
		// open file output strem to write the input into it
500
		File f = new File(certPath, filename);
501
		synchronized (f) {
502
			try {
503
				if (f.exists()) {
504
					throw new IOException("File already exist: " + f.getCanonicalFile());
505
					// if ( f.exists() && !f.canWrite() ) {
506
					// throw new IOException("Not writable: " +
507
					// f.getCanonicalFile());
508
				}
509
			} catch (SecurityException se) {
510
				// if a security manager exists,
511
				// its checkRead method is called for f.exist()
512
				// or checkWrite method is called for f.canWrite()
513
				throw se;
514
			}
515

  
516
			// create a buffered byte output stream
517
			// that uses a default-sized output buffer
518
			FileOutputStream fos = new FileOutputStream(f);
519
			BufferedOutputStream out = new BufferedOutputStream(fos);
520

  
521
			// this should be http url
522
			URL url = new URL(certURL);
523
			BufferedInputStream bis = null;
524
			try {
525
				bis = new BufferedInputStream(url.openStream());
526
				byte[] buf = new byte[4 * 1024]; // 4K buffer
527
				int b = bis.read(buf);
528
				while (b != -1) {
529
					out.write(buf, 0, b);
530
					b = bis.read(buf);
531
				}
532
			} finally {
533
				if (bis != null)
534
					bis.close();
535
			}
536
			// the input and the output streams must be closed
537
			bis.close();
538
			out.flush();
539
			out.close();
540
			fos.close();
541
		} // end of synchronized(f)
542
	}
543

  
544 474
	/**
545 475
	 * when a forcereplication request comes in, local host sends a read request
546 476
	 * to the requesting server (remote server) for the specified docid. Then

Also available in: Unified diff