VIVO-958 Accommodate a migration directly from 1.5 data to 1.8

Move data directory from ontologies/update to version-specific directory ontologies/update17to18
Create ontologies/update15to16 and ontologies/update16to17 from previous update data directories.

Revise UpdateKnowledgeBase to accept the data directory as a parameter instead of having it hard-coded.
Create classes like Release18Migrator that will call UpdateKnowledgeBase with the appropriate directory, and do other release-specific migration tasks.

Make corresponding changes in startup_listeners.txt
This commit is contained in:
Jim Blake 2015-03-13 12:13:58 -04:00
parent d6a17ef0b6
commit 4b0cdadb0d
8 changed files with 91 additions and 42 deletions

View file

@ -0,0 +1,24 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.migration.rel16;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase;
/**
* Call UpdateKnowledgeBase; migrate from release 1.5 to release 1.6
*/
public class Release16Migrator implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
new UpdateKnowledgeBase("/WEB-INF/ontologies/update15to16/", this).contextInitialized(sce);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// Nothing to do
}
}

View file

@ -0,0 +1,28 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.migration.rel17;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase;
/**
* Call UpdateKnowledgeBase; migrate from release 1.6 to release 1.7
*
* Remove permissions that are no longer used.
*/
public class Release17Migrator implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
new UpdateKnowledgeBase("/WEB-INF/ontologies/update16to17/", this).contextInitialized(sce);
new RemoveObsoletePermissions().contextInitialized(sce);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// Nothing to do
}
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup; package edu.cornell.mannlib.vitro.webapp.migration.rel17;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.USER_ACCOUNTS; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.USER_ACCOUNTS;

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.migration; package edu.cornell.mannlib.vitro.webapp.migration.rel18;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createPlainLiteral; import static com.hp.hpl.jena.rdf.model.ResourceFactory.createPlainLiteral;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty; import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;

View file

@ -1,11 +1,13 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.migration; package edu.cornell.mannlib.vitro.webapp.migration.rel18;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase;
/** /**
* Handle the tasks that move an installation from 1.7 to 1.8. * Handle the tasks that move an installation from 1.7 to 1.8.
*/ */
@ -15,6 +17,8 @@ public class Release18Migrator implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
new UpdateKnowledgeBase("/WEB-INF/ontologies/update17to18/", this).contextInitialized(sce);
new FauxPropertiesUpdater(ctx, this).migrate(); new FauxPropertiesUpdater(ctx, this).migrate();
new RemoveObsoleteMetadataGraphs(ctx, this).migrate(); new RemoveObsoleteMetadataGraphs(ctx, this).migrate();
} }

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.migration; package edu.cornell.mannlib.vitro.webapp.migration.rel18;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT; import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;

View file

@ -44,7 +44,6 @@ import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils; import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess; import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess;
@ -58,26 +57,32 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
* @author bjl23 * @author bjl23
* *
*/ */
public class UpdateKnowledgeBase implements ServletContextListener { public class UpdateKnowledgeBase {
public static final String KBM_REQURIED_AT_STARTUP = "KNOWLEDGE_BASE_MIGRATION_REQUIRED_AT_STARTUP"; public static final String KBM_REQURIED_AT_STARTUP = "KNOWLEDGE_BASE_MIGRATION_REQUIRED_AT_STARTUP";
private final static Log log = LogFactory.getLog(UpdateKnowledgeBase.class); private final static Log log = LogFactory.getLog(UpdateKnowledgeBase.class);
private static final String DATA_DIR = "/WEB-INF/ontologies/update/"; private final String dataDir;
private static final String DIFF_FILE = DATA_DIR + "diff.tab.txt"; private final ServletContextListener parent;
private static final String ASK_QUERY_FILE = DATA_DIR + "askUpdated.sparql";
private static final String SUCCESS_ASSERTIONS_FILE = DATA_DIR + "success.n3"; public UpdateKnowledgeBase(String dataDir, ServletContextListener parent) {
private static final String OLD_TBOX_MODEL_DIR = DATA_DIR + "oldVersion/"; this.dataDir = dataDir;
private static final String OLD_TBOX_ANNOTATIONS_DIR = DATA_DIR + "oldAnnotations/"; this.parent = parent;
}
private String diffFile() { return dataDir + "diff.tab.txt"; }
private String askQueryFile() { return dataDir + "askUpdated.sparql"; }
private String successAssertionsFile() { return dataDir + "success.n3"; }
private String oldTBoxModelDir() { return dataDir + "oldVersion/"; }
private String oldTBoxAnnotationsDir() { return dataDir + "oldAnnotations/"; }
//For display model migration //For display model migration
private static final String OLD_DISPLAYMODEL_TBOX_PATH = DATA_DIR + "oldDisplayModel/displayTBOX.n3"; private String oldDisplayModelTBoxPath() { return dataDir + "oldDisplayModel/displayTBOX.n3"; }
private static final String NEW_DISPLAYMODEL_TBOX_PATH = "/WEB-INF/ontologies/app/menuload/displayTBOX.n3"; private static final String NEW_DISPLAYMODEL_TBOX_PATH = "/WEB-INF/ontologies/app/menuload/displayTBOX.n3";
private static final String OLD_DISPLAYMODEL_DISPLAYMETADATA_PATH = DATA_DIR + "oldDisplayModel/displayDisplay.n3"; private String oldDisplayModelDisplayMetadataPath() { return dataDir + "oldDisplayModel/displayDisplay.n3"; }
private static final String NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH = "/WEB-INF/ontologies/app/menuload/displayDisplay.n3"; private static final String NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH = "/WEB-INF/ontologies/app/menuload/displayDisplay.n3";
private static final String NEW_DISPLAYMODEL_PATH = "/WEB-INF/ontologies/app/menu.n3"; private static final String NEW_DISPLAYMODEL_PATH = "/WEB-INF/ontologies/app/menu.n3";
private static final String LOADED_STARTUPT_DISPLAYMODEL_DIR = "/WEB-INF/ontologies/app/loadedAtStartup/"; private static final String LOADED_STARTUPT_DISPLAYMODEL_DIR = "/WEB-INF/ontologies/app/loadedAtStartup/";
private static final String OLD_DISPLAYMODEL_VIVOLISTVIEW_PATH = DATA_DIR + "oldDisplayModel/vivoListViewConfig.rdf"; private String oldDisplayModelVivoListViewPath() { return dataDir + "oldDisplayModel/vivoListViewConfig.rdf"; }
@Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext(); ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx); StartupStatus ss = StartupStatus.getBean(ctx);
@ -101,14 +106,13 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setInferenceOntModelSelector(ModelAccess.on(ctx).getOntModelSelector(INFERENCES_ONLY)); settings.setInferenceOntModelSelector(ModelAccess.on(ctx).getOntModelSelector(INFERENCES_ONLY));
settings.setUnionOntModelSelector(ModelAccess.on(ctx).getOntModelSelector()); settings.setUnionOntModelSelector(ModelAccess.on(ctx).getOntModelSelector());
ConfigurationProperties props = ConfigurationProperties.getBean(ctx);
Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath(); Path homeDir = ApplicationUtils.instance().getHomeDirectory().getPath();
settings.setDisplayModel(ModelAccess.on(ctx).getOntModel(DISPLAY)); settings.setDisplayModel(ModelAccess.on(ctx).getOntModel(DISPLAY));
OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_MODEL_DIR)); OntModel oldTBoxModel = loadModelFromDirectory(ctx.getRealPath(oldTBoxModelDir()));
settings.setOldTBoxModel(oldTBoxModel); settings.setOldTBoxModel(oldTBoxModel);
OntModel newTBoxModel = loadModelFromDirectory(createDirectory(homeDir, "rdf", "tbox", "filegraph").toString()); OntModel newTBoxModel = loadModelFromDirectory(createDirectory(homeDir, "rdf", "tbox", "filegraph").toString());
settings.setNewTBoxModel(newTBoxModel); settings.setNewTBoxModel(newTBoxModel);
OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(OLD_TBOX_ANNOTATIONS_DIR)); OntModel oldTBoxAnnotationsModel = loadModelFromDirectory(ctx.getRealPath(oldTBoxAnnotationsDir()));
settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel); settings.setOldTBoxAnnotationsModel(oldTBoxAnnotationsModel);
OntModel newTBoxAnnotationsModel = loadModelFromDirectory(createDirectory(homeDir, "rdf", "tbox", "firsttime").toString()); OntModel newTBoxAnnotationsModel = loadModelFromDirectory(createDirectory(homeDir, "rdf", "tbox", "firsttime").toString());
settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel); settings.setNewTBoxAnnotationsModel(newTBoxAnnotationsModel);
@ -118,13 +122,13 @@ public class UpdateKnowledgeBase implements ServletContextListener {
try { try {
//Display model tbox and display metadata //Display model tbox and display metadata
//old display model tbox model //old display model tbox model
OntModel oldDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_TBOX_PATH)); OntModel oldDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(oldDisplayModelTBoxPath()));
settings.setOldDisplayModelTboxModel(oldDisplayModelTboxModel); settings.setOldDisplayModelTboxModel(oldDisplayModelTboxModel);
//new display model tbox model //new display model tbox model
OntModel newDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_TBOX_PATH)); OntModel newDisplayModelTboxModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_TBOX_PATH));
settings.setNewDisplayModelTboxModel(newDisplayModelTboxModel); settings.setNewDisplayModelTboxModel(newDisplayModelTboxModel);
//old display model display model metadata //old display model display model metadata
OntModel oldDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_DISPLAYMETADATA_PATH)); OntModel oldDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(oldDisplayModelDisplayMetadataPath()));
settings.setOldDisplayModelDisplayMetadataModel(oldDisplayModelDisplayMetadataModel); settings.setOldDisplayModelDisplayMetadataModel(oldDisplayModelDisplayMetadataModel);
//new display model display model metadata //new display model display model metadata
OntModel newDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH)); OntModel newDisplayModelDisplayMetadataModel = loadModelFromFile(ctx.getRealPath(NEW_DISPLAYMODEL_DISPLAYMETADATA_PATH));
@ -134,7 +138,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setNewDisplayModelFromFile(newDisplayModelFromFile); settings.setNewDisplayModelFromFile(newDisplayModelFromFile);
OntModel loadedAtStartupFiles = loadModelFromDirectory(ctx.getRealPath(LOADED_STARTUPT_DISPLAYMODEL_DIR)); OntModel loadedAtStartupFiles = loadModelFromDirectory(ctx.getRealPath(LOADED_STARTUPT_DISPLAYMODEL_DIR));
settings.setLoadedAtStartupDisplayModel(loadedAtStartupFiles); settings.setLoadedAtStartupDisplayModel(loadedAtStartupFiles);
OntModel oldDisplayModelVivoListView = loadModelFromFile(ctx.getRealPath(OLD_DISPLAYMODEL_VIVOLISTVIEW_PATH)); OntModel oldDisplayModelVivoListView = loadModelFromFile(ctx.getRealPath(oldDisplayModelVivoListViewPath()));
settings.setVivoListViewConfigDisplayModel(oldDisplayModelVivoListView); settings.setVivoListViewConfigDisplayModel(oldDisplayModelVivoListView);
} catch (ModelFileNotFoundException e) { } catch (ModelFileNotFoundException e) {
// expected if no display migration was intended // expected if no display migration was intended
@ -164,7 +168,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
// modified it // modified it
new ConfigurationModelsSetup().contextInitialized(sce); new ConfigurationModelsSetup().contextInitialized(sce);
} catch (Exception ioe) { } catch (Exception ioe) {
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", ioe); ss.fatal(parent, "Exception updating knowledge base for ontology changes: ", ioe);
} }
} }
@ -181,7 +185,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
} }
} catch (Throwable t){ } catch (Throwable t){
ss.fatal(this, "Exception updating knowledge base for ontology changes: ", t); ss.fatal(parent, "Exception updating knowledge base for ontology changes: ", t);
} }
} }
@ -193,11 +197,11 @@ public class UpdateKnowledgeBase implements ServletContextListener {
* Set the paths for the files that specify how to perform the update * Set the paths for the files that specify how to perform the update
*/ */
private void putNonReportingPathsIntoSettings(ServletContext ctx, UpdateSettings settings) { private void putNonReportingPathsIntoSettings(ServletContext ctx, UpdateSettings settings) {
settings.setAskUpdatedQueryFile(ctx.getRealPath(ASK_QUERY_FILE)); settings.setAskUpdatedQueryFile(ctx.getRealPath(askQueryFile()));
settings.setDiffFile(ctx.getRealPath(DIFF_FILE)); settings.setDiffFile(ctx.getRealPath(diffFile()));
settings.setSparqlConstructAdditionsDir(ctx.getRealPath(DATA_DIR + "sparqlConstructs/additions")); settings.setSparqlConstructAdditionsDir(ctx.getRealPath(dataDir + "sparqlConstructs/additions"));
settings.setSparqlConstructDeletionsDir(ctx.getRealPath(DATA_DIR + "sparqlConstructs/deletions")); settings.setSparqlConstructDeletionsDir(ctx.getRealPath(dataDir + "sparqlConstructs/deletions"));
settings.setSuccessAssertionsFile(ctx.getRealPath(SUCCESS_ASSERTIONS_FILE)); settings.setSuccessAssertionsFile(ctx.getRealPath(successAssertionsFile()));
settings.setSuccessRDFFormat("N3"); settings.setSuccessRDFFormat("N3");
} }
@ -210,7 +214,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
Path dataDir = createDirectory(homeDir, "upgrade", "knowledgeBase"); Path dataDir = createDirectory(homeDir, "upgrade", "knowledgeBase");
settings.setDataDir(dataDir.toString()); settings.setDataDir(dataDir.toString());
StartupStatus.getBean(ctx).info(this, "Updating knowledge base: reports are in '" + dataDir + "'"); StartupStatus.getBean(ctx).info(parent, "Updating knowledge base: reports are in '" + dataDir + "'");
Path changedDir = createDirectory(dataDir, "changedData"); Path changedDir = createDirectory(dataDir, "changedData");
settings.setAddedDataFile(changedDir.resolve(timestampedFileName("addedData", "n3")).toString()); settings.setAddedDataFile(changedDir.resolve(timestampedFileName("addedData", "n3")).toString());
@ -220,7 +224,7 @@ public class UpdateKnowledgeBase implements ServletContextListener {
settings.setLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate", "log")).toString()); settings.setLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate", "log")).toString());
settings.setErrorLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate.error", "log")).toString()); settings.setErrorLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate.error", "log")).toString());
Path qualifiedPropertyConfigFile = getFilePath(homeDir, "rdf", "display", "everytime", "PropertyConfig.n3"); Path qualifiedPropertyConfigFile = getFilePath(homeDir, "rdf", "display", "firsttime", "PropertyConfig.n3");
settings.setQualifiedPropertyConfigFile(qualifiedPropertyConfigFile.toString()); settings.setQualifiedPropertyConfigFile(qualifiedPropertyConfigFile.toString());
} }
@ -587,11 +591,6 @@ public class UpdateKnowledgeBase implements ServletContextListener {
} }
} }
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// nothing to do
}
private static String timestampedFileName(String prefix, String suffix) { private static String timestampedFileName(String prefix, String suffix) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-sss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-sss");
return prefix + "." + sdf.format(new Date()) + "." + suffix; return prefix + "." + sdf.format(new Date()) + "." + suffix;

View file

@ -26,17 +26,11 @@ edu.cornell.mannlib.vitro.webapp.servlet.setup.ContentModelSetup
edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil$Setup edu.cornell.mannlib.vitro.webapp.web.images.PlaceholderUtil$Setup
# Some permissions were removed in release 1.7
edu.cornell.mannlib.vitro.webapp.servlet.setup.RemoveObsoletePermissions
edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup
edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$ReasonersSetup edu.cornell.mannlib.vitro.webapp.application.ApplicationImpl$ReasonersSetup
edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup
#edu.cornell.mannlib.vitro.webapp.servlet.setup.UpdateKnowledgeBase
edu.cornell.mannlib.vitro.webapp.migration.Release18Migrator
# Must run after JenaDataSourceSetup # Must run after JenaDataSourceSetup
edu.cornell.mannlib.vitro.webapp.servlet.setup.ThemeInfoSetup edu.cornell.mannlib.vitro.webapp.servlet.setup.ThemeInfoSetup