setServiceStatus() is public again, changes based on review

This commit is contained in:
Eugene Livis 2015-07-20 15:54:51 -04:00
parent c4d7f1533b
commit 87d71870aa
3 changed files with 98 additions and 60 deletions

View File

@ -12,12 +12,12 @@ org_sleuthkit_autopsy_core_update_center=http://sleuthkit.org/autopsy/updates.xm
Services/AutoupdateType/org_sleuthkit_autopsy_core_update_center.settings=Autopsy Update Center Services/AutoupdateType/org_sleuthkit_autopsy_core_update_center.settings=Autopsy Update Center
Installer.errorInitJavafx.msg=Error initializing JavaFX. Installer.errorInitJavafx.msg=Error initializing JavaFX.
Installer.errorInitJavafx.details=\ Some features will not be available. Check that you have the right JRE installed (Oracle JRE > 1.7.10). Installer.errorInitJavafx.details=\ Some features will not be available. Check that you have the right JRE installed (Oracle JRE > 1.7.10).
ServicesMonitor.failedService.notify.title=Collaboration Service Failed ServicesMonitor.failedService.notify.title=Service Failed
ServicesMonitor.failedService.notify.msg=Lost connection to {0} ServicesMonitor.failedService.notify.msg=Lost connection to {0}
ServicesMonitor.restoredService.notify.title=Collaboration Service Restored ServicesMonitor.restoredService.notify.title=Service Restored
ServicesMonitor.restoredService.notify.msg=Connection to {0} restored ServicesMonitor.restoredService.notify.msg=Connection to {0} restored
ServicesMonitor.statusChange.notify.title=Collaboration Service Status Change ServicesMonitor.statusChange.notify.title=Service Status Update
ServicesMonitor.statusChange.notify.msg=Status for {0} changed to {1} ServicesMonitor.statusChange.notify.msg=Status for {0} is {1}
ServicesMonitor.nullServiceName.excepton.txt=Requested service name is null ServicesMonitor.nullServiceName.excepton.txt=Requested service name is null
ServicesMonitor.nullStatusOrDetails.excepton.txt=Status or details string is null ServicesMonitor.nullStatusOrDetails.excepton.txt=Status or details string is null
ServicesMonitor.unknownServiceName.excepton.txt=Requested service name {0} is unknown ServicesMonitor.unknownServiceName.excepton.txt=Requested service name {0} is unknown

View File

@ -50,7 +50,8 @@ public class ServicesMonitor {
private static final int NUMBER_OF_PERIODIC_TASK_THREADS = 1; private static final int NUMBER_OF_PERIODIC_TASK_THREADS = 1;
private static final long CRASH_DETECTION_INTERVAL_MINUTES = 2; private static final long CRASH_DETECTION_INTERVAL_MINUTES = 2;
private static final Set<Service> servicesList = Stream.of(ServicesMonitor.Service.values()) private static final Set<String> servicesList = Stream.of(ServicesMonitor.Service.values())
.map(Service::toString)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
/** /**
@ -90,14 +91,14 @@ public class ServicesMonitor {
*/ */
MESSAGING("messaging service"); MESSAGING("messaging service");
private final String serviceName; private final String displayName;
private Service(String name) { private Service(String name) {
this.serviceName = name; this.displayName = name;
} }
public String getName() { public String getDisplayName() {
return serviceName; return displayName;
} }
}; };
@ -147,11 +148,24 @@ public class ServicesMonitor {
* @param service Name of the service. * @param service Name of the service.
* @param status Updated status for the service. * @param status Updated status for the service.
* @param details Details of the event. * @param details Details of the event.
* @throws
* org.sleuthkit.autopsy.core.ServicesMonitor.ServicesMonitorException
* Thrown if either of input parameters is null.
*/ */
private void setServiceStatus(String service, String status, String details) { public void setServiceStatus(String service, String status, String details) throws ServicesMonitorException {
if (service == null) {
logger.log(Level.SEVERE, "Call to setServiceStatus() with null service name"); //NON-NLS
throw new ServicesMonitorException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.nullServiceName.excepton.txt"));
}
if (status == null || details == null) {
logger.log(Level.SEVERE, "Call to setServiceStatus() with null status or details"); //NON-NLS
throw new ServicesMonitorException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.nullStatusOrDetails.excepton.txt"));
}
// if the status update is for an existing service who's status hasn't changed - do nothing. // if the status update is for an existing service who's status hasn't changed - do nothing.
if (status.equals(statusByService.get(service))) { if (statusByService.containsKey(service) && status.equals(statusByService.get(service))) {
return; return;
} }
@ -165,7 +179,7 @@ public class ServicesMonitor {
MessageNotifyUtil.Notify.error(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.failedService.notify.title"), MessageNotifyUtil.Notify.error(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.failedService.notify.title"),
NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.failedService.notify.msg", service)); NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.failedService.notify.msg", service));
} else { } else {
logger.log(Level.INFO, "Connection status for {0} changed to {1}", new Object[]{service, status}); //NON-NLS logger.log(Level.INFO, "Status for {0} is {1}", new Object[]{service, status}); //NON-NLS
MessageNotifyUtil.Notify.info(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.statusChange.notify.title"), MessageNotifyUtil.Notify.info(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.statusChange.notify.title"),
NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.statusChange.notify.msg", new Object[]{service, status})); NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.statusChange.notify.msg", new Object[]{service, status}));
} }
@ -181,19 +195,19 @@ public class ServicesMonitor {
* @param service Name of the service. * @param service Name of the service.
* @return ServiceStatus Status for the service. * @return ServiceStatus Status for the service.
* @throws * @throws
* org.sleuthkit.autopsy.core.ServicesMonitor.UnknownServiceException Thrown * org.sleuthkit.autopsy.core.ServicesMonitor.ServicesMonitorException
* if service name is null or service doesn't exist. * Thrown if service name is null or service doesn't exist.
*/ */
public String getServiceStatus(String service) throws UnknownServiceException { public String getServiceStatus(String service) throws ServicesMonitorException {
if (service == null) { if (service == null) {
throw new UnknownServiceException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.nullServiceName.excepton.txt")); throw new ServicesMonitorException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.nullServiceName.excepton.txt"));
} }
String status = statusByService.get(service); String status = statusByService.get(service);
if (status == null) { if (status == null) {
// no such service // no such service
throw new UnknownServiceException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.unknownServiceName.excepton.txt", service)); throw new ServicesMonitorException(NbBundle.getMessage(ServicesMonitor.class, "ServicesMonitor.unknownServiceName.excepton.txt", service));
} }
return status; return status;
} }
@ -204,36 +218,59 @@ public class ServicesMonitor {
* @param service Name of the service. * @param service Name of the service.
*/ */
private void checkServiceStatus(String service) { private void checkServiceStatus(String service) {
if (service.equals(Service.REMOTE_CASE_DATABASE.getName())) { if (service.equals(Service.REMOTE_CASE_DATABASE.toString())) {
checkDatabaseConnectionStatus();
} else if (service.equals(Service.REMOTE_KEYWORD_SEARCH.toString())) {
checkKeywordSearchServerConnectionStatus();
} else if (service.equals(Service.MESSAGING.toString())) {
checkMessagingServerConnectionStatus();
}
}
/**
* Performs case database service availability status check.
*/
private void checkDatabaseConnectionStatus() {
try {
if (UserPreferences.getDatabaseConnectionInfo().canConnect()) { if (UserPreferences.getDatabaseConnectionInfo().canConnect()) {
setServiceStatus(Service.REMOTE_CASE_DATABASE.getName(), ServiceStatus.UP.toString(), ""); setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.UP.toString(), "");
return;
} else { } else {
setServiceStatus(Service.REMOTE_CASE_DATABASE.getName(), ServiceStatus.DOWN.toString(), ""); setServiceStatus(Service.REMOTE_CASE_DATABASE.toString(), ServiceStatus.DOWN.toString(), "");
return;
} }
} else if (service.equals(Service.REMOTE_KEYWORD_SEARCH.getName())) { } catch (ServicesMonitorException ex) {
logger.log(Level.SEVERE, "Exception while checking database connection status", ex); //NON-NLS
}
}
/**
* Performs keyword search service availability status check.
*/
private void checkKeywordSearchServerConnectionStatus() {
try {
KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class); KeywordSearchService kwsService = Lookup.getDefault().lookup(KeywordSearchService.class);
if (kwsService != null && kwsService.canConnectToRemoteSolrServer()) { if (kwsService != null && kwsService.canConnectToRemoteSolrServer()) {
setServiceStatus(Service.REMOTE_KEYWORD_SEARCH.getName(), ServiceStatus.UP.toString(), ""); setServiceStatus(Service.REMOTE_KEYWORD_SEARCH.toString(), ServiceStatus.UP.toString(), "");
return;
} else { } else {
setServiceStatus(Service.REMOTE_KEYWORD_SEARCH.getName(), ServiceStatus.DOWN.toString(), ""); setServiceStatus(Service.REMOTE_KEYWORD_SEARCH.toString(), ServiceStatus.DOWN.toString(), "");
return;
}
} else if (service.equals(Service.MESSAGING.getName())) {
if (UserPreferences.getMessageServiceConnectionInfo().canConnect()) {
setServiceStatus(Service.MESSAGING.getName(), ServiceStatus.UP.toString(), "");
return;
} else {
setServiceStatus(Service.MESSAGING.getName(), ServiceStatus.DOWN.toString(), "");
return;
} }
} catch (ServicesMonitorException ex) {
logger.log(Level.SEVERE, "Exception while checking keyword search server connection status", ex); //NON-NLS
} }
}
// no method to check any other services /**
logger.log(Level.SEVERE, "No method exists to check status of service {0}", service); //NON-NLS * Performs messaging service availability status check.
setServiceStatus(service, ServiceStatus.DOWN.toString(), ""); */
private void checkMessagingServerConnectionStatus() {
try {
if (UserPreferences.getMessageServiceConnectionInfo().canConnect()) {
setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.UP.toString(), "");
} else {
setServiceStatus(Service.MESSAGING.toString(), ServiceStatus.DOWN.toString(), "");
}
} catch (ServicesMonitorException ex) {
logger.log(Level.SEVERE, "Exception while checking messaging server connection status", ex); //NON-NLS
}
} }
/** /**
@ -243,9 +280,7 @@ public class ServicesMonitor {
* @param subscriber The subscriber to add. * @param subscriber The subscriber to add.
*/ */
public void addSubscriber(PropertyChangeListener subscriber) { public void addSubscriber(PropertyChangeListener subscriber) {
for (Service service : servicesList) { eventPublisher.addSubscriber(servicesList, subscriber);
eventPublisher.addSubscriber(service.getName(), subscriber);
}
} }
/** /**
@ -295,17 +330,15 @@ public class ServicesMonitor {
* @param subscriber The subscriber to remove. * @param subscriber The subscriber to remove.
*/ */
public void removeSubscriber(PropertyChangeListener subscriber) { public void removeSubscriber(PropertyChangeListener subscriber) {
for (Service service : servicesList) { eventPublisher.removeSubscriber(servicesList, subscriber);
eventPublisher.removeSubscriber(service.getName(), subscriber);
}
} }
/** /**
* Verifies connectivity to all services. * Verifies connectivity to all services.
*/ */
private void checkAllServices() { private void checkAllServices() {
for (Service service : servicesList) { for (String service : servicesList) {
checkServiceStatus(service.getName()); checkServiceStatus(service);
} }
} }
@ -329,13 +362,13 @@ public class ServicesMonitor {
/** /**
* Exception thrown when service status query results in an error. * Exception thrown when service status query results in an error.
*/ */
public class UnknownServiceException extends Exception { public class ServicesMonitorException extends Exception {
public UnknownServiceException(String message) { public ServicesMonitorException(String message) {
super(message); super(message);
} }
public UnknownServiceException(String message, Throwable cause) { public ServicesMonitorException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
} }

View File

@ -335,15 +335,20 @@ public class IngestManager {
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue().equals(ServicesMonitor.ServiceStatus.DOWN.toString())) { if (evt.getNewValue().equals(ServicesMonitor.ServiceStatus.DOWN.toString())) {
// one of the services we subscribed to went down // one of the services we subscribed to went down
String serviceName = evt.getPropertyName(); String serviceDisplayName = ServicesMonitor.Service.valueOf(evt.getPropertyName()).getDisplayName();
logger.log(Level.SEVERE, "Service {0} is down! Cancelling all running ingest jobs", serviceName); //NON-NLS logger.log(Level.SEVERE, "Service {0} is down! Cancelling all running ingest jobs", serviceDisplayName); //NON-NLS
// display notification if running interactively // display notification if running interactively
if (isIngestRunning() && isRunningInteractively()){ if (isIngestRunning() && isRunningInteractively()) {
JOptionPane.showMessageDialog(null, EventQueue.invokeLater(new Runnable() {
NbBundle.getMessage(this.getClass(), "IngestManager.cancellingIngest.msgDlg.text"), @Override
NbBundle.getMessage(this.getClass(), "IngestManager.serviceIsDown.msgDlg.text", serviceName), public void run() {
JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(), "IngestManager.cancellingIngest.msgDlg.text"),
NbBundle.getMessage(this.getClass(), "IngestManager.serviceIsDown.msgDlg.text", serviceDisplayName),
JOptionPane.ERROR_MESSAGE);
}
});
} }
// cancel ingest if running // cancel ingest if running
@ -354,8 +359,8 @@ public class IngestManager {
// subscribe to services of interest // subscribe to services of interest
Set<String> servicesList = new HashSet<>(); Set<String> servicesList = new HashSet<>();
servicesList.add(ServicesMonitor.Service.REMOTE_CASE_DATABASE.getName()); servicesList.add(ServicesMonitor.Service.REMOTE_CASE_DATABASE.toString());
servicesList.add(ServicesMonitor.Service.REMOTE_KEYWORD_SEARCH.getName()); servicesList.add(ServicesMonitor.Service.REMOTE_KEYWORD_SEARCH.toString());
this.servicesMonitor.addSubscriber(servicesList, propChangeListener); this.servicesMonitor.addSubscriber(servicesList, propChangeListener);
} }