use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method rename.
/**
* {@inheritDoc}
*/
@Override
public void rename(final QualifiedName oldName, final QualifiedName newName, final boolean isMView) {
validate(oldName);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(oldName);
final TableDto oldTable = get(oldName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new TableNotFoundException(oldName));
if (oldTable != null) {
// Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
eventBus.postSync(new MetacatRenameTablePreEvent(oldName, metacatRequestContext, this, newName));
try {
log.info("Renaming {} {} to {}", isMView ? "view" : "table", oldName, newName);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
service.rename(connectorRequestContext, oldName, newName);
} catch (UnsupportedOperationException ignored) {
}
userMetadataService.renameDefinitionMetadataKey(oldName, newName);
tagService.rename(oldName, newName.getTableName());
final TableDto dto = get(newName, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build()).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatRenameTablePostEvent(oldName, metacatRequestContext, this, oldTable, dto, isMView));
}
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method deleteAndReturn.
/**
* {@inheritDoc}
*/
@Override
public TableDto deleteAndReturn(final QualifiedName name, final boolean isMView) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatDeleteTablePreEvent(name, metacatRequestContext, this));
validate(name);
final ConnectorTableService service = connectorManager.getTableService(name);
final Optional<TableDto> oTable = get(name, GetTableServiceParameters.builder().includeInfo(true).disableOnReadMetadataIntercetor(false).includeDefinitionMetadata(true).includeDataMetadata(true).build());
if (oTable.isPresent()) {
log.info("Drop table {}", name);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
service.delete(connectorRequestContext, name);
}
final TableDto tableDto = oTable.orElseGet(() -> {
// If the table doesn't exist construct a blank copy we can use to delete the definitionMetadata and tags
final TableDto t = new TableDto();
t.setName(name);
return t;
});
if (canDeleteMetadata(name)) {
// Delete the metadata. Type doesn't matter since we discard the result
log.info("Deleting user metadata for table {}", name);
userMetadataService.deleteMetadata(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto));
log.info("Deleting tags for table {}", name);
tagService.delete(name, false);
} else {
if (config.canSoftDeleteDataMetadata() && tableDto.isDataExternal()) {
userMetadataService.softDeleteDataMetadata(metacatRequestContext.getUserName(), Lists.newArrayList(tableDto.getDataUri()));
}
}
eventBus.postAsync(new MetacatDeleteTablePostEvent(name, metacatRequestContext, this, tableDto, isMView));
return tableDto;
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method get.
/**
* {@inheritDoc}
*/
@Override
public Optional<TableDto> get(final QualifiedName name, final GetTableServiceParameters getTableServiceParameters) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorTableService service = connectorManager.getTableService(name);
final TableDto tableInternal;
final TableDto table;
try {
tableInternal = converterUtil.toTableDto(service.get(connectorRequestContext, name));
} catch (NotFoundException ignored) {
return Optional.empty();
}
if (getTableServiceParameters.isIncludeInfo()) {
table = tableInternal;
} else {
table = new TableDto();
table.setName(name);
}
if (getTableServiceParameters.isIncludeDefinitionMetadata()) {
final Optional<ObjectNode> definitionMetadata = (getTableServiceParameters.isDisableOnReadMetadataIntercetor()) ? userMetadataService.getDefinitionMetadata(name) : userMetadataService.getDefinitionMetadataWithInterceptor(name, GetMetadataInterceptorParameters.builder().hasMetadata(tableInternal).build());
definitionMetadata.ifPresent(table::setDefinitionMetadata);
}
if (getTableServiceParameters.isIncludeDataMetadata()) {
TableDto dto = table;
if (!getTableServiceParameters.isIncludeInfo()) {
try {
dto = converterUtil.toTableDto(service.get(connectorRequestContext, name));
} catch (NotFoundException ignored) {
}
}
if (dto != null && dto.getSerde() != null) {
final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
dataMetadata.ifPresent(table::setDataMetadata);
}
}
return Optional.of(table);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class TableServiceImpl method exists.
/**
* {@inheritDoc}
*/
@Override
public boolean exists(final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
return service.exists(connectorRequestContext, name);
}
use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.
the class MetacatContextManager method getContext.
/**
* Returns the current thread context.
*
* @return context
*/
public static MetacatRequestContext getContext() {
MetacatRequestContext result = context.get();
if (result == null) {
result = new MetacatRequestContext();
setContext(result);
}
return result;
}
Aggregations