YARN-9985. Unsupported transitionToObserver option displaying for rmadmin command. Contributed by Ayush Saxena.

(cherry picked from commit dc66de7448)
This commit is contained in:
Akira Ajisaka 2019-12-09 18:37:34 +09:00
parent aa9cd0a2d6
commit a3cdba7713
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
3 changed files with 37 additions and 11 deletions

View File

@ -251,7 +251,8 @@ public class RMAdminCLI extends HAAdmin {
if (isHAEnabled) { if (isHAEnabled) {
for (Map.Entry<String,UsageInfo> cmdEntry : USAGE.entrySet()) { for (Map.Entry<String,UsageInfo> cmdEntry : USAGE.entrySet()) {
String cmdKey = cmdEntry.getKey(); String cmdKey = cmdEntry.getKey();
if (!cmdKey.equals("-help")) { if (!cmdKey.equals("-help") && !cmdKey.equals("-failover")
&& !cmdKey.equals("-transitionToObserver")) {
UsageInfo usageInfo = cmdEntry.getValue(); UsageInfo usageInfo = cmdEntry.getValue();
if (usageInfo.args == null) { if (usageInfo.args == null) {
builder.append(" " + cmdKey + "\n"); builder.append(" " + cmdKey + "\n");
@ -323,7 +324,8 @@ public class RMAdminCLI extends HAAdmin {
*/ */
private static void printUsage(String cmd, boolean isHAEnabled) { private static void printUsage(String cmd, boolean isHAEnabled) {
StringBuilder usageBuilder = new StringBuilder(); 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); buildIndividualUsageMsg(cmd, usageBuilder);
} else { } else {
buildUsageMsg(usageBuilder, isHAEnabled); buildUsageMsg(usageBuilder, isHAEnabled);
@ -730,7 +732,8 @@ public class RMAdminCLI extends HAAdmin {
return exitCode; return exitCode;
} }
if (USAGE.containsKey(cmd)) { if (USAGE.containsKey(cmd) && !cmd.equals("-failover")
&& !cmd.equals("-transitionToObserver")) {
if (isHAEnabled) { if (isHAEnabled) {
return super.run(args); return super.run(args);
} }

View File

@ -780,11 +780,6 @@ public class TestRMAdminCLI {
"Usage: yarn rmadmin [-getServiceState <serviceId>]", dataErr, 0); "Usage: yarn rmadmin [-getServiceState <serviceId>]", dataErr, 0);
testError(new String[] { "-help", "-checkHealth" }, testError(new String[] { "-help", "-checkHealth" },
"Usage: yarn rmadmin [-checkHealth <serviceId>]", dataErr, 0); "Usage: yarn rmadmin [-checkHealth <serviceId>]", dataErr, 0);
testError(new String[] { "-help", "-failover" },
"Usage: yarn rmadmin " +
"[-failover [--forcefence] [--forceactive] " +
"<serviceId> <serviceId>]",
dataErr, 0);
testError(new String[] { "-help", "-badParameter" }, testError(new String[] { "-help", "-badParameter" },
"Usage: yarn rmadmin", dataErr, 0); "Usage: yarn rmadmin", dataErr, 0);
@ -1067,7 +1062,7 @@ public class TestRMAdminCLI {
ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream(); ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream();
rmAdminCLIWithHAEnabled.setErrOut(new PrintStream(errOutBytes)); rmAdminCLIWithHAEnabled.setErrOut(new PrintStream(errOutBytes));
try { try {
String[] args = { "-failover" }; String[] args = {"-transitionToActive"};
assertEquals(-1, rmAdminCLIWithHAEnabled.run(args)); assertEquals(-1, rmAdminCLIWithHAEnabled.run(args));
String errOut = new String(errOutBytes.toByteArray(), Charsets.UTF_8); String errOut = new String(errOutBytes.toByteArray(), Charsets.UTF_8);
errOutBytes.reset(); errOutBytes.reset();
@ -1077,4 +1072,34 @@ public class TestRMAdminCLI {
} }
} }
@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();
}
} }

View File

@ -218,7 +218,6 @@ Usage:
-updateNodeResource [NodeID] [MemSize] [vCores] ([OvercommitTimeout]) or -updateNodeResource [NodeID] [ResourceTypes] ([OvercommitTimeout]) -updateNodeResource [NodeID] [MemSize] [vCores] ([OvercommitTimeout]) or -updateNodeResource [NodeID] [ResourceTypes] ([OvercommitTimeout])
-transitionToActive [--forceactive] <serviceId> -transitionToActive [--forceactive] <serviceId>
-transitionToStandby <serviceId> -transitionToStandby <serviceId>
-failover [--forcefence] [--forceactive] <serviceId> <serviceId>
-getServiceState <serviceId> -getServiceState <serviceId>
-getAllServiceState -getAllServiceState
-checkHealth <serviceId> -checkHealth <serviceId>
@ -244,7 +243,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| | -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] \<serviceId\> | 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.| | -transitionToActive [--forceactive] [--forcemanual] \<serviceId\> | 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] \<serviceId\> | 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. | | -transitionToStandby [--forcemanual] \<serviceId\> | 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] \<serviceId1\> \<serviceId2\> | 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 \<serviceId\> | Returns the state of the service. | | -getServiceState \<serviceId\> | Returns the state of the service. |
| -getAllServiceState | Returns the state of all the services. | | -getAllServiceState | Returns the state of all the services. |
| -checkHealth \<serviceId\> | Requests that the service perform a health check. The RMAdmin tool will exit with a non-zero exit code if the check fails. | | -checkHealth \<serviceId\> | Requests that the service perform a health check. The RMAdmin tool will exit with a non-zero exit code if the check fails. |