lucasbru commented on code in PR #18125: URL: https://github.com/apache/kafka/pull/18125#discussion_r1882086749
########## clients/src/main/java/org/apache/kafka/clients/admin/StreamsGroupDescription.java: ########## @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.clients.admin; + +import org.apache.kafka.common.GroupState; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.acl.AclOperation; +import org.apache.kafka.common.annotation.InterfaceStability; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * A detailed description of a single streams group in the cluster. + */ [email protected] +public class StreamsGroupDescription { + + private final String groupId; + private final int groupEpoch; + private final int targetAssignmentEpoch; + private final int topologyEpoch; + private final Collection<StreamsGroupSubtopologyDescription> subtopologies; + private final Collection<StreamsGroupMemberDescription> members; + private final GroupState groupState; + private final Node coordinator; + private final Set<AclOperation> authorizedOperations; + + public StreamsGroupDescription( + final String groupId, + final int groupEpoch, + final int targetAssignmentEpoch, + final int topologyEpoch, + final Collection<StreamsGroupSubtopologyDescription> subtopologies, + final Collection<StreamsGroupMemberDescription> members, + final GroupState groupState, + final Node coordinator, + final Set<AclOperation> authorizedOperations + ) { + this.groupId = Objects.requireNonNull(groupId, "groupId must be non-null"); + this.groupEpoch = groupEpoch; + this.targetAssignmentEpoch = targetAssignmentEpoch; + this.topologyEpoch = topologyEpoch; + this.subtopologies = Objects.requireNonNull(subtopologies, "subtopologies must be non-null"); + this.members = Objects.requireNonNull(members, "members must be non-null"); + this.groupState = groupState; + this.coordinator = coordinator; Review Comment: Just because I wasn't 100% sure - the other group types allow null, so I was wondering if there is a corner case where it can be null. Probably not though - lets risk it ########## clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java: ########## @@ -4907,6 +4910,527 @@ public void testDeleteConsumerGroupOffsetsFindCoordinatorNonRetriableErrors() th } } + @Test + public void testDescribeStreamsGroups() throws Exception { + try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) { + env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); + + // Retriable FindCoordinatorResponse errors should be retried + env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.COORDINATOR_NOT_AVAILABLE, Node.noNode())); + env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Node.noNode())); + env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller())); + + StreamsGroupDescribeResponseData data = new StreamsGroupDescribeResponseData(); + + // Retriable errors should be retried + data.groups().add(new StreamsGroupDescribeResponseData.DescribedGroup() + .setGroupId(GROUP_ID) + .setErrorCode(Errors.COORDINATOR_LOAD_IN_PROGRESS.code())); + env.kafkaClient().prepareResponse(new StreamsGroupDescribeResponse(data)); + + /* + * We need to return two responses here, one with NOT_COORDINATOR error when calling describe streams group + * api using coordinator that has moved. This will retry whole operation. So we need to again respond with a + * FindCoordinatorResponse. + * + * And the same reason for COORDINATOR_NOT_AVAILABLE error response + */ + data = new StreamsGroupDescribeResponseData(); + data.groups().add(new StreamsGroupDescribeResponseData.DescribedGroup() + .setGroupId(GROUP_ID) + .setErrorCode(Errors.NOT_COORDINATOR.code())); + env.kafkaClient().prepareResponse(new StreamsGroupDescribeResponse(data)); + env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller())); + + data = new StreamsGroupDescribeResponseData(); + data.groups().add(new StreamsGroupDescribeResponseData.DescribedGroup() + .setGroupId(GROUP_ID) + .setErrorCode(Errors.COORDINATOR_NOT_AVAILABLE.code())); + env.kafkaClient().prepareResponse(new StreamsGroupDescribeResponse(data)); + env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller())); + + data = makeFullStreamsGroupDescribeResponse(); + + env.kafkaClient().prepareResponse(new StreamsGroupDescribeResponse(data)); + + final DescribeStreamsGroupsResult result = env.adminClient().describeStreamsGroups(singletonList(GROUP_ID)); + final StreamsGroupDescription groupDescription = result.describedGroups().get(GROUP_ID).get(); + + StreamsGroupMemberAssignment.TaskIds expectedActiveTasks1 = + new StreamsGroupMemberAssignment.TaskIds("my_subtopology", asList(0, 1, 2)); Review Comment: I decided against it. The constants are spread over two functions. I don't want to put top-level constants in this class - it's a wonderful class, since nobody else put top-level static constants in the class, so you don't get the mess that we often have in kafka streams test classes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
