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);
}
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)));
}
Aggregations