use of com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent 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.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));
}
}
use of com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent in project metacat by Netflix.
the class TableServiceImpl method updateAndReturn.
@Override
public TableDto updateAndReturn(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto oldTable = get(name, true).orElseThrow(() -> new TableNotFoundException(name));
eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, oldTable, tableDto));
//Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
if (isTableInfoProvided(tableDto)) {
try {
log.info("Updating table {}", name);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.update(connectorContext, converterUtil.fromTableDto(tableDto));
} catch (UnsupportedOperationException ignored) {
}
}
// Merge in metadata if the user sent any
if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for table {}", name);
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, true);
}
final TableDto updatedDto = get(name, true).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, updatedDto));
return updatedDto;
}
Aggregations