Search in sources :

Example 16 with AdminRequest

use of com.github.ambry.protocol.AdminRequest 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();
}
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) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Example 17 with AdminRequest

use of com.github.ambry.protocol.AdminRequest 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);
}
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)

Example 18 with AdminRequest

use of com.github.ambry.protocol.AdminRequest 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)

Example 19 with AdminRequest

use of com.github.ambry.protocol.AdminRequest 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);
    ResponseInfo response = sendRequestGetResponse(dataNodeId, partitionId, controlRequest);
    AdminResponse adminResponse = AdminResponse.readFrom(new NettyByteBufDataInputStream(response.content()));
    response.release();
    return adminResponse.getError();
}
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) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest)

Example 20 with AdminRequest

use of com.github.ambry.protocol.AdminRequest 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();
}
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) ResponseInfo(com.github.ambry.network.ResponseInfo) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) BlobStoreControlAdminRequest(com.github.ambry.protocol.BlobStoreControlAdminRequest)

Aggregations

AdminRequest (com.github.ambry.protocol.AdminRequest)21 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)21 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)21 AdminResponse (com.github.ambry.protocol.AdminResponse)20 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)18 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)18 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)18 GetResponse (com.github.ambry.protocol.GetResponse)13 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)11 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)11 Response (com.github.ambry.protocol.Response)11 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)8 PartitionId (com.github.ambry.clustermap.PartitionId)6 ResponseInfo (com.github.ambry.network.ResponseInfo)5 DataInputStream (java.io.DataInputStream)5 IOException (java.io.IOException)4 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)3 MessageFormatException (com.github.ambry.messageformat.MessageFormatException)3 ConnectedChannel (com.github.ambry.network.ConnectedChannel)3 Histogram (com.codahale.metrics.Histogram)2