use of com.thinkbiganalytics.alerts.api.Alert in project kylo by Teradata.
the class InMemoryAlertManagerTest method testCreate.
@Test
public void testCreate() {
URI type = URI.create("urn:alert:test");
Alert alert = this.manager.create(type, "subtype", Alert.Level.INFO, "test", "content");
assertThat(alert.getType()).isEqualTo(type);
assertThat(alert.getLevel()).isEqualTo(Alert.Level.INFO);
assertThat(alert.getDescription()).isEqualTo("test");
assertThat((String) alert.getContent()).isEqualTo("content");
}
use of com.thinkbiganalytics.alerts.api.Alert in project kylo by Teradata.
the class InMemoryAlertManagerTest method testRemove.
//
// @Test
// public void testGetAlertsSinceID() throws InterruptedException {
// Alert.ID id = this.manager.create(URI.create("urn:alert:test1"), Alert.Level.INFO, "test1", "content").getId();
// Thread.sleep(25);
// this.manager.create(URI.create("urn:alert:test2"), Alert.Level.CRITICAL, "test2", "content");
// Thread.sleep(25);
//
// Iterator<? extends Alert> itr = this.manager.getAlerts(id);
//
// assertThat(itr.hasNext()).isTrue();
// assertThat(itr.next().getLevel()).isEqualTo(Level.CRITICAL);
// assertThat(itr.hasNext()).isFalse();
// }
@Test
public void testRemove() {
Alert.ID id1 = this.manager.create(URI.create("urn:alert:test1"), "subtype", Alert.Level.INFO, "test1", "content").getId();
Alert.ID id2 = this.manager.create(URI.create("urn:alert:test2"), "subtype", Alert.Level.CRITICAL, "test2", "content").getId();
Alert alert2 = this.manager.remove(id2);
Alert alert1 = this.manager.remove(id1);
Iterator<? extends Alert> itr = this.manager.getAlerts(null);
assertThat(itr.hasNext()).isFalse();
assertThat(alert1.getId()).isEqualTo(id1);
assertThat(alert2.getId()).isEqualTo(id2);
}
use of com.thinkbiganalytics.alerts.api.Alert in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method notifyFailure.
@Override
public void notifyFailure(BatchJobExecution jobExecution, OpsManagerFeed feed, boolean isStream, String status) {
jobExecutionChangedNotifier.notifyOperationStatusEvent(jobExecution, feed, FeedOperation.State.FAILURE, status);
Alert alert = null;
// see if the feed has an unhandled alert already.
String feedId = feed.getId().toString();
String alertId = jobExecution.getJobExecutionContextAsMap().get(BatchJobExecutionProvider.KYLO_ALERT_ID_PROPERTY);
String message = "Failed Job " + jobExecution.getJobExecutionId() + " for feed " + feed != null ? feed.getName() : null;
if (StringUtils.isNotBlank(alertId)) {
alert = provider.getAlertAsServiceAccount(provider.resolve(alertId)).orElse(null);
}
if (alert == null) {
alert = alertManager.createEntityAlert(OperationalAlerts.JOB_FALURE_ALERT_TYPE, Alert.Level.FATAL, message, alertManager.createEntityIdentificationAlertContent(feedId, SecurityRole.ENTITY_TYPE.FEED, jobExecution.getJobExecutionId()));
Alert.ID providerAlertId = provider.resolve(alert.getId(), alert.getSource());
JpaBatchJobExecutionContextValue executionContext = new JpaBatchJobExecutionContextValue(jobExecution, KYLO_ALERT_ID_PROPERTY);
executionContext.setStringVal(providerAlertId.toString());
((JpaBatchJobExecution) jobExecution).addJobExecutionContext(executionContext);
save(jobExecution);
} else {
// if streaming feed with unhandled alerts attempt to update alert content
DefaultAlertChangeEventContent alertContent = null;
if (isStream && alert.getState().equals(Alert.State.UNHANDLED)) {
if (alert.getEvents() != null && alert.getEvents().get(0) != null) {
alertContent = alert.getEvents().get(0).getContent();
if (alertContent == null) {
alertContent = new DefaultAlertChangeEventContent();
alertContent.getContent().put("failedCount", 1);
alertContent.getContent().put("stream", true);
} else {
Integer count = (Integer) alertContent.getContent().putIfAbsent("failedCount", 0);
count++;
alertContent.getContent().put("failedCount", count);
}
final DefaultAlertChangeEventContent content = alertContent;
provider.respondTo(alert.getId(), (alert1, response) -> response.updateAlertChange(message, content));
} else {
if (alertContent == null) {
alertContent = new DefaultAlertChangeEventContent();
alertContent.getContent().put("failedCount", 1);
alertContent.getContent().put("stream", true);
}
final DefaultAlertChangeEventContent content = alertContent;
provider.respondTo(alert.getId(), (alert1, response) -> response.unhandle(message, content));
}
} else {
alertContent = new DefaultAlertChangeEventContent();
alertContent.getContent().put("failedCount", 1);
if (isStream) {
alertContent.getContent().put("stream", true);
}
final DefaultAlertChangeEventContent content = alertContent;
provider.respondTo(alert.getId(), (alert1, response) -> response.unhandle(message, content));
}
}
}
use of com.thinkbiganalytics.alerts.api.Alert in project kylo by Teradata.
the class DefaultAlertManager method create.
/* (non-Javadoc)
* @see com.thinkbiganalytics.alerts.spi.AlertManager#create(java.net.URI, com.thinkbiganalytics.alerts.api.Alert.Level, java.lang.String, java.io.Serializable)
*/
@Override
public <C extends Serializable> Alert create(URI type, String subtype, Level level, String description, C content) {
final Principal user = SecurityContextHolder.getContext().getAuthentication() != null ? SecurityContextHolder.getContext().getAuthentication() : null;
// reset the subtype if the content is an Entity
if (subtype == null) {
subtype = "Other";
}
if (content != null && content instanceof EntityIdentificationAlertContent) {
subtype = "Entity";
}
final String finalSubType = subtype;
Alert created = this.metadataAccess.commit(() -> {
JpaAlert alert = new JpaAlert(type, finalSubType, level, user, description, content);
this.repository.save(alert);
return asValue(alert);
}, MetadataAccess.SERVICE);
updateLastUpdatedTime();
notifyReceivers(1);
return created;
}
use of com.thinkbiganalytics.alerts.api.Alert 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();
}
Aggregations