More work

This commit is contained in:
Eugene Livis 2017-01-17 16:30:10 -05:00
parent fc0fcfc3f1
commit 247b3c96aa
3 changed files with 76 additions and 31 deletions

View File

@ -28,7 +28,6 @@ import java.util.logging.Level;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService; import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
@ -74,6 +73,14 @@ class IndexFinder {
return ""; return "";
} }
static String createLatestVersionIndexDir(Case theCase) {
String indexFolderName = "solr" + CURRENT_SOLR_VERSION + "_schema_" + CURRENT_SOLR_SCHEMA_VERSION;
// new index should be stored in "\ModuleOutput\keywordsearch\data\solrX_schema_Y\index"
File targetDirPath = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, indexFolderName, INDEX_FOLDER_NAME).toFile(); //NON-NLS
targetDirPath.mkdirs();
return targetDirPath.getAbsolutePath();
}
String copyIndexAndConfigSet(Case theCase, String oldIndexDir) throws AutopsyService.AutopsyServiceException { String copyIndexAndConfigSet(Case theCase, String oldIndexDir) throws AutopsyService.AutopsyServiceException {
// Copy the "old" index into ModuleOutput/keywordsearch/data/solrX_schema_Y/index // Copy the "old" index into ModuleOutput/keywordsearch/data/solrX_schema_Y/index
String newIndexDir = createReferenceIndexCopy(theCase, oldIndexDir); String newIndexDir = createReferenceIndexCopy(theCase, oldIndexDir);

View File

@ -45,8 +45,6 @@ class Installer extends ModuleInstall {
//Setup the default KeywordSearch configuration files //Setup the default KeywordSearch configuration files
KeywordSearchSettings.setDefaults(); KeywordSearchSettings.setDefaults();
Case.addEventSubscriber(Case.Events.CURRENT_CASE.toString(), new KeywordSearch.CaseChangeListener());
final Server server = KeywordSearch.getServer(); final Server server = KeywordSearch.getServer();
try { try {
server.start(); server.start();

View File

@ -30,9 +30,11 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders; import org.openide.util.lookup.ServiceProviders;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.core.RuntimeProperties; import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService; import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;
@ -161,40 +163,62 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
List<String> indexDirs = indexFinder.findAllIndexDirs(context.getCase()); List<String> indexDirs = indexFinder.findAllIndexDirs(context.getCase());
// check if index needs upgrade // check if index needs upgrade
String schemaVer;
String currentVersionIndexDir = IndexFinder.findLatestVersionIndexDir(indexDirs); String currentVersionIndexDir = IndexFinder.findLatestVersionIndexDir(indexDirs);
if (currentVersionIndexDir.isEmpty()) { if (currentVersionIndexDir.isEmpty()) {
if (indexDirs.isEmpty()) {
// new case that doesn't have an existing index. create new index folder
currentVersionIndexDir = IndexFinder.createLatestVersionIndexDir(context.getCase());
schemaVer = IndexFinder.getCurrentSchemaVersion();
} else {
// ELTODO not sure what to do when there are multiple old indexes. grab the first one?
// ELTODO need to handle here a case where it is Solr 6 index but not latest schema
// ELTODO figure out the schema version of the "old" index
String oldIndexDir = indexDirs.get(0);
// ELTODO not sure what to do when there are multiple old indexes. grab the first one? if (RuntimeProperties.coreComponentsAreActive()) {
String oldIndexDir = indexDirs.get(0); //pop up a message box to indicate the restrictions on adding additional
//text and performing regex searches and give the user the option to decline the upgrade
if (RuntimeProperties.coreComponentsAreActive()) { if (!KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "SolrSearchService.IndexUpgradeDialog.title"),
//pop up a message box to indicate the restrictions on adding additional NbBundle.getMessage(this.getClass(), "SolrSearchService.IndexUpgradeDialog.msg"),
//text and performing regex searches and give the user the option to decline the upgrade KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) {
if (!KeywordSearchUtil.displayConfirmDialog(NbBundle.getMessage(this.getClass(), "SolrSearchService.IndexUpgradeDialog.title"), // upgrade declined - throw exception
NbBundle.getMessage(this.getClass(), "SolrSearchService.IndexUpgradeDialog.msg"), throw new AutopsyServiceException("Index upgrade was declined by user");
KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN)) { }
// upgrade declined - throw exception
throw new AutopsyServiceException("Index upgrade was declined by user");
} }
// ELTODO Check for cancellation at whatever points are feasible
// Copy the "old" index and config set into ModuleOutput/keywordsearch/data/solrX_schema_Y/
String newIndexDir = indexFinder.copyIndexAndConfigSet(context.getCase(), oldIndexDir);
// upgrade the "old" index to the latest supported Solr version
IndexUpgrader indexUpgrader = new IndexUpgrader();
indexUpgrader.performIndexUpgrade(newIndexDir, context.getCase().getTempDirectory());
// set the upgraded reference index as the index to be used for this case
currentVersionIndexDir = newIndexDir;
// schemaVer = ; // ELTODO
} }
} else {
// ELTODO Check for cancellation at whatever points are feasible // found index that is latest version of Solr and schema
schemaVer = IndexFinder.getCurrentSchemaVersion();
// Copy the "old" index and config set into ModuleOutput/keywordsearch/data/solrX_schema_Y/
String newIndexDir = indexFinder.copyIndexAndConfigSet(context.getCase(), oldIndexDir);
// upgrade the "old" index to the latest supported Solr version
IndexUpgrader indexUpgrader = new IndexUpgrader();
indexUpgrader.performIndexUpgrade(newIndexDir, context.getCase().getTempDirectory());
// set the upgraded reference index as the index to be used for this case
currentVersionIndexDir = newIndexDir;
} }
// open currentVersionIndexDir index // open core
try {
// ELTODO figure out the schema version of the core that's being opened
//KeywordSearch.getServer().openCoreForCase(context.getCase(), currentVersionIndexDir, schemaVer);
KeywordSearch.getServer().openCoreForCase(context.getCase());
} catch (Exception ex) {
logger.log(Level.SEVERE, String.format("Failed to open or create core for %s", context.getCase().getCaseDirectory()), ex); //NON-NLS
if (RuntimeProperties.coreComponentsAreActive()) {
MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getMessage());
}
}
// execute a test query // ELTODO execute a test query
// if failed, close the upgraded index? // ELTODO if failed, close the upgraded index?
} }
/** /**
@ -209,6 +233,22 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
/* /*
* Autopsy service providers may not have case-level resources. * Autopsy service providers may not have case-level resources.
*/ */
try {
KeywordSearchResultFactory.BlackboardResultWriter.stopAllWriters();
/*
* TODO (AUT-2084): The following code
* KeywordSearch.CaseChangeListener gambles that any
* BlackboardResultWriters (SwingWorkers) will complete
* in less than roughly two seconds
*/
Thread.sleep(2000);
KeywordSearch.getServer().closeCore();
} catch (Exception ex) {
logger.log(Level.SEVERE, String.format("Failed to close core for %s", context.getCase().getCaseDirectory()), ex); //NON-NLS
if (RuntimeProperties.coreComponentsAreActive()) {
MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification.msg"), ex.getMessage());
}
}
} }
@Override @Override