aliehsaeedii commented on code in PR #19646:
URL: https://github.com/apache/kafka/pull/19646#discussion_r2141038665


##########
tools/src/main/java/org/apache/kafka/tools/OffsetsUtils.java:
##########
@@ -0,0 +1,474 @@
+/*
+ * 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.admin.AbstractOptions;
+import org.apache.kafka.clients.admin.Admin;
+import org.apache.kafka.clients.admin.DescribeTopicsOptions;
+import org.apache.kafka.clients.admin.ListOffsetsOptions;
+import org.apache.kafka.clients.admin.ListOffsetsResult;
+import org.apache.kafka.clients.admin.OffsetSpec;
+import org.apache.kafka.clients.admin.TopicDescription;
+import org.apache.kafka.clients.consumer.OffsetAndMetadata;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.requests.ListOffsetsResponse;
+import org.apache.kafka.common.utils.Utils;
+import org.apache.kafka.server.util.CommandLineUtils;
+import org.apache.kafka.tools.consumer.group.CsvUtils;
+
+import com.fasterxml.jackson.databind.ObjectReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
+import java.util.function.ToIntFunction;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import joptsimple.OptionParser;
+
+
+public class OffsetsUtils {
+    public static final Logger LOGGER = 
LoggerFactory.getLogger(OffsetsUtils.class);
+    private static final String TOPIC_PARTITION_SEPARATOR = ":";
+    private final Admin adminClient;
+    private final OffsetsUtilsOptions opts;
+    private final OptionParser parser;
+
+    public OffsetsUtils(Admin adminClient, OptionParser parser, 
OffsetsUtilsOptions opts) {
+        this.adminClient = adminClient;
+        this.opts = opts;
+        this.parser = parser;
+    }
+
+    public Optional<Map<String, Map<TopicPartition, OffsetAndMetadata>>> 
resetPlanFromFile() {
+        if (opts.resetFromFileOpt != null && !opts.resetFromFileOpt.isEmpty()) 
{
+            try {
+                String resetPlanPath = opts.resetFromFileOpt.get(0);
+                String resetPlanCsv = Utils.readFileAsString(resetPlanPath);
+                Map<String, Map<TopicPartition, OffsetAndMetadata>> resetPlan 
= parseResetPlan(resetPlanCsv);
+                return Optional.of(resetPlan);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        } else return Optional.empty();
+    }
+
+    private Map<String, Map<TopicPartition, OffsetAndMetadata>> 
parseResetPlan(String resetPlanCsv) {
+        ObjectReader csvReader = 
CsvUtils.readerFor(CsvUtils.CsvRecordNoGroup.class);
+        String[] lines = resetPlanCsv.split("\n");
+        boolean isSingleGroupQuery = opts.groupOpt.size() == 1;
+        boolean isOldCsvFormat = false;
+        try {
+            if (lines.length > 0) {
+                csvReader.readValue(lines[0], CsvUtils.CsvRecordNoGroup.class);
+                isOldCsvFormat = true;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            // Ignore.
+        }

Review Comment:
   I had to ignore it again, since it is ignored in `ConsumerGroupCommand`



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