Search in sources :

Example 1 with Notification

use of org.jumpmind.symmetric.model.Notification in project symmetric-ds by JumpMind.

the class MonitorService method update.

@Override
public synchronized void update() {
    Map<String, IMonitorType> monitorTypes = extensionService.getExtensionPointMap(IMonitorType.class);
    Node identity = nodeService.findIdentity();
    List<Monitor> activeMonitors = getActiveMonitorsForNode(identity.getNodeGroupId(), identity.getExternalId());
    Map<String, MonitorEvent> unresolved = getMonitorEventsNotResolvedForNode(identity.getNodeId());
    for (Monitor monitor : activeMonitors) {
        IMonitorType monitorType = monitorTypes.get(monitor.getType());
        if (monitorType != null) {
            if (!monitorType.requiresClusterLock()) {
                Long lastCheckTimeLong = checkTimesByType.get(monitor.getMonitorId());
                long lastCheckTime = lastCheckTimeLong != null ? lastCheckTimeLong : 0;
                if (lastCheckTime == 0 || (System.currentTimeMillis() - lastCheckTime) / 1000 >= monitor.getRunPeriod()) {
                    checkTimesByType.put(monitor.getMonitorId(), System.currentTimeMillis());
                    updateMonitor(monitor, monitorType, identity, unresolved);
                }
            }
        } else {
            log.warn("Could not find monitor of type '" + monitor.getType() + "'");
        }
    }
    if (clusterService.lock(ClusterConstants.MONITOR)) {
        Lock lock = clusterService.findLocks().get(ClusterConstants.MONITOR);
        long clusterLastCheckTime = lock.getLastLockTime() != null ? lock.getLastLockTime().getTime() : 0;
        try {
            for (Monitor monitor : activeMonitors) {
                IMonitorType monitorType = monitorTypes.get(monitor.getType());
                if (monitorType != null && monitorType.requiresClusterLock() && (System.currentTimeMillis() - clusterLastCheckTime) / 1000 >= monitor.getRunPeriod()) {
                    updateMonitor(monitor, monitorType, identity, unresolved);
                }
            }
            int minSeverityLevel = Integer.MAX_VALUE;
            List<Notification> notifications = getActiveNotificationsForNode(identity.getNodeGroupId(), identity.getExternalId());
            if (notifications.size() > 0) {
                for (Notification notification : notifications) {
                    if (notification.getSeverityLevel() < minSeverityLevel) {
                        minSeverityLevel = notification.getSeverityLevel();
                    }
                }
                Map<String, INotificationType> notificationTypes = extensionService.getExtensionPointMap(INotificationType.class);
                List<MonitorEvent> allMonitorEvents = getMonitorEventsForNotification(minSeverityLevel);
                for (Notification notification : notifications) {
                    List<MonitorEvent> monitorEvents = new ArrayList<MonitorEvent>();
                    for (MonitorEvent monitorEvent : allMonitorEvents) {
                        if (monitorEvent.getSeverityLevel() >= notification.getSeverityLevel()) {
                            monitorEvents.add(monitorEvent);
                        }
                    }
                    if (monitorEvents.size() > 0) {
                        INotificationType notificationType = notificationTypes.get(notification.getType());
                        if (notificationType != null) {
                            notificationType.notify(notification, monitorEvents);
                            updateMonitorEventAsNotified(monitorEvents);
                        } else {
                            log.warn("Could not find notification of type '" + notification.getType() + "'");
                        }
                    }
                }
            }
        } finally {
            clusterService.unlock(ClusterConstants.MONITOR);
        }
    }
}
Also used : MonitorEvent(org.jumpmind.symmetric.model.MonitorEvent) Node(org.jumpmind.symmetric.model.Node) ArrayList(java.util.ArrayList) INotificationType(org.jumpmind.symmetric.notification.INotificationType) Notification(org.jumpmind.symmetric.model.Notification) Lock(org.jumpmind.symmetric.model.Lock) IMonitorType(org.jumpmind.symmetric.monitor.IMonitorType) Monitor(org.jumpmind.symmetric.model.Monitor)

Aggregations

ArrayList (java.util.ArrayList)1 Lock (org.jumpmind.symmetric.model.Lock)1 Monitor (org.jumpmind.symmetric.model.Monitor)1 MonitorEvent (org.jumpmind.symmetric.model.MonitorEvent)1 Node (org.jumpmind.symmetric.model.Node)1 Notification (org.jumpmind.symmetric.model.Notification)1 IMonitorType (org.jumpmind.symmetric.monitor.IMonitorType)1 INotificationType (org.jumpmind.symmetric.notification.INotificationType)1