Search in sources :

Example 1 with NotFoundException

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

the class MViewServiceImpl method createAndSnapshotPartitions.

/**
     * Creates the materialized view using the schema of the give table
     * Assumes that the "franklinviews" database name already exists in the given catalog.
     */
@Override
public TableDto createAndSnapshotPartitions(@Nonnull final QualifiedName name, final boolean snapshot, final String filter) {
    TableDto result;
    // Get the table
    log.info("Get the table {}", name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatCreateMViewPreEvent(name, metacatRequestContext, this, snapshot, filter));
    final Optional<TableDto> oTable = tableService.get(name, false);
    if (oTable.isPresent()) {
        final TableDto table = oTable.get();
        final String viewName = createViewName(name);
        final QualifiedName targetName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, viewName);
        // Get the view table if it exists
        log.info("Check if the view table {} exists.", targetName);
        Optional<TableDto> oViewTable = Optional.empty();
        try {
            oViewTable = tableService.get(targetName, false);
        } catch (NotFoundException ignored) {
        }
        if (!oViewTable.isPresent()) {
            log.info("Creating view {}.", targetName);
            result = tableService.copy(table, targetName);
        } else {
            result = oViewTable.get();
        }
        if (snapshot) {
            snapshotPartitions(name, filter);
        }
        eventBus.postAsync(new MetacatCreateMViewPostEvent(name, metacatRequestContext, this, result, snapshot, filter));
    } else {
        throw new TableNotFoundException(name);
    }
    return result;
}
Also used : TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) 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) MetacatCreateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPostEvent) MetacatCreateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPreEvent)

Example 2 with NotFoundException

use of com.netflix.metacat.common.server.connectors.exception.NotFoundException 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 3 with NotFoundException

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

the class RequestWrapper method processRequest.

/**
     * Request wrapper to to process request.
     *
     * @param name                name
     * @param resourceRequestName request name
     * @param supplier            supplier
     * @param <R>                 response
     * @return response of supplier
     */
public <R> R processRequest(final QualifiedName name, final String resourceRequestName, final Supplier<R> supplier) {
    final long start = registry.clock().monotonicTime();
    final Map<String, String> tags = new HashMap<String, String>(name.parts());
    tags.put("request", resourceRequestName);
    registry.counter(requestCounterId.withTags(tags)).increment();
    try {
        log.info("### Calling method: {} for {}", resourceRequestName, name);
        return supplier.get();
    } catch (UnsupportedOperationException e) {
        log.error(e.getMessage(), e);
        throw new MetacatNotSupportedException("Catalog does not support the operation");
    } catch (DatabaseAlreadyExistsException | TableAlreadyExistsException | PartitionAlreadyExistsException e) {
        log.error(e.getMessage(), e);
        throw new MetacatAlreadyExistsException(e.getMessage());
    } catch (NotFoundException | MetacatNotFoundException e) {
        log.error(e.getMessage(), e);
        throw new MetacatNotFoundException(String.format("Unable to locate for %s. Details: %s", name, e.getMessage()));
    } catch (InvalidMetaException | IllegalArgumentException e) {
        log.error(e.getMessage(), e);
        throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (ConnectorException e) {
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        registry.counter(requestFaillureCounterId.withTags(tags)).increment();
        throw new MetacatException(message, Response.Status.INTERNAL_SERVER_ERROR, e);
    } catch (UserMetadataServiceException e) {
        final String message = String.format("%s.%s -- %s usermetadata operation failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        throw new MetacatUserMetadataException(message);
    } catch (Exception e) {
        registry.counter(requestFaillureCounterId.withTags(tags)).increment();
        final String message = String.format("%s.%s -- %s failed for %s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName, name);
        log.error(message, e);
        throw new MetacatException(message, Response.Status.INTERNAL_SERVER_ERROR, e);
    } finally {
        final long duration = registry.clock().monotonicTime() - start;
        log.info("### Time taken to complete {} is {} ms", resourceRequestName, duration);
        this.registry.timer(requestTimerId.withTags(tags)).record(duration, TimeUnit.MILLISECONDS);
    }
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) HashMap(java.util.HashMap) MetacatException(com.netflix.metacat.common.exception.MetacatException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) MetacatException(com.netflix.metacat.common.exception.MetacatException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) MetacatUserMetadataException(com.netflix.metacat.common.exception.MetacatUserMetadataException)

Example 4 with NotFoundException

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

the class MetadataV1Resource method deleteDefinitionMetadata.

/**
     * {@inheritDoc}
     */
@Override
public void deleteDefinitionMetadata(final QualifiedName name, final Boolean force) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    requestWrapper.processRequest("deleteDefinitionMetadata", () -> {
        final MetacatService service = helper.getService(name);
        BaseDto dto = null;
        try {
            dto = service.get(name);
        } catch (NotFoundException ignored) {
        }
        if ((force || dto == null) && !"rds".equalsIgnoreCase(name.getCatalogName())) {
            helper.postPreUpdateEvent(name, metacatRequestContext, dto);
            userMetadataService.deleteDefinitionMetadatas(Lists.newArrayList(name));
            if (dto instanceof HasDefinitionMetadata) {
                ((HasDefinitionMetadata) dto).setDefinitionMetadata(null);
            }
            final BaseDto newDto = service.get(name);
            helper.postPostUpdateEvent(name, metacatRequestContext, dto, newDto);
        }
        return null;
    });
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatService(com.netflix.metacat.main.services.MetacatService) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) BaseDto(com.netflix.metacat.common.dto.BaseDto) HasDefinitionMetadata(com.netflix.metacat.common.dto.HasDefinitionMetadata)

Aggregations

NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)4 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)3 TableDto (com.netflix.metacat.common.dto.TableDto)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 QualifiedName (com.netflix.metacat.common.QualifiedName)1 BaseDto (com.netflix.metacat.common.dto.BaseDto)1 HasDefinitionMetadata (com.netflix.metacat.common.dto.HasDefinitionMetadata)1 MetacatAlreadyExistsException (com.netflix.metacat.common.exception.MetacatAlreadyExistsException)1 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)1 MetacatException (com.netflix.metacat.common.exception.MetacatException)1 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)1 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)1 MetacatUserMetadataException (com.netflix.metacat.common.exception.MetacatUserMetadataException)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)1 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)1 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)1 PartitionAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)1