AndrewJSchofield commented on code in PR #19820:
URL: https://github.com/apache/kafka/pull/19820#discussion_r2156911513


##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java:
##########
@@ -366,6 +428,70 @@ Entry<Throwable, Map<String, Throwable>> 
sendDeleteShareGroupOffsetsRequest(Stri
             return new SimpleImmutableEntry<>(topLevelException, 
topicLevelResult);
         }
 
+        void resetOffsets() throws ExecutionException, InterruptedException {
+            String groupId = opts.options.valueOf(opts.groupOpt);
+            Map<TopicPartition, OffsetAndMetadata> offsetsToReset = 
prepareOffsetsToReset(groupId);
+            boolean dryRun = opts.options.has(opts.dryRunOpt) || 
!opts.options.has(opts.executeOpt);
+            if (!dryRun) {
+                adminClient.alterShareGroupOffsets(groupId,
+                    offsetsToReset.entrySet().stream()
+                        .collect(Collectors.toMap(
+                            Entry::getKey,
+                            entry -> entry.getValue().offset()
+                        )),
+                    new AlterShareGroupOffsetsOptions()
+                        
.timeoutMs(opts.options.valueOf(opts.timeoutMsOpt).intValue())
+                ).all().get();
+            }
+            Set<SharePartitionOffsetInformation> partitionOffsets = 
mapOffsetsToSharePartitionInformation(groupId, offsetsToReset);
+            Map<String, ShareGroupDescription> shareGroups = 
describeShareGroups(Collections.singleton(groupId));
+            TreeMap<String, Entry<ShareGroupDescription, 
Collection<SharePartitionOffsetInformation>>> groupOffsets = new TreeMap<>();
+            shareGroups.forEach((id, description) -> groupOffsets.put(id, new 
SimpleImmutableEntry<>(description, partitionOffsets)));
+            printOffsets(groupOffsets, opts.options.has(opts.verboseOpt));
+        }
+
+        private Map<TopicPartition, OffsetAndMetadata> 
prepareOffsetsToReset(String groupId) throws ExecutionException, 
InterruptedException {
+            Map<String, ListShareGroupOffsetsSpec> groupSpecs = new 
HashMap<>();

Review Comment:
   This probably ought to be `groupSpecs = Map.of(groupId, new 
ListShareGroupOffsetsSpec())`.



##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java:
##########
@@ -366,6 +428,70 @@ Entry<Throwable, Map<String, Throwable>> 
sendDeleteShareGroupOffsetsRequest(Stri
             return new SimpleImmutableEntry<>(topLevelException, 
topicLevelResult);
         }
 
+        void resetOffsets() throws ExecutionException, InterruptedException {
+            String groupId = opts.options.valueOf(opts.groupOpt);
+            Map<TopicPartition, OffsetAndMetadata> offsetsToReset = 
prepareOffsetsToReset(groupId);
+            boolean dryRun = opts.options.has(opts.dryRunOpt) || 
!opts.options.has(opts.executeOpt);
+            if (!dryRun) {
+                adminClient.alterShareGroupOffsets(groupId,
+                    offsetsToReset.entrySet().stream()
+                        .collect(Collectors.toMap(
+                            Entry::getKey,
+                            entry -> entry.getValue().offset()
+                        )),
+                    new AlterShareGroupOffsetsOptions()
+                        
.timeoutMs(opts.options.valueOf(opts.timeoutMsOpt).intValue())
+                ).all().get();
+            }
+            Set<SharePartitionOffsetInformation> partitionOffsets = 
mapOffsetsToSharePartitionInformation(groupId, offsetsToReset);
+            Map<String, ShareGroupDescription> shareGroups = 
describeShareGroups(Collections.singleton(groupId));
+            TreeMap<String, Entry<ShareGroupDescription, 
Collection<SharePartitionOffsetInformation>>> groupOffsets = new TreeMap<>();
+            shareGroups.forEach((id, description) -> groupOffsets.put(id, new 
SimpleImmutableEntry<>(description, partitionOffsets)));
+            printOffsets(groupOffsets, opts.options.has(opts.verboseOpt));
+        }
+
+        private Map<TopicPartition, OffsetAndMetadata> 
prepareOffsetsToReset(String groupId) throws ExecutionException, 
InterruptedException {

Review Comment:
   The error handling for `bin/kafka-share-groups.sh --bootstrap-server 
localhost:9092 --group G1 --reset-offsets --dry-run` needs to be stronger. I 
didn't specify any topic information so the map `offsetsByTopicPartitions` is 
empty and the command blows up.



##########
tools/src/main/java/org/apache/kafka/tools/consumer/group/ShareGroupCommand.java:
##########
@@ -366,6 +428,70 @@ Entry<Throwable, Map<String, Throwable>> 
sendDeleteShareGroupOffsetsRequest(Stri
             return new SimpleImmutableEntry<>(topLevelException, 
topicLevelResult);
         }
 
+        void resetOffsets() throws ExecutionException, InterruptedException {
+            String groupId = opts.options.valueOf(opts.groupOpt);
+            Map<TopicPartition, OffsetAndMetadata> offsetsToReset = 
prepareOffsetsToReset(groupId);
+            boolean dryRun = opts.options.has(opts.dryRunOpt) || 
!opts.options.has(opts.executeOpt);
+            if (!dryRun) {
+                adminClient.alterShareGroupOffsets(groupId,
+                    offsetsToReset.entrySet().stream()
+                        .collect(Collectors.toMap(
+                            Entry::getKey,
+                            entry -> entry.getValue().offset()
+                        )),
+                    new AlterShareGroupOffsetsOptions()
+                        
.timeoutMs(opts.options.valueOf(opts.timeoutMsOpt).intValue())
+                ).all().get();
+            }
+            Set<SharePartitionOffsetInformation> partitionOffsets = 
mapOffsetsToSharePartitionInformation(groupId, offsetsToReset);
+            Map<String, ShareGroupDescription> shareGroups = 
describeShareGroups(Collections.singleton(groupId));
+            TreeMap<String, Entry<ShareGroupDescription, 
Collection<SharePartitionOffsetInformation>>> groupOffsets = new TreeMap<>();
+            shareGroups.forEach((id, description) -> groupOffsets.put(id, new 
SimpleImmutableEntry<>(description, partitionOffsets)));
+            printOffsets(groupOffsets, opts.options.has(opts.verboseOpt));
+        }
+
+        private Map<TopicPartition, OffsetAndMetadata> 
prepareOffsetsToReset(String groupId) throws ExecutionException, 
InterruptedException {
+            Map<String, ListShareGroupOffsetsSpec> groupSpecs = new 
HashMap<>();
+            Map<TopicPartition, OffsetAndMetadata> offsetsByTopicPartitions = 
adminClient.listShareGroupOffsets(groupSpecs).all().get().get(groupId);
+
+            if (opts.options.has(opts.topicOpt)) {
+                Set<String> topics = new 
HashSet<>(opts.options.valuesOf(opts.topicOpt));

Review Comment:
   Maybe `Set.copyOf(opts.options.valuesOf(opts.topicOpt))`



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to