Search in sources :

Example 1 with MetacatSaveTablePartitionPostEvent

use of com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent in project metacat by Netflix.

the class ElasticSearchEventHandlers method metacatSaveTablePartitionPostEventHandler.

/**
 * Subscriber.
 *
 * @param event event
 */
@EventListener
public void metacatSaveTablePartitionPostEventHandler(final MetacatSaveTablePartitionPostEvent event) {
    log.debug("Received SaveTablePartitionEvent {}", event);
    this.partitionSaveEventsDelayTimer.record(System.currentTimeMillis() - event.getRequestContext().getTimestamp(), TimeUnit.MILLISECONDS);
    if (config.isElasticSearchPublishPartitionEnabled()) {
        this.partitionSaveTimer.record(() -> {
            final List<PartitionDto> partitionDtos = event.getPartitions();
            final MetacatRequestContext context = event.getRequestContext();
            final List<ElasticSearchDoc> docs = partitionDtos.stream().map(dto -> new ElasticSearchDoc(dto.getName().toString(), dto, context.getUserName(), false)).collect(Collectors.toList());
            es.save(ElasticSearchDoc.Type.partition.name(), docs);
        });
    }
}
Also used : MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AsyncListener(com.netflix.metacat.common.server.events.AsyncListener) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Config(com.netflix.metacat.common.server.properties.Config) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) EventListener(org.springframework.context.event.EventListener) Collectors(java.util.stream.Collectors) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) Timer(com.netflix.spectator.api.Timer) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) EventListener(org.springframework.context.event.EventListener)

Example 2 with MetacatSaveTablePartitionPostEvent

use of com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent in project metacat by Netflix.

the class MetacatElasticSearchEventHandlers method metacatSaveTablePartitionPostEventHandler.

/**
     * Subscriber.
     *
     * @param event event
     */
@EventListener
public void metacatSaveTablePartitionPostEventHandler(final MetacatSaveTablePartitionPostEvent event) {
    log.debug("Received SaveTablePartitionEvent {}", event);
    registry.counter(Metrics.CounterElasticSearchPartitionSave.name()).increment();
    final List<PartitionDto> partitionDtos = event.getPartitions();
    final MetacatRequestContext context = event.getRequestContext();
    final List<ElasticSearchDoc> docs = partitionDtos.stream().map(dto -> new ElasticSearchDoc(dto.getName().toString(), dto, context.getUserName(), false)).collect(Collectors.toList());
    es.save(ElasticSearchDoc.Type.partition.name(), docs);
}
Also used : MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent) EventListener(org.springframework.context.event.EventListener) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) Objects(java.util.Objects) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) EventListener(org.springframework.context.event.EventListener)

Example 3 with MetacatSaveTablePartitionPostEvent

use of com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent in project metacat by Netflix.

the class PartitionServiceImpl method updatePartitions.

/**
 * Add, delete, update partitions.
 *
 * @param service               partition service
 * @param metacatRequestContext metacat request context
 * @param dto                   partition save request dto
 * @param name                  qualified name
 * @param partitionDtos         partitions dto
 * @return partition save response dto
 */
private PartitionsSaveResponseDto updatePartitions(final ConnectorPartitionService service, final MetacatRequestContext metacatRequestContext, final PartitionsSaveRequestDto dto, final QualifiedName name, final List<PartitionDto> partitionDtos) {
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    List<HasMetadata> deletePartitions = Lists.newArrayList();
    List<PartitionDto> deletePartitionDtos = Lists.newArrayList();
    validate(name, dto);
    registry.distributionSummary(this.partitionAddDistSummary.withTags(name.parts())).record(partitionDtos.size());
    final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        eventBus.post(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
        registry.distributionSummary(this.partitionDeleteDistSummary.withTags(name.parts())).record(partitionIdsForDeletes.size());
        final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto(null, partitionIdsForDeletes, false, true);
        final List<PartitionInfo> deletePartitionInfos = service.getPartitions(connectorRequestContext, name, converterUtil.toPartitionListRequest(requestDto, null, null), this.getTableInfo(name));
        if (deletePartitionInfos != null) {
            deletePartitionDtos = deletePartitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
            deletePartitions = new ArrayList<>(deletePartitions);
        }
    }
    // Save all the new and updated partitions
    eventBus.post(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, dto));
    log.info("Saving partitions for {} ({})", name, partitionDtos.size());
    final PartitionsSaveResponseDto result = converterUtil.toPartitionsSaveResponseDto(service.savePartitions(connectorRequestContext, name, converterUtil.toPartitionsSaveRequest(dto)));
    // Save metadata
    log.info("Saving user metadata for partitions for {}", name);
    // delete metadata
    if (!deletePartitions.isEmpty()) {
        log.info("Deleting user metadata for partitions with names {} for {}", partitionIdsForDeletes, name);
        deleteMetadatas(metacatRequestContext.getUserName(), deletePartitions);
    }
    final long start = registry.clock().wallTime();
    userMetadataService.saveMetadata(metacatRequestContext.getUserName(), partitionDtos, true);
    final long duration = registry.clock().wallTime() - start;
    log.info("Time taken to save user metadata for table {} is {} ms", name, duration);
    registry.timer(registry.createId(Metrics.TimerSavePartitionMetadata.getMetricName()).withTags(name.parts())).record(duration, TimeUnit.MILLISECONDS);
    // TODO: create MetacatUpdateTablePartitionEvents, only publish one partitionUpdateEvent here.
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        eventBus.post(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, deletePartitionDtos));
    }
    eventBus.post(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, partitionDtos, result));
    return result;
}
Also used : HasMetadata(com.netflix.metacat.common.dto.HasMetadata) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatDeleteTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Example 4 with MetacatSaveTablePartitionPostEvent

use of com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent in project metacat by Netflix.

the class MetacatServiceHelper method postPostUpdateEvent.

/**
 * Calls the right method of the event bus for the given qualified name.
 *
 * @param name                  name
 * @param metacatRequestContext context
 * @param oldDTo                dto
 * @param currentDto            dto
 */
public void postPostUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto oldDTo, final BaseDto currentDto) {
    if (name.isPartitionDefinition()) {
        final List<PartitionDto> dtos = Lists.newArrayList();
        if (currentDto != null) {
            dtos.add((PartitionDto) currentDto);
        }
        // This request neither added nor updated partitions
        final PartitionsSaveResponseDto partitionsSaveResponseDto = new PartitionsSaveResponseDto();
        this.eventBus.post(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, dtos, partitionsSaveResponseDto));
    } else if (name.isViewDefinition()) {
        final MetacatUpdateMViewPostEvent event = new MetacatUpdateMViewPostEvent(name, metacatRequestContext, this, (TableDto) currentDto);
        this.eventBus.post(event);
    } else if (name.isTableDefinition()) {
        final MetacatUpdateTablePostEvent event = new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, (TableDto) oldDTo, (TableDto) currentDto);
        this.eventBus.post(event);
    } else if (name.isDatabaseDefinition()) {
        this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) MetacatUpdateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Aggregations

PartitionDto (com.netflix.metacat.common.dto.PartitionDto)4 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)4 TableDto (com.netflix.metacat.common.dto.TableDto)3 MetacatDeleteTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent)3 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)2 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)2 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)2 MetacatJsonLocator (com.netflix.metacat.common.json.MetacatJsonLocator)2 MetacatCreateDatabasePostEvent (com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent)2 MetacatCreateTablePostEvent (com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent)2 MetacatDeleteDatabasePostEvent (com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent)2 MetacatDeleteTablePostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent)2 MetacatRenameTablePostEvent (com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)2 Metrics (com.netflix.metacat.common.server.monitoring.Metrics)2 Registry (com.netflix.spectator.api.Registry)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2