use of com.github.ambry.protocol.RequestControlAdminRequest in project ambry by linkedin.
the class AmbryRequests 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);
partitionIds = Collections.singletonList(controlRequest.getPartitionId());
} else {
partitionIds = partitionsInCurrentNode;
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
controlRequestForPartitions(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.RequestControlAdminRequest in project ambry by linkedin.
the class AmbryRequestsTest 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 = UtilsTest.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);
}
use of com.github.ambry.protocol.RequestControlAdminRequest in project ambry by linkedin.
the class ServerAdminTool method controlRequest.
/**
* Sends a {@link RequestControlAdminRequest} to set the enable state of {@code toControl} on {@code partitionIdStr}
* to {@code enable} in {@code dataNodeId}.
* @param dataNodeId the {@link DataNodeId} to contact.
* @param partitionId the {@link PartitionId} to control requests to. Can be {@code null}.
* @param toControl the {@link RequestOrResponseType} to control.
* @param enable the enable (or disable) status required for {@code toControl}.
* @return the {@link ServerErrorCode} that is returned.
* @throws IOException
* @throws TimeoutException
*/
public ServerErrorCode controlRequest(DataNodeId dataNodeId, PartitionId partitionId, RequestOrResponseType toControl, boolean enable) throws IOException, TimeoutException {
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.RequestControl, partitionId, correlationId.incrementAndGet(), CLIENT_ID);
RequestControlAdminRequest controlRequest = new RequestControlAdminRequest(toControl, enable, adminRequest);
ByteBuffer responseBytes = sendRequestGetResponse(dataNodeId, controlRequest);
AdminResponse adminResponse = AdminResponse.readFrom(new DataInputStream(new ByteBufferInputStream(responseBytes)));
return adminResponse.getError();
}
Aggregations