Search in sources :

Example 6 with RequestPath

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

the class FrontendRestRequestService method handleGet.

@Override
public void handleGet(final RestRequest restRequest, final RestResponseChannel restResponseChannel) {
    ThrowingConsumer<RequestPath> routingAction = requestPath -> {
        if (requestPath.matchesOperation(Operations.GET_PEERS)) {
            getPeersHandler.handle(restRequest, restResponseChannel, (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception));
        } else if (requestPath.matchesOperation(Operations.GET_CLUSTER_MAP_SNAPSHOT)) {
            getClusterMapSnapshotHandler.handle(restRequest, restResponseChannel, (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception));
        } else if (requestPath.matchesOperation(Operations.GET_SIGNED_URL)) {
            getSignedUrlHandler.handle(restRequest, restResponseChannel, (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception));
        } else if (requestPath.matchesOperation(Operations.ACCOUNTS)) {
            getAccountsHandler.handle(restRequest, restResponseChannel, (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception));
        } else if (requestPath.matchesOperation(Operations.STATS_REPORT)) {
            getStatsReportHandler.handle(restRequest, restResponseChannel, (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception));
        } else if (requestPath.matchesOperation(Operations.NAMED_BLOB) && NamedBlobPath.parse(requestPath, restRequest.getArgs()).getBlobName() == null) {
            listNamedBlobsHandler.handle(restRequest, restResponseChannel, ((result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception)));
        } else {
            SubResource subResource = requestPath.getSubResource();
            GetBlobOptions options = buildGetBlobOptions(restRequest.getArgs(), subResource, getGetOption(restRequest, frontendConfig.defaultRouterGetOption), restRequest, requestPath.getBlobSegmentIdx());
            GetCallback routerCallback = new GetCallback(restRequest, restResponseChannel, subResource, options);
            SecurityProcessRequestCallback securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel, routerCallback);
            if (subResource == SubResource.Replicas) {
                securityCallback = new SecurityProcessRequestCallback(restRequest, restResponseChannel);
            }
            RestRequestMetricsGroup metricsGroup = getMetricsGroupForGet(frontendMetrics, subResource);
            RestRequestMetrics restRequestMetrics = metricsGroup.getRestRequestMetrics(restRequest.isSslUsed(), false);
            restRequest.getMetricsTracker().injectMetrics(restRequestMetrics);
            // named blob requests have their account/container in the URI, so checks can be done prior to ID conversion.
            if (requestPath.matchesOperation(Operations.NAMED_BLOB)) {
                accountAndContainerInjector.injectAccountAndContainerForNamedBlob(restRequest, metricsGroup);
            }
            securityService.processRequest(restRequest, securityCallback);
        }
    };
    preProcessAndRouteRequest(restRequest, restResponseChannel, frontendMetrics.getPreProcessingMetrics, routingAction);
}
Also used : RequestPath(com.github.ambry.rest.RequestPath) Histogram(com.codahale.metrics.Histogram) GetOption(com.github.ambry.protocol.GetOption) FrontendConfig(com.github.ambry.config.FrontendConfig) ResponseStatus(com.github.ambry.rest.ResponseStatus) LoggerFactory(org.slf4j.LoggerFactory) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) AccountService(com.github.ambry.account.AccountService) QuotaManager(com.github.ambry.quota.QuotaManager) ByteBuffer(java.nio.ByteBuffer) ThrowingConsumer(com.github.ambry.utils.ThrowingConsumer) RequestPath(com.github.ambry.rest.RequestPath) NamedBlobDb(com.github.ambry.named.NamedBlobDb) RestRequestService(com.github.ambry.rest.RestRequestService) RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) SystemTime(com.github.ambry.utils.SystemTime) Router(com.github.ambry.router.Router) RouterErrorCode(com.github.ambry.router.RouterErrorCode) RestResponseHandler(com.github.ambry.rest.RestResponseHandler) ReadableStreamChannel(com.github.ambry.router.ReadableStreamChannel) Logger(org.slf4j.Logger) GregorianCalendar(java.util.GregorianCalendar) RestMethod(com.github.ambry.rest.RestMethod) RestResponseChannel(com.github.ambry.rest.RestResponseChannel) RestServiceErrorCode(com.github.ambry.rest.RestServiceErrorCode) InternalKeys(com.github.ambry.rest.RestUtils.InternalKeys) ClusterMap(com.github.ambry.clustermap.ClusterMap) Utils(com.github.ambry.utils.Utils) IOException(java.io.IOException) GetBlobOptions(com.github.ambry.router.GetBlobOptions) RouterException(com.github.ambry.router.RouterException) BlobInfo(com.github.ambry.messageformat.BlobInfo) QuotaUtils(com.github.ambry.quota.QuotaUtils) AccountStatsStore(com.github.ambry.accountstats.AccountStatsStore) RestServiceException(com.github.ambry.rest.RestServiceException) GetBlobResult(com.github.ambry.router.GetBlobResult) Callback(com.github.ambry.commons.Callback) RestUtils(com.github.ambry.rest.RestUtils) AsyncOperationTracker(com.github.ambry.utils.AsyncOperationTracker) RestRequest(com.github.ambry.rest.RestRequest) GetBlobOptionsBuilder(com.github.ambry.router.GetBlobOptionsBuilder) BlobId(com.github.ambry.commons.BlobId) RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) GetBlobOptions(com.github.ambry.router.GetBlobOptions)

Aggregations

RequestPath (com.github.ambry.rest.RequestPath)6 RestServiceException (com.github.ambry.rest.RestServiceException)5 RestMethod (com.github.ambry.rest.RestMethod)3 RestRequest (com.github.ambry.rest.RestRequest)3 RestUtils (com.github.ambry.rest.RestUtils)3 GetBlobOptions (com.github.ambry.router.GetBlobOptions)3 GregorianCalendar (java.util.GregorianCalendar)3 Histogram (com.codahale.metrics.Histogram)2 AccountService (com.github.ambry.account.AccountService)2 AccountStatsStore (com.github.ambry.accountstats.AccountStatsStore)2 ClusterMap (com.github.ambry.clustermap.ClusterMap)2 BlobId (com.github.ambry.commons.BlobId)2 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)2 Callback (com.github.ambry.commons.Callback)2 FrontendConfig (com.github.ambry.config.FrontendConfig)2 BlobInfo (com.github.ambry.messageformat.BlobInfo)2 NamedBlobDb (com.github.ambry.named.NamedBlobDb)2 GetOption (com.github.ambry.protocol.GetOption)2 QuotaException (com.github.ambry.quota.QuotaException)2 QuotaManager (com.github.ambry.quota.QuotaManager)2