use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.
the class AdminService method getServiceStatus.
/**
* Return the HA status of this RM. This includes the current state and
* whether the RM is ready to become active.
*
* @return {@link HAServiceStatus} of the current RM
* @throws IOException if the caller does not have permissions
*/
@Override
public synchronized HAServiceStatus getServiceStatus() throws IOException {
checkAccess("getServiceState");
HAServiceState haState = rmContext.getHAServiceState();
HAServiceStatus ret = new HAServiceStatus(haState);
if (isRMActive() || haState == HAServiceProtocol.HAServiceState.STANDBY) {
ret.setReadyToBecomeActive();
} else {
ret.setNotReadyToBecomeActive("State is " + haState);
}
return ret;
}
use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.
the class TestRMAdminCLI method configure.
@SuppressWarnings("static-access")
@Before
public void configure() throws IOException, YarnException {
remoteAdminServiceAccessed = false;
admin = mock(ResourceManagerAdministrationProtocol.class);
when(admin.addToClusterNodeLabels(any(AddToClusterNodeLabelsRequest.class))).thenAnswer(new Answer<AddToClusterNodeLabelsResponse>() {
@Override
public AddToClusterNodeLabelsResponse answer(InvocationOnMock invocation) throws Throwable {
remoteAdminServiceAccessed = true;
return AddToClusterNodeLabelsResponse.newInstance();
}
});
haadmin = mock(HAServiceProtocol.class);
when(haadmin.getServiceStatus()).thenReturn(new HAServiceStatus(HAServiceProtocol.HAServiceState.INITIALIZING));
final HAServiceTarget haServiceTarget = mock(HAServiceTarget.class);
when(haServiceTarget.getProxy(any(Configuration.class), anyInt())).thenReturn(haadmin);
rmAdminCLI = new RMAdminCLI(new Configuration()) {
@Override
protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
return admin;
}
@Override
protected HAServiceTarget resolveTarget(String rmId) {
return haServiceTarget;
}
};
initDummyNodeLabelsManager();
rmAdminCLI.localNodeLabelsManager = dummyNodeLabelsManager;
YarnConfiguration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
conf.set(YarnConfiguration.RM_HA_IDS, "rm1,rm2");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm1"), HOST_A + ":12345");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm1"), HOST_A + ":12346");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADDRESS, "rm2"), HOST_B + ":12345");
conf.set(HAUtil.addSuffix(YarnConfiguration.RM_ADMIN_ADDRESS, "rm2"), HOST_B + ":12346");
rmAdminCLIWithHAEnabled = new RMAdminCLI(conf) {
@Override
protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
return admin;
}
@Override
protected HAServiceTarget resolveTarget(String rmId) {
HAServiceTarget target = super.resolveTarget(rmId);
HAServiceTarget spy = Mockito.spy(target);
// Override the target to return our mock protocol
try {
Mockito.doReturn(haadmin).when(spy).getProxy(Mockito.<Configuration>any(), Mockito.anyInt());
Mockito.doReturn(false).when(spy).isAutoFailoverEnabled();
} catch (IOException e) {
// mock setup doesn't really throw
throw new AssertionError(e);
}
return spy;
}
};
}
use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.
the class TestRMAdminCLI method testGetAllServiceState.
@Test
public void testGetAllServiceState() throws Exception {
HAServiceStatus standbyStatus = new HAServiceStatus(HAServiceState.STANDBY).setReadyToBecomeActive();
Mockito.doReturn(standbyStatus).when(haadmin).getServiceStatus();
ByteArrayOutputStream dataOut = new ByteArrayOutputStream();
rmAdminCLIWithHAEnabled.setOut(new PrintStream(dataOut));
String[] args = { "-getAllServiceState" };
assertEquals(0, rmAdminCLIWithHAEnabled.run(args));
assertTrue(dataOut.toString().contains(String.format("%-50s %-10s", (HOST_A + ":" + 12346), standbyStatus.getState())));
assertTrue(dataOut.toString().contains(String.format("%-50s %-10s", (HOST_B + ":" + 12346), standbyStatus.getState())));
rmAdminCLIWithHAEnabled.setOut(System.out);
}
use of org.apache.hadoop.ha.HAServiceStatus in project hadoop by apache.
the class NameNode method getServiceStatus.
synchronized HAServiceStatus getServiceStatus() throws ServiceFailedException, AccessControlException {
namesystem.checkSuperuserPrivilege();
if (!haEnabled) {
throw new ServiceFailedException("HA for namenode is not enabled");
}
if (state == null) {
return new HAServiceStatus(HAServiceState.INITIALIZING);
}
HAServiceState retState = state.getServiceState();
HAServiceStatus ret = new HAServiceStatus(retState);
if (retState == HAServiceState.STANDBY) {
if (namesystem.isInSafeMode()) {
ret.setNotReadyToBecomeActive("The NameNode is in safemode. " + namesystem.getSafeModeTip());
} else {
ret.setReadyToBecomeActive();
}
} else if (retState == HAServiceState.ACTIVE) {
ret.setReadyToBecomeActive();
} else {
ret.setNotReadyToBecomeActive("State is " + state);
}
return ret;
}
use of org.apache.hadoop.ha.HAServiceStatus in project cdap by caskdata.
the class YarnInfo method getHAWebURL.
/**
* Should only be called when HA is enabled.
*/
private URL getHAWebURL() throws IOException {
InetSocketAddress activeRM = null;
Collection<String> rmIds = HAUtil.getRMHAIds(conf);
if (rmIds.isEmpty()) {
throw new IllegalStateException("Resource Manager HA web URL requested in non-HA mode.");
}
for (String rmId : rmIds) {
try {
YarnConfiguration yarnConf = new YarnConfiguration(conf);
yarnConf.set(YarnConfiguration.RM_HA_ID, rmId);
yarnConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, conf.get(YarnConfiguration.RM_PRINCIPAL, ""));
RMHAServiceTarget rmhaServiceTarget = new RMHAServiceTarget(yarnConf);
HAServiceProtocol proxy = rmhaServiceTarget.getProxy(yarnConf, 10000);
HAServiceStatus serviceStatus = proxy.getServiceStatus();
if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
continue;
}
activeRM = rmhaServiceTarget.getAddress();
} catch (ConnectException e) {
LOG.trace("Connection refused when attempting to connect to ResourceManager {}. " + "Assuming that it is not available.", rmId);
}
}
if (activeRM == null) {
throw new IllegalStateException("Could not find an active resource manager");
}
return adminToWebappAddress(activeRM);
}
Aggregations