Search in sources :

Example 56 with MetacatRequestContext

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

the class DatabaseServiceImpl method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final QualifiedName name) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    this.authorizationService.checkPermission(metacatRequestContext.getUserName(), name, MetacatOperation.DELETE);
    log.info("Dropping schema {}", name);
    final DatabaseDto dto = get(name, GetDatabaseServiceParameters.builder().disableOnReadMetadataIntercetor(false).includeUserMetadata(true).includeTableNames(true).build());
    eventBus.post(new MetacatDeleteDatabasePreEvent(name, metacatRequestContext, this, dto));
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    connectorManager.getDatabaseService(name).delete(connectorRequestContext, name);
    // Delete definition metadata if it exists
    if (userMetadataService.getDefinitionMetadata(name).isPresent()) {
        log.info("Deleting user metadata for schema {}", name);
        userMetadataService.deleteDefinitionMetadata(ImmutableList.of(name));
    }
    eventBus.post(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) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 57 with MetacatRequestContext

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

the class PartitionServiceImpl method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final QualifiedName name, final List<String> partitionIds) {
    validateDeletes(name, partitionIds != null ? partitionIds.size() : 0);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    registry.distributionSummary(this.partitionDeleteDistSummary.withTags(name.parts())).record(partitionIds.size());
    if (!tableService.exists(name)) {
        throw new TableNotFoundException(name);
    }
    if (!partitionIds.isEmpty()) {
        final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
        dto.setPartitionIdsForDeletes(partitionIds);
        eventBus.post(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
        final ConnectorPartitionService service = connectorManager.getPartitionService(name);
        // Get the partitions before calling delete
        final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto(null, partitionIds, false, true);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        final List<PartitionInfo> partitionInfos = service.getPartitions(connectorRequestContext, name, converterUtil.toPartitionListRequest(requestDto, null, null), this.getTableInfo(name));
        List<HasMetadata> partitions = Lists.newArrayList();
        List<PartitionDto> partitionDtos = Lists.newArrayList();
        if (partitionInfos != null) {
            partitionDtos = partitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
            partitions = new ArrayList<>(partitions);
        }
        log.info("Deleting partitions with names {} for {}", partitionIds, name);
        service.deletePartitions(connectorRequestContext, name, partitionIds, this.getTableInfo(name));
        // delete metadata
        log.info("Deleting user metadata for partitions with names {} for {}", partitionIds, name);
        if (!partitions.isEmpty()) {
            deleteMetadatas(metacatRequestContext.getUserName(), partitions);
        }
        eventBus.post(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionDtos));
    }
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) MetacatDeleteTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo)

Example 58 with MetacatRequestContext

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

the class PartitionServiceImpl method getQualifiedNames.

/**
 * {@inheritDoc}
 */
@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();
    connectorManager.getPartitionServices().forEach(service -> {
        futures.add(threadServiceManager.getExecutor().submit(() -> {
            final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
            try {
                final Map<String, List<QualifiedName>> partitionNames = service.getPartitionNames(connectorRequestContext, 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("Partition service doesn't support getPartitionNames. Ignoring.");
            }
            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) 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) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Collection(java.util.Collection) Pageable(com.netflix.metacat.common.dto.Pageable) QualifiedName(com.netflix.metacat.common.QualifiedName) Collectors(java.util.stream.Collectors) PartitionsSaveResponse(com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) MetacatSaveTablePartitionMetadataOnlyPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionMetadataOnlyPostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) GetTableServiceParameters(com.netflix.metacat.main.services.GetTableServiceParameters) Sort(com.netflix.metacat.common.dto.Sort) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) Id(com.netflix.spectator.api.Id) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) 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) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Config(com.netflix.metacat.common.server.properties.Config) Nullable(javax.annotation.Nullable) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) Throwables(com.google.common.base.Throwables) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) PartitionListRequest(com.netflix.metacat.common.server.connectors.model.PartitionListRequest) MetacatDeleteTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent) MetacatSaveTablePartitionMetadataOnlyPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionMetadataOnlyPreEvent) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) ArrayList(java.util.ArrayList) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) Map(java.util.Map) HashMap(java.util.HashMap) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)

Example 59 with MetacatRequestContext

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

the class MetadataController method deleteDefinitionMetadata.

/**
 * Delete the definition metadata for the given name.
 *
 * @param name  Name of definition metadata to be deleted
 * @param force If true, deletes the metadata without checking if the database/table/partition exists
 */
@RequestMapping(method = RequestMethod.DELETE, path = "/definition")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(position = 4, value = "Deletes the given definition metadata")
public void deleteDefinitionMetadata(@ApiParam(value = "Name of definition metadata to be deleted", required = true) @RequestParam(name = "name") final String name, @ApiParam(value = "If true, deletes the metadata without checking if the database/table/partition exists") @RequestParam(name = "force", defaultValue = "false") final boolean force) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    requestWrapper.processRequest("deleteDefinitionMetadata", () -> {
        metadataService.deleteDefinitionMetadata(QualifiedName.fromString(name), force, metacatRequestContext);
        return null;
    });
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 60 with MetacatRequestContext

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

the class TagController method setResourceTags.

private Set<String> setResourceTags(@NonNull final TagCreateRequestDto tagCreateRequestDto) {
    final QualifiedName name = tagCreateRequestDto.getName();
    final Set<String> tags = new HashSet<>(tagCreateRequestDto.getTags());
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    Set<String> result = new HashSet<>();
    switch(name.getType()) {
        case CATALOG:
            // catalog service will throw exception if not found
            this.catalogService.get(name, GetCatalogServiceParameters.builder().includeDatabaseNames(false).includeUserMetadata(false).build());
            return this.tagService.setTags(name, tags, true);
        case DATABASE:
            if (!this.databaseService.exists(name)) {
                throw new DatabaseNotFoundException(name);
            }
            result = this.tagService.setTags(name, tags, true);
            this.eventBus.post(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
            return result;
        case TABLE:
            if (!this.tableService.exists(name)) {
                throw new TableNotFoundException(name);
            }
            final TableDto oldTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
            result = this.tagService.setTags(name, tags, true);
            final TableDto currentTable = this.tableService.get(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build()).orElseThrow(IllegalStateException::new);
            this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldTable, currentTable));
            return result;
        case MVIEW:
            if (!this.mViewService.exists(name)) {
                throw new MetacatNotFoundException(name.toString());
            }
            final Optional<TableDto> oldView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
            if (oldView.isPresent()) {
                result = this.tagService.setTags(name, tags, true);
                final Optional<TableDto> currentView = this.mViewService.getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDataMetadata(true).includeDefinitionMetadata(true).disableOnReadMetadataIntercetor(false).build());
                currentView.ifPresent(p -> this.eventBus.post(new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, oldView.get(), currentView.get())));
                return result;
            }
            break;
        default:
            throw new MetacatNotFoundException("Unsupported qualifiedName type {}" + name);
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) HashSet(java.util.HashSet)

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