From dc66de744826e0501040f8c2ca9e1edc076a80cf Mon Sep 17 00:00:00 2001 From: Akira Ajisaka Date: Mon, 9 Dec 2019 18:37:34 +0900 Subject: [PATCH] YARN-9985. Unsupported transitionToObserver option displaying for rmadmin command. Contributed by Ayush Saxena. --- .../hadoop/yarn/client/cli/RMAdminCLI.java | 9 +++-- .../yarn/client/cli/TestRMAdminCLI.java | 37 ++++++++++++++++--- .../src/site/markdown/YarnCommands.md | 2 - 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java index 708af3d176..0e860463c8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java @@ -251,7 +251,8 @@ private static void buildUsageMsg(StringBuilder builder, if (isHAEnabled) { for (Map.Entry cmdEntry : USAGE.entrySet()) { String cmdKey = cmdEntry.getKey(); - if (!cmdKey.equals("-help")) { + if (!cmdKey.equals("-help") && !cmdKey.equals("-failover") + && !cmdKey.equals("-transitionToObserver")) { UsageInfo usageInfo = cmdEntry.getValue(); if (usageInfo.args == null) { builder.append(" " + cmdKey + "\n"); @@ -323,7 +324,8 @@ private static void printHelp(String cmd, boolean isHAEnabled) { */ private static void printUsage(String cmd, boolean isHAEnabled) { StringBuilder usageBuilder = new StringBuilder(); - if (ADMIN_USAGE.containsKey(cmd) || USAGE.containsKey(cmd)) { + if (ADMIN_USAGE.containsKey(cmd) || USAGE.containsKey(cmd) + && (!cmd.equals("-failover") && !cmd.equals("-transitionToObserver"))) { buildIndividualUsageMsg(cmd, usageBuilder); } else { buildUsageMsg(usageBuilder, isHAEnabled); @@ -730,7 +732,8 @@ public int run(String[] args) throws Exception { return exitCode; } - if (USAGE.containsKey(cmd)) { + if (USAGE.containsKey(cmd) && !cmd.equals("-failover") + && !cmd.equals("-transitionToObserver")) { if (isHAEnabled) { return super.run(args); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java index 637f121d56..40b393ff3f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java @@ -777,11 +777,6 @@ public void testHelp() throws Exception { "Usage: yarn rmadmin [-getServiceState ]", dataErr, 0); testError(new String[] { "-help", "-checkHealth" }, "Usage: yarn rmadmin [-checkHealth ]", dataErr, 0); - testError(new String[] { "-help", "-failover" }, - "Usage: yarn rmadmin " + - "[-failover [--forcefence] [--forceactive] " + - " ]", - dataErr, 0); testError(new String[] { "-help", "-badParameter" }, "Usage: yarn rmadmin", dataErr, 0); @@ -1064,7 +1059,7 @@ public void testRMHAErrorUsage() throws Exception { ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream(); rmAdminCLIWithHAEnabled.setErrOut(new PrintStream(errOutBytes)); try { - String[] args = { "-failover" }; + String[] args = {"-transitionToActive"}; assertEquals(-1, rmAdminCLIWithHAEnabled.run(args)); String errOut = new String(errOutBytes.toByteArray(), Charsets.UTF_8); errOutBytes.reset(); @@ -1074,4 +1069,34 @@ public void testRMHAErrorUsage() throws Exception { } } + @Test + public void testNoUnsupportedHACommandsInHelp() throws Exception { + ByteArrayOutputStream dataErr = new ByteArrayOutputStream(); + System.setErr(new PrintStream(dataErr)); + String[] args = {}; + assertEquals(-1, rmAdminCLIWithHAEnabled.run(args)); + String errOut = dataErr.toString(); + assertFalse(errOut.contains("-transitionToObserver")); + dataErr.reset(); + String[] args1 = {"-transitionToObserver"}; + assertEquals(-1, rmAdminCLIWithHAEnabled.run(args1)); + errOut = dataErr.toString(); + assertTrue(errOut.contains("transitionToObserver: Unknown command")); + dataErr.reset(); + args1[0] = "-failover"; + assertEquals(-1, rmAdminCLIWithHAEnabled.run(args1)); + errOut = dataErr.toString(); + assertTrue(errOut.contains("failover: Unknown command")); + dataErr.reset(); + String[] args2 = {"-help", "-transitionToObserver"}; + assertEquals(0, rmAdminCLIWithHAEnabled.run(args2)); + errOut = dataErr.toString(); + assertFalse(errOut.contains("-transitionToObserver")); + dataErr.reset(); + args2[1] = "-failover"; + assertEquals(0, rmAdminCLIWithHAEnabled.run(args2)); + errOut = dataErr.toString(); + assertFalse(errOut.contains("-failover")); + dataErr.reset(); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md index a772860b63..0f2b379f98 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md @@ -220,7 +220,6 @@ Usage: -updateNodeResource [NodeID] [MemSize] [vCores] ([OvercommitTimeout]) or -updateNodeResource [NodeID] [ResourceTypes] ([OvercommitTimeout]) -transitionToActive [--forceactive] -transitionToStandby - -failover [--forcefence] [--forceactive] -getServiceState -getAllServiceState -checkHealth @@ -246,7 +245,6 @@ Usage: | -updateNodeResource [NodeID] [ResourceTypes] \([OvercommitTimeout]\) | Update resource types on specific node. Resource Types is comma-delimited key value pairs of any resources availale at Resource Manager. For example, memory-mb=1024Mi,vcores=1,resource1=2G,resource2=4m| | -transitionToActive [--forceactive] [--forcemanual] \ | Transitions the service into Active state. Try to make the target active without checking that there is no active node if the --forceactive option is used. This command can not be used if automatic failover is enabled. Though you can override this by --forcemanual option, you need caution. This command can not be used if automatic failover is enabled.| | -transitionToStandby [--forcemanual] \ | Transitions the service into Standby state. This command can not be used if automatic failover is enabled. Though you can override this by --forcemanual option, you need caution. | -| -failover [--forceactive] \ \ | Initiate a failover from serviceId1 to serviceId2. Try to failover to the target service even if it is not ready if the --forceactive option is used. This command can not be used if automatic failover is enabled. | | -getServiceState \ | Returns the state of the service. | | -getAllServiceState | Returns the state of all the services. | | -checkHealth \ | Requests that the service perform a health check. The RMAdmin tool will exit with a non-zero exit code if the check fails. |