Search in sources :

Example 1 with ReplicationControlAdminRequest

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);
}
Also used : CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId) ServerErrorCode(com.github.ambry.commons.ServerErrorCode)

Example 2 with ReplicationControlAdminRequest

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));
    }
}
Also used : CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) Response(com.github.ambry.protocol.Response) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 3 with ReplicationControlAdminRequest

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());
    }
}
Also used : ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) ConnectedChannel(com.github.ambry.network.ConnectedChannel) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) DataInputStream(java.io.DataInputStream)

Example 4 with ReplicationControlAdminRequest

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);
}
Also used : AdminResponse(com.github.ambry.protocol.AdminResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) PartitionId(com.github.ambry.clustermap.PartitionId)

Example 5 with ReplicationControlAdminRequest

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();
}
Also used : ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest) CatchupStatusAdminRequest(com.github.ambry.protocol.CatchupStatusAdminRequest) AdminRequest(com.github.ambry.protocol.AdminRequest) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) Response(com.github.ambry.protocol.Response) GetResponse(com.github.ambry.protocol.GetResponse) ReplicaMetadataResponse(com.github.ambry.protocol.ReplicaMetadataResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestOrResponse(com.github.ambry.protocol.RequestOrResponse) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) ReplicationControlAdminRequest(com.github.ambry.protocol.ReplicationControlAdminRequest) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId)

Aggregations

AdminResponse (com.github.ambry.protocol.AdminResponse)6 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)6 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)5 PartitionId (com.github.ambry.clustermap.PartitionId)4 AdminRequest (com.github.ambry.protocol.AdminRequest)4 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)4 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)3 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)3 GetResponse (com.github.ambry.protocol.GetResponse)2 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)2 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)2 Response (com.github.ambry.protocol.Response)2 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)2 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)1 ConnectedChannel (com.github.ambry.network.ConnectedChannel)1 ResponseInfo (com.github.ambry.network.ResponseInfo)1 DataInputStream (java.io.DataInputStream)1