[ 
https://issues.apache.org/jira/browse/HDFS-17809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18070709#comment-18070709
 ] 

ASF GitHub Bot commented on HDFS-17809:
---------------------------------------

ayushtkn commented on code in PR #8324:
URL: https://github.com/apache/hadoop/pull/8324#discussion_r3030498438


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java:
##########
@@ -56,6 +56,15 @@ public void execute(CommandLine cmd) throws Exception {
     Preconditions.checkState(cmd.hasOption(DiskBalancerCLI.HELP));
     verifyCommandOptions(DiskBalancerCLI.HELP, cmd);
     String helpCommand = cmd.getOptionValue(DiskBalancerCLI.HELP);
+    if (helpCommand == null || helpCommand.isEmpty()) {
+      // With optionalArg(true), space-separated form "-help <cmd>" leaves the
+      // sub-command as a positional arg rather than the option's value.
+      // Fall back to the first leftover arg so "-help plan" works as expected.
+      String[] leftoverArgs = cmd.getArgs();
+      if (leftoverArgs != null && leftoverArgs.length > 0) {
+        helpCommand = leftoverArgs[0];
+      }
+    }

Review Comment:
   we have normalised already, will this ever hit?



##########
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java:
##########
@@ -756,6 +756,33 @@ public void testHelpCommand() throws Exception {
     runCommand(cmdLine);
   }
 
+  /**
+   * HDFS-17809: "-help <command>" must display command-specific help text,
+   * not just the generic usage summary.
+   */
+  @Test
+  @Timeout(value = 60)
+  public void testHelpCommandWithSubCommand() throws Exception {
+    // Each sub-command help should contain its own option/keyword.
+    String[][] subCommands = {
+        {PLAN,    "plan"},
+        {EXECUTE, "execute"},
+        {QUERY,   "query"},
+        {CANCEL,  "cancel"},
+        {REPORT,  "report"},
+    };
+    for (String[] pair : subCommands) {
+      String subCmd = pair[0];
+      String expectedToken = pair[1];
+      String cmdLine = String.format("hdfs diskbalancer -%s %s", HELP, subCmd);
+      List<String> output = runCommand(cmdLine);
+      String joined = String.join("\n", output).toLowerCase();
+      assertTrue(joined.contains(expectedToken),

Review Comment:
   we should have -ve test cases as well





> hdfs diskbalancer -help plan or other commands are not giving correct 
> explanation in hadoop version 3.4.1
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: HDFS-17809
>                 URL: https://issues.apache.org/jira/browse/HDFS-17809
>             Project: Hadoop HDFS
>          Issue Type: Bug
>          Components: diskbalancer
>    Affects Versions: 3.4.1
>            Reporter: Raju Balpande
>            Priority: Major
>              Labels: pull-request-available
>
> For HDFS with hadoop version 3.4.1, facing problem in help for diskbalancer 
> commands.
> {code:java}
> [[email protected] ~]# hdfs diskbalancer -help query
> usage: hdfs diskbalancer [command] [options]DiskBalancer distributes data 
> evenly between different disks on a
> datanode. DiskBalancer operates by generating a plan, that tells datanode
> how to move data between disks. Users can execute a plan by submitting it
> to the datanode.
> To get specific help on a particular command please run hdfs diskbalancer 
> -help <command>.
>     --help   valid commands are plan | execute | query | cancel | report 
> {code}
> I tried similar for all the commands l{*}ike plan, execute, report{*} and 
> getting same response as if it is ignoring any text after help. Also tried 
> with *--help* as well.
> {code:java}
> [[email protected] ~]# hdfs diskbalancer --help 
> execute
> usage: hdfs diskbalancer [command] [options]DiskBalancer distributes data 
> evenly between different disks on a
> datanode. DiskBalancer operates by generating a plan, that tells datanode
> how to move data between disks. Users can execute a plan by submitting it
> to the datanode.
> To get specific help on a particular command please run hdfs diskbalancer 
> -help <command>.
>     --help   valid commands are plan | execute | query | cancel | report 
> {code}
>  Whereas the same commands works fine in *Hadoop version 3.1.1*
> {code:java}
> [[email protected] ~]# hdfs diskbalancer -help query
> usage: hdfs diskbalancer -query <hostname>  [options]
> Query Plan queries a given data node about the current state of disk
> balancer execution.
>     --query <arg>   Queries the disk balancer status of a given datanode.
>     --v             Prints details of the plan that is being executed on
>                     the node.Query command retrievs the plan ID and the 
> current running state. {code}
> Can someone please look into this.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to