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();
}
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);
}
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);
}
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();
}
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();
}
Aggregations