Search in sources :

Example 6 with PartitionResult

use of org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult in project kafka by apache.

the class ElectLeadersRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    ApiError apiError = ApiError.fromThrowable(e);
    List<ReplicaElectionResult> electionResults = new ArrayList<>();
    if (data.topicPartitions() != null) {
        for (TopicPartitions topic : data.topicPartitions()) {
            ReplicaElectionResult electionResult = new ReplicaElectionResult();
            electionResult.setTopic(topic.topic());
            for (Integer partitionId : topic.partitions()) {
                PartitionResult partitionResult = new PartitionResult();
                partitionResult.setPartitionId(partitionId);
                partitionResult.setErrorCode(apiError.error().code());
                partitionResult.setErrorMessage(apiError.message());
                electionResult.partitionResult().add(partitionResult);
            }
            electionResults.add(electionResult);
        }
    }
    return new ElectLeadersResponse(throttleTimeMs, apiError.error().code(), electionResults, version());
}
Also used : ArrayList(java.util.ArrayList) ReplicaElectionResult(org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult) PartitionResult(org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult) TopicPartitions(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitions)

Aggregations

PartitionResult (org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult)6 ArrayList (java.util.ArrayList)5 ReplicaElectionResult (org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult)5 ElectionType (org.apache.kafka.common.ElectionType)3 TopicPartition (org.apache.kafka.common.TopicPartition)3 ApiError (org.apache.kafka.common.requests.ApiError)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Uuid (org.apache.kafka.common.Uuid)2 TopicPartitions (org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitions)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1