Search in sources :

Example 6 with BlobStoreControlAdminRequest

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

Example 7 with BlobStoreControlAdminRequest

use of com.github.ambry.protocol.BlobStoreControlAdminRequest 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 8 with BlobStoreControlAdminRequest

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

AdminResponse (com.github.ambry.protocol.AdminResponse)8 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)8 PartitionId (com.github.ambry.clustermap.PartitionId)6 AdminRequest (com.github.ambry.protocol.AdminRequest)6 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)6 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)6 GetResponse (com.github.ambry.protocol.GetResponse)5 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)4 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)4 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)3 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)3 Response (com.github.ambry.protocol.Response)3 AccountService (com.github.ambry.account.AccountService)2 InMemAccountService (com.github.ambry.account.InMemAccountService)2 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)2 MockDiskId (com.github.ambry.clustermap.MockDiskId)2 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)2 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)2 ReplicaId (com.github.ambry.clustermap.ReplicaId)2 BlobId (com.github.ambry.commons.BlobId)2