mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-20 03:24:55 +00:00
Changed how service status updates are set and obtained
This commit is contained in:
parent
01e19c3bc3
commit
041f2644ee
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -59,24 +60,48 @@ public class ServicesMonitor {
|
|||||||
.map(ServicesMonitor.Service::toString)
|
.map(ServicesMonitor.Service::toString)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The service monitor maintains a mapping of each service to it's last status update.
|
||||||
|
*/
|
||||||
|
private final ConcurrentHashMap<Service, ServiceStatus> statusByService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of services that are being monitored.
|
* List of services that are being monitored.
|
||||||
*/
|
*/
|
||||||
public enum Service {
|
public enum Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property change event fired when ....TODO.... The old value of the
|
* Property change event fired when remote case database status changes.
|
||||||
* PropertyChangeEvent object is set to the ingest job id, and the new
|
* New value is set to updated ServiceStatus, old value is null.
|
||||||
* value is set to null.
|
|
||||||
*/
|
*/
|
||||||
REMOTE_CASE_DATABASE,
|
REMOTE_CASE_DATABASE,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property change event fired when remote keyword search service status changes.
|
||||||
|
* New value is set to updated ServiceStatus, old value is null.
|
||||||
|
*/
|
||||||
REMOTE_KEYWORD_SEARCH,
|
REMOTE_KEYWORD_SEARCH,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property change event fired when messaging service status changes.
|
||||||
|
* New value is set to updated ServiceStatus, old value is null.
|
||||||
|
*/
|
||||||
MESSAGING
|
MESSAGING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of possible service statuses.
|
||||||
|
*/
|
||||||
public enum ServiceStatus {
|
public enum ServiceStatus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service is currently up.
|
||||||
|
*/
|
||||||
UP,
|
UP,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service is currently down.
|
||||||
|
*/
|
||||||
DOWN
|
DOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,6 +115,7 @@ public class ServicesMonitor {
|
|||||||
private ServicesMonitor() {
|
private ServicesMonitor() {
|
||||||
|
|
||||||
this.eventPublisher = new AutopsyEventPublisher();
|
this.eventPublisher = new AutopsyEventPublisher();
|
||||||
|
this.statusByService = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start periodic task that check the availability of key collaboration
|
* Start periodic task that check the availability of key collaboration
|
||||||
@ -99,6 +125,49 @@ public class ServicesMonitor {
|
|||||||
periodicTasksExecutor.scheduleAtFixedRate(new CrashDetectionTask(), CRASH_DETECTION_INTERVAL_MINUTES, CRASH_DETECTION_INTERVAL_MINUTES, TimeUnit.MINUTES);
|
periodicTasksExecutor.scheduleAtFixedRate(new CrashDetectionTask(), CRASH_DETECTION_INTERVAL_MINUTES, CRASH_DETECTION_INTERVAL_MINUTES, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store and publish service status update.
|
||||||
|
*
|
||||||
|
* @param service Name of the service.
|
||||||
|
* @param status Updated status for the service.
|
||||||
|
*/
|
||||||
|
private void setServiceStatus(Service service, ServiceStatus status){
|
||||||
|
this.statusByService.put(service, status);
|
||||||
|
publishServiceStatusUpdate(service, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get last status update for a service.
|
||||||
|
*
|
||||||
|
* @param service Name of the service.
|
||||||
|
* @return ServiceStatus Status for the service.
|
||||||
|
*/
|
||||||
|
public ServiceStatus getServiceStatus(Service service){
|
||||||
|
// Services are assumed to be "UP" by default. See CrashDetectionTask class for more info.
|
||||||
|
return this.statusByService.getOrDefault(service, ServiceStatus.UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish an event signifying change in service status. Event is published locally.
|
||||||
|
*
|
||||||
|
* @param service Name of the service.
|
||||||
|
* @param status Updated status for the event.
|
||||||
|
*/
|
||||||
|
private void publishServiceStatusUpdate(Service service, ServiceStatus status) {
|
||||||
|
eventPublisher.publishLocally(new ServiceEvent(service.toString(), status.toString(), ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish a custom event. Event is published locally.
|
||||||
|
*
|
||||||
|
* @param service Name of the service.
|
||||||
|
* @param status Updated status for the event.
|
||||||
|
* @param details Details of the event.
|
||||||
|
*/
|
||||||
|
public void publishCustomServiceStatus(String service, String status, String details) {
|
||||||
|
eventPublisher.publishLocally(new ServiceEvent(service, status, details));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an event subscriber to this publisher. Subscriber will be subscribed
|
* Adds an event subscriber to this publisher. Subscriber will be subscribed
|
||||||
* to all events from this publisher.
|
* to all events from this publisher.
|
||||||
@ -159,47 +228,6 @@ public class ServicesMonitor {
|
|||||||
eventPublisher.removeSubscriber(serviceNames, subscriber);
|
eventPublisher.removeSubscriber(serviceNames, subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish an event signifying change in remote database (e.g. PostgreSQL)
|
|
||||||
* service status.
|
|
||||||
*
|
|
||||||
* @param status Updated status for the event.
|
|
||||||
*/
|
|
||||||
private void publishRemoteDatabaseStatusChange(ServiceStatus status) {
|
|
||||||
eventPublisher.publishLocally(new ServiceEvent(ServicesMonitor.Service.REMOTE_CASE_DATABASE.toString(), null, status.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish an event signifying change in remote database (e.g. PostgreSQL)
|
|
||||||
* service status.
|
|
||||||
*
|
|
||||||
* @param status Updated status for the event.
|
|
||||||
*/
|
|
||||||
private void publishRemoteKeywordSearchStatusChange(ServiceStatus status) {
|
|
||||||
eventPublisher.publishLocally(new ServiceEvent(ServicesMonitor.Service.REMOTE_CASE_DATABASE.toString(), null, status.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish an event signifying change in remote database (e.g. PostgreSQL)
|
|
||||||
* service status.
|
|
||||||
*
|
|
||||||
* @param status Updated status for the event.
|
|
||||||
*/
|
|
||||||
private void publishMessagingStatusChange(ServiceStatus status) {
|
|
||||||
eventPublisher.publishLocally(new ServiceEvent(ServicesMonitor.Service.REMOTE_CASE_DATABASE.toString(), null, status.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish a custom event.
|
|
||||||
*
|
|
||||||
* @param service Name of the service.
|
|
||||||
* @param status Updated status for the event.
|
|
||||||
* @param details Details of the event.
|
|
||||||
*/
|
|
||||||
public void publishServiceStatus(String service, String status, String details) {
|
|
||||||
eventPublisher.publishLocally(new ServiceEvent(service, status, details));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Runnable task that periodically checks the availability of
|
* A Runnable task that periodically checks the availability of
|
||||||
* collaboration resources (PostgreSQL server, Solr server, Active MQ
|
* collaboration resources (PostgreSQL server, Solr server, Active MQ
|
||||||
@ -208,9 +236,12 @@ public class ServicesMonitor {
|
|||||||
*/
|
*/
|
||||||
private final class CrashDetectionTask implements Runnable {
|
private final class CrashDetectionTask implements Runnable {
|
||||||
|
|
||||||
|
// Services are assumed to be "UP" by default. Change default value in getServiceStatus()
|
||||||
|
// if this assumption changes.
|
||||||
private boolean dbServerIsRunning = true;
|
private boolean dbServerIsRunning = true;
|
||||||
private boolean solrServerIsRunning = true;
|
private boolean solrServerIsRunning = true;
|
||||||
private boolean messageServerIsRunning = true;
|
private boolean messageServerIsRunning = true;
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,14 +256,14 @@ public class ServicesMonitor {
|
|||||||
dbServerIsRunning = true;
|
dbServerIsRunning = true;
|
||||||
logger.log(Level.INFO, "Connection to PostgreSQL server restored"); //NON-NLS
|
logger.log(Level.INFO, "Connection to PostgreSQL server restored"); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredDbService.notify.msg"));
|
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredDbService.notify.msg"));
|
||||||
publishRemoteDatabaseStatusChange(ServiceStatus.UP);
|
setServiceStatus(Service.REMOTE_CASE_DATABASE, ServiceStatus.UP);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (dbServerIsRunning) {
|
if (dbServerIsRunning) {
|
||||||
dbServerIsRunning = false;
|
dbServerIsRunning = false;
|
||||||
logger.log(Level.SEVERE, "Failed to connect to PostgreSQL server"); //NON-NLS
|
logger.log(Level.SEVERE, "Failed to connect to PostgreSQL server"); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedDbService.notify.msg"));
|
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedDbService.notify.msg"));
|
||||||
publishRemoteDatabaseStatusChange(ServiceStatus.DOWN);
|
setServiceStatus(Service.REMOTE_CASE_DATABASE, ServiceStatus.DOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,14 +274,14 @@ public class ServicesMonitor {
|
|||||||
solrServerIsRunning = true;
|
solrServerIsRunning = true;
|
||||||
logger.log(Level.INFO, "Connection to Solr server restored"); //NON-NLS
|
logger.log(Level.INFO, "Connection to Solr server restored"); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredSolrService.notify.msg"));
|
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredSolrService.notify.msg"));
|
||||||
publishRemoteKeywordSearchStatusChange(ServiceStatus.UP);
|
setServiceStatus(Service.REMOTE_KEYWORD_SEARCH, ServiceStatus.UP);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (solrServerIsRunning) {
|
if (solrServerIsRunning) {
|
||||||
solrServerIsRunning = false;
|
solrServerIsRunning = false;
|
||||||
logger.log(Level.SEVERE, "Failed to connect to Solr server"); //NON-NLS
|
logger.log(Level.SEVERE, "Failed to connect to Solr server"); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedSolrService.notify.msg"));
|
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedSolrService.notify.msg"));
|
||||||
publishRemoteKeywordSearchStatusChange(ServiceStatus.DOWN);
|
setServiceStatus(Service.REMOTE_KEYWORD_SEARCH, ServiceStatus.DOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,18 +295,17 @@ public class ServicesMonitor {
|
|||||||
messageServerIsRunning = true;
|
messageServerIsRunning = true;
|
||||||
logger.log(Level.INFO, "Connection to ActiveMQ server restored"); //NON-NLS
|
logger.log(Level.INFO, "Connection to ActiveMQ server restored"); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredMessageService.notify.msg"));
|
//MessageNotifyUtil.Notify.info(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.restoredMessageService.notify.msg"));
|
||||||
publishMessagingStatusChange(ServiceStatus.UP);
|
setServiceStatus(Service.MESSAGING, ServiceStatus.UP);
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException | JMSException ex) {
|
} catch (URISyntaxException | JMSException ex) {
|
||||||
if (messageServerIsRunning) {
|
if (messageServerIsRunning) {
|
||||||
messageServerIsRunning = false;
|
messageServerIsRunning = false;
|
||||||
logger.log(Level.SEVERE, "Failed to connect to ActiveMQ server", ex); //NON-NLS
|
logger.log(Level.SEVERE, "Failed to connect to ActiveMQ server", ex); //NON-NLS
|
||||||
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedMessageService.notify.msg"));
|
//MessageNotifyUtil.Notify.error(NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedService.notify.title"), NbBundle.getMessage(CollaborationMonitor.class, "CollaborationMonitor.failedMessageService.notify.msg"));
|
||||||
publishMessagingStatusChange(ServiceStatus.DOWN);
|
setServiceStatus(Service.MESSAGING, ServiceStatus.DOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user