Search in sources :

Example 1 with MetacatSaveTablePartitionPreEvent

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

the class MetacatServiceHelper method postPreUpdateEvent.

/**
 * Calls the right method of the event bus for the given qualified name.
 *
 * @param name                  name
 * @param metacatRequestContext context
 * @param dto                   dto
 */
public void postPreUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto dto) {
    if (name.isPartitionDefinition()) {
        final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
        if (dto != null) {
            partitionsSaveRequestDto.setPartitions(ImmutableList.of((PartitionDto) dto));
        }
        this.eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, partitionsSaveRequestDto));
    } else if (name.isViewDefinition()) {
        this.eventBus.postSync(new MetacatUpdateMViewPreEvent(name, metacatRequestContext, this, (TableDto) dto));
    } else if (name.isTableDefinition()) {
        this.eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, (TableDto) dto, (TableDto) dto));
    } else if (name.isDatabaseDefinition()) {
        eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatUpdateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 2 with MetacatSaveTablePartitionPreEvent

use of com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent 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();
    registry.distributionSummary(this.partitionAddDistSummary.withTags(name.parts())).record(partitionDtos.size());
    final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        eventBus.postSync(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));
        if (deletePartitionInfos != null) {
            deletePartitionDtos = deletePartitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
            deletePartitions = new ArrayList<>(deletePartitions);
        }
    }
    // Save all the new and updated partitions
    eventBus.postSync(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.postAsync(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, deletePartitionDtos));
    }
    eventBus.postAsync(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)

Aggregations

PartitionDto (com.netflix.metacat.common.dto.PartitionDto)2 MetacatSaveTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent)2 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)1 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)1 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)1 MetacatDeleteTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent)1 MetacatDeleteTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent)1 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)1 MetacatUpdateDatabasePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent)1 MetacatUpdateMViewPreEvent (com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent)1 MetacatUpdateTablePreEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)1