Skip to content

Commit a57caf1

Browse files
aajisakaRogPodge
authored andcommitted
YARN-9985. Unsupported transitionToObserver option displaying for rmadmin command. Contributed by Ayush Saxena.
1 parent 0a398e5 commit a57caf1

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ private static void buildUsageMsg(StringBuilder builder,
251251
if (isHAEnabled) {
252252
for (Map.Entry<String,UsageInfo> cmdEntry : USAGE.entrySet()) {
253253
String cmdKey = cmdEntry.getKey();
254-
if (!cmdKey.equals("-help")) {
254+
if (!cmdKey.equals("-help") && !cmdKey.equals("-failover")
255+
&& !cmdKey.equals("-transitionToObserver")) {
255256
UsageInfo usageInfo = cmdEntry.getValue();
256257
if (usageInfo.args == null) {
257258
builder.append(" " + cmdKey + "\n");
@@ -323,7 +324,8 @@ private static void printHelp(String cmd, boolean isHAEnabled) {
323324
*/
324325
private static void printUsage(String cmd, boolean isHAEnabled) {
325326
StringBuilder usageBuilder = new StringBuilder();
326-
if (ADMIN_USAGE.containsKey(cmd) || USAGE.containsKey(cmd)) {
327+
if (ADMIN_USAGE.containsKey(cmd) || USAGE.containsKey(cmd)
328+
&& (!cmd.equals("-failover") && !cmd.equals("-transitionToObserver"))) {
327329
buildIndividualUsageMsg(cmd, usageBuilder);
328330
} else {
329331
buildUsageMsg(usageBuilder, isHAEnabled);
@@ -730,7 +732,8 @@ public int run(String[] args) throws Exception {
730732
return exitCode;
731733
}
732734

733-
if (USAGE.containsKey(cmd)) {
735+
if (USAGE.containsKey(cmd) && !cmd.equals("-failover")
736+
&& !cmd.equals("-transitionToObserver")) {
734737
if (isHAEnabled) {
735738
return super.run(args);
736739
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,6 @@ public void testHelp() throws Exception {
777777
"Usage: yarn rmadmin [-getServiceState <serviceId>]", dataErr, 0);
778778
testError(new String[] { "-help", "-checkHealth" },
779779
"Usage: yarn rmadmin [-checkHealth <serviceId>]", dataErr, 0);
780-
testError(new String[] { "-help", "-failover" },
781-
"Usage: yarn rmadmin " +
782-
"[-failover [--forcefence] [--forceactive] " +
783-
"<serviceId> <serviceId>]",
784-
dataErr, 0);
785780

786781
testError(new String[] { "-help", "-badParameter" },
787782
"Usage: yarn rmadmin", dataErr, 0);
@@ -1064,7 +1059,7 @@ public void testRMHAErrorUsage() throws Exception {
10641059
ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream();
10651060
rmAdminCLIWithHAEnabled.setErrOut(new PrintStream(errOutBytes));
10661061
try {
1067-
String[] args = { "-failover" };
1062+
String[] args = {"-transitionToActive"};
10681063
assertEquals(-1, rmAdminCLIWithHAEnabled.run(args));
10691064
String errOut = new String(errOutBytes.toByteArray(), Charsets.UTF_8);
10701065
errOutBytes.reset();
@@ -1074,4 +1069,34 @@ public void testRMHAErrorUsage() throws Exception {
10741069
}
10751070
}
10761071

1072+
@Test
1073+
public void testNoUnsupportedHACommandsInHelp() throws Exception {
1074+
ByteArrayOutputStream dataErr = new ByteArrayOutputStream();
1075+
System.setErr(new PrintStream(dataErr));
1076+
String[] args = {};
1077+
assertEquals(-1, rmAdminCLIWithHAEnabled.run(args));
1078+
String errOut = dataErr.toString();
1079+
assertFalse(errOut.contains("-transitionToObserver"));
1080+
dataErr.reset();
1081+
String[] args1 = {"-transitionToObserver"};
1082+
assertEquals(-1, rmAdminCLIWithHAEnabled.run(args1));
1083+
errOut = dataErr.toString();
1084+
assertTrue(errOut.contains("transitionToObserver: Unknown command"));
1085+
dataErr.reset();
1086+
args1[0] = "-failover";
1087+
assertEquals(-1, rmAdminCLIWithHAEnabled.run(args1));
1088+
errOut = dataErr.toString();
1089+
assertTrue(errOut.contains("failover: Unknown command"));
1090+
dataErr.reset();
1091+
String[] args2 = {"-help", "-transitionToObserver"};
1092+
assertEquals(0, rmAdminCLIWithHAEnabled.run(args2));
1093+
errOut = dataErr.toString();
1094+
assertFalse(errOut.contains("-transitionToObserver"));
1095+
dataErr.reset();
1096+
args2[1] = "-failover";
1097+
assertEquals(0, rmAdminCLIWithHAEnabled.run(args2));
1098+
errOut = dataErr.toString();
1099+
assertFalse(errOut.contains("-failover"));
1100+
dataErr.reset();
1101+
}
10771102
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/YarnCommands.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ Usage:
220220
-updateNodeResource [NodeID] [MemSize] [vCores] ([OvercommitTimeout]) or -updateNodeResource [NodeID] [ResourceTypes] ([OvercommitTimeout])
221221
-transitionToActive [--forceactive] <serviceId>
222222
-transitionToStandby <serviceId>
223-
-failover [--forcefence] [--forceactive] <serviceId> <serviceId>
224223
-getServiceState <serviceId>
225224
-getAllServiceState
226225
-checkHealth <serviceId>
@@ -246,7 +245,6 @@ Usage:
246245
| -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|
247246
| -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.|
248247
| -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. |
249-
| -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. |
250248
| -getServiceState \<serviceId\> | Returns the state of the service. |
251249
| -getAllServiceState | Returns the state of all the services. |
252250
| -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. |

0 commit comments

Comments
 (0)