use of org.apache.hadoop.ha.HAServiceProtocol.HAServiceState in project hadoop by apache.
the class NameNode method getState.
// NameNodeStatusMXBean
@Override
public String getState() {
String servStateStr = "";
HAServiceState servState = getServiceState();
if (null != servState) {
servStateStr = servState.toString();
}
return servStateStr;
}
use of org.apache.hadoop.ha.HAServiceProtocol.HAServiceState 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.HAServiceProtocol.HAServiceState in project hadoop by apache.
the class ResourceManager method transitionToStandby.
synchronized void transitionToStandby(boolean initialize) throws Exception {
if (rmContext.getHAServiceState() == HAServiceProtocol.HAServiceState.STANDBY) {
LOG.info("Already in standby state");
return;
}
LOG.info("Transitioning to standby state");
HAServiceState state = rmContext.getHAServiceState();
rmContext.setHAServiceState(HAServiceProtocol.HAServiceState.STANDBY);
if (state == HAServiceProtocol.HAServiceState.ACTIVE) {
stopActiveServices();
reinitialize(initialize);
}
LOG.info("Transitioned to standby state");
}
use of org.apache.hadoop.ha.HAServiceProtocol.HAServiceState in project hadoop by apache.
the class RMHAUtils method getHAState.
private static HAServiceState getHAState(YarnConfiguration yarnConf) throws Exception {
HAServiceTarget haServiceTarget;
int rpcTimeoutForChecks = yarnConf.getInt(CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_KEY, CommonConfigurationKeys.HA_FC_CLI_CHECK_TIMEOUT_DEFAULT);
yarnConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, yarnConf.get(YarnConfiguration.RM_PRINCIPAL, ""));
haServiceTarget = new RMHAServiceTarget(yarnConf);
HAServiceProtocol proto = haServiceTarget.getProxy(yarnConf, rpcTimeoutForChecks);
HAServiceState haState = proto.getServiceStatus().getState();
return haState;
}
use of org.apache.hadoop.ha.HAServiceProtocol.HAServiceState in project hadoop by apache.
the class TestLeaderElectorService method testKillZKInstance.
// 1. rm1 active
// 2. rm2 standby
// 3. kill the current connected zk instance
// 4. either rm1 or rm2 will become active.
@Test
public void testKillZKInstance() throws Exception {
rm1 = startRM("rm1", HAServiceState.ACTIVE);
rm2 = startRM("rm2", HAServiceState.STANDBY);
CuratorBasedElectorService service = (CuratorBasedElectorService) rm1.getRMContext().getLeaderElectorService();
ZooKeeper zkClient = service.getCuratorClient().getZookeeperClient().getZooKeeper();
InstanceSpec connectionInstance = zkCluster.findConnectionInstance(zkClient);
zkCluster.killServer(connectionInstance);
// wait for rm1 or rm2 to be active by randomness
GenericTestUtils.waitFor(new Supplier<Boolean>() {
@Override
public Boolean get() {
try {
HAServiceState rm1State = rm1.getAdminService().getServiceStatus().getState();
HAServiceState rm2State = rm2.getAdminService().getServiceStatus().getState();
return (rm1State.equals(HAServiceState.ACTIVE) && rm2State.equals(HAServiceState.STANDBY)) || (rm1State.equals(HAServiceState.STANDBY) && rm2State.equals(HAServiceState.ACTIVE));
} catch (IOException e) {
}
return false;
}
}, 2000, 15000);
}
Aggregations