diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties index 44d28244e724d75a26a214abf1154a9f97ca916f..44e1664d25b3b657898c9bab34c6e8fab32e055a 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Bundle.properties @@ -223,7 +223,7 @@ Server.query2.exception.msg=Error running query\: {0} Server.queryTerms.exception.msg=Error running terms query\: {0} Server.connect.exception.msg=Failed to connect to Solr server\: Server.openCore.exception.msg=Keyword search service not yet running -Server.openCore.exception.cantOpen.msg=Could not open index +Server.openCore.exception.cantOpen.msg=Could not create or open index Server.openCore.exception.noIndexDir.msg=Index directory could not be created or is missing Server.request.exception.exception.msg=Could not issue Solr request Server.commit.exception.msg=Could not commit index diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/DropdownToolbar.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/DropdownToolbar.java index 7752adede93658e8e11e28c045baae99d4caea56..7c24b99337d5d0be1ecc7c7d49a497df67c42911 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/DropdownToolbar.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/DropdownToolbar.java @@ -223,7 +223,7 @@ public void propertyChange(PropertyChangeEvent evt) { String changed = evt.getPropertyName(); if (changed.equals(Case.Events.CURRENT_CASE.toString())) { dropPanel.resetSearchBox(); - setFields(null != evt.getNewValue() && RuntimeProperties.coreComponentsAreActive() && KeywordSearch.getServer().coreIsOpen()); + setFields(null != evt.getNewValue() && RuntimeProperties.coreComponentsAreActive()); } else if (changed.equals(Server.CORE_EVT)) { final Server.CORE_EVT_STATES state = (Server.CORE_EVT_STATES) evt.getNewValue(); switch (state) { diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearch.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearch.java index ed6c4621de6444d5b45901d348958b787b1ed59c..9c276115cebfa4c1aeee63397d4fe677ef96975c 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearch.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearch.java @@ -126,7 +126,7 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (Exception ex) { String caseName = closedCase.getName(); logger.log(Level.SEVERE, String.format("Failed to close core for %s", caseName), ex); - MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification..msg"), ex.getCause().getMessage()); + MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification.msg"), ex.getMessage()); } } if (null != evt.getNewValue()) { @@ -136,7 +136,7 @@ public void propertyChange(PropertyChangeEvent evt) { } catch (Exception ex) { String caseName = openedCase.getName(); logger.log(Level.SEVERE, String.format("Failed to open or create core for %s", caseName), ex); - MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getCause().getMessage()); + MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getMessage()); } } } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index dab7248f599e364bccdc7b1b0b3ee0e33ae2c44f..7696b67318ce4d34be6a80cd2a3568495219913a 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -169,7 +169,6 @@ public String toString() { private int currentSolrStopPort = 0; private static final boolean DEBUG = false;//(Version.getBuildType() == Version.Type.DEVELOPMENT); private final UNCPathUtilities uncPathUtilities = new UNCPathUtilities(); - private static final String INDEX_DIR_NAME = "index"; public enum CORE_EVT_STATES { @@ -684,13 +683,11 @@ private Core openCore(Case theCase) throws KeywordSearchModuleException { } else { String host = UserPreferences.getIndexingServerHost(); String port = UserPreferences.getIndexingServerPort(); - currentSolrServer = new HttpSolrServer("http://" + host + ":" + port + "/solr"); //NON-NLS } connectToSolrServer(currentSolrServer); } catch (SolrServerException | IOException ex) { - MessageNotifyUtil.Notify.error(NbBundle.getMessage(Server.class, "Server.connect.exception.msg"), ex.getCause().getMessage()); - throw new KeywordSearchModuleException(NbBundle.getMessage(Server.class, "Server.connect.exception.msg")); + throw new KeywordSearchModuleException(NbBundle.getMessage(Server.class, "Server.connect.exception.msg"), ex); } String dataDir = getIndexDirPath(theCase); @@ -1068,7 +1065,7 @@ private Core openCore(String coreName, File dataDir, CaseType caseType) throws K NbBundle.getMessage(this.getClass(), "Server.openCore.exception.msg")); } - if (!isCoreLoaded(coreName)) { + if (!coreExistsOnServer(coreName)) { CoreAdminRequest.Create createCoreRequest = new CoreAdminRequest.Create(); createCoreRequest.setDataDir(dataDir.getAbsolutePath()); createCoreRequest.setCoreName(coreName); @@ -1078,12 +1075,9 @@ private Core openCore(String coreName, File dataDir, CaseType caseType) throws K currentSolrServer.request(createCoreRequest); } - // TODO (RC): This check only works for single-user cases. For multi-user cases - // the path from the case metadata file needs to be checked. -// File indexDir = Paths.get(dataDir.getAbsolutePath(), INDEX_DIR_NAME).toFile(); -// if (!indexDir.exists()) { -// throw new IOException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg")); -// } + if (!coreIndexFolderExists(coreName)) { + throw new KeywordSearchModuleException(NbBundle.getMessage(this.getClass(), "Server.openCore.exception.noIndexDir.msg")); + } return new Core(coreName, caseType); @@ -1106,20 +1100,42 @@ void connectToSolrServer(HttpSolrServer solrServer) throws SolrServerException, } /** - * Determines whether the Solr core with the given name already exists. + * Determines whether or not a Solr core instance exists on the current Solr + * server. * - * @param coreName + * @param coreName the name of the core. * - * @return true if core exists, otherwise false. + * @return true or false. * * @throws SolrServerException * @throws IOException */ - private boolean isCoreLoaded(String coreName) throws SolrServerException, IOException { + private boolean coreExistsOnServer(String coreName) throws SolrServerException, IOException { CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, currentSolrServer); return response.getCoreStatus(coreName).get("instanceDir") != null; //NON-NLS } + /** + * Determines whether or not the index files folder for a Solr core exists. + * + * @param coreName the name of the core. + * + * @return true or false + * + * @throws SolrServerException + * @throws IOException + */ + private boolean coreIndexFolderExists(String coreName) throws SolrServerException, IOException { + CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, currentSolrServer); + Object dataDirPath = response.getCoreStatus(coreName).get("dataDir"); //NON-NLS + if (null != dataDirPath) { + File indexDir = Paths.get((String)dataDirPath, "index").toFile(); //NON-NLS + return indexDir.exists(); + } else { + return false; + } + } + class Core { // handle to the core in Solr