Added KeywordSearchService.canConnectToRemoteSolr() method and updated CollaborationMonitor to use it.

This commit is contained in:
Eamonn Saunders 2015-06-25 12:48:56 -04:00
parent 641e33cf51
commit 92e3dd26a4
4 changed files with 43 additions and 27 deletions

View File

@ -57,6 +57,7 @@ import org.sleuthkit.autopsy.events.MessageServiceConnectionInfo;
import org.sleuthkit.autopsy.ingest.IngestManager; import org.sleuthkit.autopsy.ingest.IngestManager;
import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisCompletedEvent; import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisCompletedEvent;
import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisStartedEvent; import org.sleuthkit.autopsy.ingest.events.DataSourceAnalysisStartedEvent;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.datamodel.CaseDbConnectionInfo; import org.sleuthkit.datamodel.CaseDbConnectionInfo;
/** /**
@ -525,7 +526,7 @@ final class CollaborationMonitor {
private final static class CrashDetectionTask implements Runnable { private final static class CrashDetectionTask implements Runnable {
private static boolean dbServerIsRunning = true; private static boolean dbServerIsRunning = true;
// private static boolean solrServerIsRunning = true; private static boolean solrServerIsRunning = true;
private static boolean messageServerIsRunning = true; private static boolean messageServerIsRunning = true;
private static final Object lock = new Object(); private static final Object lock = new Object();
@ -550,31 +551,23 @@ final class CollaborationMonitor {
} }
} }
/** KeywordSearchService kwsService = Case.getCurrentCase().getServices().getKeywordSearchService();
* TODO: Figure out what is wrong with this code. The call to
* construct the HttpSolrServer object never returns. Perhaps if (kwsService.canConnectToRemoteSolrServer()) {
* this is the result of a dependency of the solr-solrj-4.91.jar if (!solrServerIsRunning) {
* that is not satisfied. Removing the jar from wrapped jars for solrServerIsRunning = true;
* now. 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"));
// try { }
// String host = UserPreferences.getIndexingServerHost(); }
// String port = UserPreferences.getIndexingServerPort(); else {
// HttpSolrServer solr = new HttpSolrServer("http://" + host + ":" + port + "/solr"); //NON-NLS if (solrServerIsRunning) {
// CoreAdminRequest.getStatus(Case.getCurrentCase().getTextIndexName(), solr); solrServerIsRunning = false;
// if (!solrServerIsRunning) { logger.log(Level.SEVERE, "Failed to connect to Solr server"); //NON-NLS
// solrServerIsRunning = true; 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"));
// 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"));
// }
// }
//
MessageServiceConnectionInfo msgInfo = UserPreferences.getMessageServiceConnectionInfo(); MessageServiceConnectionInfo msgInfo = UserPreferences.getMessageServiceConnectionInfo();
try { try {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(msgInfo.getUserName(), msgInfo.getPassword(), msgInfo.getURI()); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(msgInfo.getUserName(), msgInfo.getPassword(), msgInfo.getURI());

View File

@ -35,4 +35,10 @@ public interface KeywordSearchService extends Closeable {
* @throws org.sleuthkit.datamodel.TskCoreException * @throws org.sleuthkit.datamodel.TskCoreException
*/ */
public void indexArtifact(BlackboardArtifact artifact) throws 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();
} }

View File

@ -984,7 +984,7 @@ public class Server {
} }
} }
private HttpSolrServer connectToRemoteSolrServer() { HttpSolrServer connectToRemoteSolrServer() {
String host = UserPreferences.getIndexingServerHost(); String host = UserPreferences.getIndexingServerHost();
String port = UserPreferences.getIndexingServerPort(); String port = UserPreferences.getIndexingServerPort();

View File

@ -20,11 +20,15 @@ package org.sleuthkit.autopsy.keywordsearch;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; 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.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.apache.solr.common.util.ContentStreamBase.StringStream; import org.apache.solr.common.util.ContentStreamBase.StringStream;
import org.openide.util.Exceptions;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.datamodel.ContentUtils; 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 @Override
public void close() throws IOException { public void close() throws IOException {
} }