Search in sources :

Example 1 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class PartitionServiceImpl method getPartitionKeys.

@Override
public List<String> getPartitionKeys(final QualifiedName name, final String filter, final List<String> partitionNames, final Sort sort, final Pageable pageable) {
    List<String> result = Lists.newArrayList();
    if (tableService.exists(name)) {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
        final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
        requestDto.setFilter(filter);
        requestDto.setPartitionNames(partitionNames);
        final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
        try {
            result = service.getPartitionKeys(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, pageable, sort));
        } catch (final UnsupportedOperationException uoe) {
            log.debug("Catalog {} doesn't support getPartitionKeys. Ignoring.", name.getCatalogName());
        }
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto)

Example 2 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class TagV1Resource method removeTableTags.

/**
     * {@inheritDoc}
     */
@Override
public void removeTableTags(final String catalogName, final String databaseName, final String tableName, final Boolean deleteAll, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    requestWrapper.processRequest(name, "TagV1Resource.removeTableTags", () -> {
        if (!tableService.exists(name)) {
            // Delete tags if exists
            tagService.delete(name, false);
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        tagService.removeTableTags(name, deleteAll, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return null;
    });
}
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) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 3 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class TagV1Resource method setTableTags.

/**
     * {@inheritDoc}
     */
@Override
public Set<String> setTableTags(final String catalogName, final String databaseName, final String tableName, final Set<String> tags) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName name = requestWrapper.qualifyName(() -> QualifiedName.ofTable(catalogName, databaseName, tableName));
    return requestWrapper.processRequest(name, "TagV1Resource.setTableTags", () -> {
        if (!tableService.exists(name)) {
            throw new TableNotFoundException(name);
        }
        final TableDto oldTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        final Set<String> result = tagService.setTableTags(name, tags, true);
        final TableDto currentTable = this.tableService.get(name, true).orElseThrow(IllegalStateException::new);
        eventBus.postAsync(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
        return result;
    });
}
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) QualifiedName(com.netflix.metacat.common.QualifiedName) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 4 with MetacatRequestContext

use of com.netflix.metacat.common.MetacatRequestContext in project metacat by Netflix.

the class TableServiceImpl method getQualifiedNames.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
    final Map<String, List<QualifiedName>> result = Maps.newHashMap();
    connectorManager.getTableServices().forEach(service -> {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        try {
            final Map<String, List<QualifiedName>> names = service.getTableNames(connectorRequestContext, uris, prefixSearch);
            names.forEach((uri, qNames) -> {
                final List<QualifiedName> existingNames = result.get(uri);
                if (existingNames == null) {
                    result.put(uri, qNames);
                } else {
                    existingNames.addAll(qNames);
                }
            });
        } catch (final UnsupportedOperationException uoe) {
            log.debug("Table service doesn't support getting table names by URI. Skipping");
        }
    });
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) List(java.util.List) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 5 with MetacatRequestContext

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

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)65 QualifiedName (com.netflix.metacat.common.QualifiedName)28 ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)24 TableDto (com.netflix.metacat.common.dto.TableDto)22 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)19 List (java.util.List)16 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)13 Collectors (java.util.stream.Collectors)12 Slf4j (lombok.extern.slf4j.Slf4j)12 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)11 Lists (com.google.common.collect.Lists)10 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)10 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)10 Metrics (com.netflix.metacat.common.server.monitoring.Metrics)10 UserMetadataService (com.netflix.metacat.common.server.usermetadata.UserMetadataService)10 Registry (com.netflix.spectator.api.Registry)10 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)9 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)9 MetacatUpdateTablePostEvent (com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent)9 Config (com.netflix.metacat.common.server.properties.Config)9