Search in sources :

Example 1 with MetacatBadRequestException

use of com.netflix.metacat.common.exception.MetacatBadRequestException in project metacat by Netflix.

the class RequestWrapper method processRequest.

/**
     * Simple request wrapper to process request.
     *
     * @param resourceRequestName request name
     * @param supplier            supplier
     * @param <R>                 response
     * @return response of the supplier
     */
public <R> R processRequest(final String resourceRequestName, final Supplier<R> supplier) {
    final long start = registry.clock().monotonicTime();
    final Map<String, String> tags = Maps.newHashMap();
    tags.put("request", resourceRequestName);
    registry.counter(requestCounterId.withTags(tags)).increment();
    try {
        log.info("### Calling method: {}", resourceRequestName);
        return supplier.get();
    } catch (UnsupportedOperationException e) {
        log.error(e.getMessage(), e);
        throw new MetacatNotSupportedException("Catalog does not support the operation");
    } catch (IllegalArgumentException e) {
        log.error(e.getMessage(), e);
        throw new MetacatBadRequestException(String.format("%s.%s", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage()));
    } catch (Exception e) {
        registry.counter(requestFaillureCounterId.withTags(tags)).increment();
        final String message = String.format("%s.%s -- %s failed.", e.getMessage(), e.getCause() == null ? "" : e.getCause().getMessage(), resourceRequestName);
        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 : MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) MetacatException(com.netflix.metacat.common.exception.MetacatException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) 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)

Example 2 with MetacatBadRequestException

use of com.netflix.metacat.common.exception.MetacatBadRequestException in project metacat by Netflix.

the class MetacatErrorDecoder method decode.

/**
     * {@inheritDoc}
     */
@Override
public Exception decode(final String methodKey, final Response response) {
    try {
        String message = "";
        if (response.body() != null) {
            message = Util.toString(response.body().asReader());
            try {
                final ObjectNode body = METACAT_JSON.parseJsonObject(message);
                message = body.path("error").asText();
            } catch (MetacatJsonException ignored) {
            }
        }
        switch(response.status()) {
            //NOT IMPLEMENTED
            case 501:
            case //UNSUPPORTED_MEDIA_TYPE
            415:
                return new MetacatNotSupportedException(message);
            case //BAD_REQUEST
            400:
                return new MetacatBadRequestException(message);
            case //NOT_FOUND
            404:
                return new MetacatNotFoundException(message);
            case //CONFLICT
            409:
                return new MetacatAlreadyExistsException(message);
            //INTERNAL_SERVER_ERROR
            case 500:
            case //SERVICE_UNAVAILABLE
            503:
                return new RetryableException(message, null);
            default:
                return new MetacatException(message, javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, null);
        }
    } catch (final IOException e) {
        return super.decode(methodKey, response);
    }
}
Also used : MetacatNotFoundException(com.netflix.metacat.common.exception.MetacatNotFoundException) RetryableException(feign.RetryableException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatNotSupportedException(com.netflix.metacat.common.exception.MetacatNotSupportedException) MetacatJsonException(com.netflix.metacat.common.json.MetacatJsonException) MetacatException(com.netflix.metacat.common.exception.MetacatException) IOException(java.io.IOException) MetacatBadRequestException(com.netflix.metacat.common.exception.MetacatBadRequestException) MetacatAlreadyExistsException(com.netflix.metacat.common.exception.MetacatAlreadyExistsException)

Example 3 with MetacatBadRequestException

use of com.netflix.metacat.common.exception.MetacatBadRequestException 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)

Aggregations

MetacatAlreadyExistsException (com.netflix.metacat.common.exception.MetacatAlreadyExistsException)3 MetacatBadRequestException (com.netflix.metacat.common.exception.MetacatBadRequestException)3 MetacatException (com.netflix.metacat.common.exception.MetacatException)3 MetacatNotFoundException (com.netflix.metacat.common.exception.MetacatNotFoundException)3 MetacatNotSupportedException (com.netflix.metacat.common.exception.MetacatNotSupportedException)3 MetacatUserMetadataException (com.netflix.metacat.common.exception.MetacatUserMetadataException)2 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)2 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)2 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)2 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)2 PartitionAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)2 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)2 UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MetacatJsonException (com.netflix.metacat.common.json.MetacatJsonException)1 RetryableException (feign.RetryableException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1