Search in sources :

Example 1 with RequestControlAdminRequest

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

Example 2 with RequestControlAdminRequest

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);
}
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) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest)

Example 3 with RequestControlAdminRequest

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();
}
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) CatchupStatusAdminResponse(com.github.ambry.protocol.CatchupStatusAdminResponse) AdminResponse(com.github.ambry.protocol.AdminResponse) RequestControlAdminRequest(com.github.ambry.protocol.RequestControlAdminRequest) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

AdminResponse (com.github.ambry.protocol.AdminResponse)3 CatchupStatusAdminResponse (com.github.ambry.protocol.CatchupStatusAdminResponse)3 RequestControlAdminRequest (com.github.ambry.protocol.RequestControlAdminRequest)3 AdminRequest (com.github.ambry.protocol.AdminRequest)2 CatchupStatusAdminRequest (com.github.ambry.protocol.CatchupStatusAdminRequest)2 ReplicationControlAdminRequest (com.github.ambry.protocol.ReplicationControlAdminRequest)2 PartitionId (com.github.ambry.clustermap.PartitionId)1 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)1 BlobStoreControlAdminRequest (com.github.ambry.protocol.BlobStoreControlAdminRequest)1 GetResponse (com.github.ambry.protocol.GetResponse)1 ReplicaMetadataResponse (com.github.ambry.protocol.ReplicaMetadataResponse)1 RequestOrResponse (com.github.ambry.protocol.RequestOrResponse)1 RequestOrResponseType (com.github.ambry.protocol.RequestOrResponseType)1 Response (com.github.ambry.protocol.Response)1 ByteBufferInputStream (com.github.ambry.utils.ByteBufferInputStream)1 DataInputStream (java.io.DataInputStream)1 ByteBuffer (java.nio.ByteBuffer)1