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);
}
}
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);
}
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);
}
}
}
Aggregations