use of com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent in project metacat by Netflix.
the class PartitionServiceImpl method save.
@Override
public PartitionsSaveResponseDto save(@Nonnull final QualifiedName name, final PartitionsSaveRequestDto dto) {
PartitionsSaveResponseDto result = new PartitionsSaveResponseDto();
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
final List<PartitionDto> partitionDtos = dto.getPartitions();
// If no partitions are passed, then return
if (partitionDtos == null || partitionDtos.isEmpty()) {
return result;
}
final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
registry.gauge(this.partitionAddedCountId.withTags(new HashMap<>(name.parts())), partitionDtos.size());
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
List<HasMetadata> deletePartitions = Lists.newArrayList();
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postSync(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
registry.gauge(this.partitionDeletedCountId.withTags(new HashMap<>(name.parts())), partitionIdsForDeletes.size());
final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
requestDto.setIncludePartitionDetails(false);
requestDto.setPartitionNames(partitionIdsForDeletes);
final List<PartitionInfo> deletePartitionInfos = service.getPartitions(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, null, null));
if (deletePartitionInfos != null) {
deletePartitions = deletePartitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
}
}
//
// Save all the new and updated partitions
//
eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, dto));
log.info("Saving partitions({}) for {}", partitionDtos.size(), name);
result = converterUtil.toPartitionsSaveResponseDto(service.savePartitions(connectorContext, 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);
}
userMetadataService.saveMetadatas(metacatRequestContext.getUserName(), partitionDtos, true);
eventBus.postAsync(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, partitionDtos, result));
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postAsync(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionIdsForDeletes));
}
return result;
}
use of com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent in project metacat by Netflix.
the class PartitionServiceImpl method delete.
@Override
public void delete(final QualifiedName name, final List<String> partitionIds) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
registry.gauge(this.partitionDeletedCountId.withTags(new HashMap<>(name.parts())), partitionIds.size());
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
if (!partitionIds.isEmpty()) {
final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
dto.setPartitionIdsForDeletes(partitionIds);
eventBus.postSync(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
// Get the partitions before calling delete
final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
requestDto.setIncludePartitionDetails(false);
requestDto.setPartitionNames(partitionIds);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final List<PartitionInfo> partitionInfos = service.getPartitions(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, null, null));
List<HasMetadata> partitions = Lists.newArrayList();
if (partitionInfos != null) {
partitions = partitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
}
log.info("Deleting partitions with names {} for {}", partitionIds, name);
service.deletePartitions(connectorContext, name, partitionIds);
// delete metadata
log.info("Deleting user metadata for partitions with names {} for {}", partitionIds, name);
if (!partitions.isEmpty()) {
deleteMetadatas(metacatRequestContext.getUserName(), partitions);
}
eventBus.postAsync(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionIds));
}
}
Aggregations