1919import org .apache .kafka .clients .CommonClientConfigs ;
2020import org .apache .kafka .clients .admin .AbstractOptions ;
2121import org .apache .kafka .clients .admin .Admin ;
22+ import org .apache .kafka .clients .admin .AlterStreamsGroupOffsetsOptions ;
2223import org .apache .kafka .clients .admin .DeleteStreamsGroupOffsetsOptions ;
2324import org .apache .kafka .clients .admin .DeleteStreamsGroupOffsetsResult ;
2425import org .apache .kafka .clients .admin .DeleteStreamsGroupsOptions ;
26+ import org .apache .kafka .clients .admin .DeleteTopicsOptions ;
2527import org .apache .kafka .clients .admin .DeleteTopicsResult ;
2628import org .apache .kafka .clients .admin .DescribeStreamsGroupsOptions ;
2729import org .apache .kafka .clients .admin .DescribeStreamsGroupsResult ;
3032import org .apache .kafka .clients .admin .GroupListing ;
3133import org .apache .kafka .clients .admin .ListGroupsOptions ;
3234import org .apache .kafka .clients .admin .ListGroupsResult ;
35+ import org .apache .kafka .clients .admin .ListOffsetsOptions ;
3336import org .apache .kafka .clients .admin .ListOffsetsResult ;
37+ import org .apache .kafka .clients .admin .ListStreamsGroupOffsetsOptions ;
3438import org .apache .kafka .clients .admin .ListStreamsGroupOffsetsSpec ;
39+ import org .apache .kafka .clients .admin .ListTopicsOptions ;
3540import org .apache .kafka .clients .admin .OffsetSpec ;
3641import org .apache .kafka .clients .admin .StreamsGroupDescription ;
3742import org .apache .kafka .clients .admin .StreamsGroupMemberAssignment ;
@@ -279,7 +284,7 @@ public void describeGroups() throws ExecutionException, InterruptedException {
279284 StreamsGroupDescription getDescribeGroup (String group ) throws ExecutionException , InterruptedException {
280285 DescribeStreamsGroupsResult result = adminClient .describeStreamsGroups (
281286 List .of (group ),
282- new DescribeStreamsGroupsOptions (). timeoutMs ( opts . options . valueOf ( opts . timeoutMsOpt ). intValue ()));
287+ withTimeoutMs ( new DescribeStreamsGroupsOptions ()));
283288 Map <String , StreamsGroupDescription > descriptionMap = result .all ().get ();
284289 return descriptionMap .get (group );
285290 }
@@ -428,8 +433,14 @@ Map<TopicPartition, OffsetsInfo> getOffsets(StreamsGroupDescription description)
428433 earliest .put (tp , OffsetSpec .earliest ());
429434 latest .put (tp , OffsetSpec .latest ());
430435 }
431- Map <TopicPartition , ListOffsetsResult .ListOffsetsResultInfo > earliestResult = adminClient .listOffsets (earliest ).all ().get ();
432- Map <TopicPartition , ListOffsetsResult .ListOffsetsResultInfo > latestResult = adminClient .listOffsets (latest ).all ().get ();
436+ Map <TopicPartition , ListOffsetsResult .ListOffsetsResultInfo > earliestResult = adminClient .listOffsets (
437+ earliest ,
438+ withTimeoutMs (new ListOffsetsOptions ())
439+ ).all ().get ();
440+ Map <TopicPartition , ListOffsetsResult .ListOffsetsResultInfo > latestResult = adminClient .listOffsets (
441+ latest ,
442+ withTimeoutMs (new ListOffsetsOptions ())
443+ ).all ().get ();
433444 Map <TopicPartition , OffsetAndMetadata > committedOffsets = getCommittedOffsets (description .groupId ());
434445
435446 Map <TopicPartition , OffsetsInfo > output = new HashMap <>();
@@ -449,14 +460,18 @@ Map<TopicPartition, OffsetsInfo> getOffsets(StreamsGroupDescription description)
449460
450461 Map <TopicPartition , OffsetAndMetadata > getCommittedOffsets (String groupId ) {
451462 try {
452- var sourceTopics = adminClient .describeStreamsGroups (List .of (groupId ))
453- .all ().get ().get (groupId )
463+ var sourceTopics = adminClient .describeStreamsGroups (
464+ List .of (groupId ),
465+ withTimeoutMs (new DescribeStreamsGroupsOptions ())
466+ ).all ().get ().get (groupId )
454467 .subtopologies ().stream ()
455468 .flatMap (subtopology -> subtopology .sourceTopics ().stream ())
456469 .collect (Collectors .toSet ());
457470
458- var allTopicPartitions = adminClient .listStreamsGroupOffsets (Map .of (groupId , new ListStreamsGroupOffsetsSpec ()))
459- .partitionsToOffsetAndMetadata (groupId ).get ();
471+ var allTopicPartitions = adminClient .listStreamsGroupOffsets (
472+ Map .of (groupId , new ListStreamsGroupOffsetsSpec ()),
473+ withTimeoutMs (new ListStreamsGroupOffsetsOptions ())
474+ ).partitionsToOffsetAndMetadata (groupId ).get ();
460475
461476 allTopicPartitions .keySet ().removeIf (tp -> !sourceTopics .contains (tp .topic ()));
462477 return allTopicPartitions ;
@@ -467,8 +482,10 @@ Map<TopicPartition, OffsetAndMetadata> getCommittedOffsets(String groupId) {
467482
468483 private List <TopicPartition > filterExistingGroupTopics (String groupId , List <TopicPartition > topicPartitions ) {
469484 try {
470- var allTopicPartitions = adminClient .listStreamsGroupOffsets (Map .of (groupId , new ListStreamsGroupOffsetsSpec ()))
471- .partitionsToOffsetAndMetadata (groupId ).get ();
485+ var allTopicPartitions = adminClient .listStreamsGroupOffsets (
486+ Map .of (groupId , new ListStreamsGroupOffsetsSpec ()),
487+ withTimeoutMs (new ListStreamsGroupOffsetsOptions ())
488+ ).partitionsToOffsetAndMetadata (groupId ).get ();
472489 boolean allPresent = topicPartitions .stream ().allMatch (allTopicPartitions ::containsKey );
473490 if (!allPresent ) {
474491 printError ("One or more topics are not part of the group '" + groupId + "'." , Optional .empty ());
@@ -490,7 +507,8 @@ Map<String, Map<TopicPartition, OffsetAndMetadata>> resetOffsets() {
490507 : opts .options .valuesOf (opts .groupOpt );
491508 if (!groupIds .isEmpty ()) {
492509 Map <String , KafkaFuture <StreamsGroupDescription >> streamsGroups = adminClient .describeStreamsGroups (
493- groupIds
510+ groupIds ,
511+ withTimeoutMs (new DescribeStreamsGroupsOptions ())
494512 ).describedGroups ();
495513
496514 streamsGroups .forEach ((groupId , groupDescription ) -> {
@@ -506,7 +524,10 @@ Map<String, Map<TopicPartition, OffsetAndMetadata>> resetOffsets() {
506524 List <String > internalTopics = getInternalTopicsToBeDeleted (groupId );
507525 if (!internalTopics .isEmpty ()) {
508526 try {
509- adminClient .deleteTopics (internalTopics ).all ().get ();
527+ adminClient .deleteTopics (
528+ internalTopics ,
529+ withTimeoutMs (new DeleteTopicsOptions ())
530+ ).all ().get ();
510531 } catch (InterruptedException | ExecutionException e ) {
511532 if (e .getCause () instanceof UnknownTopicOrPartitionException ) {
512533 printError ("Deleting internal topics for group '" + groupId + "' failed because the topics do not exist." , Optional .empty ());
@@ -742,7 +763,10 @@ private Map<String, Throwable> maybeDeleteInternalTopics(Map<String, Throwable>
742763 if (internalTopicsToDelete != null && !internalTopicsToDelete .isEmpty ()) {
743764 DeleteTopicsResult deleteTopicsResult = null ;
744765 try {
745- deleteTopicsResult = adminClient .deleteTopics (internalTopicsToDelete );
766+ deleteTopicsResult = adminClient .deleteTopics (
767+ internalTopicsToDelete ,
768+ withTimeoutMs (new DeleteTopicsOptions ())
769+ );
746770 deleteTopicsResult .all ().get ();
747771 } catch (InterruptedException | ExecutionException e ) {
748772 if (deleteTopicsResult != null ) {
@@ -820,7 +844,10 @@ private void printInternalTopicErrors(Map<String, Throwable> internalTopicsDelet
820844 Map <String , List <String >> retrieveInternalTopics (List <String > groupIds ) {
821845 Map <String , List <String >> groupToInternalTopics = new HashMap <>();
822846 try {
823- Map <String , StreamsGroupDescription > descriptionMap = adminClient .describeStreamsGroups (groupIds ).all ().get ();
847+ Map <String , StreamsGroupDescription > descriptionMap = adminClient .describeStreamsGroups (
848+ groupIds ,
849+ withTimeoutMs (new DescribeStreamsGroupsOptions ())
850+ ).all ().get ();
824851 for (StreamsGroupDescription description : descriptionMap .values ()) {
825852
826853 List <String > sourceTopics = description .subtopologies ().stream ()
@@ -848,7 +875,7 @@ Map<String, List<String>> retrieveInternalTopics(List<String> groupIds) {
848875 if (e .getCause () instanceof UnsupportedVersionException ) {
849876 try {
850877 // Retrieve internal topic list if possible, and add the list of topic names to error message
851- Set <String > allTopics = adminClient .listTopics ().names ().get ();
878+ Set <String > allTopics = adminClient .listTopics (withTimeoutMs ( new ListTopicsOptions ()) ).names ().get ();
852879 List <String > internalTopics = allTopics .stream ()
853880 .filter (topic -> groupIds .stream ().anyMatch (groupId -> isInferredInternalTopic (topic , groupId )))
854881 .collect (Collectors .toList ());
@@ -873,7 +900,8 @@ private Map<TopicPartition, OffsetAndMetadata> resetOffsetsForInactiveGroup(Stri
873900 if (!dryRun ) {
874901 adminClient .alterStreamsGroupOffsets (
875902 groupId ,
876- preparedOffsets
903+ preparedOffsets ,
904+ withTimeoutMs (new AlterStreamsGroupOffsetsOptions ())
877905 ).all ().get ();
878906 }
879907
@@ -947,22 +975,6 @@ public static boolean matchesInternalTopicFormat(final String topicName) {
947975 || topicName .matches (".+-KTABLE-FK-JOIN-SUBSCRIPTION-RESPONSE-\\ d+-topic" );
948976 }
949977
950- List <String > collectAllTopics (String groupId ) {
951- try {
952- return adminClient .describeStreamsGroups (List .of (groupId ))
953- .all ().get ().get (groupId )
954- .subtopologies ().stream ()
955- .flatMap (subtopology -> Stream .of (
956- subtopology .sourceTopics ().stream (),
957- subtopology .repartitionSinkTopics ().stream (),
958- subtopology .repartitionSourceTopics ().keySet ().stream (),
959- subtopology .stateChangelogTopics ().keySet ().stream ()
960- ).flatMap (s -> s )).distinct ().collect (Collectors .toList ());
961- } catch (InterruptedException | ExecutionException e ) {
962- throw new RuntimeException (e );
963- }
964- }
965-
966978 Collection <StreamsGroupMemberDescription > collectGroupMembers (String groupId ) throws Exception {
967979 return getDescribeGroup (groupId ).members ();
968980 }
0 commit comments