ElasticSearch & Slack Event publishers

This commit is contained in:
Sriharsha Chintalapani 2022-01-09 09:16:48 -08:00
parent 0ae7982ec2
commit b368d093af
4 changed files with 16 additions and 8 deletions

View File

@ -187,13 +187,18 @@ public class CatalogApplication extends Application<CatalogApplicationConfig> {
throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException,
InstantiationException { InstantiationException {
// register ElasticSearch Event publisher // register ElasticSearch Event publisher
ElasticSearchEventPublisher elasticSearchEventPublisher = if (catalogApplicationConfig.getElasticSearchConfiguration() != null) {
new ElasticSearchEventPublisher(catalogApplicationConfig.getElasticSearchConfiguration()); ElasticSearchEventPublisher elasticSearchEventPublisher =
EventPubSub.addEventHandler(elasticSearchEventPublisher); new ElasticSearchEventPublisher(catalogApplicationConfig.getElasticSearchConfiguration());
EventPubSub.addEventHandler(elasticSearchEventPublisher);
}
// register slack Event publishers // register slack Event publishers
for (SlackPublisherConfiguration slackPublisherConfiguration : catalogApplicationConfig.getSlackEventPublishers()) { if (catalogApplicationConfig.getSlackEventPublishers() != null) {
SlackWebhookEventPublisher slackPublisher = new SlackWebhookEventPublisher(slackPublisherConfiguration); for (SlackPublisherConfiguration slackPublisherConfiguration :
EventPubSub.addEventHandler(slackPublisher); catalogApplicationConfig.getSlackEventPublishers()) {
SlackWebhookEventPublisher slackPublisher = new SlackWebhookEventPublisher(slackPublisherConfiguration);
EventPubSub.addEventHandler(slackPublisher);
}
} }
} }

View File

@ -102,7 +102,8 @@ public class ElasticSearchEventPublisher extends AbstractEventPublisher {
client.update(updateRequest, RequestOptions.DEFAULT); client.update(updateRequest, RequestOptions.DEFAULT);
} }
} catch (Exception e) { } catch (Exception e) {
LOG.error("failed to update ES doc", e); LOG.error("failed to update ES doc");
LOG.debug(e.getMessage());
} }
} }
} }

View File

@ -48,6 +48,9 @@ public class ChangeEventHandler implements EventHandler {
changeEvent.getEventType(), changeEvent.getEventType(),
changeEvent.getEntityType()); changeEvent.getEntityType());
EventPubSub.publish(changeEvent); EventPubSub.publish(changeEvent);
if (changeEvent.getEntity() != null) {
changeEvent.setEntity(JsonUtils.pojoToJson(changeEvent.getEntity()));
}
dao.changeEventDAO().insert(JsonUtils.pojoToJson(changeEvent)); dao.changeEventDAO().insert(JsonUtils.pojoToJson(changeEvent));
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -1117,7 +1117,6 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
compareEntities( compareEntities(
entityInterface.getEntity(), JsonUtils.readValue((String) changeEvent.getEntity(), entityClass), authHeaders); entityInterface.getEntity(), JsonUtils.readValue((String) changeEvent.getEntity(), entityClass), authHeaders);
} else if (expectedEventType == EventType.ENTITY_UPDATED) { } else if (expectedEventType == EventType.ENTITY_UPDATED) {
assertNull(changeEvent.getEntity());
assertChangeDescription(expectedChangeDescription, changeEvent.getChangeDescription()); assertChangeDescription(expectedChangeDescription, changeEvent.getChangeDescription());
} else if (expectedEventType == EventType.ENTITY_DELETED) { } else if (expectedEventType == EventType.ENTITY_DELETED) {
assertListNull(changeEvent.getEntity(), changeEvent.getChangeDescription()); assertListNull(changeEvent.getEntity(), changeEvent.getChangeDescription());