Search in sources :

Example 11 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext 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));
    }
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatRenameTablePreEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePreEvent) TableDto(com.netflix.metacat.common.dto.TableDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent)

Example 12 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext 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;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatDeleteTablePreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePreEvent)

Example 13 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext 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);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 14 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext 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);
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 15 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class DatabaseServiceImpl method create.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto create(final QualifiedName name, final DatabaseDto dto) {
    validate(name);
    log.info("Creating schema {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatCreateDatabasePreEvent(name, metacatRequestContext, this));
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorManager.getDatabaseService(name).create(connectorRequestContext, converterUtil.fromDatabaseDto(dto));
    if (dto.getDefinitionMetadata() != null) {
        log.info("Saving user metadata for schema {}", name);
        userMetadataService.saveDefinitionMetadata(name, metacatRequestContext.getUserName(), Optional.of(dto.getDefinitionMetadata()), true);
    }
    final DatabaseDto createdDto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(true).includeUserMetadata(dto.getDefinitionMetadata() != null).includeTableNames(true).build());
    eventBus.postAsync(new MetacatCreateDatabasePostEvent(name, metacatRequestContext, this, createdDto));
    return createdDto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) MetacatCreateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePreEvent) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Aggregations

ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)29 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)20 QualifiedName (com.netflix.metacat.common.QualifiedName)15 List (java.util.List)13 Lists (com.google.common.collect.Lists)11 Pageable (com.netflix.metacat.common.dto.Pageable)10 Sort (com.netflix.metacat.common.dto.Sort)10 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)10 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)10 Map (java.util.Map)10 Nullable (javax.annotation.Nullable)10 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)9 Collectors (java.util.stream.Collectors)9 Strings (com.google.common.base.Strings)8 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)8 PartitionListRequest (com.netflix.metacat.common.server.connectors.model.PartitionListRequest)8 Maps (com.google.common.collect.Maps)7 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 TableDto (com.netflix.metacat.common.dto.TableDto)6