Search in sources :

Example 1 with OffsetCommitResponseTopic

use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic in project kafka by apache.

the class OffsetCommitRequest method getErrorResponseTopics.

public static List<OffsetCommitResponseTopic> getErrorResponseTopics(List<OffsetCommitRequestTopic> requestTopics, Errors e) {
    List<OffsetCommitResponseTopic> responseTopicData = new ArrayList<>();
    for (OffsetCommitRequestTopic entry : requestTopics) {
        List<OffsetCommitResponsePartition> responsePartitions = new ArrayList<>();
        for (OffsetCommitRequestData.OffsetCommitRequestPartition requestPartition : entry.partitions()) {
            responsePartitions.add(new OffsetCommitResponsePartition().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(e.code()));
        }
        responseTopicData.add(new OffsetCommitResponseTopic().setName(entry.name()).setPartitions(responsePartitions));
    }
    return responseTopicData;
}
Also used : OffsetCommitRequestTopic(org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic) OffsetCommitRequestData(org.apache.kafka.common.message.OffsetCommitRequestData) OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) ArrayList(java.util.ArrayList) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition)

Example 2 with OffsetCommitResponseTopic

use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic in project kafka by apache.

the class OffsetCommitResponseTest method testParse.

@Test
public void testParse() {
    OffsetCommitResponseData data = new OffsetCommitResponseData().setTopics(Arrays.asList(new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionOne).setErrorCode(errorOne.code()))), new OffsetCommitResponseTopic().setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setPartitionIndex(partitionTwo).setErrorCode(errorTwo.code()))))).setThrottleTimeMs(throttleTimeMs);
    for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
        ByteBuffer buffer = MessageUtil.toByteBuffer(data, version);
        OffsetCommitResponse response = OffsetCommitResponse.parse(buffer, version);
        assertEquals(expectedErrorCounts, response.errorCounts());
        if (version >= 3) {
            assertEquals(throttleTimeMs, response.throttleTimeMs());
        } else {
            assertEquals(DEFAULT_THROTTLE_TIME, response.throttleTimeMs());
        }
        assertEquals(version >= 4, response.shouldClientThrottle(version));
    }
}
Also used : OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) ByteBuffer(java.nio.ByteBuffer) OffsetCommitResponseData(org.apache.kafka.common.message.OffsetCommitResponseData) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition) Test(org.junit.jupiter.api.Test)

Example 3 with OffsetCommitResponseTopic

use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic in project kafka by apache.

the class AlterConsumerGroupOffsetsHandler method handleResponse.

@Override
public ApiResult<CoordinatorKey, Map<TopicPartition, Errors>> handleResponse(Node coordinator, Set<CoordinatorKey> groupIds, AbstractResponse abstractResponse) {
    validateKeys(groupIds);
    final OffsetCommitResponse response = (OffsetCommitResponse) abstractResponse;
    final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
    final Set<CoordinatorKey> groupsToRetry = new HashSet<>();
    final Map<TopicPartition, Errors> partitionResults = new HashMap<>();
    for (OffsetCommitResponseTopic topic : response.data().topics()) {
        for (OffsetCommitResponsePartition partition : topic.partitions()) {
            TopicPartition topicPartition = new TopicPartition(topic.name(), partition.partitionIndex());
            Errors error = Errors.forCode(partition.errorCode());
            if (error != Errors.NONE) {
                handleError(groupId, topicPartition, error, partitionResults, groupsToUnmap, groupsToRetry);
            } else {
                partitionResults.put(topicPartition, error);
            }
        }
    }
    if (groupsToUnmap.isEmpty() && groupsToRetry.isEmpty()) {
        return ApiResult.completed(groupId, partitionResults);
    } else {
        return ApiResult.unmapped(new ArrayList<>(groupsToUnmap));
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) OffsetCommitResponse(org.apache.kafka.common.requests.OffsetCommitResponse) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition) HashSet(java.util.HashSet)

Example 4 with OffsetCommitResponseTopic

use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic in project kafka by apache.

the class MessageTest method testOffsetCommitResponseVersions.

@Test
public void testOffsetCommitResponseVersions() throws Exception {
    Supplier<OffsetCommitResponseData> response = () -> new OffsetCommitResponseData().setTopics(singletonList(new OffsetCommitResponseTopic().setName("topic").setPartitions(singletonList(new OffsetCommitResponsePartition().setPartitionIndex(1).setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()))))).setThrottleTimeMs(20);
    for (short version : ApiKeys.OFFSET_COMMIT.allVersions()) {
        OffsetCommitResponseData responseData = response.get();
        if (version < 3) {
            responseData.setThrottleTimeMs(0);
        }
        testAllMessageRoundTripsFromVersion(version, responseData);
    }
}
Also used : TxnOffsetCommitResponseTopic(org.apache.kafka.common.message.TxnOffsetCommitResponseData.TxnOffsetCommitResponseTopic) OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) TxnOffsetCommitResponsePartition(org.apache.kafka.common.message.TxnOffsetCommitResponseData.TxnOffsetCommitResponsePartition) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition) Test(org.junit.jupiter.api.Test)

Example 5 with OffsetCommitResponseTopic

use of org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic in project kafka by apache.

the class OffsetCommitRequestTest method testGetErrorResponseTopics.

@Test
public void testGetErrorResponseTopics() {
    List<OffsetCommitResponseTopic> expectedTopics = Arrays.asList(new OffsetCommitResponseTopic().setName(topicOne).setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()).setPartitionIndex(partitionOne))), new OffsetCommitResponseTopic().setName(topicTwo).setPartitions(Collections.singletonList(new OffsetCommitResponsePartition().setErrorCode(Errors.UNKNOWN_MEMBER_ID.code()).setPartitionIndex(partitionTwo))));
    assertEquals(expectedTopics, getErrorResponseTopics(topics, Errors.UNKNOWN_MEMBER_ID));
}
Also used : OffsetCommitResponseTopic(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic) OffsetCommitResponsePartition(org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition) Test(org.junit.jupiter.api.Test)

Aggregations

OffsetCommitResponsePartition (org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponsePartition)5 OffsetCommitResponseTopic (org.apache.kafka.common.message.OffsetCommitResponseData.OffsetCommitResponseTopic)5 Test (org.junit.jupiter.api.Test)3 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 OffsetCommitRequestData (org.apache.kafka.common.message.OffsetCommitRequestData)1 OffsetCommitRequestTopic (org.apache.kafka.common.message.OffsetCommitRequestData.OffsetCommitRequestTopic)1 OffsetCommitResponseData (org.apache.kafka.common.message.OffsetCommitResponseData)1 TxnOffsetCommitResponsePartition (org.apache.kafka.common.message.TxnOffsetCommitResponseData.TxnOffsetCommitResponsePartition)1 TxnOffsetCommitResponseTopic (org.apache.kafka.common.message.TxnOffsetCommitResponseData.TxnOffsetCommitResponseTopic)1 Errors (org.apache.kafka.common.protocol.Errors)1 OffsetCommitResponse (org.apache.kafka.common.requests.OffsetCommitResponse)1