Search in sources :

Example 1 with RestRequestMetrics

use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.

the class AmbryBlobStorageService method handleOptions.

@Override
public void handleOptions(RestRequest restRequest, RestResponseChannel restResponseChannel) {
    long processingStartTime = System.currentTimeMillis();
    handlePrechecks(restRequest, restResponseChannel);
    RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? frontendMetrics.optionsSSLMetrics : frontendMetrics.optionsMetrics;
    restRequest.getMetricsTracker().injectMetrics(requestMetrics);
    Exception exception = null;
    try {
        logger.trace("Handling OPTIONS request - {}", restRequest.getUri());
        checkAvailable();
        // TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
        securityService.preProcessRequest(restRequest).get();
        long preProcessingEndTime = System.currentTimeMillis();
        frontendMetrics.optionsPreProcessingTimeInMs.update(preProcessingEndTime - processingStartTime);
        // making this blocking for now. TODO: convert to non blocking
        securityService.processRequest(restRequest).get();
        long securityRequestProcessingEndTime = System.currentTimeMillis();
        frontendMetrics.optionsSecurityRequestTimeInMs.update(securityRequestProcessingEndTime - preProcessingEndTime);
        restResponseChannel.setStatus(ResponseStatus.Ok);
        restResponseChannel.setHeader(RestUtils.Headers.DATE, new GregorianCalendar().getTime());
        restResponseChannel.setHeader(RestUtils.Headers.CONTENT_LENGTH, 0);
        restResponseChannel.setHeader(Headers.ACCESS_CONTROL_ALLOW_METHODS, frontendConfig.frontendOptionsAllowMethods);
        restResponseChannel.setHeader(Headers.ACCESS_CONTROL_MAX_AGE, frontendConfig.frontendOptionsValiditySeconds);
        securityService.processResponse(restRequest, restResponseChannel, null).get();
        long securityResponseProcessingEndTime = System.currentTimeMillis();
        frontendMetrics.optionsSecurityResponseTimeInMs.update(securityResponseProcessingEndTime - securityRequestProcessingEndTime);
    } catch (Exception e) {
        exception = extractExecutionExceptionCause(e);
    }
    submitResponse(restRequest, restResponseChannel, null, exception);
}
Also used : RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) GregorianCalendar(java.util.GregorianCalendar) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) RestServiceException(com.github.ambry.rest.RestServiceException)

Example 2 with RestRequestMetrics

use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.

the class AmbryBlobStorageService method handleDelete.

@Override
public void handleDelete(RestRequest restRequest, RestResponseChannel restResponseChannel) {
    long processingStartTime = System.currentTimeMillis();
    long preProcessingTime = 0;
    handlePrechecks(restRequest, restResponseChannel);
    RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? frontendMetrics.deleteBlobSSLMetrics : frontendMetrics.deleteBlobMetrics;
    restRequest.getMetricsTracker().injectMetrics(requestMetrics);
    try {
        logger.trace("Handling DELETE request - {}", restRequest.getUri());
        checkAvailable();
        // TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
        securityService.preProcessRequest(restRequest).get();
        DeleteCallback routerCallback = new DeleteCallback(restRequest, restResponseChannel);
        preProcessingTime = System.currentTimeMillis() - processingStartTime;
        SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, routerCallback);
        securityService.processRequest(restRequest, securityCallback);
    } catch (Exception e) {
        submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
    } finally {
        frontendMetrics.deletePreProcessingTimeInMs.update(preProcessingTime);
    }
}
Also used : RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) RestServiceException(com.github.ambry.rest.RestServiceException)

Example 3 with RestRequestMetrics

use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.

the class GetSignedUrlHandler method handle.

/**
 * Handles a request for getting signed URLs.
 * @param restRequest the {@link RestRequest} that contains the request parameters.
 * @param restResponseChannel the {@link RestResponseChannel} where headers should be set.
 * @param callback the {@link Callback} to invoke when the response is ready (or if there is an exception).
 * @throws RestServiceException if required parameters are not found or are invalid
 */
void handle(RestRequest restRequest, RestResponseChannel restResponseChannel, Callback<ReadableStreamChannel> callback) throws RestServiceException {
    RestRequestMetrics requestMetrics = restRequest.getSSLSession() != null ? metrics.getSignedUrlSSLMetrics : metrics.getSignedUrlMetrics;
    restRequest.getMetricsTracker().injectMetrics(requestMetrics);
    String restMethodInSignedUrlStr = RestUtils.getHeader(restRequest.getArgs(), RestUtils.Headers.URL_TYPE, true);
    RestMethod restMethodInUrl;
    try {
        restMethodInUrl = RestMethod.valueOf(restMethodInSignedUrlStr);
    } catch (IllegalArgumentException e) {
        throw new RestServiceException("Unrecognized RestMethod: " + restMethodInSignedUrlStr, RestServiceErrorCode.InvalidArgs);
    }
    securityService.processRequest(restRequest, new SecurityProcessRequestCallback(restRequest, restMethodInUrl, restResponseChannel, callback));
}
Also used : RestServiceException(com.github.ambry.rest.RestServiceException) RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) RestMethod(com.github.ambry.rest.RestMethod)

Example 4 with RestRequestMetrics

use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.

the class AmbryBlobStorageService method handlePost.

@Override
public void handlePost(RestRequest restRequest, RestResponseChannel restResponseChannel) {
    long processingStartTime = System.currentTimeMillis();
    long preProcessingTime = 0;
    handlePrechecks(restRequest, restResponseChannel);
    boolean sslUsed = restRequest.getSSLSession() != null;
    RestRequestMetrics metrics = frontendMetrics.postRequestMetricsGroup.getRestRequestMetrics(sslUsed, false);
    restRequest.getMetricsTracker().injectMetrics(metrics);
    try {
        logger.trace("Handling POST request - {}", restRequest.getUri());
        checkAvailable();
        // TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
        securityService.preProcessRequest(restRequest).get();
        long propsBuildStartTime = System.currentTimeMillis();
        accountAndContainerInjector.injectAccountAndContainerForPostRequest(restRequest);
        BlobProperties blobProperties = RestUtils.buildBlobProperties(restRequest.getArgs());
        if (blobProperties.getTimeToLiveInSeconds() + TimeUnit.MILLISECONDS.toSeconds(blobProperties.getCreationTimeInMs()) > Integer.MAX_VALUE) {
            logger.debug("TTL set to very large value in POST request with BlobProperties {}", blobProperties);
            frontendMetrics.ttlTooLargeError.inc();
        }
        // inject encryption metrics if applicable
        if (blobProperties.isEncrypted()) {
            metrics = frontendMetrics.postRequestMetricsGroup.getRestRequestMetrics(sslUsed, true);
            restRequest.getMetricsTracker().injectMetrics(metrics);
        }
        byte[] usermetadata = RestUtils.buildUsermetadata(restRequest.getArgs());
        frontendMetrics.blobPropsBuildTimeInMs.update(System.currentTimeMillis() - propsBuildStartTime);
        logger.trace("Blob properties of blob being POSTed - {}", blobProperties);
        PostCallback routerCallback = new PostCallback(restRequest, restResponseChannel, new BlobInfo(blobProperties, usermetadata));
        preProcessingTime = System.currentTimeMillis() - processingStartTime;
        SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, blobProperties, usermetadata, routerCallback);
        securityService.processRequest(restRequest, securityCallback);
    } catch (Exception e) {
        submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
    } finally {
        frontendMetrics.postPreProcessingTimeInMs.update(preProcessingTime);
    }
}
Also used : RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) BlobProperties(com.github.ambry.messageformat.BlobProperties) BlobInfo(com.github.ambry.messageformat.BlobInfo) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) RestServiceException(com.github.ambry.rest.RestServiceException)

Example 5 with RestRequestMetrics

use of com.github.ambry.rest.RestRequestMetrics in project ambry by linkedin.

the class AmbryBlobStorageService method handleHead.

@Override
public void handleHead(RestRequest restRequest, RestResponseChannel restResponseChannel) {
    long processingStartTime = System.currentTimeMillis();
    long preProcessingTime = 0;
    handlePrechecks(restRequest, restResponseChannel);
    try {
        RestRequestMetrics requestMetrics = frontendMetrics.headRequestMetricsGroup.getRestRequestMetrics(restRequest.getSSLSession() != null, false);
        restRequest.getMetricsTracker().injectMetrics(requestMetrics);
        logger.trace("Handling HEAD request - {}", restRequest.getUri());
        checkAvailable();
        // TODO: make this non blocking once all handling of indiviual methods is moved to their own classes
        securityService.preProcessRequest(restRequest).get();
        HeadCallback routerCallback = new HeadCallback(restRequest, restResponseChannel);
        preProcessingTime = System.currentTimeMillis() - processingStartTime;
        SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, routerCallback);
        securityService.processRequest(restRequest, securityCallback);
    } catch (Exception e) {
        submitResponse(restRequest, restResponseChannel, null, extractExecutionExceptionCause(e));
    } finally {
        frontendMetrics.headPreProcessingTimeInMs.update(preProcessingTime);
    }
}
Also used : RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) RestServiceException(com.github.ambry.rest.RestServiceException)

Aggregations

RestRequestMetrics (com.github.ambry.rest.RestRequestMetrics)6 RestServiceException (com.github.ambry.rest.RestServiceException)5 RouterException (com.github.ambry.router.RouterException)4 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 BlobInfo (com.github.ambry.messageformat.BlobInfo)1 BlobProperties (com.github.ambry.messageformat.BlobProperties)1 RestMethod (com.github.ambry.rest.RestMethod)1 GregorianCalendar (java.util.GregorianCalendar)1