Search in sources :

Example 1 with AlertSummary

use of com.thinkbiganalytics.alerts.api.AlertSummary 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)

Example 2 with AlertSummary

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

the class AlertsController method getAlertSummaryUnhandled.

@GET
@Path("/summary/unhandled")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Lists summary grouped alerts.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns summary of the alerts grouped.", response = AlertRange.class))
public Collection<AlertSummaryGrouped> getAlertSummaryUnhandled(@QueryParam("type") String type, @QueryParam("subtype") String subtype) {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = createCriteria(null, type, subtype, Alert.State.UNHANDLED.name(), null, null, null, "false");
    provider.getAlertsSummary(criteria).forEachRemaining(alerts::add);
    return alertsModel.groupAlertSummaries(alerts);
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with AlertSummary

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

the class AlertsController method getAlertSummary.

@GET
@Path("/summary")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Lists summary grouped alerts.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns summary of the alerts grouped.", response = AlertRange.class))
public Collection<AlertSummaryGrouped> getAlertSummary(@QueryParam("state") String state, @QueryParam("level") String level, @QueryParam("type") String type, @QueryParam("subtype") String subtype, @QueryParam("cleared") @DefaultValue("false") String cleared) {
    List<AlertSummary> alerts = new ArrayList<>();
    AlertCriteria criteria = createCriteria(null, type, subtype, state, level, null, null, cleared);
    provider.getAlertsSummary(criteria).forEachRemaining(alerts::add);
    return alertsModel.groupAlertSummaries(alerts);
}
Also used : AlertCriteria(com.thinkbiganalytics.alerts.api.AlertCriteria) ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with AlertSummary

use of com.thinkbiganalytics.alerts.api.AlertSummary 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 5 with AlertSummary

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

the class DefaultAlertManager method getAlertsSummary.

public Iterator<AlertSummary> getAlertsSummary(AlertCriteria criteria) {
    Long now = DateTime.now().getMillis();
    Principal[] principal = null;
    if (criteria != null && criteria.isAsServiceAccount()) {
        principal = new Principal[1];
        principal[0] = MetadataAccess.SERVICE;
    } else {
        principal = new Principal[0];
    }
    if (criteria.isOnlyIfChangesDetected() && !hasAlertsSummaryChanged(criteria)) {
        log.debug("Returning cached Alerts Summary data");
        return new ArrayList(latestAlertsSummary.get(criteria.toString()).getAlertSummaryList()).iterator();
    }
    log.debug("Query for Alerts Summary data");
    List<AlertSummary> latest = this.metadataAccess.read(() -> {
        DefaultAlertCriteria critImpl = ensureAlertCriteriaType(criteria);
        return critImpl.createSummaryQuery().fetch().stream().collect(Collectors.toList());
    }, principal);
    if (criteria.isOnlyIfChangesDetected()) {
        latestAlertsSummary.put(criteria.toString(), new AlertSummaryCache(now, latest));
    }
    return latest.iterator();
}
Also used : ArrayList(java.util.ArrayList) AlertSummary(com.thinkbiganalytics.alerts.api.AlertSummary) Principal(java.security.Principal)

Aggregations

AlertSummary (com.thinkbiganalytics.alerts.api.AlertSummary)7 ArrayList (java.util.ArrayList)6 AlertCriteria (com.thinkbiganalytics.alerts.api.AlertCriteria)4 AlertSummaryGrouped (com.thinkbiganalytics.alerts.rest.model.AlertSummaryGrouped)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 AlertConstants (com.thinkbiganalytics.alerts.AlertConstants)1 Alert (com.thinkbiganalytics.alerts.api.Alert)1 EntityAlert (com.thinkbiganalytics.alerts.api.EntityAlert)1 SourceAlert (com.thinkbiganalytics.alerts.api.SourceAlert)1 BaseAlertCriteria (com.thinkbiganalytics.alerts.api.core.BaseAlertCriteria)1 Alert (com.thinkbiganalytics.alerts.rest.model.Alert)1 ObjectMapperSerializer (com.thinkbiganalytics.json.ObjectMapperSerializer)1 EntityAwareAlertSummary (com.thinkbiganalytics.metadata.api.alerts.EntityAwareAlertSummary)1 OpsManagerFeed (com.thinkbiganalytics.metadata.api.feed.OpsManagerFeed)1