Search in sources :

Example 1 with BaseAlertCriteria

use of com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria in project kylo by Teradata.

the class InMemoryAlertManager method getAlertsSummary.

@Override
public Iterator<AlertSummary> getAlertsSummary(AlertCriteria criteria) {
    BaseAlertCriteria predicate = (BaseAlertCriteria) (criteria == null ? criteria() : criteria);
    // TODO Grab a partition of the map first based on before/after times of criteria
    List<Alert> alerts = this.alertsByTime.values().stream().map(ref -> (Alert) ref.get()).filter(predicate).collect(Collectors.toList());
    List<AlertSummary> summaryList = new ArrayList<>();
    Map<String, AlertSummary> groupedAlerts = new HashMap<>();
    alerts.stream().forEach(alert -> {
        String key = alert.getType() + ":" + alert.getSubtype() + ":" + alert.getLevel();
        groupedAlerts.computeIfAbsent(key, groupKey -> new GenericAlertSummary(alert.getType().toString(), alert.getSubtype(), alert.getLevel()));
        ((GenericAlertSummary) groupedAlerts.get(key)).incrementCount();
    });
    return groupedAlerts.values().iterator();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseAlertCriteria(com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria) ArrayList(java.util.ArrayList) Alert(com.thinkbiganalytics.alerts.api.Alert) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary)

Aggregations

Alert (com.thinkbiganalytics.alerts.api.Alert)1 AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)1 BaseAlertCriteria (com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1