Tejaskriya commented on code in PR #8902:
URL: https://github.com/apache/ozone/pull/8902#discussion_r2319419811


##########
hadoop-hdds/docs/content/tools/debug/RatisLogParser.md:
##########
@@ -22,18 +22,16 @@ weight: 5
   limitations under the License.
 -->
 
-The Ratis log parser tool takes a segment file as input, and give the output 
in a human-readable format.
-It has the following subcommands, which can be used to parse the Ratis logs of 
different components:
-
+The Ratis log parser tool takes a role and a segment file as input and gives a 
human-readable output.

Review Comment:
   Role can be an optional input if you accept my suggestion (as mentioned in 
other comments)



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ratis/parse/RatisLogParser.java:
##########
@@ -15,44 +15,64 @@
  * limitations under the License.
  */
 
-package org.apache.hadoop.ozone.debug.segmentparser;
+package org.apache.hadoop.ozone.debug.ratis.parse;
 
 import java.util.concurrent.Callable;
 import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisRequest;
 import 
org.apache.hadoop.ozone.container.common.transport.server.ratis.ContainerStateMachine;
+import org.apache.hadoop.ozone.om.helpers.OMRatisHelper;
 import org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import picocli.CommandLine;
 
 /**
- * Command line utility to parse and dump a datanode ratis segment file.
+ * Parse Ratis Log CLI implementation.
  */
 @CommandLine.Command(
-    name = "datanode",
-    description = "dump datanode segment file",
-    mixinStandardHelpOptions = true,
-    versionProvider = HddsVersionProvider.class)
-public class DatanodeRatisLogParser extends BaseLogParser
-    implements Callable<Void> {
-  @CommandLine.ParentCommand
-  private RatisLogParser logParser;
+    name = "parse",
+    description = "Shell for printing Ratis Log in understandable text",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true)
+public class RatisLogParser extends BaseLogParser implements Callable<Void> {
+  @CommandLine.Option(names = {"--role"},
+      required = true,
+      description = "Component role for parsing. Values: om, scm, datanode, 
generic")
+  private String role;

Review Comment:
   Instead of making the role mandatory, how about keeping "generic" as the 
default if no role is passed? Keeping "generic" when the option is called 
"roles" doesn't seem right.
   The description can be updated accordingly.



##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/ratis/parse/RatisLogParser.java:
##########
@@ -15,44 +15,64 @@
  * limitations under the License.
  */
 
-package org.apache.hadoop.ozone.debug.segmentparser;
+package org.apache.hadoop.ozone.debug.ratis.parse;
 
 import java.util.concurrent.Callable;
 import org.apache.hadoop.hdds.cli.HddsVersionProvider;
+import org.apache.hadoop.hdds.scm.ha.SCMRatisRequest;
 import 
org.apache.hadoop.ozone.container.common.transport.server.ratis.ContainerStateMachine;
+import org.apache.hadoop.ozone.om.helpers.OMRatisHelper;
 import org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import picocli.CommandLine;
 
 /**
- * Command line utility to parse and dump a datanode ratis segment file.
+ * Parse Ratis Log CLI implementation.
  */
 @CommandLine.Command(
-    name = "datanode",
-    description = "dump datanode segment file",
-    mixinStandardHelpOptions = true,
-    versionProvider = HddsVersionProvider.class)
-public class DatanodeRatisLogParser extends BaseLogParser
-    implements Callable<Void> {
-  @CommandLine.ParentCommand
-  private RatisLogParser logParser;
+    name = "parse",
+    description = "Shell for printing Ratis Log in understandable text",
+    versionProvider = HddsVersionProvider.class,
+    mixinStandardHelpOptions = true)
+public class RatisLogParser extends BaseLogParser implements Callable<Void> {
+  @CommandLine.Option(names = {"--role"},
+      required = true,
+      description = "Component role for parsing. Values: om, scm, datanode, 
generic")
+  private String role;
 
   private static final RaftGroupId DUMMY_PIPELINE_ID =
       RaftGroupId.valueOf(ByteString.copyFromUtf8("ADummyRatisGroup"));
 
   public static String smToContainerLogString(
       StateMachineLogEntryProto logEntryProto) {
-    return ContainerStateMachine.
-        smProtoToString(DUMMY_PIPELINE_ID, null, logEntryProto);
+    return ContainerStateMachine.smProtoToString(DUMMY_PIPELINE_ID, null, 
logEntryProto);
   }
 
   @Override
   public Void call() throws Exception {
-    System.out.println("Dumping Datanode Ratis Log");
-    System.out.println("Using Dummy PipelineID:" + DUMMY_PIPELINE_ID + "\n\n");
-
-    parseRatisLogs(DatanodeRatisLogParser::smToContainerLogString);
+    switch (role.toLowerCase()) {
+    case "om":
+      System.out.println("Dumping OM Ratis Log");
+      parseRatisLogs(OMRatisHelper::smProtoToString);
+      break;
+    case "scm":
+      System.out.println("Dumping SCM Ratis Log");
+      parseRatisLogs(SCMRatisRequest::smProtoToString);
+      break;
+    case "datanode":
+      System.out.println("Dumping Datanode Ratis Log");
+      System.out.println("Using Dummy PipelineID:" + DUMMY_PIPELINE_ID + 
"\n\n");
+      parseRatisLogs(RatisLogParser::smToContainerLogString);
+      break;
+    case "generic":
+      System.out.println("Dumping Generic Ratis Log");
+      parseRatisLogs(null);
+      break;
+    default:
+      System.err.println("Invalid role: " + role + ". Supported roles are: om, 
scm, datanode, generic");

Review Comment:
   If you take my above suggestion then this error message will need to be 
updated too.



##########
hadoop-hdds/docs/content/tools/debug/RatisLogParser.md:
##########
@@ -22,18 +22,16 @@ weight: 5
   limitations under the License.
 -->
 
-The Ratis log parser tool takes a segment file as input, and give the output 
in a human-readable format.
-It has the following subcommands, which can be used to parse the Ratis logs of 
different components:
-
+The Ratis log parser tool takes a role and a segment file as input and gives a 
human-readable output.
+It can be used to parse Ratis logs from different components by specifying the 
corresponding role.
 ```bash
-Usage: ozone debug ratislogparser [-hV] [--verbose] [COMMAND]
-Shell of printing Ratis Log in understandable text
-  -h, --help      Show this help message and exit.
-  -V, --version   Print version information and exit.
-      --verbose   More verbose output. Show the stack trace of the errors.
-Commands:
-  datanode  dump datanode segment file
-  generic   dump generic ratis segment file
-  om        dump om ratis segment file
-  scm       dump scm ratis segment file
+Usage: ozone debug ratis parse [-hV] [--verbose] --role=<role> -s=<segmentFile>
+Shell for printing Ratis Log in understandable text
+  -h, --help          Show this help message and exit.
+      --role=<role>   Dump the specified role ratis segment file. Format: [om,

Review Comment:
   The description for the command options says "values", but here it says 
"Format". Could you please make that consistent?



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