Search in sources :

Example 1 with OffsetFetchResponseGroup

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.

the class OffsetFetchResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> counts = new HashMap<>();
    if (!groupLevelErrors.isEmpty()) {
        // built response with v8 or above
        for (Map.Entry<String, Errors> entry : groupLevelErrors.entrySet()) {
            updateErrorCounts(counts, entry.getValue());
        }
        for (OffsetFetchResponseGroup group : data.groups()) {
            group.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
        }
    } else {
        // built response with v0-v7
        updateErrorCounts(counts, error);
        data.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
    }
    return counts;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Arrays(java.util.Arrays) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) HashMap(java.util.HashMap) NO_PARTITION_LEADER_EPOCH(org.apache.kafka.common.record.RecordBatch.NO_PARTITION_LEADER_EPOCH) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) Objects(java.util.Objects) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) List(java.util.List) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) Map(java.util.Map) Entry(java.util.Map.Entry) Errors(org.apache.kafka.common.protocol.Errors) Optional(java.util.Optional) OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with OffsetFetchResponseGroup

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.

the class OffsetFetchResponse method buildResponseData.

private Map<TopicPartition, PartitionData> buildResponseData(String groupId) {
    Map<TopicPartition, PartitionData> responseData = new HashMap<>();
    OffsetFetchResponseGroup group = data.groups().stream().filter(g -> g.groupId().equals(groupId)).collect(Collectors.toList()).get(0);
    for (OffsetFetchResponseTopics topic : group.topics()) {
        for (OffsetFetchResponsePartitions partition : topic.partitions()) {
            responseData.put(new TopicPartition(topic.name(), partition.partitionIndex()), new PartitionData(partition.committedOffset(), RequestUtils.getLeaderEpoch(partition.committedLeaderEpoch()), partition.metadata(), Errors.forCode(partition.errorCode())));
        }
    }
    return responseData;
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)

Example 3 with OffsetFetchResponseGroup

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.

the class OffsetFetchResponseTest method testUseDefaultLeaderEpochV8.

@Test
public void testUseDefaultLeaderEpochV8() {
    final Optional<Integer> emptyLeaderEpoch = Optional.empty();
    partitionDataMap.clear();
    partitionDataMap.put(new TopicPartition(topicOne, partitionOne), new PartitionData(offset, emptyLeaderEpoch, metadata, Errors.UNKNOWN_TOPIC_OR_PARTITION));
    OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.NOT_COORDINATOR), Collections.singletonMap(groupOne, partitionDataMap));
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(RecordBatch.NO_PARTITION_LEADER_EPOCH).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(metadata))))).setErrorCode(Errors.NOT_COORDINATOR.code()))).setThrottleTimeMs(throttleTimeMs);
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 4 with OffsetFetchResponseGroup

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.

the class OffsetFetchResponseTest method testNullableMetadataV8AndAbove.

@Test
public void testNullableMetadataV8AndAbove() {
    PartitionData pd = new PartitionData(offset, leaderEpochOne, null, Errors.UNKNOWN_TOPIC_OR_PARTITION);
    // test PartitionData.equals with null metadata
    assertEquals(pd, pd);
    partitionDataMap.clear();
    partitionDataMap.put(new TopicPartition(topicOne, partitionOne), pd);
    OffsetFetchResponse response = new OffsetFetchResponse(throttleTimeMs, Collections.singletonMap(groupOne, Errors.GROUP_AUTHORIZATION_FAILED), Collections.singletonMap(groupOne, partitionDataMap));
    OffsetFetchResponseData expectedData = new OffsetFetchResponseData().setGroups(Collections.singletonList(new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(new OffsetFetchResponseTopics().setName(topicOne).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(partitionOne).setCommittedOffset(offset).setCommittedLeaderEpoch(leaderEpochOne.orElse(-1)).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setMetadata(null))))).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code()))).setThrottleTimeMs(throttleTimeMs);
    assertEquals(expectedData, response.data());
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) PartitionData(org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Example 5 with OffsetFetchResponseGroup

use of org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup in project kafka by apache.

the class MessageTest method testOffsetFetchV8AndAbove.

@Test
public void testOffsetFetchV8AndAbove() throws Exception {
    String groupOne = "group1";
    String groupTwo = "group2";
    String groupThree = "group3";
    String groupFour = "group4";
    String groupFive = "group5";
    String topic1 = "topic1";
    String topic2 = "topic2";
    String topic3 = "topic3";
    OffsetFetchRequestTopics topicOne = new OffsetFetchRequestTopics().setName(topic1).setPartitionIndexes(Collections.singletonList(5));
    OffsetFetchRequestTopics topicTwo = new OffsetFetchRequestTopics().setName(topic2).setPartitionIndexes(Collections.singletonList(10));
    OffsetFetchRequestTopics topicThree = new OffsetFetchRequestTopics().setName(topic3).setPartitionIndexes(Collections.singletonList(15));
    List<OffsetFetchRequestTopics> groupOneTopics = singletonList(topicOne);
    OffsetFetchRequestGroup group1 = new OffsetFetchRequestGroup().setGroupId(groupOne).setTopics(groupOneTopics);
    List<OffsetFetchRequestTopics> groupTwoTopics = Arrays.asList(topicOne, topicTwo);
    OffsetFetchRequestGroup group2 = new OffsetFetchRequestGroup().setGroupId(groupTwo).setTopics(groupTwoTopics);
    List<OffsetFetchRequestTopics> groupThreeTopics = Arrays.asList(topicOne, topicTwo, topicThree);
    OffsetFetchRequestGroup group3 = new OffsetFetchRequestGroup().setGroupId(groupThree).setTopics(groupThreeTopics);
    OffsetFetchRequestGroup group4 = new OffsetFetchRequestGroup().setGroupId(groupFour).setTopics(null);
    OffsetFetchRequestGroup group5 = new OffsetFetchRequestGroup().setGroupId(groupFive).setTopics(null);
    OffsetFetchRequestData requestData = new OffsetFetchRequestData().setGroups(Arrays.asList(group1, group2, group3, group4, group5)).setRequireStable(true);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData);
    testAllMessageRoundTripsOffsetFetchV8AndAbove(requestData.setRequireStable(false));
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, requestData);
        }
    }
    OffsetFetchResponseTopics responseTopic1 = new OffsetFetchResponseTopics().setName(topic1).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(5).setMetadata(null).setCommittedOffset(100).setCommittedLeaderEpoch(3).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code())));
    OffsetFetchResponseTopics responseTopic2 = new OffsetFetchResponseTopics().setName(topic2).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(10).setMetadata("foo").setCommittedOffset(200).setCommittedLeaderEpoch(2).setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code())));
    OffsetFetchResponseTopics responseTopic3 = new OffsetFetchResponseTopics().setName(topic3).setPartitions(Collections.singletonList(new OffsetFetchResponsePartitions().setPartitionIndex(15).setMetadata("bar").setCommittedOffset(300).setCommittedLeaderEpoch(1).setErrorCode(Errors.GROUP_AUTHORIZATION_FAILED.code())));
    OffsetFetchResponseGroup responseGroup1 = new OffsetFetchResponseGroup().setGroupId(groupOne).setTopics(Collections.singletonList(responseTopic1)).setErrorCode(Errors.NOT_COORDINATOR.code());
    OffsetFetchResponseGroup responseGroup2 = new OffsetFetchResponseGroup().setGroupId(groupTwo).setTopics(Arrays.asList(responseTopic1, responseTopic2)).setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code());
    OffsetFetchResponseGroup responseGroup3 = new OffsetFetchResponseGroup().setGroupId(groupThree).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    OffsetFetchResponseGroup responseGroup4 = new OffsetFetchResponseGroup().setGroupId(groupFour).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    OffsetFetchResponseGroup responseGroup5 = new OffsetFetchResponseGroup().setGroupId(groupFive).setTopics(Arrays.asList(responseTopic1, responseTopic2, responseTopic3)).setErrorCode(Errors.NONE.code());
    Supplier<OffsetFetchResponseData> response = () -> new OffsetFetchResponseData().setGroups(Arrays.asList(responseGroup1, responseGroup2, responseGroup3, responseGroup4, responseGroup5)).setThrottleTimeMs(10);
    for (short version : ApiKeys.OFFSET_FETCH.allVersions()) {
        if (version >= 8) {
            OffsetFetchResponseData responseData = response.get();
            testAllMessageRoundTripsOffsetFetchFromVersionV8AndAbove(version, responseData);
        }
    }
}
Also used : OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchRequestGroup(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) OffsetFetchRequestTopics(org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetFetchResponseGroup (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup)6 OffsetFetchResponsePartitions (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions)6 OffsetFetchResponseTopics (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics)6 TopicPartition (org.apache.kafka.common.TopicPartition)4 Test (org.junit.jupiter.api.Test)4 OffsetFetchResponseData (org.apache.kafka.common.message.OffsetFetchResponseData)3 HashMap (java.util.HashMap)2 OffsetFetchRequestGroup (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestGroup)2 OffsetFetchRequestTopics (org.apache.kafka.common.message.OffsetFetchRequestData.OffsetFetchRequestTopics)2 PartitionData (org.apache.kafka.common.requests.OffsetFetchResponse.PartitionData)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 OffsetFetchResponsePartition (org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition)1