use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryServerRequests method handleRequestControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#RequestControl}.
* @param requestStream the serialized bytes of the request.
* @param adminRequest the {@link AdminRequest} received.
* @return the {@link AdminResponse} to the request.
* @throws IOException if there is any I/O error reading from the {@code requestStream}.
*/
private AdminResponse handleRequestControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
RequestControlAdminRequest controlRequest = RequestControlAdminRequest.readFrom(requestStream, adminRequest);
RequestOrResponseType toControl = controlRequest.getRequestTypeToControl();
ServerErrorCode error;
Collection<PartitionId> partitionIds;
if (!requestsDisableInfo.containsKey(toControl)) {
metrics.badRequestError.inc();
error = ServerErrorCode.Bad_Request;
} else {
error = ServerErrorCode.No_Error;
if (controlRequest.getPartitionId() != null) {
error = validateRequest(controlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
partitionIds = Collections.singletonList(controlRequest.getPartitionId());
} else {
partitionIds = storeManager.getLocalPartitions();
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
controlRequestForPartitions(EnumSet.of(toControl), partitionIds, controlRequest.shouldEnable());
for (PartitionId partitionId : partitionIds) {
logger.info("Enable state for {} on {} is {}", toControl, partitionId, isRequestEnabled(toControl, partitionId));
}
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryServerRequests method handleReplicationControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#ReplicationControl}.
* @param requestStream the serialized bytes of the request.
* @param adminRequest the {@link AdminRequest} received.
* @return the {@link AdminResponse} to the request.
* @throws IOException if there is any I/O error reading from the {@code requestStream}.
*/
private AdminResponse handleReplicationControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
Collection<PartitionId> partitionIds;
ServerErrorCode error = ServerErrorCode.No_Error;
ReplicationControlAdminRequest replControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, adminRequest);
if (replControlRequest.getPartitionId() != null) {
error = validateRequest(replControlRequest.getPartitionId(), RequestOrResponseType.AdminRequest, false);
partitionIds = Collections.singletonList(replControlRequest.getPartitionId());
} else {
partitionIds = storeManager.getLocalPartitions();
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
if (replicationEngine.controlReplicationForPartitions(partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable())) {
error = ServerErrorCode.No_Error;
} else {
logger.error("Could not set enable status for replication of {} from {} to {}. Check partition validity and" + " origins list", partitionIds, replControlRequest.getOrigins(), replControlRequest.shouldEnable());
error = ServerErrorCode.Bad_Request;
}
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryServerRequestsTest method doCatchupStatusTest.
// catchupStatusSuccessTest() and catchupStatusFailureTest() helpers
/**
* Does the test for {@link AdminRequestOrResponseType#CatchupStatus} by checking that the request is correctly
* deserialized in {@link AmbryRequests} and the necessary info obtained from {@link ReplicationManager}.
* @param id the {@link PartitionId} to disable replication on. Can be {@code null}.
* @param acceptableLagInBytes the value of acceptable lag to set in the {@link CatchupStatusAdminRequest}.
* @param numReplicasCaughtUpPerPartition the value of num replicas caught up per partition to set in the
* {@link CatchupStatusAdminRequest}.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @param expectedIsCaughtUp the expected return from {@link CatchupStatusAdminResponse#isCaughtUp()}.
* @throws InterruptedException
* @throws IOException
*/
private void doCatchupStatusTest(PartitionId id, long acceptableLagInBytes, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode, boolean expectedIsCaughtUp) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.CatchupStatus, id, correlationId, clientId);
CatchupStatusAdminRequest catchupStatusRequest = new CatchupStatusAdminRequest(acceptableLagInBytes, numReplicasCaughtUpPerPartition, adminRequest);
Response response = sendRequestGetResponse(catchupStatusRequest, expectedServerErrorCode);
assertTrue("Response not of type CatchupStatusAdminResponse", response instanceof CatchupStatusAdminResponse);
CatchupStatusAdminResponse adminResponse = (CatchupStatusAdminResponse) response;
assertEquals("Catchup status not as expected", expectedIsCaughtUp, adminResponse.isCaughtUp());
response.release();
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryServerRequestsTest method sendAndVerifyRequestControlRequest.
/**
* Sends and verifies that a {@link AdminRequestOrResponseType#RequestControl} request received the error code
* expected.
* @param toControl the {@link AdminRequestOrResponseType#RequestControl} to control.
* @param enable {@code true} if {@code toControl} needs to be enabled. {@code false} otherwise.
* @param id the {@link PartitionId} to send the request for. Can be {@code null}.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @throws InterruptedException
* @throws IOException
*/
private void sendAndVerifyRequestControlRequest(RequestOrResponseType toControl, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.RequestControl, id, correlationId, clientId);
RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(toControl, enable, adminRequest);
Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
response.release();
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryRequests method handleBlobStoreControlRequest.
/**
* Handles {@link com.github.ambry.protocol.AdminRequestOrResponseType#BlobStoreControl}.
* @param requestStream the serialized bytes of the request.
* @param adminRequest the {@link AdminRequest} received.
* @return the {@link AdminResponse} to the request.
* @throws IOException if there is any I/O error reading from the {@code requestStream}.
*/
private AdminResponse handleBlobStoreControlRequest(DataInputStream requestStream, AdminRequest adminRequest) throws IOException {
ServerErrorCode error;
BlobStoreControlAdminRequest blobStoreControlAdminRequest = BlobStoreControlAdminRequest.readFrom(requestStream, adminRequest);
if (blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition() > 0) {
PartitionId partitionId = blobStoreControlAdminRequest.getPartitionId();
if (partitionId != null) {
error = validateRequest(partitionId, RequestOrResponseType.AdminRequest);
if (error.equals(ServerErrorCode.No_Error)) {
if (blobStoreControlAdminRequest.shouldEnable()) {
// TODO: start BlobStore properly
error = ServerErrorCode.Temporarily_Disabled;
} else {
Collection<PartitionId> partitionIds = Collections.singletonList(partitionId);
if (storageManager.disableCompactionForBlobStore(partitionId)) {
controlRequestForPartitions(RequestOrResponseType.PutRequest, partitionIds, false);
controlRequestForPartitions(RequestOrResponseType.DeleteRequest, partitionIds, false);
if (replicationManager.controlReplicationForPartitions(partitionIds, Collections.<String>emptyList(), false)) {
if (isRemoteLagLesserOrEqual(partitionIds, 0, blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition())) {
controlRequestForPartitions(RequestOrResponseType.GetRequest, partitionIds, false);
controlRequestForPartitions(RequestOrResponseType.ReplicaMetadataRequest, partitionIds, false);
// Shutdown the BlobStore completely
if (storageManager.shutdownBlobStore(partitionId)) {
error = ServerErrorCode.No_Error;
logger.info("store shutdown for partition: {}", partitionId);
} else {
error = ServerErrorCode.Unknown_Error;
logger.error("Shutting down BlobStore fails on {}", partitionId);
}
} else {
error = ServerErrorCode.Retry_After_Backoff;
logger.debug("Catchup not done on {}", partitionIds);
}
} else {
error = ServerErrorCode.Unknown_Error;
logger.error("Could not disable replication on {}", partitionIds);
}
} else {
error = ServerErrorCode.Unknown_Error;
logger.error("Disable compaction on given BlobStore failed for {}", partitionId);
}
}
} else {
logger.debug("Validate request fails for {} with error code {}", partitionId, error);
}
} else {
error = ServerErrorCode.Partition_Unknown;
logger.debug("The partition Id should not be null.");
}
} else {
error = ServerErrorCode.Bad_Request;
logger.debug("The number of replicas to catch up should not be less or equal to zero {}", blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition());
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
Aggregations