diff --git a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutopsyServiceProvider.java b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutopsyServiceProvider.java index 4635c584a8..889ee0b21d 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutopsyServiceProvider.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponentinterfaces/AutopsyServiceProvider.java @@ -117,7 +117,7 @@ public interface AutopsyServiceProvider { * * @param message Exception message. */ - AutopsyServiceProviderException(String message) { + public AutopsyServiceProviderException(String message) { super(message); } @@ -128,7 +128,7 @@ public interface AutopsyServiceProvider { * @param message Exception message. * @param throwable Exception cause. */ - AutopsyServiceProviderException(String message, Throwable throwable) { + public AutopsyServiceProviderException(String message, Throwable throwable) { super(message, throwable); } } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index 3f79b42f19..61c3694314 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -191,6 +191,8 @@ public class Server { private static final String KWS_OUTPUT_FOLDER_NAME = "keywordsearch"; private static final String KWS_DATA_FOLDER_NAME = "data"; private static final String INDEX_FOLDER_NAME = "index"; + private static final String CURRENT_SOLR_VERSION = "6"; + private static final String CURRENT_SOLR_SCHEMA_VERSION = "2.0"; public enum CORE_EVT_STATES { @@ -306,6 +308,14 @@ public class Server { int getCurrentSolrStopPort() { return currentSolrStopPort; } + + String getCurrentSolrVersion() { + return CURRENT_SOLR_VERSION; + } + + String getCurrentSchemaVersion() { + return CURRENT_SOLR_SCHEMA_VERSION; + } /** * Helper threads to handle stderr/stdout from Solr process @@ -731,17 +741,25 @@ public class Server { return indexDir; } + String findLatestIndexDataDir(Case theCase) { + String dataFolderName = "solr" + CURRENT_SOLR_VERSION + "_schema_" + CURRENT_SOLR_SCHEMA_VERSION; + return findIndexDataDir(theCase, dataFolderName); + } + + String findOldIndexDataDir(Case theCase) { + return findIndexDataDir(theCase, ""); + } /** - * Find index dir location for the case. This is done by doing a subdirectory + * Find index directory location for the case. This is done via subdirectory * search of all existing "ModuleOutput/node_name/keywordsearch/data/" folders. * * @param theCase the case to get index dir for * * @return absolute path to index dir */ - String findIndexDataDir(Case theCase) { - String indexDir = ""; + private List findIndexDataDir(Case theCase, String dataFolderName) { + ArrayList indexDirs = new ArrayList<>(); // look for existing index folder if (theCase.getCaseType() == CaseType.MULTI_USER_CASE) { // multi user cases contain a subfolder for each node that participated in case ingest or review. @@ -756,26 +774,28 @@ public class Server { continue; } // ELTODO is it possible that index is in a different location? what about new solr6 index? - String path = Paths.get(item.getAbsolutePath(), MODULE_OUTPUT, KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME).toString(); //NON-NLS + String path = Paths.get(item.getAbsolutePath(), MODULE_OUTPUT, KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, dataFolderName).toString(); //NON-NLS if (containsValidIndexFolder(path)) { - indexDir = path; - // ELTODO analyze possibilities of multiple indexes - break; // there should only be one index + indexDirs.add(path); + // there can be multiple index folders (e.g. current version and "old" version) so keep looking } } } else { - String path = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME).toString(); //NON-NLS + // single user case + String path = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, dataFolderName).toString(); //NON-NLS if (containsValidIndexFolder(path)) { - indexDir = path; + indexDirs.add(path); } } - // if we still did not find index then it is a new case + // did we find an index that requires an upgrade? if (indexDir.isEmpty()) { - indexDir = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME).toString(); //NON-NLS + return indexDir; + // ELTODO if we still did not find index then it is a new case + // ELTODO indexDir = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME).toString(); //NON-NLS } - // ELTODO do we still need this? + // ELTODO do we need to do this when searching for old index? if (uncPathUtilities != null) { // if we can check for UNC paths, do so, otherwise just return the indexDir String result = uncPathUtilities.mappedDriveToUNC(indexDir); @@ -864,7 +884,6 @@ public class Server { throw new KeywordSearchModuleException(NbBundle.getMessage(Server.class, "Server.connect.exception.msg"), ex); } - //String indexDir = findIndexDataDir(theCase); // ELTODO String dataDir = geCoreDataDirPath(theCase); String coreName = theCase.getTextIndexName(); return this.openCore(coreName.isEmpty() ? DEFAULT_CORE_NAME : coreName, new File(dataDir), theCase.getCaseType()); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java index ecbeefa98b..f1a0f3ca37 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java @@ -36,6 +36,8 @@ import org.sleuthkit.datamodel.SleuthkitCase; import org.openide.util.NbBundle; import java.net.InetAddress; import java.util.MissingResourceException; +import org.sleuthkit.autopsy.core.RuntimeProperties; +import org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyServiceProvider; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; /** @@ -43,7 +45,7 @@ import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchServiceException; * text indexing and search. */ @ServiceProvider(service = KeywordSearchService.class) -public class SolrSearchService implements KeywordSearchService { +public class SolrSearchService implements KeywordSearchService, AutopsyServiceProvider { private static final String BAD_IP_ADDRESS_FORMAT = "ioexception occurred when talking to server"; //NON-NLS private static final String SERVER_REFUSED_CONNECTION = "server refused connection"; //NON-NLS @@ -230,4 +232,76 @@ public class SolrSearchService implements KeywordSearchService { @Override public void close() throws IOException { } + + /** + * + * @param context + * + * @throws + * org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyServiceProvider.AutopsyServiceProviderException + */ + @Override + public void openCaseResources(Context context) throws AutopsyServiceProviderException { + /* + * Autopsy service providers may not have case-level resources. + */ + Server server = KeywordSearch.getServer(); + if (server.coreIsOpen() == false) { + throw new AutopsyServiceProviderException("ELTODO"); + } + + // do a case subdirectory search to check if latest index exists + + // do a case subdirectory search to check for the existence and upgrade status of cores + String indexDir = server.findLatestIndexDataDir(Case.getCurrentCase()); // ELTODO + + // check if index needs upgrade + boolean needsUpgrade = true; + + if (needsUpgrade && RuntimeProperties.coreComponentsAreActive()) { + //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 + boolean upgradeDeclined = true; + if (upgradeDeclined) { + throw new AutopsyServiceProviderException("ELTODO"); + } + } + + if (needsUpgrade) { + // ELTODO Check for cancellation at whatever points are feasible + + // Copy the contents (core) of ModuleOutput/keywordsearch/data/index into ModuleOutput/keywordsearch/data/solr6_schema_2.0/index + + // Make a “reference copy” of the configset and place it in ModuleOutput/keywordsearch/data/solr6_schema_2.0/configset + + // Run the upgrade tools on the contents (core) in ModuleOutput/keywordsearch/data/solr6_schema_2.0/index + + // Open the upgraded index + + // execute a test query + boolean success = true; + + if (!success) { + // delete the new directories + + // close the upgraded index? + + throw new AutopsyServiceProviderException("ELTODO"); + } + } + } + + /** + * + * @param context + * + * @throws + * org.sleuthkit.autopsy.corecomponentinterfaces.AutopsyServiceProvider.AutopsyServiceProviderException + */ + @Override + public void closeCaseResources(Context context) throws AutopsyServiceProviderException { + /* + * Autopsy service providers may not have case-level resources. + */ + } }