You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/09/20 07:35:52 UTC

[GitHub] [ozone] lokeshj1703 commented on a diff in pull request #3762: HDDS-7234. Add a common option for DiskBalancer commands

lokeshj1703 commented on code in PR #3762:
URL: https://github.com/apache/ozone/pull/3762#discussion_r974986689


##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/DiskBalancerStartSubcommand.java:
##########
@@ -55,31 +54,23 @@ public class DiskBalancerStartSubcommand extends ScmSubcommand {
       description = "Max parallelThread for DiskBalancer.")
   private Optional<Integer> parallelThread;
 
-  @Option(names = {"-a", "--allDatanodes"},
-      description = "Start diskBalancer on all datanodes.")
-  private boolean allHosts;
-
-  @Parameters(description = "List of fully qualified host names")
-  private List<String> hosts = new ArrayList<>();
+  @CommandLine.Mixin
+  private DiskBalancerCommonOptions commonOptions =
+      new DiskBalancerCommonOptions();
 
   @Override
   public void execute(ScmClient scmClient) throws IOException {
-    if (hosts.size() == 0 && !allHosts) {
-      System.out.println("Datanode not specified. Please specify " +
-          "\"--allDatanodes\" to start diskBalancer on all datanodes");
-      return;
-    }
-    if (hosts.size() != 0 && allHosts) {
-      System.out.println("Confused options. Omit \"--allDatanodes\" or " +
-          "Datanodes.");
+    if (!commonOptions.check()) {
       return;
     }
     List<DatanodeAdminError> errors =
         scmClient.startDiskBalancer(threshold, bandwidthInMB, parallelThread,
-            hosts.size() == 0 ? Optional.empty() : Optional.of(hosts));
+            commonOptions.getHosts().size() == 0 ? Optional.empty() :
+                Optional.of(commonOptions.getHosts()));

Review Comment:
   Create a function in DiskBalancerCommonOptions for this. We can reuse it in other classes as well.



##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/DiskBalancerCommonOptions.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hdds.scm.cli.datanode;
+
+import picocli.CommandLine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Common options for DiskBalancer commands.
+ */
+public class DiskBalancerCommonOptions {
+
+  @CommandLine.Option(names = {"-a", "--all"},
+      description = "Run commands on all datanodes.")
+  private boolean allHosts;
+
+  @CommandLine.Option(names = {"-d", "--datanodes"},
+      description = "Run commands on specific datanodes.")

Review Comment:
   Could we add some more info on how these datanodes should be specified? Like a comma separated list of datanodes ip or hostname. And we can provide an example as well.



##########
hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/DiskBalancerStartSubcommand.java:
##########
@@ -55,31 +54,23 @@ public class DiskBalancerStartSubcommand extends ScmSubcommand {
       description = "Max parallelThread for DiskBalancer.")
   private Optional<Integer> parallelThread;
 
-  @Option(names = {"-a", "--allDatanodes"},
-      description = "Start diskBalancer on all datanodes.")
-  private boolean allHosts;
-
-  @Parameters(description = "List of fully qualified host names")
-  private List<String> hosts = new ArrayList<>();
+  @CommandLine.Mixin
+  private DiskBalancerCommonOptions commonOptions =
+      new DiskBalancerCommonOptions();
 
   @Override
   public void execute(ScmClient scmClient) throws IOException {
-    if (hosts.size() == 0 && !allHosts) {
-      System.out.println("Datanode not specified. Please specify " +
-          "\"--allDatanodes\" to start diskBalancer on all datanodes");
-      return;
-    }
-    if (hosts.size() != 0 && allHosts) {
-      System.out.println("Confused options. Omit \"--allDatanodes\" or " +
-          "Datanodes.");
+    if (!commonOptions.check()) {
       return;
     }
     List<DatanodeAdminError> errors =
         scmClient.startDiskBalancer(threshold, bandwidthInMB, parallelThread,
-            hosts.size() == 0 ? Optional.empty() : Optional.of(hosts));
+            commonOptions.getHosts().size() == 0 ? Optional.empty() :
+                Optional.of(commonOptions.getHosts()));
 
     System.out.println("Start DiskBalancer on datanode(s):\n" +
-        (allHosts ? "All datanodes" : String.join("\n", hosts)));
+        (commonOptions.isAllHosts() ? "All datanodes" :
+            String.join("\n", commonOptions.getHosts())));

Review Comment:
   Create a function in DiskBalancerCommonOptions for this. We can reuse it in other classes as well.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org