Search in sources :

Example 1 with AlertSummaryGrouped

use of com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped in project kylo by Teradata.

the class AlertsModel method groupAlertSummaries.

public Collection<AlertSummaryGrouped> groupAlertSummaries(List<AlertSummary> alertSummaries) {
    Map<String, AlertSummaryGrouped> group = new HashMap<>();
    alertSummaries.forEach(alertSummary -> {
        String key = alertSummary.getType() + ":" + alertSummary.getSubtype();
        String displayName = alertTypeDisplayName(alertSummary);
        if (alertSummary instanceof EntityAwareAlertSummary) {
            EntityAwareAlertSummary entityAwareAlertSummary = (EntityAwareAlertSummary) alertSummary;
            key = entityAwareAlertSummary.getGroupByKey();
            group.computeIfAbsent(key, key1 -> new AlertSummaryGrouped.Builder().typeString(alertSummary.getType()).typeDisplayName(displayName).subType(entityAwareAlertSummary.getSubtype()).feedId(entityAwareAlertSummary.getFeedId() != null ? entityAwareAlertSummary.getFeedId().toString() : null).feedName(entityAwareAlertSummary.getFeedName()).slaId(entityAwareAlertSummary.getSlaId() != null ? entityAwareAlertSummary.getSlaId().toString() : null).slaName(entityAwareAlertSummary.getSlaName()).build()).add(toModel(alertSummary.getLevel()), alertSummary.getCount(), alertSummary.getLastAlertTimestamp());
        } else {
            group.computeIfAbsent(key, key1 -> new AlertSummaryGrouped.Builder().typeString(alertSummary.getType()).typeDisplayName(displayName).subType(alertSummary.getSubtype()).build()).add(toModel(alertSummary.getLevel()), alertSummary.getCount(), alertSummary.getLastAlertTimestamp());
        }
    });
    return group.values();
}
Also used : EntityAwareAlertSummary(com.thinkbiganalytics.metadata.api.alerts.EntityAwareAlertSummary) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Proxy(java.lang.reflect.Proxy) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SourceAlert(com.thinkbiganalytics.alerts.api.SourceAlert) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) EntityAwareAlertSummary(com.thinkbiganalytics.metadata.api.alerts.EntityAwareAlertSummary) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) ObjectMapperSerializer(com.thinkbiganalytics.json.ObjectMapperSerializer) EntityAlert(com.thinkbiganalytics.alerts.api.EntityAlert) Component(org.springframework.stereotype.Component) List(java.util.List) AlertConstants(com.thinkbiganalytics.alerts.AlertConstants) Map(java.util.Map) Alert(com.thinkbiganalytics.alerts.rest.model.Alert) AlertSummaryGrouped(com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped) HashMap(java.util.HashMap) AlertSummaryGrouped(com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped)

Example 2 with AlertSummaryGrouped

use of com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped in project kylo by Teradata.

the class AlertsCache method fetchUnhandledAlerts.

protected List<AlertSummaryGrouped> fetchUnhandledAlerts() {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = alertProvider.criteria();
    new AlertCriteriaInput.Builder().state(Alert.State.UNHANDLED).asServiceAccount(true).onlyIfChangesDetected(true).applyToCriteria(criteria);
    Iterator<? extends AlertSummary> itr = alertProvider.getAlertsSummary(criteria);
    if (itr.hasNext()) {
        itr.forEachRemaining(alerts::add);
        List<AlertSummaryGrouped> latestAlerts = new ArrayList<>(alertsModel.groupAlertSummaries(alerts));
        return latestAlerts;
    } else {
        return Collections.emptyList();
    }
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) CacheBuilder(com.google.common.cache.CacheBuilder) AlertSummaryGrouped(com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary)

Aggregations

AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)2 AlertSummaryGrouped (com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 AlertConstants (com.thinkbiganalytics.alerts.AlertConstants)1 AlertCriteria (com.thinkbiganalytics.alerts.api.AlertCriteria)1 EntityAlert (com.thinkbiganalytics.alerts.api.EntityAlert)1 SourceAlert (com.thinkbiganalytics.alerts.api.SourceAlert)1 Alert (com.thinkbiganalytics.alerts.rest.model.Alert)1 ObjectMapperSerializer (com.thinkbiganalytics.json.ObjectMapperSerializer)1 EntityAwareAlertSummary (com.thinkbiganalytics.metadata.api.alerts.EntityAwareAlertSummary)1 Proxy (java.lang.reflect.Proxy)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1