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" /> message="${deploy.properties.file} must contain a value for tomcat.home" />
<fail unless="webapp.name" <fail unless="webapp.name"
message="${deploy.properties.file} must contain a value for webapp.name" /> message="${deploy.properties.file} must contain a value for webapp.name" />
<fail unless="upload.directory" <fail unless="vitro.home.directory"
message="${deploy.properties.file} must contain a value for upload.directory" /> message="${deploy.properties.file} must contain a value for vitro.home.directory" />
<fail unless="LuceneSetup.indexDir"
message="${deploy.properties.file} must contain a value for LuceneSetup.indexDir" />
<fail unless="Vitro.defaultNamespace" <fail unless="Vitro.defaultNamespace"
message="${deploy.properties.file} must contain a value for Vitro.defaultNamespace" /> message="${deploy.properties.file} must contain a value for Vitro.defaultNamespace" />
<fail unless="Vitro.smtpHost" <fail unless="Vitro.smtpHost"

View file

@ -32,17 +32,10 @@ tomcat.home = /usr/local/tomcat
webapp.name = vitro webapp.name = vitro
# #
# The location where the VIVO application will store uploaded files # The location where the VIVO application will store the data that it creates.
# (usually images). You should arrange for these files to be backed up in some # This includes uploaded files (usually images) and the Lucene search index.
# way.
# #
upload.directory = /usr/local/vivo/data/uploads vitro.home.directory = /usr/local/vivo/data
#
# The location where the VIVO application will create its Lucene search
# index.
#
LuceneSetup.indexDir = /usr/local/vivo/data/luceneIndex
# #
# SMTP host which the "Contact Us" form can use to send mail. If this is left # 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; package edu.cornell.mannlib.vitro.webapp.filestorage.backend;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -30,9 +31,11 @@ public class FileStorageSetup implements ServletContextListener {
/** /**
* The default implementation will use this key to ask * 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 * 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}. * For use by the constructor in implementations of {@link FileStorage}.
*/ */
private File figureBaseDir(ServletContextEvent sce) { private File figureBaseDir(ServletContextEvent sce) throws IOException {
String baseDirPath = ConfigurationProperties.getBean(sce) String homeDirPath = ConfigurationProperties.getBean(sce)
.getProperty(PROPERTY_FILE_STORAGE_BASE_DIR); .getProperty(PROPERTY_VITRO_HOME_DIR);
if (baseDirPath == null) { if (homeDirPath == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Configuration properties must contain a value for '" "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.ALLTEXT;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.ALLTEXTUNSTEMMED; 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.CLASSLOCALNAME;
import static edu.cornell.mannlib.vitro.webapp.search.lucene.Entity2LuceneDoc.VitroLuceneTermNames.CLASSLOCALNAMELOWERCASE; 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.File;
import java.io.IOException; import java.io.IOException;
@ -25,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.PerFieldAnalyzerWrapper; import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
@ -72,6 +70,9 @@ import edu.cornell.mannlib.vitro.webapp.servlet.setup.AbortStartup;
public class LuceneSetup implements javax.servlet.ServletContextListener { 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 * Gets run to set up DataSource when the webapp servlet context gets
* created. * created.
@ -196,36 +197,42 @@ public class LuceneSetup implements javax.servlet.ServletContextListener {
/** /**
* Gets the name of the directory to store the lucene index in. The * Gets the name of the directory to store the lucene index in. The
* {@link ConfigurationProperties} should have a property named * {@link ConfigurationProperties} should have a property named
* 'LuceneSetup.indexDir' which has the directory to store the lucene index * 'vitro.home.directory' which has the parent directory of the directory to
* for this clone in. If the property is not found, an exception will be * store the lucene index for this clone in. If the property is not found,
* thrown. * an exception will be thrown.
* *
* @return a string that is the directory to store the lucene index. * @return a string that is the directory to store the lucene index.
* @throws IllegalStateException * @throws IllegalStateException
* if the property is not found. * if the property is not found, or if the home directory does
* not exist.
* @throws IOException * @throws IOException
* if the directory doesn't exist and we fail to create it. * if the directory doesn't exist and we fail to create it.
*/ */
private String getBaseIndexDirName(ServletContext ctx) private String getBaseIndexDirName(ServletContext ctx) throws IOException {
throws IOException { String homeDirName = ConfigurationProperties.getBean(ctx).getProperty(
String dirName = ConfigurationProperties.getBean(ctx) PROPERTY_VITRO_HOME);
.getProperty("LuceneSetup.indexDir"); if (homeDirName == null) {
if (dirName == null) { throw new IllegalStateException(PROPERTY_VITRO_HOME
throw new IllegalStateException( + " not found in properties file.");
"LuceneSetup.indexDir not found in properties file.");
} }
File dir = new File(dirName); File homeDir = new File(homeDirName);
if (!dir.exists()) { if (!homeDir.exists()) {
boolean created = dir.mkdir(); 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) { if (!created) {
throw new IOException( 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

@ -57,6 +57,8 @@ import edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder;
public class LuceneSetupCJK implements javax.servlet.ServletContextListener { 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 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. * Gets run to set up DataSource when the webapp servlet context gets created.
@ -152,36 +154,42 @@ public class LuceneSetupCJK implements javax.servlet.ServletContextListener {
/** /**
* Gets the name of the directory to store the lucene index in. The * Gets the name of the directory to store the lucene index in. The
* {@link ConfigurationProperties} should have a property named * {@link ConfigurationProperties} should have a property named
* 'LuceneSetup.indexDir' which has the directory to store the lucene index * 'vitro.home.directory' which has the parent directory of the directory to
* for this clone in. If the property is not found, an exception will be * store the lucene index for this clone in. If the property is not found,
* thrown. * an exception will be thrown.
* *
* @return a string that is the directory to store the lucene index. * @return a string that is the directory to store the lucene index.
* @throws IllegalStateException * @throws IllegalStateException
* if the property is not found. * if the property is not found,
* or if the home directory does not exist.
* @throws IOException * @throws IOException
* if the directory doesn't exist and we fail to create it. * if the directory doesn't exist and we fail to create it.
*/ */
private String getIndexDirName(ServletContextEvent sce) private String getIndexDirName(ServletContextEvent cte) throws IOException {
throws IOException { String homeDirName = ConfigurationProperties.getBean(cte).getProperty(
String dirName = ConfigurationProperties.getBean(sce) PROPERTY_VITRO_HOME);
.getProperty("LuceneSetup.indexDir"); if (homeDirName == null) {
if (dirName == null) { throw new IllegalStateException(PROPERTY_VITRO_HOME
throw new IllegalStateException( + " not found in properties file.");
"LuceneSetup.indexDir not found in properties file.");
} }
File dir = new File(dirName); File homeDir = new File(homeDirName);
if (!dir.exists()) { if (!homeDir.exists()) {
boolean created = dir.mkdir(); 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) { if (!created) {
throw new IOException( 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

@ -94,17 +94,28 @@ public class UpdateUploadedFiles implements ServletContextListener {
+ "UpdateUploadedFiles?"); + "UpdateUploadedFiles?");
} }
String uploadDirectoryName = ConfigurationProperties.getBean(ctx) String vitroHomeDirectoryName = ConfigurationProperties
.getProperty(FileStorageSetup.PROPERTY_FILE_STORAGE_BASE_DIR); .getBean(ctx).getProperty(
if (uploadDirectoryName == null) { FileStorageSetup.PROPERTY_VITRO_HOME_DIR);
if (vitroHomeDirectoryName == null) {
throw new IllegalStateException("Upload directory name is null"); throw new IllegalStateException("Upload directory name is null");
} }
File uploadDirectory = new File(uploadDirectoryName); File vitroHomeDirectory = new File(vitroHomeDirectoryName);
if (!uploadDirectory.exists()) { if (!vitroHomeDirectory.exists()) {
throw new IllegalStateException("Upload directory '" throw new IllegalStateException("Vitro home directory '"
+ uploadDirectory.getAbsolutePath() + vitroHomeDirectory.getAbsolutePath()
+ "' does not exist."); + "' 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) String vivoDefaultNamespace = ConfigurationProperties.getBean(ctx)
.getProperty(FileStorageSetup.PROPERTY_DEFAULT_NAMESPACE); .getProperty(FileStorageSetup.PROPERTY_DEFAULT_NAMESPACE);

View file

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