Search in sources :

Example 6 with LeaderAndIsrPartitionState

use of org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState in project kafka by apache.

the class PartitionRegistrationTest method testToLeaderAndIsrPartitionState.

@Test
public void testToLeaderAndIsrPartitionState() {
    PartitionRegistration a = new PartitionRegistration(new int[] { 1, 2, 3 }, new int[] { 1, 2 }, Replicas.NONE, Replicas.NONE, 1, 123, 456);
    PartitionRegistration b = new PartitionRegistration(new int[] { 2, 3, 4 }, new int[] { 2, 3, 4 }, Replicas.NONE, Replicas.NONE, 2, 234, 567);
    assertEquals(new LeaderAndIsrPartitionState().setTopicName("foo").setPartitionIndex(1).setControllerEpoch(-1).setLeader(1).setLeaderEpoch(123).setIsr(Arrays.asList(1, 2)).setZkVersion(456).setReplicas(Arrays.asList(1, 2, 3)).setAddingReplicas(Collections.emptyList()).setRemovingReplicas(Collections.emptyList()).setIsNew(true).toString(), a.toLeaderAndIsrPartitionState(new TopicPartition("foo", 1), true).toString());
    assertEquals(new LeaderAndIsrPartitionState().setTopicName("bar").setPartitionIndex(0).setControllerEpoch(-1).setLeader(2).setLeaderEpoch(234).setIsr(Arrays.asList(2, 3, 4)).setZkVersion(567).setReplicas(Arrays.asList(2, 3, 4)).setAddingReplicas(Collections.emptyList()).setRemovingReplicas(Collections.emptyList()).setIsNew(false).toString(), b.toLeaderAndIsrPartitionState(new TopicPartition("bar", 0), false).toString());
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState) Test(org.junit.jupiter.api.Test)

Example 7 with LeaderAndIsrPartitionState

use of org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState in project kafka by apache.

the class LeaderAndIsrRequest method getErrorResponse.

@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    LeaderAndIsrResponseData responseData = new LeaderAndIsrResponseData();
    Errors error = Errors.forException(e);
    responseData.setErrorCode(error.code());
    if (version() < 5) {
        List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
        for (LeaderAndIsrPartitionState partition : partitionStates()) {
            partitions.add(new LeaderAndIsrPartitionError().setTopicName(partition.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
        }
        responseData.setPartitionErrors(partitions);
    } else {
        for (LeaderAndIsrTopicState topicState : data.topicStates()) {
            List<LeaderAndIsrPartitionError> partitions = new ArrayList<>(topicState.partitionStates().size());
            for (LeaderAndIsrPartitionState partition : topicState.partitionStates()) {
                partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
            }
            responseData.topics().add(new LeaderAndIsrTopicError().setTopicId(topicState.topicId()).setPartitionErrors(partitions));
        }
    }
    return new LeaderAndIsrResponse(responseData, version());
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) ArrayList(java.util.ArrayList) LeaderAndIsrTopicState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)

Aggregations

LeaderAndIsrPartitionState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)7 ArrayList (java.util.ArrayList)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 Uuid (org.apache.kafka.common.Uuid)4 Test (org.junit.jupiter.api.Test)4 HashMap (java.util.HashMap)3 LeaderAndIsrPartitionError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError)3 LeaderAndIsrTopicError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)3 Node (org.apache.kafka.common.Node)2 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)2 Errors (org.apache.kafka.common.protocol.Errors)2 ByteBuffer (java.nio.ByteBuffer)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1