use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method exists.
@Override
public boolean exists(@Nonnull final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
return service.exists(connectorContext, name);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MViewServiceImpl method updateAndReturn.
@Override
public TableDto updateAndReturn(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatUpdateMViewPreEvent(name, metacatRequestContext, this, tableDto));
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
log.info("Updating view {}.", viewQName);
tableService.update(viewQName, tableDto);
final TableDto updatedDto = getOpt(name).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatUpdateMViewPostEvent(name, metacatRequestContext, this, updatedDto));
return updatedDto;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MViewServiceImpl method savePartitions.
@Override
public PartitionsSaveResponseDto savePartitions(@Nonnull final QualifiedName name, final PartitionsSaveRequestDto dto, final boolean merge) {
PartitionsSaveResponseDto result;
final List<PartitionDto> partitionDtos = dto.getPartitions();
if (partitionDtos == null || partitionDtos.isEmpty()) {
return new PartitionsSaveResponseDto();
}
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
partitionDtos.forEach(partitionDto -> partitionDto.setName(QualifiedName.ofPartition(viewQName.getCatalogName(), viewQName.getDatabaseName(), viewQName.getTableName(), partitionDto.getName().getPartitionName())));
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatSaveMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
}
if (merge) {
final List<String> partitionNames = partitionDtos.stream().map(partitionDto -> partitionDto.getName().getPartitionName()).collect(Collectors.toList());
final List<PartitionDto> existingPartitions = partitionService.list(viewQName, null, partitionNames, null, null, false, false, false);
final Map<String, PartitionDto> existingPartitionsMap = existingPartitions.stream().collect(Collectors.toMap(partitionDto -> partitionDto.getName().getPartitionName(), Function.identity()));
final List<PartitionDto> mergedPartitions = partitionDtos.stream().map(partitionDto -> {
final String partitionName = partitionDto.getName().getPartitionName();
final PartitionDto existingPartition = existingPartitionsMap.get(partitionName);
return mergePartition(partitionDto, existingPartition);
}).collect(Collectors.toList());
dto.setPartitions(mergedPartitions);
result = partitionService.save(viewQName, dto);
} else {
result = partitionService.save(viewQName, dto);
}
eventBus.postAsync(new MetacatSaveMViewPartitionPostEvent(name, metacatRequestContext, this, dto.getPartitions()));
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIdsForDeletes));
}
return result;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class CatalogServiceImpl method update.
/**
* {@inheritDoc}
*/
@Override
public void update(@Nonnull final QualifiedName name, @Nonnull final CreateCatalogDto createCatalogDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
connectorManager.getCatalogConfig(name);
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), createCatalogDto, true);
eventBus.postAsync(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class DatabaseServiceImpl method update.
@Override
public void update(@Nonnull final QualifiedName name, @Nonnull final DatabaseDto dto) {
validate(name);
log.info("Updating schema {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
try {
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorManager.getDatabaseService(name.getCatalogName()).update(connectorContext, converterUtil.fromDatabaseDto(dto));
} catch (UnsupportedOperationException ignored) {
}
if (dto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for schema {}", name);
userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
}
eventBus.postAsync(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
}
Aggregations