aswinshakil commented on code in PR #9090:
URL: https://github.com/apache/ozone/pull/9090#discussion_r2408603595


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/datanode/container/ChecksumSubcommand.java:
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.hadoop.ozone.debug.datanode.container;
+
+import com.fasterxml.jackson.databind.SequenceWriter;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.google.common.annotations.VisibleForTesting;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
+import org.apache.hadoop.hdds.server.JsonUtils;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+
+/**
+ * Handles {@code ozone debug datanode container checksum} command.
+ * Displays the unserialized version of a container checksum tree file in JSON 
format.
+ */
+@Command(
+    name = "checksum",
+    description = "Display container checksum tree file in JSON format")
+public class ChecksumSubcommand implements Callable<Void> {
+
+  @CommandLine.Option(names = {"--tree", "-t"},
+      required = true,
+      description = "Path to the container checksum tree file (.tree)")
+  private String treeFilePath;
+
+  /**
+   * Sets the tree file path. Used for testing.
+   */
+  @VisibleForTesting
+  public void setTreeFilePath(String treeFilePath) {
+    this.treeFilePath = treeFilePath;
+  }
+
+  @Override
+  public Void call() throws Exception {
+    File treeFile = new File(treeFilePath);
+    if (!treeFile.exists()) {
+      System.err.println("Error: Tree file does not exist: " + treeFilePath);
+      throw new RuntimeException("Tree file does not exist: " + treeFilePath);
+    }
+
+    try {
+      ContainerProtos.ContainerChecksumInfo checksumInfo = 
readChecksumInfo(treeFile);
+      ChecksumInfoWrapper wrapper = new ChecksumInfoWrapper(checksumInfo, 
treeFilePath);
+      
+      try (SequenceWriter writer = JsonUtils.getStdoutSequenceWriter()) {
+        writer.write(wrapper);
+        writer.flush();
+      }
+      System.out.println();
+      System.out.flush();

Review Comment:
   Not needed. We only have one output



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to