1 |
4080
|
daigle
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A Class that implements main property configuration methods
|
4 |
|
|
* Copyright: 2008 Regents of the University of California and the
|
5 |
|
|
* National Center for Ecological Analysis and Synthesis
|
6 |
|
|
* Authors: Michael Daigle
|
7 |
|
|
*
|
8 |
|
|
* '$Author$'
|
9 |
|
|
* '$Date$'
|
10 |
|
|
* '$Revision$'
|
11 |
|
|
*
|
12 |
|
|
* This program is free software; you can redistribute it and/or modify
|
13 |
|
|
* it under the terms of the GNU General Public License as published by
|
14 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
15 |
|
|
* (at your option) any later version.
|
16 |
|
|
*
|
17 |
|
|
* This program is distributed in the hope that it will be useful,
|
18 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
|
|
* GNU General Public License for more details.
|
21 |
|
|
*
|
22 |
|
|
* You should have received a copy of the GNU General Public License
|
23 |
|
|
* along with this program; if not, write to the Free Software
|
24 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
package edu.ucsb.nceas.metacat.admin;
|
28 |
|
|
|
29 |
6497
|
jones
|
import java.io.File;
|
30 |
8074
|
tao
|
import java.io.StringReader;
|
31 |
4080
|
daigle
|
import java.util.Vector;
|
32 |
|
|
|
33 |
|
|
import javax.servlet.http.HttpServletRequest;
|
34 |
|
|
import javax.servlet.http.HttpServletResponse;
|
35 |
|
|
|
36 |
7694
|
leinfelder
|
import org.apache.commons.io.FileUtils;
|
37 |
|
|
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
38 |
|
|
import org.apache.commons.io.filefilter.OrFileFilter;
|
39 |
|
|
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
40 |
4080
|
daigle
|
import org.apache.log4j.Logger;
|
41 |
|
|
|
42 |
5027
|
daigle
|
import edu.ucsb.nceas.metacat.MetacatVersion;
|
43 |
5015
|
daigle
|
import edu.ucsb.nceas.metacat.database.DBVersion;
|
44 |
5030
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
45 |
4795
|
daigle
|
import edu.ucsb.nceas.metacat.service.ServiceService;
|
46 |
5076
|
daigle
|
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
|
47 |
5015
|
daigle
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
48 |
4080
|
daigle
|
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
49 |
|
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
50 |
|
|
import edu.ucsb.nceas.utilities.FileUtil;
|
51 |
|
|
import edu.ucsb.nceas.utilities.GeneralPropertyException;
|
52 |
|
|
import edu.ucsb.nceas.utilities.PropertiesMetaData;
|
53 |
8074
|
tao
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
54 |
4080
|
daigle
|
import edu.ucsb.nceas.utilities.SortedProperties;
|
55 |
4950
|
daigle
|
import edu.ucsb.nceas.utilities.UtilException;
|
56 |
4080
|
daigle
|
|
57 |
|
|
/**
|
58 |
|
|
* Control the display of the main properties configuration page and the
|
59 |
|
|
* processing of the configuration values.
|
60 |
|
|
*/
|
61 |
5027
|
daigle
|
public class PropertiesAdmin extends MetacatAdmin {
|
62 |
8074
|
tao
|
private static String BACKSLASH = "/";
|
63 |
|
|
private static String DEFAULTMETACATCONTEXT = "knb";
|
64 |
|
|
private static String METACATPROPERTYAPPENDIX = "/WEB-INF/metacat.properties";
|
65 |
4080
|
daigle
|
private static PropertiesAdmin propertiesAdmin = null;
|
66 |
|
|
private static Logger logMetacat = Logger.getLogger(PropertiesAdmin.class);
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* private constructor since this is a singleton
|
70 |
|
|
*/
|
71 |
|
|
private PropertiesAdmin() {}
|
72 |
|
|
|
73 |
|
|
/**
|
74 |
|
|
* Get the single instance of the MetaCatConfig.
|
75 |
|
|
*
|
76 |
|
|
* @return the single instance of MetaCatConfig
|
77 |
|
|
*/
|
78 |
|
|
public static PropertiesAdmin getInstance() {
|
79 |
|
|
if (propertiesAdmin == null) {
|
80 |
|
|
propertiesAdmin = new PropertiesAdmin();
|
81 |
|
|
}
|
82 |
|
|
return propertiesAdmin;
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
/**
|
86 |
|
|
* Handle configuration of the main application properties
|
87 |
|
|
*
|
88 |
|
|
* @param request
|
89 |
|
|
* the http request object
|
90 |
|
|
* @param response
|
91 |
|
|
* the http response to be sent back to the client
|
92 |
|
|
*/
|
93 |
|
|
public void configureProperties(HttpServletRequest request,
|
94 |
|
|
HttpServletResponse response) throws AdminException {
|
95 |
|
|
|
96 |
|
|
String processForm = request.getParameter("processForm");
|
97 |
|
|
String formErrors = (String)request.getAttribute("formErrors");
|
98 |
|
|
|
99 |
|
|
if (processForm == null || !processForm.equals("true") || formErrors != null) {
|
100 |
|
|
// The servlet configuration parameters have not been set, or there
|
101 |
|
|
// were form errors on the last attempt to configure, so redirect to
|
102 |
|
|
// the web form for configuring metacat
|
103 |
|
|
|
104 |
|
|
try {
|
105 |
|
|
// Load the properties metadata file so that the JSP page can
|
106 |
|
|
// use the metadata to construct the editing form
|
107 |
|
|
PropertiesMetaData metadata = PropertyService.getMainMetaData();
|
108 |
|
|
request.setAttribute("metadata", metadata);
|
109 |
|
|
|
110 |
4795
|
daigle
|
String externalDir = PropertyService.getRecommendedExternalDir();
|
111 |
4706
|
daigle
|
|
112 |
|
|
if (externalDir == null) {
|
113 |
4795
|
daigle
|
throw new AdminException("Could not initialize property configuration "
|
114 |
|
|
+ "page recommended application backup directory was null");
|
115 |
4706
|
daigle
|
}
|
116 |
|
|
|
117 |
4080
|
daigle
|
// Attempt to discover the following properties. These will show
|
118 |
|
|
// up in the configuration fields if nothing else is provided.
|
119 |
|
|
PropertyService.setPropertyNoPersist("application.context",
|
120 |
4795
|
daigle
|
ServiceService.getRealApplicationContext());
|
121 |
4080
|
daigle
|
PropertyService.setPropertyNoPersist("server.name", SystemUtil
|
122 |
|
|
.discoverServerName(request));
|
123 |
|
|
PropertyService.setPropertyNoPersist("server.httpPort", SystemUtil
|
124 |
|
|
.discoverServerPort(request));
|
125 |
|
|
PropertyService.setPropertyNoPersist("server.httpSSLPort",
|
126 |
|
|
SystemUtil.discoverServerSSLPort(request));
|
127 |
4174
|
daigle
|
PropertyService.setPropertyNoPersist("application.deployDir",
|
128 |
4183
|
daigle
|
SystemUtil.discoverDeployDir(request));
|
129 |
4662
|
daigle
|
PropertyService.setPropertyNoPersist("application.datafilepath",
|
130 |
4706
|
daigle
|
externalDir + FileUtil.getFS() + "data");
|
131 |
4662
|
daigle
|
PropertyService.setPropertyNoPersist("application.inlinedatafilepath",
|
132 |
4706
|
daigle
|
externalDir + FileUtil.getFS() + "inline-data");
|
133 |
4662
|
daigle
|
PropertyService.setPropertyNoPersist("application.documentfilepath",
|
134 |
4706
|
daigle
|
externalDir + FileUtil.getFS() + "documents");
|
135 |
4662
|
daigle
|
PropertyService.setPropertyNoPersist("application.tempDir",
|
136 |
4706
|
daigle
|
externalDir + FileUtil.getFS() + "temporary");
|
137 |
4662
|
daigle
|
PropertyService.setPropertyNoPersist("replication.logdir",
|
138 |
4706
|
daigle
|
externalDir + FileUtil.getFS() + "logs");
|
139 |
7694
|
leinfelder
|
PropertyService.setPropertyNoPersist("solr.homeDir",
|
140 |
|
|
externalDir + FileUtil.getFS() + "solr-home");
|
141 |
4080
|
daigle
|
|
142 |
|
|
PropertyService.persistProperties();
|
143 |
|
|
|
144 |
|
|
// Add the list of properties from metacat.properties to the request
|
145 |
|
|
Vector<String> propertyNames = PropertyService.getPropertyNames();
|
146 |
|
|
for (String propertyName : propertyNames) {
|
147 |
|
|
request.setAttribute(propertyName, PropertyService.getProperty(propertyName));
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
// Check for any backup properties and apply them to the
|
151 |
|
|
// request. These are properties from previous configurations.
|
152 |
|
|
// They keep the user from having to re-enter all values when
|
153 |
|
|
// upgrading. If this is a first time install, getBackupProperties
|
154 |
|
|
// will return null.
|
155 |
|
|
SortedProperties backupProperties = null;
|
156 |
|
|
if ((backupProperties =
|
157 |
|
|
PropertyService.getMainBackupProperties()) != null) {
|
158 |
|
|
Vector<String> backupKeys = backupProperties.getPropertyNames();
|
159 |
|
|
for (String key : backupKeys) {
|
160 |
|
|
String value = backupProperties.getProperty(key);
|
161 |
|
|
if (value != null) {
|
162 |
|
|
request.setAttribute(key, value);
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
// Forward the request to the JSP page
|
168 |
|
|
RequestUtil.forwardRequest(request, response,
|
169 |
5027
|
daigle
|
"/admin/properties-configuration.jsp", null);
|
170 |
4080
|
daigle
|
|
171 |
4084
|
daigle
|
} catch (GeneralPropertyException gpe) {
|
172 |
5030
|
daigle
|
throw new AdminException("PropertiesAdmin.configureProperties - Problem getting or " +
|
173 |
|
|
"setting property while initializing system properties page: " + gpe.getMessage());
|
174 |
5076
|
daigle
|
} catch (MetacatUtilException mue) {
|
175 |
|
|
throw new AdminException("PropertiesAdmin.configureProperties - utility problem while initializing "
|
176 |
|
|
+ "system properties page:" + mue.getMessage());
|
177 |
4795
|
daigle
|
} catch (ServiceException se) {
|
178 |
5030
|
daigle
|
throw new AdminException("PropertiesAdmin.configureProperties - Service problem while initializing "
|
179 |
4795
|
daigle
|
+ "system properties page:" + se.getMessage());
|
180 |
5076
|
daigle
|
}
|
181 |
4080
|
daigle
|
} else {
|
182 |
|
|
// The configuration form is being submitted and needs to be
|
183 |
|
|
// processed.
|
184 |
|
|
Vector<String> validationErrors = new Vector<String>();
|
185 |
|
|
Vector<String> processingErrors = new Vector<String>();
|
186 |
|
|
Vector<String> processingSuccess = new Vector<String>();
|
187 |
|
|
|
188 |
5027
|
daigle
|
MetacatVersion metacatVersion = null;
|
189 |
4080
|
daigle
|
|
190 |
|
|
try {
|
191 |
|
|
metacatVersion = SystemUtil.getMetacatVersion();
|
192 |
|
|
|
193 |
|
|
// For each property, check if it is changed and save it
|
194 |
|
|
Vector<String> propertyNames = PropertyService.getPropertyNames();
|
195 |
|
|
for (String name : propertyNames) {
|
196 |
|
|
PropertyService.checkAndSetProperty(request, name);
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
// we need to write the options from memory to the properties
|
200 |
|
|
// file
|
201 |
|
|
PropertyService.persistProperties();
|
202 |
|
|
|
203 |
|
|
// Validate that the options provided are legitimate. Note that
|
204 |
|
|
// we've allowed them to persist their entries. As of this point
|
205 |
|
|
// there is no other easy way to go back to the configure form
|
206 |
|
|
// and preserve their entries.
|
207 |
|
|
validationErrors.addAll(validateOptions(request));
|
208 |
4183
|
daigle
|
|
209 |
|
|
// Try to create data directories if necessary.
|
210 |
|
|
String dataDir = PropertyService.getProperty("application.datafilepath");
|
211 |
4440
|
daigle
|
try {
|
212 |
|
|
FileUtil.createDirectory(dataDir);
|
213 |
4950
|
daigle
|
} catch (UtilException ue) {
|
214 |
5030
|
daigle
|
String errorString = "PropertiesAdmin.configureProperties - Could not create directory: " + dataDir +
|
215 |
4950
|
daigle
|
" : " + ue.getMessage();
|
216 |
4183
|
daigle
|
logMetacat.error(errorString);
|
217 |
|
|
validationErrors.add(errorString);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
// Try to create inline-data directories if necessary.
|
221 |
|
|
String inlineDataDir = PropertyService.getProperty("application.inlinedatafilepath");
|
222 |
4440
|
daigle
|
try {
|
223 |
|
|
FileUtil.createDirectory(inlineDataDir);
|
224 |
4950
|
daigle
|
} catch (UtilException ue) {
|
225 |
5030
|
daigle
|
String errorString = "PropertiesAdmin.configureProperties - Could not create directory: " + inlineDataDir +
|
226 |
4950
|
daigle
|
" : " + ue.getMessage();
|
227 |
4183
|
daigle
|
logMetacat.error(errorString);
|
228 |
|
|
validationErrors.add(errorString);
|
229 |
|
|
}
|
230 |
4428
|
daigle
|
|
231 |
|
|
// Try to create document directories if necessary.
|
232 |
|
|
String documentfilepath = PropertyService.getProperty("application.documentfilepath");
|
233 |
4440
|
daigle
|
try {
|
234 |
|
|
FileUtil.createDirectory(documentfilepath);
|
235 |
4950
|
daigle
|
} catch (UtilException ue) {
|
236 |
5030
|
daigle
|
String errorString = "PropertiesAdmin.configureProperties - Could not create directory: " + documentfilepath +
|
237 |
4950
|
daigle
|
" : " + ue.getMessage();
|
238 |
4428
|
daigle
|
logMetacat.error(errorString);
|
239 |
|
|
validationErrors.add(errorString);
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
// Try to create temporary directories if necessary.
|
243 |
|
|
String tempDir = PropertyService.getProperty("application.tempDir");
|
244 |
4440
|
daigle
|
try {
|
245 |
|
|
FileUtil.createDirectory(tempDir);
|
246 |
4950
|
daigle
|
} catch (UtilException ue) {
|
247 |
5030
|
daigle
|
String errorString = "PropertiesAdmin.configureProperties - Could not create directory: " + tempDir +
|
248 |
4950
|
daigle
|
" : " + ue.getMessage();
|
249 |
4428
|
daigle
|
logMetacat.error(errorString);
|
250 |
|
|
validationErrors.add(errorString);
|
251 |
|
|
}
|
252 |
4808
|
daigle
|
|
253 |
|
|
// Try to create temporary directories if necessary.
|
254 |
|
|
String replLogDir = PropertyService.getProperty("replication.logdir");
|
255 |
|
|
try {
|
256 |
|
|
FileUtil.createDirectory(replLogDir);
|
257 |
4950
|
daigle
|
} catch (UtilException ue) {
|
258 |
5030
|
daigle
|
String errorString = "PropertiesAdmin.configureProperties - Could not create directory: " + replLogDir +
|
259 |
4950
|
daigle
|
" : " + ue.getMessage();
|
260 |
4808
|
daigle
|
logMetacat.error(errorString);
|
261 |
|
|
validationErrors.add(errorString);
|
262 |
|
|
}
|
263 |
6493
|
jones
|
|
264 |
7694
|
leinfelder
|
// Try to create and initialize the solr-home directory if necessary.
|
265 |
|
|
String solrHomePath = PropertyService.getProperty("solr.homeDir");
|
266 |
|
|
String indexContext = PropertyService.getProperty("index.context");
|
267 |
|
|
boolean solrHomeExists = new File(solrHomePath).exists();
|
268 |
|
|
if (!solrHomeExists) {
|
269 |
|
|
try {
|
270 |
|
|
String metacatWebInf = ServiceService.getRealConfigDir();
|
271 |
|
|
String metacatIndexSolrHome = metacatWebInf + "/../../" + indexContext + "/WEB-INF/classes/solr-home";
|
272 |
7808
|
leinfelder
|
// only attempt to copy if we have the source directory to copy from
|
273 |
|
|
File sourceDir = new File(metacatIndexSolrHome);
|
274 |
|
|
if (sourceDir.exists()) {
|
275 |
7809
|
leinfelder
|
FileUtil.createDirectory(solrHomePath);
|
276 |
7808
|
leinfelder
|
OrFileFilter fileFilter = new OrFileFilter();
|
277 |
|
|
fileFilter.addFileFilter(DirectoryFileFilter.DIRECTORY);
|
278 |
|
|
fileFilter.addFileFilter(new WildcardFileFilter("*"));
|
279 |
|
|
FileUtils.copyDirectory(new File(metacatIndexSolrHome), new File(solrHomePath), fileFilter );
|
280 |
|
|
}
|
281 |
7694
|
leinfelder
|
} catch (Exception ue) {
|
282 |
|
|
String errorString = "PropertiesAdmin.configureProperties - Could not initialize directory: " + solrHomePath +
|
283 |
|
|
" : " + ue.getMessage();
|
284 |
|
|
logMetacat.error(errorString);
|
285 |
|
|
validationErrors.add(errorString);
|
286 |
|
|
}
|
287 |
|
|
} else {
|
288 |
|
|
// check it
|
289 |
|
|
if (!FileUtil.isDirectory(solrHomePath)) {
|
290 |
|
|
String errorString = "PropertiesAdmin.configureProperties - SOLR home is not a directory: " + solrHomePath;
|
291 |
|
|
logMetacat.error(errorString);
|
292 |
|
|
validationErrors.add(errorString);
|
293 |
|
|
}
|
294 |
|
|
}
|
295 |
8184
|
leinfelder
|
|
296 |
8074
|
tao
|
//modify some params of the index context
|
297 |
8184
|
leinfelder
|
this.modifyIndexContextParams(indexContext);
|
298 |
7694
|
leinfelder
|
|
299 |
8184
|
leinfelder
|
// make sure hazelcast.xml uses a unique group name
|
300 |
|
|
this.modifyHazelcastConfig();
|
301 |
|
|
|
302 |
4080
|
daigle
|
// write the backup properties to a location outside the
|
303 |
|
|
// application directories so they will be available after
|
304 |
|
|
// the next upgrade
|
305 |
5028
|
daigle
|
PropertyService.persistMainBackupProperties();
|
306 |
4080
|
daigle
|
|
307 |
|
|
} catch (GeneralPropertyException gpe) {
|
308 |
5030
|
daigle
|
String errorMessage = "PropertiesAdmin.configureProperties - Problem getting or setting property while "
|
309 |
4080
|
daigle
|
+ "processing system properties page: " + gpe.getMessage();
|
310 |
|
|
logMetacat.error(errorMessage);
|
311 |
|
|
processingErrors.add(errorMessage);
|
312 |
4440
|
daigle
|
}
|
313 |
4080
|
daigle
|
|
314 |
|
|
try {
|
315 |
|
|
if (validationErrors.size() > 0 || processingErrors.size() > 0) {
|
316 |
|
|
RequestUtil.clearRequestMessages(request);
|
317 |
|
|
RequestUtil.setRequestFormErrors(request, validationErrors);
|
318 |
|
|
RequestUtil.setRequestErrors(request, processingErrors);
|
319 |
5027
|
daigle
|
RequestUtil.forwardRequest(request, response, "/admin", null);
|
320 |
4080
|
daigle
|
} else {
|
321 |
|
|
// Now that the options have been set, change the
|
322 |
|
|
// 'propertiesConfigured' option to 'true'
|
323 |
|
|
PropertyService.setProperty("configutil.propertiesConfigured",
|
324 |
|
|
PropertyService.CONFIGURED);
|
325 |
|
|
|
326 |
|
|
// if the db version is already the same as the metacat version,
|
327 |
|
|
// update metacat.properties. Have to do this after
|
328 |
|
|
// propertiesConfigured is set to CONFIGURED
|
329 |
|
|
DBVersion dbVersion = DBAdmin.getInstance().getDBVersion();
|
330 |
|
|
if (dbVersion != null && metacatVersion != null &&
|
331 |
|
|
dbVersion.compareTo(metacatVersion) == 0) {
|
332 |
4084
|
daigle
|
PropertyService.setProperty("configutil.databaseConfigured",
|
333 |
4080
|
daigle
|
PropertyService.CONFIGURED);
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
// Reload the main metacat configuration page
|
337 |
|
|
processingSuccess.add("Properties successfully configured");
|
338 |
|
|
RequestUtil.clearRequestMessages(request);
|
339 |
|
|
RequestUtil.setRequestSuccess(request, processingSuccess);
|
340 |
|
|
RequestUtil.forwardRequest(request, response,
|
341 |
5027
|
daigle
|
"/admin?configureType=configure&processForm=false", null);
|
342 |
4080
|
daigle
|
}
|
343 |
5076
|
daigle
|
} catch (MetacatUtilException mue) {
|
344 |
|
|
throw new AdminException("PropertiesAdmin.configureProperties - utility problem while processing system "
|
345 |
|
|
+ "properties page: " + mue.getMessage());
|
346 |
4084
|
daigle
|
} catch (GeneralPropertyException gpe) {
|
347 |
5030
|
daigle
|
throw new AdminException("PropertiesAdmin.configureProperties - problem with properties while "
|
348 |
4084
|
daigle
|
+ "processing system properties page: " + gpe.getMessage());
|
349 |
4080
|
daigle
|
}
|
350 |
|
|
}
|
351 |
|
|
}
|
352 |
8074
|
tao
|
|
353 |
8184
|
leinfelder
|
/**
|
354 |
8074
|
tao
|
* In the web.xml of the Metacat-index context, there is a parameter:
|
355 |
|
|
* <context-param>
|
356 |
|
|
* <param-name>metacat.properties.path</param-name>
|
357 |
|
|
* <param-value>/knb/WEB-INF/metacat.properties</param-value>
|
358 |
|
|
* <description>The metacat.properties file for sibling metacat deployment. Note that the context can change</description>
|
359 |
|
|
* </context-param>
|
360 |
|
|
* It points to the default metacat context - knb. If we rename the context, we need to change the value of there.
|
361 |
|
|
*/
|
362 |
|
|
private void modifyIndexContextParams(String indexContext) {
|
363 |
|
|
if(indexContext != null) {
|
364 |
|
|
try {
|
365 |
|
|
String metacatContext = PropertyService.getProperty("application.context");
|
366 |
|
|
//System.out.println("the metacat context is ========================="+metacatContext);
|
367 |
|
|
if(metacatContext != null && !metacatContext.equals(DEFAULTMETACATCONTEXT)) {
|
368 |
|
|
String indexConfigFile =
|
369 |
|
|
PropertyService.getProperty("application.deployDir")
|
370 |
|
|
+ FileUtil.getFS()
|
371 |
|
|
+ indexContext
|
372 |
|
|
+ FileUtil.getFS()
|
373 |
|
|
+ "WEB-INF"
|
374 |
|
|
+ FileUtil.getFS()
|
375 |
|
|
+ "web.xml";
|
376 |
|
|
//System.out.println("============================== the web.xml file is "+indexConfigFile);
|
377 |
|
|
String configContents = FileUtil.readFileToString(indexConfigFile, "UTF-8");
|
378 |
|
|
//System.out.println("============================== the content of web.xml file is "+configContents);
|
379 |
|
|
configContents = configContents.replace(BACKSLASH+DEFAULTMETACATCONTEXT+METACATPROPERTYAPPENDIX, BACKSLASH+metacatContext+METACATPROPERTYAPPENDIX);
|
380 |
|
|
FileUtil.writeFile(indexConfigFile, new StringReader(configContents), "UTF-8");
|
381 |
|
|
}
|
382 |
|
|
|
383 |
|
|
} catch (Exception e) {
|
384 |
|
|
String errorMessage = "PropertiesAdmin.configureProperties - Problem getting/setting the \"metacat.properties.path\" in the web.xml of the index context : " + e.getMessage();
|
385 |
|
|
logMetacat.error(errorMessage);
|
386 |
|
|
}
|
387 |
|
|
}
|
388 |
|
|
}
|
389 |
8184
|
leinfelder
|
|
390 |
|
|
/**
|
391 |
|
|
* Changes the Hazelcast group name to match the current context
|
392 |
|
|
* This ensures we do not share the same group if multiple Metacat
|
393 |
|
|
* instances are running in the same Tomcat container.
|
394 |
|
|
*/
|
395 |
|
|
private void modifyHazelcastConfig() {
|
396 |
|
|
try {
|
397 |
|
|
String metacatContext = PropertyService.getProperty("application.context");
|
398 |
|
|
//System.out.println("the metacat context is ========================="+metacatContext);
|
399 |
|
|
if (metacatContext != null) {
|
400 |
|
|
String hzConfigFile =
|
401 |
|
|
PropertyService.getProperty("application.deployDir")
|
402 |
|
|
+ FileUtil.getFS()
|
403 |
|
|
+ metacatContext
|
404 |
|
|
+ FileUtil.getFS()
|
405 |
|
|
+ "WEB-INF"
|
406 |
|
|
+ FileUtil.getFS()
|
407 |
|
|
+ "hazelcast.xml";
|
408 |
|
|
//System.out.println("============================== the web.xml file is "+indexConfigFile);
|
409 |
|
|
String configContents = FileUtil.readFileToString(hzConfigFile, "UTF-8");
|
410 |
|
|
//System.out.println("============================== the content of web.xml file is "+configContents);
|
411 |
|
|
configContents = configContents.replace("<name>DataONE</name>", "<name>" + metacatContext + "</name>");
|
412 |
|
|
FileUtil.writeFile(hzConfigFile, new StringReader(configContents), "UTF-8");
|
413 |
|
|
}
|
414 |
|
|
|
415 |
|
|
} catch (Exception e) {
|
416 |
|
|
String errorMessage = "PropertiesAdmin.configureProperties - Problem setting groupName in hazelcast.xml: " + e.getMessage();
|
417 |
|
|
logMetacat.error(errorMessage);
|
418 |
|
|
}
|
419 |
|
|
}
|
420 |
4080
|
daigle
|
|
421 |
|
|
/**
|
422 |
|
|
* Validate the most important configuration options submitted by the user.
|
423 |
|
|
*
|
424 |
|
|
* @param request
|
425 |
|
|
* the http request object
|
426 |
|
|
*
|
427 |
|
|
* @return a vector holding error message for any fields that fail
|
428 |
|
|
* validation.
|
429 |
|
|
*/
|
430 |
|
|
protected Vector<String> validateOptions(HttpServletRequest request) {
|
431 |
|
|
Vector<String> errorVector = new Vector<String>();
|
432 |
|
|
|
433 |
|
|
// Test database connectivity
|
434 |
|
|
try {
|
435 |
|
|
String dbError = DBAdmin.getInstance().validateDBConnectivity(
|
436 |
|
|
request.getParameter("database.driver"),
|
437 |
|
|
request.getParameter("database.connectionURI"),
|
438 |
|
|
request.getParameter("database.user"),
|
439 |
|
|
request.getParameter("database.password"));
|
440 |
|
|
if (dbError != null) {
|
441 |
|
|
errorVector.add(dbError);
|
442 |
|
|
}
|
443 |
|
|
} catch (AdminException ae) {
|
444 |
|
|
errorVector.add("Could not instantiate database admin: "
|
445 |
|
|
+ ae.getMessage());
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
return errorVector;
|
449 |
|
|
}
|
450 |
6493
|
jones
|
|
451 |
6635
|
leinfelder
|
|
452 |
4080
|
daigle
|
}
|