diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java index ee389b3..570ca06 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java @@ -27,13 +27,11 @@ import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceStability.Unstable; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.ha.HAAdmin; import org.apache.hadoop.ha.HAServiceTarget; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.security.UserGroupInformation; -import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.yarn.client.ClientRMProxy; import org.apache.hadoop.yarn.client.RMHAServiceTarget; @@ -297,7 +295,14 @@ public int run(String[] args) throws Exception { } if (USAGE.containsKey(cmd)) { - return super.run(args); + YarnConfiguration conf = new YarnConfiguration(getConf()); + if (conf.getBoolean(YarnConfiguration.RM_HA_ENABLED, + YarnConfiguration.DEFAULT_RM_HA_ENABLED)) { + return super.run(args); + } + System.out.println("The RM HA is disabled. " + cmd + + " can only be executed when RM HA is enabled"); + return exitCode; } // diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMAdminCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMAdminCLI.java index cec8fcc..fddff3f 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMAdminCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMAdminCLI.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.never; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -54,6 +55,7 @@ private ResourceManagerAdministrationProtocol admin; private HAServiceProtocol haadmin; private RMAdminCLI rmAdminCLI; + private RMAdminCLI rmAdminCLIWithHAEnabled; @Before public void configure() throws IOException { @@ -66,7 +68,23 @@ public void configure() throws IOException { final HAServiceTarget haServiceTarget = mock(HAServiceTarget.class); when(haServiceTarget.getProxy(any(Configuration.class), anyInt())) .thenReturn(haadmin); - rmAdminCLI = new RMAdminCLI() { + rmAdminCLI = new RMAdminCLI(new Configuration()) { + + @Override + protected ResourceManagerAdministrationProtocol createAdminProtocol() + throws IOException { + return admin; + } + + @Override + protected HAServiceTarget resolveTarget(String rmId) { + return haServiceTarget; + } + }; + + YarnConfiguration conf = new YarnConfiguration(); + conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true); + rmAdminCLIWithHAEnabled = new RMAdminCLI(conf) { @Override protected ResourceManagerAdministrationProtocol createAdminProtocol() @@ -150,7 +168,16 @@ public boolean matches(Object argument) { @Test(timeout = 500) public void testTransitionToActive() throws Exception { String[] args = {"-transitionToActive", "rm1"}; + + // RM HA is disabled. + // transitionToActive should not be executed assertEquals(0, rmAdminCLI.run(args)); + verify(haadmin, never()).transitionToActive( + any(HAServiceProtocol.StateChangeRequestInfo.class)); + + // Now RM HA is enabled. + // transitionToActive should be executed + assertEquals(0, rmAdminCLIWithHAEnabled.run(args)); verify(haadmin).transitionToActive( any(HAServiceProtocol.StateChangeRequestInfo.class)); } @@ -158,7 +185,16 @@ public void testTransitionToActive() throws Exception { @Test(timeout = 500) public void testTransitionToStandby() throws Exception { String[] args = {"-transitionToStandby", "rm1"}; + + // RM HA is disabled. + // transitionToStandby should not be executed assertEquals(0, rmAdminCLI.run(args)); + verify(haadmin, never()).transitionToStandby( + any(HAServiceProtocol.StateChangeRequestInfo.class)); + + // Now RM HA is enabled. + // transitionToActive should be executed + assertEquals(0, rmAdminCLIWithHAEnabled.run(args)); verify(haadmin).transitionToStandby( any(HAServiceProtocol.StateChangeRequestInfo.class)); } @@ -166,14 +202,30 @@ public void testTransitionToStandby() throws Exception { @Test(timeout = 500) public void testGetServiceState() throws Exception { String[] args = {"-getServiceState", "rm1"}; + + // RM HA is disabled. + // getServiceState should not be executed assertEquals(0, rmAdminCLI.run(args)); + verify(haadmin, never()).getServiceStatus(); + + // Now RM HA is enabled. + // getServiceState should be executed + assertEquals(0, rmAdminCLIWithHAEnabled.run(args)); verify(haadmin).getServiceStatus(); } @Test(timeout = 500) public void testCheckHealth() throws Exception { String[] args = {"-checkHealth", "rm1"}; + + // RM HA is disabled. + // getServiceState should not be executed assertEquals(0, rmAdminCLI.run(args)); + verify(haadmin, never()).monitorHealth(); + + // Now RM HA is enabled. + // getServiceState should be executed + assertEquals(0, rmAdminCLIWithHAEnabled.run(args)); verify(haadmin).monitorHealth(); }