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.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());

View File

@ -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();
}

View File

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

View File

@ -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 {
}