From 92e3dd26a4ef4455a8c8678d60b27e830c46eb13 Mon Sep 17 00:00:00 2001 From: Eamonn Saunders Date: Thu, 25 Jun 2015 12:48:56 -0400 Subject: [PATCH] Added KeywordSearchService.canConnectToRemoteSolr() method and updated CollaborationMonitor to use it. --- .../casemodule/CollaborationMonitor.java | 45 ++++++++----------- .../KeywordSearchService.java | 6 +++ .../autopsy/keywordsearch/Server.java | 2 +- .../keywordsearch/SolrSearchService.java | 17 +++++++ 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CollaborationMonitor.java b/Core/src/org/sleuthkit/autopsy/casemodule/CollaborationMonitor.java index 5626942e83..62e87d3a73 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CollaborationMonitor.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CollaborationMonitor.java @@ -57,6 +57,7 @@ import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo; import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisCompletedEvent; import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisStartedEvent; +import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.datamodel.CaseDbConnectionInfo; /** @@ -525,7 +526,7 @@ final class CollaborationMonitor { private final static class CrashDetectionTask implements Runnable { private static boolean dbServerIsRunning = true; -// private static boolean solrServerIsRunning = true; + private static boolean solrServerIsRunning = true; private static boolean messageServerIsRunning = true; private static final Object lock = new Object(); @@ -550,31 +551,23 @@ final class CollaborationMonitor { } } - /** - * TODO: Figure out what is wrong with this code. The call to - * construct the HttpSolrServer object never returns. Perhaps - * this is the result of a dependency of the solr-solrj-4.91.jar - * that is not satisfied. Removing the jar from wrapped jars for - * now. - */ -// try { -// String host = UserPreferences.getIndexingServerHost(); -// String port = UserPreferences.getIndexingServerPort(); -// HttpSolrServer solr = new HttpSolrServer("http://" + host + ":" + port + "/solr"); //NON-NLS -// CoreAdminRequest.getStatus(Case.getCurrentCase().getTextIndexName(), solr); -// if (!solrServerIsRunning) { -// solrServerIsRunning = true; -// logger.log(Level.INFO, "Connection to Solr server restored"); //NON-NLS -// MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title", SERVICE_MSG_DATE_FORMAT.format(new Date())), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredSolrService.notify.msg")); -// } -// } catch (SolrServerException | IOException ex) { -// if (solrServerIsRunning) { -// solrServerIsRunning = false; -// logger.log(Level.SEVERE, "Failed to connect to Solr server", ex); //NON-NLS -// MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title", SERVICE_MSG_DATE_FORMAT.format(new Date())), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedSolrService.notify.msg")); -// } -// } -// + KeywordSearchService kwsService = Case.getCurrentCase().getServices().getKeywordSearchService(); + + if (kwsService.canConnectToRemoteSolrServer()) { + if (!solrServerIsRunning) { + solrServerIsRunning = true; + logger.log(Level.INFO, "Connection to Solr server restored"); //NON-NLS + MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title", SERVICE_MSG_DATE_FORMAT.format(new Date())), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredSolrService.notify.msg")); + } + } + else { + if (solrServerIsRunning) { + solrServerIsRunning = false; + logger.log(Level.SEVERE, "Failed to connect to Solr server"); //NON-NLS + MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title", SERVICE_MSG_DATE_FORMAT.format(new Date())), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedSolrService.notify.msg")); + } + } + MessageServiceConnectionInfo msgInfo = UserPreferences.getMessageServiceConnectionInfo(); try { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(msgInfo.getUserName(), msgInfo.getPassword(), msgInfo.getURI()); diff --git a/Core/src/org/sleuthkit/autopsy/keywordsearchservice/KeywordSearchService.java b/Core/src/org/sleuthkit/autopsy/keywordsearchservice/KeywordSearchService.java index c14adbb0bb..e4c15e8721 100644 --- a/Core/src/org/sleuthkit/autopsy/keywordsearchservice/KeywordSearchService.java +++ b/Core/src/org/sleuthkit/autopsy/keywordsearchservice/KeywordSearchService.java @@ -35,4 +35,10 @@ public interface KeywordSearchService extends Closeable { * @throws org.sleuthkit.datamodel.TskCoreException */ public void indexArtifact(BlackboardArtifact artifact) throws TskCoreException; + + /** + * Are we able to connect to the remote Solr server. + * @return true if we can connect, otherwise false + */ + public boolean canConnectToRemoteSolrServer(); } diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java index 2f6997be76..49a62021a0 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/Server.java @@ -984,7 +984,7 @@ public class Server { } } - private HttpSolrServer connectToRemoteSolrServer() { + HttpSolrServer connectToRemoteSolrServer() { String host = UserPreferences.getIndexingServerHost(); String port = UserPreferences.getIndexingServerPort(); diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java index 061a7f872d..51d2e3ebbe 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/SolrSearchService.java @@ -20,11 +20,15 @@ package org.sleuthkit.autopsy.keywordsearch; import java.io.IOException; import java.util.HashMap; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.HttpSolrServer; +import org.apache.solr.client.solrj.request.CoreAdminRequest; import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.apache.solr.common.util.ContentStreamBase.StringStream; +import org.openide.util.Exceptions; import org.openide.util.lookup.ServiceProvider; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.datamodel.ContentUtils; @@ -145,6 +149,19 @@ public class SolrSearchService implements KeywordSearchService { } } + @Override + public boolean canConnectToRemoteSolrServer() { + try { + HttpSolrServer solrServer = KeywordSearch.getServer().connectToRemoteSolrServer(); + CoreAdminRequest.getStatus(null, solrServer); + } + catch (SolrServerException | IOException ex) { + return false; + } + + return true; + } + @Override public void close() throws IOException { }