Search in sources :

Example 1 with DescribeQuorumRequestData

use of org.apache.kafka.common.message.DescribeQuorumRequestData in project kafka by apache.

the class DescribeQuorumRequest method getPartitionLevelErrorResponse.

public static DescribeQuorumResponseData getPartitionLevelErrorResponse(DescribeQuorumRequestData data, Errors error) {
    short errorCode = error.code();
    List<DescribeQuorumResponseData.TopicData> topicResponses = new ArrayList<>();
    for (DescribeQuorumRequestData.TopicData topic : data.topics()) {
        topicResponses.add(new DescribeQuorumResponseData.TopicData().setTopicName(topic.topicName()).setPartitions(topic.partitions().stream().map(requestPartition -> new DescribeQuorumResponseData.PartitionData().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(errorCode)).collect(Collectors.toList())));
    }
    return new DescribeQuorumResponseData().setTopics(topicResponses);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) DescribeQuorumResponseData(org.apache.kafka.common.message.DescribeQuorumResponseData) Errors(org.apache.kafka.common.protocol.Errors) DescribeQuorumRequestData(org.apache.kafka.common.message.DescribeQuorumRequestData) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DescribeQuorumRequestData(org.apache.kafka.common.message.DescribeQuorumRequestData) DescribeQuorumResponseData(org.apache.kafka.common.message.DescribeQuorumResponseData) ArrayList(java.util.ArrayList)

Example 2 with DescribeQuorumRequestData

use of org.apache.kafka.common.message.DescribeQuorumRequestData in project kafka by apache.

the class KafkaRaftClient method handleDescribeQuorumRequest.

private DescribeQuorumResponseData handleDescribeQuorumRequest(RaftRequest.Inbound requestMetadata, long currentTimeMs) {
    DescribeQuorumRequestData describeQuorumRequestData = (DescribeQuorumRequestData) requestMetadata.data;
    if (!hasValidTopicPartition(describeQuorumRequestData, log.topicPartition())) {
        return DescribeQuorumRequest.getPartitionLevelErrorResponse(describeQuorumRequestData, Errors.UNKNOWN_TOPIC_OR_PARTITION);
    }
    if (!quorum.isLeader()) {
        return DescribeQuorumRequest.getTopLevelErrorResponse(Errors.INVALID_REQUEST);
    }
    LeaderState<T> leaderState = quorum.leaderStateOrThrow();
    return DescribeQuorumResponse.singletonResponse(log.topicPartition(), leaderState.localId(), leaderState.epoch(), leaderState.highWatermark().isPresent() ? leaderState.highWatermark().get().offset : -1, convertToReplicaStates(leaderState.getVoterEndOffsets()), convertToReplicaStates(leaderState.getObserverStates(currentTimeMs)));
}
Also used : DescribeQuorumRequestData(org.apache.kafka.common.message.DescribeQuorumRequestData)

Aggregations

DescribeQuorumRequestData (org.apache.kafka.common.message.DescribeQuorumRequestData)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 DescribeQuorumResponseData (org.apache.kafka.common.message.DescribeQuorumResponseData)1 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)1 ByteBufferAccessor (org.apache.kafka.common.protocol.ByteBufferAccessor)1 Errors (org.apache.kafka.common.protocol.Errors)1