NIHVIVO-2450 combine upload.directory and LuceneSetup.indexDir under vitro.home.directory

This commit is contained in:
j2blake 2011-04-04 16:35:22 +00:00
parent 412d25e800
commit 08770c8bd0
7 changed files with 124 additions and 85 deletions

View file

@ -102,10 +102,8 @@ deploy - Deploy the application directly into the Tomcat webapps directory.
message="${deploy.properties.file} must contain a value for tomcat.home" />
<fail unless="webapp.name"
message="${deploy.properties.file} must contain a value for webapp.name" />
<fail unless="upload.directory"
message="${deploy.properties.file} must contain a value for upload.directory" />
<fail unless="LuceneSetup.indexDir"
message="${deploy.properties.file} must contain a value for LuceneSetup.indexDir" />
<fail unless="vitro.home.directory"
message="${deploy.properties.file} must contain a value for vitro.home.directory" />
<fail unless="Vitro.defaultNamespace"
message="${deploy.properties.file} must contain a value for Vitro.defaultNamespace" />
<fail unless="Vitro.smtpHost"

View file

@ -32,17 +32,10 @@ tomcat.home = /usr/local/tomcat
webapp.name = vitro
#
# The location where the VIVO application will store uploaded files
# (usually images). You should arrange for these files to be backed up in some
# way.
# The location where the VIVO application will store the data that it creates.
# This includes uploaded files (usually images) and the Lucene search index.
#
upload.directory = /usr/local/vivo/data/uploads
#
# The location where the VIVO application will create its Lucene search
# index.
#
LuceneSetup.indexDir = /usr/local/vivo/data/luceneIndex
vitro.home.directory = /usr/local/vivo/data
#
# SMTP host which the "Contact Us" form can use to send mail. If this is left

View file

@ -3,6 +3,7 @@
package edu.cornell.mannlib.vitro.webapp.filestorage.backend;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
@ -30,9 +31,11 @@ public class FileStorageSetup implements ServletContextListener {
/**
* The default implementation will use this key to ask
* {@link ConfigurationProperties} for the file storage base directory.
* {@link ConfigurationProperties} for the vivo home directory. The file
* storage base directory is in a subdirectory below this one.
*/
public static final String PROPERTY_FILE_STORAGE_BASE_DIR = "upload.directory";
public static final String PROPERTY_VITRO_HOME_DIR = "vitro.home.directory";
public static final String FILE_STORAGE_SUBDIRECTORY = "uploads";
/**
* The default implementation will use this key to ask
@ -65,15 +68,31 @@ public class FileStorageSetup implements ServletContextListener {
*
* For use by the constructor in implementations of {@link FileStorage}.
*/
private File figureBaseDir(ServletContextEvent sce) {
String baseDirPath = ConfigurationProperties.getBean(sce)
.getProperty(PROPERTY_FILE_STORAGE_BASE_DIR);
if (baseDirPath == null) {
private File figureBaseDir(ServletContextEvent sce) throws IOException {
String homeDirPath = ConfigurationProperties.getBean(sce)
.getProperty(PROPERTY_VITRO_HOME_DIR);
if (homeDirPath == null) {
throw new IllegalArgumentException(
"Configuration properties must contain a value for '"
+ PROPERTY_FILE_STORAGE_BASE_DIR + "'");
+ PROPERTY_VITRO_HOME_DIR + "'");
}
return new File(baseDirPath);
File homeDir = new File(homeDirPath);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ homeDir.getAbsolutePath() + "' does not exist.");
}
File baseDir = new File(homeDir, FILE_STORAGE_SUBDIRECTORY);
if (!baseDir.exists()) {
boolean created = baseDir.mkdir();
if (!created) {
throw new IOException(
"Unable to create uploads directory at '"
+ baseDir + "'");
}
}
return baseDir;
}
/**

View file

@ -4,13 +4,12 @@ package edu.cornell.mannlib.vitro.webapp.search.lucene;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.ALLTEXT;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.ALLTEXTUNSTEMMED;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.NAME;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.NAMEUNSTEMMED;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.MONIKER;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.RDFTYPE;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.CLASSLOCALNAME;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.CLASSLOCALNAMELOWERCASE;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.MONIKER;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.NAME;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.NAMEUNSTEMMED;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.RDFTYPE;
import java.io.File;
import java.io.IOException;
@ -25,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.util.Version;
@ -70,7 +68,10 @@ import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
*
*/
public class LuceneSetup implements javax.servlet.ServletContextListener {
private static final Log log = LogFactory.getLog(LuceneSetup.class.getName());
private static final Log log = LogFactory.getLog(LuceneSetup.class.getName());
private static final String PROPERTY_VITRO_HOME = "vitro.home.directory";
private static final String LUCENE_SUBDIRECTORY_NAME = "luceneIndex";
/**
* Gets run to set up DataSource when the webapp servlet context gets
@ -196,36 +197,42 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
/**
* Gets the name of the directory to store the lucene index in. The
* {@link ConfigurationProperties} should have a property named
* 'LuceneSetup.indexDir' which has the directory to store the lucene index
* for this clone in. If the property is not found, an exception will be
* thrown.
* 'vitro.home.directory' which has the parent directory of the directory to
* store the lucene index for this clone in. If the property is not found,
* an exception will be thrown.
*
* @return a string that is the directory to store the lucene index.
* @throws IllegalStateException
* if the property is not found.
* if the property is not found, or if the home directory does
* not exist.
* @throws IOException
* if the directory doesn't exist and we fail to create it.
*/
private String getBaseIndexDirName(ServletContext ctx)
throws IOException {
String dirName = ConfigurationProperties.getBean(ctx)
.getProperty("LuceneSetup.indexDir");
if (dirName == null) {
throw new IllegalStateException(
"LuceneSetup.indexDir not found in properties file.");
private String getBaseIndexDirName(ServletContext ctx) throws IOException {
String homeDirName = ConfigurationProperties.getBean(ctx).getProperty(
PROPERTY_VITRO_HOME);
if (homeDirName == null) {
throw new IllegalStateException(PROPERTY_VITRO_HOME
+ " not found in properties file.");
}
File dir = new File(dirName);
if (!dir.exists()) {
boolean created = dir.mkdir();
File homeDir = new File(homeDirName);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ homeDir.getAbsolutePath() + "' does not exist.");
}
File luceneDir = new File(homeDir, LUCENE_SUBDIRECTORY_NAME);
if (!luceneDir.exists()) {
boolean created = luceneDir.mkdir();
if (!created) {
throw new IOException(
"Unable to create Lucene index directory at '" + dir
+ "'");
"Unable to create Lucene index directory at '"
+ luceneDir + "'");
}
}
return dirName;
return luceneDir.getPath();
}
/**

View file

@ -55,8 +55,10 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
*
*/
public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
private static String indexDir = null;
private static String indexDir = null;
private static final Log log = LogFactory.getLog(LuceneSetupCJK.class.getName());
private static final String PROPERTY_VITRO_HOME = "vitro.home.directory";
private static final String LUCENE_SUBDIRECTORY_NAME = "luceneIndex";
/**
* Gets run to set up DataSource when the webapp servlet context gets created.
@ -152,37 +154,43 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
/**
* Gets the name of the directory to store the lucene index in. The
* {@link ConfigurationProperties} should have a property named
* 'LuceneSetup.indexDir' which has the directory to store the lucene index
* for this clone in. If the property is not found, an exception will be
* thrown.
* 'vitro.home.directory' which has the parent directory of the directory to
* store the lucene index for this clone in. If the property is not found,
* an exception will be thrown.
*
* @return a string that is the directory to store the lucene index.
* @throws IllegalStateException
* if the property is not found.
* if the property is not found,
* or if the home directory does not exist.
* @throws IOException
* if the directory doesn't exist and we fail to create it.
*/
private String getIndexDirName(ServletContextEvent sce)
throws IOException {
String dirName = ConfigurationProperties.getBean(sce)
.getProperty("LuceneSetup.indexDir");
if (dirName == null) {
throw new IllegalStateException(
"LuceneSetup.indexDir not found in properties file.");
}
private String getIndexDirName(ServletContextEvent cte) throws IOException {
String homeDirName = ConfigurationProperties.getBean(cte).getProperty(
PROPERTY_VITRO_HOME);
if (homeDirName == null) {
throw new IllegalStateException(PROPERTY_VITRO_HOME
+ " not found in properties file.");
}
File dir = new File(dirName);
if (!dir.exists()) {
boolean created = dir.mkdir();
if (!created) {
throw new IOException(
"Unable to create Lucene index directory at '" + dir
+ "'");
}
}
File homeDir = new File(homeDirName);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ homeDir.getAbsolutePath() + "' does not exist.");
}
return dirName;
}
File luceneDir = new File(homeDir, LUCENE_SUBDIRECTORY_NAME);
if (!luceneDir.exists()) {
boolean created = luceneDir.mkdir();
if (!created) {
throw new IOException(
"Unable to create Lucene index directory at '"
+ luceneDir + "'");
}
}
return luceneDir.getPath();
}
/**
* Gets the analyzer that will be used when building the indexing

View file

@ -94,17 +94,28 @@ public class UpdateUploadedFiles implements ServletContextListener {
+ "UpdateUploadedFiles?");
}
String uploadDirectoryName = ConfigurationProperties.getBean(ctx)
.getProperty(FileStorageSetup.PROPERTY_FILE_STORAGE_BASE_DIR);
if (uploadDirectoryName == null) {
String vitroHomeDirectoryName = ConfigurationProperties
.getBean(ctx).getProperty(
FileStorageSetup.PROPERTY_VITRO_HOME_DIR);
if (vitroHomeDirectoryName == null) {
throw new IllegalStateException("Upload directory name is null");
}
File uploadDirectory = new File(uploadDirectoryName);
if (!uploadDirectory.exists()) {
throw new IllegalStateException("Upload directory '"
+ uploadDirectory.getAbsolutePath()
File vitroHomeDirectory = new File(vitroHomeDirectoryName);
if (!vitroHomeDirectory.exists()) {
throw new IllegalStateException("Vitro home directory '"
+ vitroHomeDirectory.getAbsolutePath()
+ "' does not exist.");
}
File uploadDirectory = new File(vitroHomeDirectory,
FileStorageSetup.FILE_STORAGE_SUBDIRECTORY);
if (!uploadDirectory.exists()) {
uploadDirectory.mkdir();
if (!uploadDirectory.exists()) {
throw new IllegalStateException(
"Failed to create the file uploads directory: "
+ uploadDirectory.getAbsolutePath());
}
}
String vivoDefaultNamespace = ConfigurationProperties.getBean(ctx)
.getProperty(FileStorageSetup.PROPERTY_DEFAULT_NAMESPACE);

View file

@ -30,6 +30,7 @@ public class FileStorageSetupTest extends AbstractTestClass {
// ----------------------------------------------------------------------
private static File tempDir;
private static File vivoHomeDir;
private static File fsBaseDir;
private FileStorageSetup fss;
@ -50,7 +51,9 @@ public class FileStorageSetupTest extends AbstractTestClass {
@Before
public void createBaseDirectory() throws IOException {
tempDir = createTempDirectory("FileStorageFactoryTest");
fsBaseDir = new File(tempDir, "fsBaseDirectory");
vivoHomeDir = new File(tempDir, "fsBaseDirectory");
vivoHomeDir.mkdir();
fsBaseDir = new File(vivoHomeDir, FileStorageSetup.FILE_STORAGE_SUBDIRECTORY);
fsBaseDir.mkdir();
}
@ -85,7 +88,7 @@ public class FileStorageSetupTest extends AbstractTestClass {
@Test
public void defaultNamespaceNotSpecified() {
setLoggerLevel(FileStorageSetup.class, Level.OFF);
setConfigurationProperties(fsBaseDir.getPath(), null);
setConfigurationProperties(vivoHomeDir.getPath(), null);
fss.contextInitialized(sce);
assertNull("no default namespace",
sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME));
@ -95,7 +98,7 @@ public class FileStorageSetupTest extends AbstractTestClass {
@Test
public void defaultNamespaceIsBogus() {
setLoggerLevel(FileStorageSetup.class, Level.ERROR);
setConfigurationProperties(fsBaseDir.getPath(), "namespace");
setConfigurationProperties(vivoHomeDir.getPath(), "namespace");
fss.contextInitialized(sce);
Object o = sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME);
@ -107,7 +110,7 @@ public class FileStorageSetupTest extends AbstractTestClass {
@Test
public void success() {
setConfigurationProperties(fsBaseDir.getPath(),
setConfigurationProperties(vivoHomeDir.getPath(),
"http://vivo.myDomain.edu/individual/");
fss.contextInitialized(sce);
@ -127,7 +130,7 @@ public class FileStorageSetupTest extends AbstractTestClass {
ConfigurationPropertiesStub props = new ConfigurationPropertiesStub();
if (baseDir != null) {
props.setProperty(FileStorageSetup.PROPERTY_FILE_STORAGE_BASE_DIR,
props.setProperty(FileStorageSetup.PROPERTY_VITRO_HOME_DIR,
baseDir);
}
if (defaultNamespace != null) {