use of com.github.ambry.protocol.BlobStoreControlAdminRequest in project ambry by linkedin.
the class AmbryServerRequests 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 StoreException, IOException {
ServerErrorCode error;
BlobStoreControlAdminRequest blobStoreControlAdminRequest = BlobStoreControlAdminRequest.readFrom(requestStream, adminRequest);
PartitionId partitionId = blobStoreControlAdminRequest.getPartitionId();
if (partitionId != null) {
switch(blobStoreControlAdminRequest.getStoreControlAction()) {
case StopStore:
short numReplicasCaughtUpPerPartition = blobStoreControlAdminRequest.getNumReplicasCaughtUpPerPartition();
logger.info("Handling stop store request and {} replica(s) per partition should catch up before stopping store {}", numReplicasCaughtUpPerPartition, partitionId);
error = handleStopStoreRequest(partitionId, numReplicasCaughtUpPerPartition);
break;
case StartStore:
logger.info("Handling start store request on {}", partitionId);
error = handleStartStoreRequest(partitionId);
break;
case AddStore:
logger.info("Handling add store request for {}", partitionId);
error = handleAddStoreRequest(partitionId);
break;
case RemoveStore:
logger.info("Handling remove store request on {}", partitionId);
error = handleRemoveStoreRequest(partitionId);
break;
default:
throw new IllegalArgumentException("NetworkRequest type not supported: " + blobStoreControlAdminRequest.getStoreControlAction());
}
} else {
error = ServerErrorCode.Bad_Request;
logger.debug("The partition Id should not be null.");
}
return new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), error);
}
use of com.github.ambry.protocol.BlobStoreControlAdminRequest in project ambry by linkedin.
the class AmbryServerRequestsTest method sendAndVerifyStoreControlRequest.
/**
* Sends and verifies that a {@link AdminRequestOrResponseType#BlobStoreControl} request received the error code
* expected.
* @param partitionId the {@link PartitionId} to send the request for. Can be {@code null}.
* @param storeControlRequestType type of control operation that will be performed on certain store.
* @param numReplicasCaughtUpPerPartition the number of peer replicas which have caught up with this store before proceeding.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @throws InterruptedException
* @throws IOException
*/
private void sendAndVerifyStoreControlRequest(PartitionId partitionId, BlobStoreControlAction storeControlRequestType, short numReplicasCaughtUpPerPartition, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, partitionId, correlationId, clientId);
BlobStoreControlAdminRequest blobStoreControlAdminRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, storeControlRequestType, adminRequest);
Response response = sendRequestGetResponse(blobStoreControlAdminRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
response.release();
}
use of com.github.ambry.protocol.BlobStoreControlAdminRequest in project ambry by linkedin.
the class ServerAdminTool method controlBlobStore.
/**
* Sends a {@link BlobStoreControlAdminRequest} to start or stop a store associated with {@code partitionId}
* on {@code dataNodeId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param partitionId the {@link PartitionId} to start or stop.
* @param numReplicasCaughtUpPerPartition the minimum number of peers should catch up with partition if the store is
* being stopped
* @param storeControlRequestType the type of control operation that will performed on certain store.
* @return the {@link ServerErrorCode} that is returned.
* @throws IOException
* @throws TimeoutException
*/
private ServerErrorCode controlBlobStore(DataNodeId dataNodeId, PartitionId partitionId, short numReplicasCaughtUpPerPartition, BlobStoreControlAction storeControlRequestType) throws IOException, TimeoutException {
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.BlobStoreControl, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
BlobStoreControlAdminRequest controlRequest = new BlobStoreControlAdminRequest(numReplicasCaughtUpPerPartition, storeControlRequestType, adminRequest);
ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, controlRequest);
AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
response.release();
return adminResponse.getError();
}
Aggregations