diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java index 152a59d41e25..705909fc90f1 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/cli/GenericCli.java @@ -48,6 +48,7 @@ public abstract class GenericCli implements GenericParentCommand { private UserGroupInformation user; @Option(names = {"--verbose"}, + scope = CommandLine.ScopeType.INHERIT, description = "More verbose output. Show the stack trace of the errors.") private boolean verbose; diff --git a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerStatusSubcommand.java b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerStatusSubcommand.java index 7edecd782207..c18491c2da51 100644 --- a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerStatusSubcommand.java +++ b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerStatusSubcommand.java @@ -49,10 +49,6 @@ versionProvider = HddsVersionProvider.class) public class ContainerBalancerStatusSubcommand extends ScmSubcommand { - @CommandLine.Option(names = {"-v", "--verbose"}, - description = "Verbose output. Show current iteration info.") - private boolean verbose; - @CommandLine.Option(names = {"-H", "--history"}, description = "Verbose output with history. Show current iteration info and history of iterations. " + "Works only with -v.") @@ -69,7 +65,7 @@ public void execute(ScmClient scmClient) throws IOException { LocalDateTime.ofInstant(startedAtInstant, ZoneId.systemDefault()); System.out.println("ContainerBalancer is Running."); - if (verbose) { + if (isVerbose()) { System.out.printf("Started at: %s %s%n", dateTime.toLocalDate().format(DateTimeFormatter.ISO_LOCAL_DATE), dateTime.toLocalTime().format(DateTimeFormatter.ISO_LOCAL_TIME)); diff --git a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java index 265b23c25d36..d15be56410f8 100644 --- a/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java +++ b/hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SafeModeCheckSubcommand.java @@ -22,7 +22,6 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.hadoop.hdds.cli.HddsVersionProvider; import org.apache.hadoop.hdds.scm.client.ScmClient; -import picocli.CommandLine; import picocli.CommandLine.Command; /** @@ -35,10 +34,6 @@ versionProvider = HddsVersionProvider.class) public class SafeModeCheckSubcommand extends ScmSubcommand { - @CommandLine.Option(names = {"--verbose"}, - description = "Show detailed status of rules.") - private boolean verbose; - @Override public void execute(ScmClient scmClient) throws IOException { boolean execReturn = scmClient.inSafeMode(); @@ -49,7 +44,7 @@ public void execute(ScmClient scmClient) throws IOException { } else { System.out.println("SCM is out of safe mode."); } - if (verbose) { + if (isVerbose()) { for (Map.Entry> entry : scmClient.getSafeModeRuleStatuses().entrySet()) { Pair value = entry.getValue(); diff --git a/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestContainerBalancerSubCommand.java b/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestContainerBalancerSubCommand.java index 30919d525fef..48fddc6236fa 100644 --- a/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestContainerBalancerSubCommand.java +++ b/hadoop-hdds/tools/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestContainerBalancerSubCommand.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.time.OffsetDateTime; import java.util.Arrays; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos; import org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerBalancerStatusInfoProto; @@ -85,6 +86,7 @@ class TestContainerBalancerSubCommand { private ContainerBalancerStatusSubcommand statusCmd; private GenericTestUtils.PrintStreamCapturer out; private GenericTestUtils.PrintStreamCapturer err; + private AtomicBoolean verbose; private static ContainerBalancerStatusInfoResponseProto getContainerBalancerStatusInfoResponseProto( ContainerBalancerConfiguration config) { @@ -230,9 +232,15 @@ private static ContainerBalancerConfiguration getContainerBalancerConfiguration( @BeforeEach void setup() { + verbose = new AtomicBoolean(); stopCmd = new ContainerBalancerStopSubcommand(); startCmd = new ContainerBalancerStartSubcommand(); - statusCmd = new ContainerBalancerStatusSubcommand(); + statusCmd = new ContainerBalancerStatusSubcommand() { + @Override + protected boolean isVerbose() { + return verbose.get(); + } + }; out = GenericTestUtils.captureOut(); err = GenericTestUtils.captureErr(); } @@ -294,7 +302,8 @@ void testContainerBalancerStatusInfoSubcommandVerboseHistory() //test status is running when(scmClient.getContainerBalancerStatusInfo()).thenReturn(statusInfoResponseProto); CommandLine c = new CommandLine(statusCmd); - c.parseArgs("--verbose", "--history"); + verbose.set(true); + c.parseArgs("--history"); statusCmd.execute(scmClient); String firstHistoryIterationOutput = @@ -355,8 +364,7 @@ void testContainerBalancerStatusInfoSubcommandVerbose() statusInfoResponseProto = getContainerBalancerStatusInfoResponseProto(config); //test status is running when(scmClient.getContainerBalancerStatusInfo()).thenReturn(statusInfoResponseProto); - CommandLine c = new CommandLine(statusCmd); - c.parseArgs("--verbose"); + verbose.set(true); statusCmd.execute(scmClient); String currentIterationOutput = diff --git a/hadoop-ozone/dist/src/main/smoketest/balancer/testBalancer.robot b/hadoop-ozone/dist/src/main/smoketest/balancer/testBalancer.robot index 641bc1462bbc..44754f1fd078 100644 --- a/hadoop-ozone/dist/src/main/smoketest/balancer/testBalancer.robot +++ b/hadoop-ozone/dist/src/main/smoketest/balancer/testBalancer.robot @@ -98,13 +98,13 @@ Run Balancer Status Should Contain ${result} ContainerBalancer is Running. Run Balancer Verbose Status - ${result} = Execute ozone admin containerbalancer status -v + ${result} = Execute ozone admin containerbalancer status --verbose Verify Balancer Iteration ${result} 1 Should Contain ${result} Iteration result - collapse_spaces=True Run Balancer Verbose History Status - ${result} = Execute ozone admin containerbalancer status -v --history + ${result} = Execute ozone admin containerbalancer status --verbose --history Verify Balancer Iteration ${result} 1 Verify Balancer Iteration History ${result} @@ -186,4 +186,4 @@ Verify Container Balancer for RATIS/EC containers #We need to ensure that after balancing, the amount of data recorded on each datanode falls within the following ranges: #{SIZE}*3 < used < {SIZE}*3.5 for RATIS containers, and {SIZE}*0.7 < used < {SIZE}*1.5 for EC containers. Should Be True ${datanodeOzoneUsedBytesInfoAfterContainerBalancing} < ${SIZE} * ${UPPER_LIMIT} - Should Be True ${datanodeOzoneUsedBytesInfoAfterContainerBalancing} > ${SIZE} * ${LOWER_LIMIT} \ No newline at end of file + Should Be True ${datanodeOzoneUsedBytesInfoAfterContainerBalancing} > ${SIZE} * ${LOWER_LIMIT} diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java index c7b2ed28073a..eb9be2c292e9 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java @@ -117,11 +117,6 @@ public class BaseFreonGenerator implements FreonSubcommand { defaultValue = "") private String prefix = ""; - @Option(names = {"--verbose"}, - description = "More verbose output. " - + "Show all the command line Option info.") - private boolean verbose; - @CommandLine.Spec private CommandLine.Model.CommandSpec spec; @@ -324,7 +319,7 @@ public void init() { LOG.error("HTTP server can't be stopped.", ex); } printReport(); - if (verbose) { + if (freonCommand.isVerbose()) { printOption(); } }, 10); diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairTool.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairTool.java index 8b45435a4f97..66460b9f85a1 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairTool.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/repair/om/FSORepairTool.java @@ -93,10 +93,6 @@ public class FSORepairTool extends RepairTool { description = "Filter by bucket name") private String bucketFilter; - @CommandLine.Option(names = {"--verbose"}, - description = "Verbose output. Show all intermediate steps.") - private boolean verbose; - @Nonnull @Override protected Component serviceToBeOffline() { @@ -112,7 +108,7 @@ public void execute() throws Exception { throw new IllegalArgumentException("FSO repair failed: " + ex.getMessage()); } - if (verbose) { + if (isVerbose()) { info("FSO repair finished."); } } @@ -407,7 +403,7 @@ protected void markFileForDeletion(String fileKey, OmKeyInfo fileInfo) throws IO // directory delete. It is also not possible here if the file's parent // is gone. The name of the key does not matter so just use IDs. deletedTable.putWithBatch(batch, fileKey, updatedRepeatedOmKeyInfo); - if (verbose) { + if (isVerbose()) { info("Added entry " + fileKey + " to open key table: " + updatedRepeatedOmKeyInfo); } store.commitBatchOperation(batch);