Search in sources :

Example 21 with ConnectorContext

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;
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 22 with ConnectorContext

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;
}
Also used : MetacatCreateTablePreEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePreEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 23 with ConnectorContext

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

Example 24 with ConnectorContext

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;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) List(java.util.List)

Example 25 with ConnectorContext

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));
}
Also used : MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePreEvent) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext)

Aggregations

ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)29 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)21 QualifiedName (com.netflix.metacat.common.QualifiedName)15 List (java.util.List)13 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)11 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)11 Map (java.util.Map)11 Nonnull (javax.annotation.Nonnull)11 Lists (com.google.common.collect.Lists)10 Pageable (com.netflix.metacat.common.dto.Pageable)9 Sort (com.netflix.metacat.common.dto.Sort)9 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)9 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 Strings (com.google.common.base.Strings)7 Maps (com.google.common.collect.Maps)7 HiveConnectorInfoConverter (com.netflix.metacat.connector.hive.converters.HiveConnectorInfoConverter)7