use of com.netflix.metacat.common.server.connectors.ConnectorContext 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;
}
use of com.netflix.metacat.common.server.connectors.ConnectorContext in project metacat by Netflix.
the class TableServiceImpl method create.
@Override
public TableDto create(@Nonnull final QualifiedName name, @Nonnull final TableDto tableDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
validate(name);
//
// Set the owner,if null, with the session user name.
//
setOwnerIfNull(tableDto, metacatRequestContext.getUserName());
log.info("Creating table {}", name);
eventBus.postSync(new MetacatCreateTablePreEvent(name, metacatRequestContext, this, tableDto));
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
service.create(connectorContext, converterUtil.fromTableDto(tableDto));
if (tableDto.getDataMetadata() != null || tableDto.getDefinitionMetadata() != null) {
log.info("Saving user metadata for table {}", name);
userMetadataService.saveMetadata(metacatRequestContext.getUserName(), tableDto, false);
tag(name, tableDto.getDefinitionMetadata());
}
final TableDto dto = get(name, true).orElseThrow(() -> new IllegalStateException("Should exist"));
eventBus.postAsync(new MetacatCreateTablePostEvent(name, metacatRequestContext, this, dto));
return dto;
}
use of com.netflix.metacat.common.server.connectors.ConnectorContext in project metacat by Netflix.
the class TableServiceImpl method get.
@Override
public Optional<TableDto> get(@Nonnull final QualifiedName name, final boolean includeInfo, final boolean includeDefinitionMetadata, final boolean includeDataMetadata) {
validate(name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
final TableDto table;
if (includeInfo) {
try {
table = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
return Optional.empty();
}
} else {
table = new TableDto();
table.setName(name);
}
if (includeDefinitionMetadata) {
final Optional<ObjectNode> definitionMetadata = userMetadataService.getDefinitionMetadata(name);
if (definitionMetadata.isPresent()) {
table.setDefinitionMetadata(definitionMetadata.get());
}
}
if (includeDataMetadata) {
TableDto dto = table;
if (!includeInfo) {
try {
dto = converterUtil.toTableDto(service.get(connectorContext, name));
} catch (NotFoundException ignored) {
}
}
if (dto != null && dto.getSerde() != null) {
final Optional<ObjectNode> dataMetadata = userMetadataService.getDataMetadata(dto.getSerde().getUri());
if (dataMetadata.isPresent()) {
table.setDataMetadata(dataMetadata.get());
}
}
}
return Optional.of(table);
}
use of com.netflix.metacat.common.server.connectors.ConnectorContext in project metacat by Netflix.
the class TableServiceImpl method getQualifiedNames.
@Override
public List<QualifiedName> getQualifiedNames(final String uri, final boolean prefixSearch) {
final List<QualifiedName> result = Lists.newArrayList();
connectorManager.getCatalogs().keySet().forEach(catalogName -> {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(catalogName);
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> names = service.getTableNames(connectorContext, Lists.newArrayList(uri), prefixSearch);
final List<QualifiedName> qualifiedNames = names.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
result.addAll(qualifiedNames);
} catch (final UnsupportedOperationException uoe) {
log.debug("Catalog {} doesn't support getting table names by URI. Skipping", catalogName);
}
});
return result;
}
use of com.netflix.metacat.common.server.connectors.ConnectorContext in project metacat by Netflix.
the class DatabaseServiceImpl method delete.
@Override
public void delete(@Nonnull final QualifiedName name) {
validate(name);
log.info("Dropping schema {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final DatabaseDto dto = get(name, true);
eventBus.postSync(new MetacatDeleteDatabasePreEvent(name, metacatRequestContext, this, dto));
final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
connectorManager.getDatabaseService(name.getCatalogName()).delete(connectorContext, name);
// Delete definition metadata if it exists
if (userMetadataService.getDefinitionMetadata(name).isPresent()) {
log.info("Deleting user metadata for schema {}", name);
userMetadataService.deleteDefinitionMetadatas(ImmutableList.of(name));
}
eventBus.postAsync(new MetacatDeleteDatabasePostEvent(name, metacatRequestContext, this, dto));
}
Aggregations