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.Pattern;
import org.apache.commons.io.FileUtils;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -74,6 +73,14 @@ class IndexFinder {
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 {
// Copy the "old" index into ModuleOutput/keywordsearch/data/solrX_schema_Y/index
String newIndexDir = createReferenceIndexCopy(theCase, oldIndexDir);

View File

@ -45,8 +45,6 @@ class Installer extends ModuleInstall {
//Setup the default KeywordSearch configuration files
KeywordSearchSettings.setDefaults();
Case.addEventSubscriber(Case.Events.CURRENT_CASE.toString(), new KeywordSearch.CaseChangeListener());
final Server server = KeywordSearch.getServer();
try {
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.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyService;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException;
import org.sleuthkit.datamodel.BlackboardArtifact;
@ -161,10 +163,17 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
List<String> indexDirs = indexFinder.findAllIndexDirs(context.getCase());
// check if index needs upgrade
String schemaVer;
String currentVersionIndexDir = IndexFinder.findLatestVersionIndexDir(indexDirs);
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);
if (RuntimeProperties.coreComponentsAreActive()) {
@ -189,12 +198,27 @@ public class SolrSearchService implements KeywordSearchService, AutopsyService
// set the upgraded reference index as the index to be used for this case
currentVersionIndexDir = newIndexDir;
// schemaVer = ; // ELTODO
}
} else {
// found index that is latest version of Solr and schema
schemaVer = IndexFinder.getCurrentSchemaVersion();
}
// 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
// if failed, close the upgraded index?
// ELTODO execute a test query
// 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.
*/
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