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

##########
tools/src/main/java/org/apache/kafka/tools/VerifiableShareConsumer.java:
##########
@@ -0,0 +1,630 @@
+/*
+ * 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.tools;
+
+import org.apache.kafka.clients.CommonClientConfigs;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.AlterConfigOp;
+import org.apache.kafka.clients.admin.AlterConfigsOptions;
+import org.apache.kafka.clients.admin.ConfigEntry;
+import org.apache.kafka.clients.consumer.AcknowledgementCommitCallback;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.clients.consumer.ConsumerRecords;
+import org.apache.kafka.clients.consumer.KafkaShareConsumer;
+import org.apache.kafka.common.KafkaException;
+import org.apache.kafka.common.TopicIdPartition;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.config.ConfigResource;
+import org.apache.kafka.common.errors.WakeupException;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.apache.kafka.common.utils.Utils;
+import org.apache.kafka.coordinator.group.GroupConfig;
+import org.apache.kafka.coordinator.group.ShareGroupAutoOffsetResetStrategy;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+import net.sourceforge.argparse4j.ArgumentParsers;
+import net.sourceforge.argparse4j.inf.ArgumentParser;
+import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup;
+import net.sourceforge.argparse4j.inf.Namespace;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static net.sourceforge.argparse4j.impl.Arguments.store;
+import static net.sourceforge.argparse4j.impl.Arguments.storeTrue;
+
+public class VerifiableShareConsumer implements Closeable, 
AcknowledgementCommitCallback {
+
+    private static final Logger log = 
LoggerFactory.getLogger(VerifiableShareConsumer.class);
+
+    private final ObjectMapper mapper = new ObjectMapper();
+    private final PrintStream out;
+    private final KafkaShareConsumer<String, String> consumer;
+    private final String topic;
+    private final AcknowledgementMode acknowledgementMode;
+    private final String offsetResetStrategy;
+    private final Boolean verbose;
+    private final int maxMessages;
+    private Integer totalAcknowledged = 0;
+    private final String brokerHostandPort;
+    private final String groupId;
+    private final CountDownLatch shutdownLatch = new CountDownLatch(1);
+
+    public static class PartitionData {
+        private final String topic;
+        private final int partition;
+
+        public PartitionData(String topic, int partition) {
+            this.topic = topic;
+            this.partition = partition;
+        }
+
+        @JsonProperty
+        public String topic() {
+            return topic;
+        }
+
+        @JsonProperty
+        public int partition() {
+            return partition;
+        }
+    }
+
+    public static class RecordSetSummary extends PartitionData {
+        private final long count;
+        private final Set<Long> offsets;
+
+        public RecordSetSummary(String topic, int partition, Set<Long> 
offsets) {
+            super(topic, partition);
+            this.offsets = offsets;
+            this.count = offsets.size();
+        }
+
+        @JsonProperty
+        public long count() {
+            return count;
+        }
+
+        @JsonProperty
+        public Set<Long> offsets() {
+            return offsets;
+        }
+
+    }
+
+    protected static class AcknowledgedData extends PartitionData {
+        private final long count;
+        private final Set<Long> offsets;
+
+        public AcknowledgedData(String topic, int partition, Set<Long> 
offsets) {
+            super(topic, partition);
+            this.offsets = offsets;
+            this.count = offsets.size();
+        }
+
+        @JsonProperty
+        public long count() {
+            return count;
+        }
+
+        @JsonProperty
+        public Set<Long> offsets() {
+            return offsets;
+        }
+    }
+
+    @JsonPropertyOrder({ "timestamp", "name" })
+    private abstract static class ShareConsumerEvent {
+        private final long timestamp = System.currentTimeMillis();
+
+        @JsonProperty
+        public abstract String name();
+
+        @JsonProperty
+        public long timestamp() {
+            return timestamp;
+        }
+    }
+
+    protected static class StartupComplete extends ShareConsumerEvent {
+
+        @Override
+        public String name() {
+            return "startup_complete";
+        }
+    }
+
+    @JsonPropertyOrder({ "timestamp", "name", "offsetResetStrategy" })
+    protected static class OffsetResetStrategySet extends ShareConsumerEvent {
+
+        private final String offsetResetStrategy;
+
+        public OffsetResetStrategySet(String offsetResetStrategy) {
+            this.offsetResetStrategy = offsetResetStrategy;
+        }
+
+        @Override
+        public String name() {
+            return "offset_reset_strategy_set";
+        }
+
+        @JsonProperty
+        public String offsetResetStrategy() {
+            return offsetResetStrategy;
+        }
+    }
+
+    protected static class ShutdownComplete extends ShareConsumerEvent {
+
+        @Override
+        public String name() {
+            return "shutdown_complete";
+        }
+    }
+
+    @JsonPropertyOrder({ "timestamp", "name", "count", "partitions" })
+    public static class RecordsConsumed extends ShareConsumerEvent {
+        private final long count;
+        private final List<RecordSetSummary> partitionSummaries;
+
+        public RecordsConsumed(long count, List<RecordSetSummary> 
partitionSummaries) {
+            this.count = count;
+            this.partitionSummaries = partitionSummaries;
+        }
+
+        @Override
+        public String name() {
+            return "records_consumed";
+        }
+
+        @JsonProperty
+        public long count() {
+            return count;
+        }
+
+        @JsonProperty
+        public List<RecordSetSummary> partitions() {
+            return partitionSummaries;
+        }
+    }
+
+    @JsonPropertyOrder({ "timestamp", "name", "count", "partitions", 
"success", "error" })
+    protected static class OffsetsAcknowledged extends ShareConsumerEvent {
+
+        private final long count;
+        private final List<AcknowledgedData> partitions;
+        private final String error;
+        private final boolean success;
+
+        public OffsetsAcknowledged(long count, List<AcknowledgedData> 
partitions, String error, boolean success) {
+            this.count = count;
+            this.partitions = partitions;
+            this.error = error;
+            this.success = success;
+        }
+
+        @Override
+        public String name() {
+            return "offsets_acknowledged";
+        }
+
+        @JsonProperty
+        public long count() {
+            return count;
+        }
+
+        @JsonProperty
+        public List<AcknowledgedData> partitions() {
+            return partitions;
+        }
+
+        @JsonProperty
+        @JsonInclude(JsonInclude.Include.NON_NULL)
+        public String error() {
+            return error;
+        }
+
+        @JsonProperty
+        public boolean success() {
+            return success;
+        }
+
+    }
+
+    @JsonPropertyOrder({ "timestamp", "name", "key", "value", "topic", 
"partition", "offset" })
+    public static class RecordData extends ShareConsumerEvent {
+
+        private final ConsumerRecord<String, String> record;
+
+        public RecordData(ConsumerRecord<String, String> record) {
+            this.record = record;
+        }
+
+        @Override
+        public String name() {
+            return "record_data";
+        }
+
+        @JsonProperty
+        public String topic() {
+            return record.topic();
+        }
+
+        @JsonProperty
+        public int partition() {
+            return record.partition();
+        }
+
+        @JsonProperty

Review Comment:
   My mistake.



-- 
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