Search in sources :

Example 1 with OffsetDeleteResponse

use of org.apache.kafka.common.requests.OffsetDeleteResponse in project kafka by apache.

the class DeleteConsumerGroupOffsetsHandler method handleResponse.

@Override
public ApiResult<CoordinatorKey, Map<TopicPartition, Errors>> handleResponse(Node coordinator, Set<CoordinatorKey> groupIds, AbstractResponse abstractResponse) {
    validateKeys(groupIds);
    final OffsetDeleteResponse response = (OffsetDeleteResponse) abstractResponse;
    final Errors error = Errors.forCode(response.data().errorCode());
    if (error != Errors.NONE) {
        final Map<CoordinatorKey, Throwable> failed = new HashMap<>();
        final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
        handleGroupError(groupId, error, failed, groupsToUnmap);
        return new ApiResult<>(Collections.emptyMap(), failed, new ArrayList<>(groupsToUnmap));
    } else {
        final Map<TopicPartition, Errors> partitionResults = new HashMap<>();
        response.data().topics().forEach(topic -> topic.partitions().forEach(partition -> partitionResults.put(new TopicPartition(topic.name(), partition.partitionIndex()), Errors.forCode(partition.errorCode()))));
        return ApiResult.completed(groupId, partitionResults);
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Logger(org.slf4j.Logger) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) OffsetDeleteRequestTopic(org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestTopic) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) OffsetDeleteRequest(org.apache.kafka.common.requests.OffsetDeleteRequest) HashSet(java.util.HashSet) OffsetDeleteRequestData(org.apache.kafka.common.message.OffsetDeleteRequestData) OffsetDeleteRequestTopicCollection(org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestTopicCollection) CoordinatorType(org.apache.kafka.common.requests.FindCoordinatorRequest.CoordinatorType) Map(java.util.Map) LogContext(org.apache.kafka.common.utils.LogContext) Errors(org.apache.kafka.common.protocol.Errors) Node(org.apache.kafka.common.Node) OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) OffsetDeleteRequestPartition(org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestPartition) Collections(java.util.Collections) OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) HashMap(java.util.HashMap) Errors(org.apache.kafka.common.protocol.Errors) TopicPartition(org.apache.kafka.common.TopicPartition) HashSet(java.util.HashSet)

Example 2 with OffsetDeleteResponse

use of org.apache.kafka.common.requests.OffsetDeleteResponse in project kafka by apache.

the class DeleteConsumerGroupOffsetsHandlerTest method handleWithGroupError.

private AdminApiHandler.ApiResult<CoordinatorKey, Map<TopicPartition, Errors>> handleWithGroupError(Errors error) {
    DeleteConsumerGroupOffsetsHandler handler = new DeleteConsumerGroupOffsetsHandler(groupId, tps, logContext);
    OffsetDeleteResponse response = buildGroupErrorResponse(error);
    return handler.handleResponse(new Node(1, "host", 1234), singleton(CoordinatorKey.byGroupId(groupId)), response);
}
Also used : OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) Node(org.apache.kafka.common.Node)

Example 3 with OffsetDeleteResponse

use of org.apache.kafka.common.requests.OffsetDeleteResponse in project kafka by apache.

the class KafkaAdminClientTest method testDeleteConsumerGroupOffsets.

@Test
public void testDeleteConsumerGroupOffsets() throws Exception {
    // Happy path
    final TopicPartition tp1 = new TopicPartition("foo", 0);
    final TopicPartition tp2 = new TopicPartition("bar", 0);
    final TopicPartition tp3 = new TopicPartition("foobar", 0);
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
        env.kafkaClient().prepareResponse(new OffsetDeleteResponse(new OffsetDeleteResponseData().setTopics(new OffsetDeleteResponseTopicCollection(Stream.of(new OffsetDeleteResponseTopic().setName("foo").setPartitions(new OffsetDeleteResponsePartitionCollection(Collections.singletonList(new OffsetDeleteResponsePartition().setPartitionIndex(0).setErrorCode(Errors.NONE.code())).iterator())), new OffsetDeleteResponseTopic().setName("bar").setPartitions(new OffsetDeleteResponsePartitionCollection(Collections.singletonList(new OffsetDeleteResponsePartition().setPartitionIndex(0).setErrorCode(Errors.GROUP_SUBSCRIBED_TO_TOPIC.code())).iterator()))).collect(Collectors.toList()).iterator()))));
        final DeleteConsumerGroupOffsetsResult errorResult = env.adminClient().deleteConsumerGroupOffsets(GROUP_ID, Stream.of(tp1, tp2).collect(Collectors.toSet()));
        assertNull(errorResult.partitionResult(tp1).get());
        TestUtils.assertFutureError(errorResult.all(), GroupSubscribedToTopicException.class);
        TestUtils.assertFutureError(errorResult.partitionResult(tp2), GroupSubscribedToTopicException.class);
        assertThrows(IllegalArgumentException.class, () -> errorResult.partitionResult(tp3));
    }
}
Also used : OffsetDeleteResponsePartitionCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection) OffsetDeleteResponseTopic(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopic) OffsetDeleteResponsePartition(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartition) OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetDeleteResponseTopicCollection(org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection) OffsetDeleteResponseData(org.apache.kafka.common.message.OffsetDeleteResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 4 with OffsetDeleteResponse

use of org.apache.kafka.common.requests.OffsetDeleteResponse in project kafka by apache.

the class DeleteConsumerGroupOffsetsHandlerTest method handleWithPartitionError.

private AdminApiHandler.ApiResult<CoordinatorKey, Map<TopicPartition, Errors>> handleWithPartitionError(Errors error) {
    DeleteConsumerGroupOffsetsHandler handler = new DeleteConsumerGroupOffsetsHandler(groupId, tps, logContext);
    OffsetDeleteResponse response = buildPartitionErrorResponse(error);
    return handler.handleResponse(new Node(1, "host", 1234), singleton(CoordinatorKey.byGroupId(groupId)), response);
}
Also used : OffsetDeleteResponse(org.apache.kafka.common.requests.OffsetDeleteResponse) Node(org.apache.kafka.common.Node)

Aggregations

OffsetDeleteResponse (org.apache.kafka.common.requests.OffsetDeleteResponse)4 Node (org.apache.kafka.common.Node)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 OffsetDeleteRequestData (org.apache.kafka.common.message.OffsetDeleteRequestData)1 OffsetDeleteRequestPartition (org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestPartition)1 OffsetDeleteRequestTopic (org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestTopic)1 OffsetDeleteRequestTopicCollection (org.apache.kafka.common.message.OffsetDeleteRequestData.OffsetDeleteRequestTopicCollection)1 OffsetDeleteResponseData (org.apache.kafka.common.message.OffsetDeleteResponseData)1 OffsetDeleteResponsePartition (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartition)1 OffsetDeleteResponsePartitionCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponsePartitionCollection)1 OffsetDeleteResponseTopic (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopic)1 OffsetDeleteResponseTopicCollection (org.apache.kafka.common.message.OffsetDeleteResponseData.OffsetDeleteResponseTopicCollection)1 Errors (org.apache.kafka.common.protocol.Errors)1