Search in sources :

Example 1 with ConsumerGroupDescription

use of org.apache.kafka.clients.admin.ConsumerGroupDescription in project kafka by apache.

the class DescribeConsumerGroupsHandlerTest method testSuccessfulHandleResponse.

@Test
public void testSuccessfulHandleResponse() {
    Collection<MemberDescription> members = singletonList(new MemberDescription("memberId", "clientId", "host", new MemberAssignment(tps)));
    ConsumerGroupDescription expected = new ConsumerGroupDescription(groupId1, true, members, "assignor", ConsumerGroupState.STABLE, coordinator);
    assertCompleted(handleWithError(Errors.NONE, ""), expected);
}
Also used : MemberAssignment(org.apache.kafka.clients.admin.MemberAssignment) MemberDescription(org.apache.kafka.clients.admin.MemberDescription) ConsumerGroupDescription(org.apache.kafka.clients.admin.ConsumerGroupDescription) Test(org.junit.jupiter.api.Test)

Example 2 with ConsumerGroupDescription

use of org.apache.kafka.clients.admin.ConsumerGroupDescription in project kafka by apache.

the class EosTestDriver method ensureStreamsApplicationDown.

private static void ensureStreamsApplicationDown(final Admin adminClient) {
    final long maxWaitTime = System.currentTimeMillis() + MAX_IDLE_TIME_MS;
    ConsumerGroupDescription description;
    do {
        description = getConsumerGroupDescription(adminClient);
        if (System.currentTimeMillis() > maxWaitTime && !description.members().isEmpty()) {
            throw new RuntimeException("Streams application not down after " + (MAX_IDLE_TIME_MS / 1000L) + " seconds. " + "Group: " + description);
        }
        sleep(1000L);
    } while (!description.members().isEmpty());
}
Also used : ConsumerGroupDescription(org.apache.kafka.clients.admin.ConsumerGroupDescription)

Example 3 with ConsumerGroupDescription

use of org.apache.kafka.clients.admin.ConsumerGroupDescription in project kafka by apache.

the class MirrorCheckpointTask method refreshIdleConsumerGroupOffset.

private void refreshIdleConsumerGroupOffset() {
    Map<String, KafkaFuture<ConsumerGroupDescription>> consumerGroupsDesc = targetAdminClient.describeConsumerGroups(consumerGroups).describedGroups();
    for (String group : consumerGroups) {
        try {
            ConsumerGroupDescription consumerGroupDesc = consumerGroupsDesc.get(group).get();
            ConsumerGroupState consumerGroupState = consumerGroupDesc.state();
            // (2) dead: the new consumer that is recently created at source and never exist at target
            if (consumerGroupState.equals(ConsumerGroupState.EMPTY)) {
                idleConsumerGroupsOffset.put(group, targetAdminClient.listConsumerGroupOffsets(group).partitionsToOffsetAndMetadata().get().entrySet().stream().collect(Collectors.toMap(Entry::getKey, Entry::getValue)));
            }
        // new consumer upstream has state "DEAD" and will be identified during the offset sync-up
        } catch (InterruptedException | ExecutionException e) {
            log.error("Error querying for consumer group {} on cluster {}.", group, targetClusterAlias, e);
        }
    }
}
Also used : Entry(java.util.Map.Entry) KafkaFuture(org.apache.kafka.common.KafkaFuture) ConsumerGroupDescription(org.apache.kafka.clients.admin.ConsumerGroupDescription) ConsumerGroupState(org.apache.kafka.common.ConsumerGroupState) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ConsumerGroupDescription

use of org.apache.kafka.clients.admin.ConsumerGroupDescription in project kafka by apache.

the class DescribeConsumerGroupsHandler method handleResponse.

@Override
public ApiResult<CoordinatorKey, ConsumerGroupDescription> handleResponse(Node coordinator, Set<CoordinatorKey> groupIds, AbstractResponse abstractResponse) {
    final DescribeGroupsResponse response = (DescribeGroupsResponse) abstractResponse;
    final Map<CoordinatorKey, ConsumerGroupDescription> completed = new HashMap<>();
    final Map<CoordinatorKey, Throwable> failed = new HashMap<>();
    final Set<CoordinatorKey> groupsToUnmap = new HashSet<>();
    for (DescribedGroup describedGroup : response.data().groups()) {
        CoordinatorKey groupIdKey = CoordinatorKey.byGroupId(describedGroup.groupId());
        Errors error = Errors.forCode(describedGroup.errorCode());
        if (error != Errors.NONE) {
            handleError(groupIdKey, error, failed, groupsToUnmap);
            continue;
        }
        final String protocolType = describedGroup.protocolType();
        if (protocolType.equals(ConsumerProtocol.PROTOCOL_TYPE) || protocolType.isEmpty()) {
            final List<DescribedGroupMember> members = describedGroup.members();
            final List<MemberDescription> memberDescriptions = new ArrayList<>(members.size());
            final Set<AclOperation> authorizedOperations = validAclOperations(describedGroup.authorizedOperations());
            for (DescribedGroupMember groupMember : members) {
                Set<TopicPartition> partitions = Collections.emptySet();
                if (groupMember.memberAssignment().length > 0) {
                    final Assignment assignment = ConsumerProtocol.deserializeAssignment(ByteBuffer.wrap(groupMember.memberAssignment()));
                    partitions = new HashSet<>(assignment.partitions());
                }
                memberDescriptions.add(new MemberDescription(groupMember.memberId(), Optional.ofNullable(groupMember.groupInstanceId()), groupMember.clientId(), groupMember.clientHost(), new MemberAssignment(partitions)));
            }
            final ConsumerGroupDescription consumerGroupDescription = new ConsumerGroupDescription(groupIdKey.idValue, protocolType.isEmpty(), memberDescriptions, describedGroup.protocolData(), ConsumerGroupState.parse(describedGroup.groupState()), coordinator, authorizedOperations);
            completed.put(groupIdKey, consumerGroupDescription);
        } else {
            failed.put(groupIdKey, new IllegalArgumentException(String.format("GroupId %s is not a consumer group (%s).", groupIdKey.idValue, protocolType)));
        }
    }
    return new ApiResult<>(completed, failed, new ArrayList<>(groupsToUnmap));
}
Also used : HashMap(java.util.HashMap) MemberDescription(org.apache.kafka.clients.admin.MemberDescription) ArrayList(java.util.ArrayList) AclOperation(org.apache.kafka.common.acl.AclOperation) DescribedGroup(org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroup) Assignment(org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Assignment) MemberAssignment(org.apache.kafka.clients.admin.MemberAssignment) MemberAssignment(org.apache.kafka.clients.admin.MemberAssignment) DescribedGroupMember(org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroupMember) DescribeGroupsResponse(org.apache.kafka.common.requests.DescribeGroupsResponse) HashSet(java.util.HashSet) ConsumerGroupDescription(org.apache.kafka.clients.admin.ConsumerGroupDescription) Errors(org.apache.kafka.common.protocol.Errors) TopicPartition(org.apache.kafka.common.TopicPartition)

Aggregations

ConsumerGroupDescription (org.apache.kafka.clients.admin.ConsumerGroupDescription)4 MemberAssignment (org.apache.kafka.clients.admin.MemberAssignment)2 MemberDescription (org.apache.kafka.clients.admin.MemberDescription)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 Assignment (org.apache.kafka.clients.consumer.ConsumerPartitionAssignor.Assignment)1 ConsumerGroupState (org.apache.kafka.common.ConsumerGroupState)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 AclOperation (org.apache.kafka.common.acl.AclOperation)1 DescribedGroup (org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroup)1 DescribedGroupMember (org.apache.kafka.common.message.DescribeGroupsResponseData.DescribedGroupMember)1 Errors (org.apache.kafka.common.protocol.Errors)1 DescribeGroupsResponse (org.apache.kafka.common.requests.DescribeGroupsResponse)1 Test (org.junit.jupiter.api.Test)1