Search in sources :

Example 6 with ConnectorPartitionService

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

the class PartitionServiceImpl method getQualifiedNames.

@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
    final Map<String, List<QualifiedName>> result = Maps.newConcurrentMap();
    final List<ListenableFuture<Void>> futures = Lists.newArrayList();
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    catalogService.getCatalogNames().forEach(catalog -> {
        futures.add(threadServiceManager.getExecutor().submit(() -> {
            final ConnectorPartitionService service = connectorManager.getPartitionService(catalog.getCatalogName());
            final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
            try {
                final Map<String, List<QualifiedName>> partitionNames = service.getPartitionNames(connectorContext, uris, prefixSearch);
                partitionNames.forEach((uri, subPartitionNames) -> {
                    final List<QualifiedName> existingPartitionNames = result.get(uri);
                    if (existingPartitionNames == null) {
                        result.put(uri, subPartitionNames);
                    } else {
                        existingPartitionNames.addAll(subPartitionNames);
                    }
                });
            } catch (final UnsupportedOperationException uoe) {
                log.debug("Catalog {} doesn't support getPartitionNames. Ignoring.", catalog.getCatalogName());
            }
            return null;
        }));
    });
    try {
        Futures.allAsList(futures).get(1, TimeUnit.HOURS);
    } catch (Exception e) {
        Throwables.propagate(e);
    }
    return result;
}
Also used : UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) CatalogService(com.netflix.metacat.main.services.CatalogService) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) ConverterUtil(com.netflix.metacat.common.server.converter.ConverterUtil) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) PartitionService(com.netflix.metacat.main.services.PartitionService) HashMap(java.util.HashMap) Id(com.netflix.spectator.api.Id) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Strings(com.google.common.base.Strings) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) Lists(com.google.common.collect.Lists) ThreadServiceManager(com.netflix.metacat.common.server.util.ThreadServiceManager) TableService(com.netflix.metacat.main.services.TableService) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) Config(com.netflix.metacat.common.server.properties.Config) Nonnull(javax.annotation.Nonnull) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) Collection(java.util.Collection) Pageable(com.netflix.metacat.common.dto.Pageable) Throwables(com.google.common.base.Throwables) QualifiedName(com.netflix.metacat.common.QualifiedName) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatDeleteTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) Sort(com.netflix.metacat.common.dto.Sort) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ConnectorPartitionService

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

the class PartitionServiceImpl method list.

@Override
public List<PartitionDto> list(final QualifiedName name, final String filter, final List<String> partitionNames, final Sort sort, final Pageable pageable, final boolean includeUserDefinitionMetadata, final boolean includeUserDataMetadata, final boolean includePartitionDetails) {
    if (Strings.isNullOrEmpty(filter) && (pageable == null || !pageable.isPageable()) && (partitionNames == null || partitionNames.isEmpty()) && config.getQualifiedNamesToThrowErrorWhenNoFilterOnListPartitions().contains(name)) {
        throw new IllegalArgumentException(String.format("No filter or limit specified for table %s", name));
    }
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
    final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
    requestDto.setFilter(filter);
    requestDto.setIncludePartitionDetails(includePartitionDetails);
    requestDto.setPartitionNames(partitionNames);
    final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
    final List<PartitionInfo> resultInfo = service.getPartitions(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, pageable, sort));
    List<PartitionDto> result = Lists.newArrayList();
    if (resultInfo != null && !resultInfo.isEmpty()) {
        result = resultInfo.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
        final List<QualifiedName> names = Lists.newArrayList();
        final List<String> uris = Lists.newArrayList();
        result.forEach(partitionDto -> {
            names.add(partitionDto.getName());
            uris.add(partitionDto.getDataUri());
        });
        registry.gauge(this.partitionGetCountId.withTags(new HashMap<>(name.parts())), result.size());
        log.info("Got {} partitions for {} using filter: {} and partition names: {}", result.size(), name, filter, partitionNames);
        if (includeUserDefinitionMetadata || includeUserDataMetadata) {
            final List<ListenableFuture<Map<String, ObjectNode>>> futures = Lists.newArrayList();
            futures.add(threadServiceManager.getExecutor().submit(() -> includeUserDefinitionMetadata ? userMetadataService.getDefinitionMetadataMap(names) : Maps.newHashMap()));
            futures.add(threadServiceManager.getExecutor().submit(() -> includeUserDataMetadata ? userMetadataService.getDataMetadataMap(uris) : Maps.newHashMap()));
            try {
                final List<Map<String, ObjectNode>> metadataResults = Futures.successfulAsList(futures).get(1, TimeUnit.HOURS);
                final Map<String, ObjectNode> definitionMetadataMap = metadataResults.get(0);
                final Map<String, ObjectNode> dataMetadataMap = metadataResults.get(1);
                result.forEach(partitionDto -> userMetadataService.populateMetadata(partitionDto, definitionMetadataMap.get(partitionDto.getName().toString()), dataMetadataMap.get(partitionDto.getDataUri())));
            } catch (Exception e) {
                Throwables.propagate(e);
            }
        }
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) QualifiedName(com.netflix.metacat.common.QualifiedName) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)7 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)7 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)7 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)6 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)4 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)4 HashMap (java.util.HashMap)4 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)3 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)3 MetacatDeleteTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent)3 MetacatDeleteTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 QualifiedName (com.netflix.metacat.common.QualifiedName)2 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)2 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)2 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)2 MetacatSaveTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent)2 Map (java.util.Map)2 Strings (com.google.common.base.Strings)1