use of com.github.ambry.protocol.ReplicationControlAdminRequest in project ambry by linkedin.
the class AmbryRequests 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);
partitionIds = Collections.singletonList(replControlRequest.getPartitionId());
} else {
partitionIds = partitionsInCurrentNode;
}
if (!error.equals(ServerErrorCode.Partition_Unknown)) {
if (replicationManager.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.ReplicationControlAdminRequest in project ambry by linkedin.
the class AmbryRequestsTest 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 = UtilsTest.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();
} 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));
}
}
use of com.github.ambry.protocol.ReplicationControlAdminRequest in project ambry by linkedin.
the class ServerTestUtil method controlReplicationForPartition.
private static void controlReplicationForPartition(List<ConnectedChannel> channels, PartitionId partitionId, boolean enable) throws Exception {
for (ConnectedChannel connectedChannel : channels) {
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, partitionId, 1, "clientid2");
ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(Collections.emptyList(), enable, adminRequest);
DataInputStream stream = connectedChannel.sendAndReceive(controlRequest).getInputStream();
AdminResponse adminResponse = AdminResponse.readFrom(stream);
releaseNettyBufUnderneathStream(stream);
assertEquals("Stop store admin request should succeed", ServerErrorCode.No_Error, adminResponse.getError());
}
}
use of com.github.ambry.protocol.ReplicationControlAdminRequest 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.ReplicationControlAdminRequest 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