use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.
the class DefaultAlertManager method getAlerts.
/* (non-Javadoc)
* @see com.thinkbiganalytics.alerts.spi.AlertSource#getAlerts()
*/
@Override
public Iterator<Alert> getAlerts(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() && !hasAlertsChanged(criteria)) {
log.debug("Returning cached Alerts data");
return new ArrayList(latestAlerts.get(criteria.toString()).getAlertList()).iterator();
}
log.debug("Query for Alerts data");
List<Alert> alerts = this.metadataAccess.read(() -> {
DefaultAlertCriteria critImpl = ensureAlertCriteriaType(criteria);
return critImpl.createQuery().fetch().stream().map(a -> asValue(a)).collect(Collectors.toList());
}, principal);
if (criteria.isOnlyIfChangesDetected()) {
latestAlerts.put(criteria.toString(), new AlertsCache(now, alerts));
}
return alerts.iterator();
}
use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.
the class KyloEntityAwareAlertCriteria method transfer.
@Override
public AlertCriteria transfer(AlertCriteria criteria) {
AlertCriteria c = super.transfer(criteria);
AtomicReference<KyloEntityAwareAlertCriteria> updated = new AtomicReference<>((KyloEntityAwareAlertCriteria) c);
this.entityCriteria.forEach((t) -> updated.set(updated.get().entityCriteria(t)));
return updated.get();
}
use of com.thinkbiganalytics.alerts.api.AlertCriteria in project kylo by Teradata.
the class AlertsController method createCriteria.
private AlertCriteria createCriteria(UriInfo uriInfo) {
// Query params: limit, state, level, before-time, after-time, before-alert, after-alert
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
AlertCriteria criteria = provider.criteria();
try {
Optional.ofNullable(params.get("type")).ifPresent(list -> list.forEach(typeStr -> criteria.type(URI.create(typeStr))));
Optional.ofNullable(params.get("subtype")).ifPresent(list -> list.forEach(subtype -> criteria.subtype(subtype)));
Optional.ofNullable(params.get("limit")).ifPresent(list -> list.forEach(limitStr -> criteria.limit(Integer.parseInt(limitStr))));
Optional.ofNullable(params.get("state")).ifPresent(list -> list.forEach(stateStr -> criteria.state(Alert.State.valueOf(stateStr.toUpperCase()))));
Optional.ofNullable(params.get("level")).ifPresent(list -> list.forEach(levelStr -> criteria.level(Alert.Level.valueOf(levelStr.toUpperCase()))));
Optional.ofNullable(params.get("before")).ifPresent(list -> list.forEach(timeStr -> criteria.before(Formatters.parseDateTime(timeStr))));
Optional.ofNullable(params.get("after")).ifPresent(list -> list.forEach(timeStr -> criteria.after(Formatters.parseDateTime(timeStr))));
return criteria;
} catch (IllegalArgumentException e) {
throw new WebApplicationException("Invalid query parameter: " + e.getMessage(), Status.BAD_REQUEST);
}
}
use of com.thinkbiganalytics.alerts.api.AlertCriteria 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.AlertCriteria in project kylo by Teradata.
the class OpsFeedManagerFeedProvider method abandonFeedJobs.
/**
* This will call the stored procedure abandon_feed_jobs
*/
public void abandonFeedJobs(String feed) {
String exitMessage = String.format("Job manually abandoned @ %s", DateTimeUtil.getNowFormattedWithTimeZone());
String username = SecurityContextHolder.getContext().getAuthentication().getName();
repository.abandonFeedJobs(feed, exitMessage, username);
// TODO Notify the JobExecution Cache of updates
// all the alerts manager to handle all job failures
AlertCriteria criteria = alertProvider.criteria().type(OperationalAlerts.JOB_FALURE_ALERT_TYPE).subtype(feed);
Iterator<? extends Alert> alerts = alertProvider.getAlerts(criteria);
StreamSupport.stream(Spliterators.spliteratorUnknownSize(alerts, Spliterator.ORDERED), false).forEach(alert -> alertProvider.respondTo(alert.getId(), (alert1, response) -> response.handle(exitMessage)));
alertManager.updateLastUpdatedTime();
}
Aggregations