use of org.springframework.context.event.EventListener in project metacat by Netflix.
the class ElasticSearchEventHandlers method metacatDeleteDatabasePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatDeleteDatabasePostEventHandler(final MetacatDeleteDatabasePostEvent event) {
log.debug("Received DeleteDatabaseEvent {}", event);
this.databaseDeleteEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
this.databaseDeleteTimer.record(() -> {
final DatabaseDto dto = event.getDatabase();
es.softDelete(ElasticSearchDoc.Type.database.name(), dto.getName().toString(), event.getRequestContext());
});
}
use of org.springframework.context.event.EventListener in project metacat by Netflix.
the class ElasticSearchEventHandlers method metacatCreateDatabasePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatCreateDatabasePostEventHandler(final MetacatCreateDatabasePostEvent event) {
log.debug("Received CreateDatabaseEvent {}", event);
this.databaseCreateEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
this.databaseCreateTimer.record(() -> {
final DatabaseDto dto = event.getDatabase();
final ElasticSearchDoc doc = new ElasticSearchDoc(dto.getName().toString(), dto, event.getRequestContext().getUserName(), false);
es.save(ElasticSearchDoc.Type.database.name(), doc.getId(), doc);
});
}
use of org.springframework.context.event.EventListener in project metacat by Netflix.
the class ElasticSearchEventHandlers method metacatDeleteTablePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatDeleteTablePostEventHandler(final MetacatDeleteTablePostEvent event) {
log.debug("Received DeleteTableEvent {}", event);
this.tableDeleteEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
this.tableDeleteTimer.record(() -> {
final TableDto dto = event.getTable();
es.softDelete(ElasticSearchDoc.Type.table.name(), dto.getName().toString(), event.getRequestContext());
if (config.isElasticSearchPublishPartitionEnabled()) {
try {
final List<String> partitionIdsToBeDeleted = es.getIdsByQualifiedName(ElasticSearchDoc.Type.partition.name(), dto.getName());
es.delete(ElasticSearchDoc.Type.partition.name(), partitionIdsToBeDeleted);
} catch (Exception e) {
log.warn("Failed deleting the partitions for the dropped table/view:{}", dto.getName());
}
}
});
}
use of org.springframework.context.event.EventListener in project metacat by Netflix.
the class MViewServiceEventHandler method metacatRenameTablePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatRenameTablePostEventHandler(final MetacatRenameTablePostEvent event) {
if (!event.isMView()) {
final QualifiedName oldName = event.getOldTable().getName();
final QualifiedName newName = event.getCurrentTable().getName();
final List<NameDateDto> views = mViewService.list(oldName);
if (views != null && !views.isEmpty()) {
views.forEach(view -> {
final QualifiedName newViewName = QualifiedName.ofView(oldName.getCatalogName(), oldName.getDatabaseName(), newName.getTableName(), view.getName().getViewName());
mViewService.rename(view.getName(), newViewName);
});
}
}
}
use of org.springframework.context.event.EventListener in project metacat by Netflix.
the class MViewServiceEventHandler method metacatDeleteTablePostEventHandler.
/**
* Subscriber.
*
* @param event event
*/
@EventListener
public void metacatDeleteTablePostEventHandler(final MetacatDeleteTablePostEvent event) {
if (config.canCascadeViewsMetadataOnTableDelete() && !event.isMView()) {
final QualifiedName name = event.getTable().getName();
try {
// delete views associated with this table
final List<NameDateDto> viewNames = mViewService.list(name);
viewNames.forEach(viewName -> mViewService.deleteAndReturn(viewName.getName()));
} catch (Exception e) {
log.warn("Failed cleaning mviews after deleting table {}", name);
}
// delete table partitions metadata
try {
final List<QualifiedName> names = userMetadataService.getDescendantDefinitionNames(name);
if (names != null && !names.isEmpty()) {
userMetadataService.deleteDefinitionMetadata(names);
}
} catch (Exception e) {
log.warn("Failed cleaning partition definition metadata after deleting table {}", name);
}
}
}
Aggregations