use of com.github.ambry.protocol.AdminResponse 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.AdminResponse in project ambry by linkedin.
the class AmbryServerRequests method handleAdminRequest.
/**
* Handles an administration request. These requests can query for or change the internal state of the server.
* @param request the request that needs to be handled.
* @throws InterruptedException if response sending is interrupted.
* @throws IOException if there are I/O errors carrying our the required operation.
*/
@Override
public void handleAdminRequest(NetworkRequest request) throws InterruptedException, IOException {
long requestQueueTime = SystemTime.getInstance().milliseconds() - request.getStartTimeInMs();
long totalTimeSpent = requestQueueTime;
long startTime = SystemTime.getInstance().milliseconds();
DataInputStream requestStream = new DataInputStream(request.getInputStream());
AdminRequest adminRequest = AdminRequest.readFrom(requestStream, clusterMap);
Histogram processingTimeHistogram = null;
Histogram responseQueueTimeHistogram = null;
Histogram responseSendTimeHistogram = null;
Histogram requestTotalTimeHistogram = null;
AdminResponse response = null;
try {
switch(adminRequest.getType()) {
case TriggerCompaction:
metrics.triggerCompactionRequestQueueTimeInMs.update(requestQueueTime);
metrics.triggerCompactionRequestRate.mark();
processingTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
responseQueueTimeHistogram = metrics.triggerCompactionResponseQueueTimeInMs;
responseSendTimeHistogram = metrics.triggerCompactionResponseSendTimeInMs;
requestTotalTimeHistogram = metrics.triggerCompactionRequestTotalTimeInMs;
response = handleTriggerCompactionRequest(adminRequest);
break;
case RequestControl:
metrics.requestControlRequestQueueTimeInMs.update(requestQueueTime);
metrics.requestControlRequestRate.mark();
processingTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
responseQueueTimeHistogram = metrics.requestControlResponseQueueTimeInMs;
responseSendTimeHistogram = metrics.requestControlResponseSendTimeInMs;
requestTotalTimeHistogram = metrics.requestControlRequestTotalTimeInMs;
response = handleRequestControlRequest(requestStream, adminRequest);
break;
case ReplicationControl:
metrics.replicationControlRequestQueueTimeInMs.update(requestQueueTime);
metrics.replicationControlRequestRate.mark();
processingTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
responseQueueTimeHistogram = metrics.replicationControlResponseQueueTimeInMs;
responseSendTimeHistogram = metrics.replicationControlResponseSendTimeInMs;
requestTotalTimeHistogram = metrics.replicationControlRequestTotalTimeInMs;
response = handleReplicationControlRequest(requestStream, adminRequest);
break;
case CatchupStatus:
metrics.catchupStatusRequestQueueTimeInMs.update(requestQueueTime);
metrics.catchupStatusRequestRate.mark();
processingTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
responseQueueTimeHistogram = metrics.catchupStatusResponseQueueTimeInMs;
responseSendTimeHistogram = metrics.catchupStatusResponseSendTimeInMs;
requestTotalTimeHistogram = metrics.catchupStatusRequestTotalTimeInMs;
response = handleCatchupStatusRequest(requestStream, adminRequest);
break;
case BlobStoreControl:
metrics.blobStoreControlRequestQueueTimeInMs.update(requestQueueTime);
metrics.blobStoreControlRequestRate.mark();
processingTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
responseQueueTimeHistogram = metrics.blobStoreControlRequestQueueTimeInMs;
responseSendTimeHistogram = metrics.blobStoreControlResponseSendTimeInMs;
requestTotalTimeHistogram = metrics.blobStoreControlRequestTotalTimeInMs;
response = handleBlobStoreControlRequest(requestStream, adminRequest);
break;
}
} catch (Exception e) {
logger.error("Unknown exception for admin request {}", adminRequest, e);
metrics.unExpectedAdminOperationError.inc();
response = new AdminResponse(adminRequest.getCorrelationId(), adminRequest.getClientId(), ServerErrorCode.Unknown_Error);
switch(adminRequest.getType()) {
case CatchupStatus:
response = new CatchupStatusAdminResponse(false, response);
break;
}
} finally {
long processingTime = SystemTime.getInstance().milliseconds() - startTime;
totalTimeSpent += processingTime;
publicAccessLogger.info("{} {} processingTime {}", adminRequest, response, processingTime);
processingTimeHistogram.update(processingTime);
}
requestResponseChannel.sendResponse(response, request, new ServerNetworkResponseMetrics(responseQueueTimeHistogram, responseSendTimeHistogram, requestTotalTimeHistogram, null, null, totalTimeSpent));
}
use of com.github.ambry.protocol.AdminResponse 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.AdminResponse in project ambry by linkedin.
the class AmbryServerRequestsTest method doScheduleCompactionTest.
// scheduleCompactionSuccessTest() and scheduleCompactionFailuresTest() helpers
/**
* Schedules a compaction for {@code id} and checks that the {@link ServerErrorCode} returned matches
* {@code expectedServerErrorCode}.
* @param id the {@link PartitionId} to schedule compaction for.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected when the request is processed.
* @throws InterruptedException
* @throws IOException
*/
private void doScheduleCompactionTest(PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.TriggerCompaction, id, correlationId, clientId);
Response response = sendRequestGetResponse(adminRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
}
use of com.github.ambry.protocol.AdminResponse in project ambry by linkedin.
the class AmbryServerRequestsTest method sendAndVerifyReplicationControlRequest.
/**
* Sends and verifies that a {@link AdminRequestOrResponseType#ReplicationControl} request received the error code
* expected and that {@link AmbryRequests} sent the right details to {@link ReplicationManager}.
* @param origins the list of datacenters from which replication should be enabled/disabled.
* @param enable {@code true} if replication 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 sendAndVerifyReplicationControlRequest(List<String> origins, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, id, correlationId, clientId);
ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
List<PartitionId> idsVal;
if (id == null) {
idsVal = clusterMap.getAllPartitionIds(null);
} else {
idsVal = Collections.singletonList(id);
}
if (!expectedServerErrorCode.equals(ServerErrorCode.Unknown_Error)) {
assertEquals("Origins not as provided in request", origins, replicationManager.originsVal);
assertEquals("Enable not as provided in request", enable, replicationManager.enableVal);
assertEquals("Ids not as provided in request", idsVal.size(), replicationManager.idsVal.size());
assertTrue("Ids not as provided in request", replicationManager.idsVal.containsAll(idsVal));
}
response.release();
}
Aggregations