Search in sources :

Example 11 with EventListener

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());
    });
}
Also used : DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) EventListener(org.springframework.context.event.EventListener)

Example 12 with EventListener

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);
    });
}
Also used : DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) EventListener(org.springframework.context.event.EventListener)

Example 13 with EventListener

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());
            }
        }
    });
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) EventListener(org.springframework.context.event.EventListener)

Example 14 with EventListener

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);
            });
        }
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) NameDateDto(com.netflix.metacat.common.NameDateDto) EventListener(org.springframework.context.event.EventListener)

Example 15 with EventListener

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);
        }
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) NameDateDto(com.netflix.metacat.common.NameDateDto) EventListener(org.springframework.context.event.EventListener)

Aggregations

EventListener (org.springframework.context.event.EventListener)34 TableDto (com.netflix.metacat.common.dto.TableDto)10 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)6 AbstractCasEvent (org.apereo.cas.support.events.AbstractCasEvent)4 CasEvent (org.apereo.cas.support.events.dao.CasEvent)4 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)3 AntivirusJobResponse (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse)3 IOException (java.io.IOException)3 List (java.util.List)3 Transactional (org.springframework.transaction.annotation.Transactional)3 InvalidParameterException (com.amazonaws.services.sns.model.InvalidParameterException)2 InvalidParameterValueException (com.amazonaws.services.sns.model.InvalidParameterValueException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)2 NameDateDto (com.netflix.metacat.common.NameDateDto)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2 UpdateTableMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTableMessage)2 UpdateTablePartitionsMessage (com.netflix.metacat.common.dto.notifications.sns.messages.UpdateTablePartitionsMessage)2 TablePartitionsUpdatePayload (com.netflix.metacat.common.dto.notifications.sns.payloads.TablePartitionsUpdatePayload)2 MetacatJsonLocator (com.netflix.metacat.common.json.MetacatJsonLocator)2