Search in sources :

Example 11 with GetOption

use of com.github.ambry.protocol.GetOption in project ambry by linkedin.

the class FrontendTestUrlSigningServiceFactory method verifyOperationsAfterDelete.

/**
 * Verifies that the right {@link ResponseStatus} is returned for GET, HEAD, TTL update and DELETE once a blob is
 * deleted.
 * @param blobId the ID of the blob that was deleted.
 * @param expectedHeaders the expected headers in the response if the right options are provided.
 * @param expectedContent the expected content of the blob if the right options are provided.
 * @param expectedAccount the {@link Account} details that are eventually expected to be populated.
 * @param expectedContainer the {@link Container} details that are eventually expected to be populated.
 * @throws Exception
 */
private void verifyOperationsAfterDelete(String blobId, JSONObject expectedHeaders, ByteBuffer expectedContent, Account expectedAccount, Container expectedContainer) throws Exception {
    RestRequest restRequest = createRestRequest(RestMethod.GET, blobId, null, null);
    verifyOperationFailure(restRequest, RestServiceErrorCode.Deleted);
    restRequest = createRestRequest(RestMethod.HEAD, blobId, null, null);
    verifyOperationFailure(restRequest, RestServiceErrorCode.Deleted);
    JSONObject headers = new JSONObject();
    setUpdateTtlHeaders(headers, blobId, "verifyOperationsAfterDelete");
    restRequest = createRestRequest(RestMethod.PUT, Operations.UPDATE_TTL, headers, null);
    verifyOperationFailure(restRequest, RestServiceErrorCode.Deleted);
    restRequest = createRestRequest(RestMethod.DELETE, blobId, null, null);
    verifyDeleteAccepted(restRequest);
    GetOption[] options = { GetOption.Include_Deleted_Blobs, GetOption.Include_All };
    for (GetOption option : options) {
        getBlobAndVerify(blobId, null, option, expectedHeaders, expectedContent, expectedAccount, expectedContainer);
        getNotModifiedBlobAndVerify(blobId, option);
        getUserMetadataAndVerify(blobId, option, expectedHeaders);
        getBlobInfoAndVerify(blobId, option, expectedHeaders, expectedAccount, expectedContainer);
        getHeadAndVerify(blobId, null, option, expectedHeaders, expectedAccount, expectedContainer);
    }
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) JSONObject(org.json.JSONObject) GetOption(com.github.ambry.protocol.GetOption)

Example 12 with GetOption

use of com.github.ambry.protocol.GetOption in project ambry by linkedin.

the class FrontendRestRequestService method securityPostProcessRequestCallback.

/**
 * Build a callback to use for {@link SecurityService#postProcessRequest}. This callback forwards request to the
 * {@link Router} once ID conversion is completed. In the case of some sub-resources
 * (e.g., {@link SubResource#Replicas}), the request is completed and not forwarded to the {@link Router}.
 * @param convertedId the converted blob ID to use in router requests.
 * @param restRequest the {@link RestRequest}.
 * @param restResponseChannel the {@link RestResponseChannel}.
 * @param getCallback the {@link GetCallback} to use if this is a {@link RestMethod#GET} request, or null for other
 *                    request types.
 * @param headCallback the {@link HeadCallback} to use if this is a {@link RestMethod#HEAD} request, or null for other
 *                    request types.
 * @param deleteCallback the {@link DeleteCallback} to use if this is a {@link RestMethod#DELETE} request, or null for
 *                       other request types.
 * @return the {@link Callback} to use.
 */
private Callback<Void> securityPostProcessRequestCallback(String convertedId, RestRequest restRequest, RestResponseChannel restResponseChannel, GetCallback getCallback, HeadCallback headCallback, DeleteCallback deleteCallback) {
    Callback<ReadableStreamChannel> completionCallback = (result, exception) -> submitResponse(restRequest, restResponseChannel, result, exception);
    RestMethod restMethod = restRequest.getRestMethod();
    AsyncOperationTracker.Metrics metrics;
    switch(restMethod) {
        case GET:
            metrics = frontendMetrics.getSecurityPostProcessRequestMetrics;
            break;
        case HEAD:
            metrics = frontendMetrics.headSecurityPostProcessRequestMetrics;
            break;
        case DELETE:
            metrics = frontendMetrics.deleteSecurityPostProcessRequestMetrics;
            break;
        default:
            throw new IllegalStateException("Unrecognized RestMethod: " + restMethod);
    }
    return FrontendUtils.buildCallback(metrics, result -> {
        ReadableStreamChannel response = null;
        switch(restMethod) {
            case GET:
                SubResource subResource = getRequestPath(restRequest).getSubResource();
                // inject encryption metrics if need be
                if (BlobId.isEncrypted(convertedId)) {
                    RestRequestMetrics restRequestMetrics = getMetricsGroupForGet(frontendMetrics, subResource).getRestRequestMetrics(restRequest.isSslUsed(), true);
                    restRequest.getMetricsTracker().injectMetrics(restRequestMetrics);
                }
                if (subResource == null) {
                    getCallback.markStartTime();
                    router.getBlob(convertedId, getCallback.options, getCallback, QuotaUtils.buildQuotaChargeCallback(restRequest, quotaManager, true));
                } else {
                    switch(subResource) {
                        case BlobInfo:
                        case UserMetadata:
                        case Segment:
                            getCallback.markStartTime();
                            router.getBlob(convertedId, getCallback.options, getCallback, QuotaUtils.buildQuotaChargeCallback(restRequest, quotaManager, true));
                            break;
                        case Replicas:
                            response = getReplicasHandler.getReplicas(convertedId, restResponseChannel);
                            break;
                    }
                }
                break;
            case HEAD:
                GetOption getOption = getGetOption(restRequest, frontendConfig.defaultRouterGetOption);
                // inject encryption metrics if need be
                if (BlobId.isEncrypted(convertedId)) {
                    RestRequestMetrics requestMetrics = frontendMetrics.headBlobMetricsGroup.getRestRequestMetrics(restRequest.isSslUsed(), true);
                    restRequest.getMetricsTracker().injectMetrics(requestMetrics);
                }
                headCallback.markStartTime();
                router.getBlob(convertedId, new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.BlobInfo).getOption(getOption).restRequest(restRequest).build(), headCallback, QuotaUtils.buildQuotaChargeCallback(restRequest, quotaManager, false));
                break;
            case DELETE:
                deleteCallback.markStartTime();
                router.deleteBlob(convertedId, getHeader(restRequest.getArgs(), Headers.SERVICE_ID, false), deleteCallback, QuotaUtils.buildQuotaChargeCallback(restRequest, quotaManager, false));
                break;
            default:
                throw new IllegalStateException("Unrecognized RestMethod: " + restMethod);
        }
        if (response != null) {
            completionCallback.onCompletion(response, null);
        }
    }, restRequest.getUri(), logger, completionCallback);
}
Also used : 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) GetBlobOptionsBuilder(com.github.ambry.router.GetBlobOptionsBuilder) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) ReadableStreamChannel(com.github.ambry.router.ReadableStreamChannel) RestRequestMetrics(com.github.ambry.rest.RestRequestMetrics) GetOption(com.github.ambry.protocol.GetOption) AsyncOperationTracker(com.github.ambry.utils.AsyncOperationTracker) RestMethod(com.github.ambry.rest.RestMethod)

Example 13 with GetOption

use of com.github.ambry.protocol.GetOption in project ambry by linkedin.

the class RouterServerTestFramework method continueChain.

/**
 * Submit the next operation in the chain to the router. If there are no more operations in the queue,
 * mark the chain as completed.
 * @param opChain the {@link OperationChain} to get the next operation from.
 */
private void continueChain(final OperationChain opChain) {
    synchronized (opChain.testFutures) {
        OperationType nextOp = opChain.nextOp();
        if (nextOp == null) {
            opChain.latch.countDown();
            return;
        }
        GetOption options = GetOption.None;
        switch(nextOp) {
            case PUT:
                startPutBlob(opChain);
                break;
            case TTL_UPDATE:
                startTtlUpdate(opChain);
                break;
            case GET_INFO_DELETED_SUCCESS:
                options = GetOption.Include_Deleted_Blobs;
            case GET_INFO:
            case GET_INFO_DELETED:
                startGetBlobInfo(options, nextOp.checkDeleted, opChain);
                break;
            case GET_DELETED_SUCCESS:
                options = GetOption.Include_Deleted_Blobs;
            case GET:
            case GET_DELETED:
                startGetBlob(options, nextOp.checkDeleted, opChain);
                break;
            case DELETE:
                startDeleteBlob(opChain);
                break;
            case AWAIT_CREATION:
                startAwaitCreation(opChain);
                break;
            case AWAIT_DELETION:
                startAwaitDeletion(opChain);
                break;
            case AWAIT_TTL_UPDATE:
                startAwaitTtlUpdate(opChain);
                break;
            case GET_AUTHORIZATION_FAILURE:
                startGetBlobAuthorizationFailTest(opChain);
                break;
            case DELETE_AUTHORIZATION_FAILURE:
                startDeleteBlobAuthorizationFailTest(opChain);
                break;
            case UNDELETE:
                startUndeleteBlob(opChain);
                break;
            case AWAIT_UNDELETE:
                startAwaitUndelete(opChain);
                break;
            default:
                throw new IllegalArgumentException("Unknown op: " + nextOp);
        }
    }
}
Also used : GetOption(com.github.ambry.protocol.GetOption)

Aggregations

GetOption (com.github.ambry.protocol.GetOption)13 RestRequest (com.github.ambry.rest.RestRequest)4 Test (org.junit.Test)4 Utils (com.github.ambry.utils.Utils)3 AccountService (com.github.ambry.account.AccountService)2 AccountStatsStore (com.github.ambry.accountstats.AccountStatsStore)2 BlobId (com.github.ambry.commons.BlobId)2 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 MessageFormatRecord (com.github.ambry.messageformat.MessageFormatRecord)2 TestUtils (com.github.ambry.utils.TestUtils)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2