Search in sources :

Example 1 with HAServiceState

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;
}
Also used : HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)

Example 2 with HAServiceState

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;
}
Also used : HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) HAServiceStatus(org.apache.hadoop.ha.HAServiceStatus) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException)

Example 3 with HAServiceState

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");
}
Also used : HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)

Example 4 with HAServiceState

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;
}
Also used : RMHAServiceTarget(org.apache.hadoop.yarn.client.RMHAServiceTarget) HAServiceProtocol(org.apache.hadoop.ha.HAServiceProtocol) HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) HAServiceTarget(org.apache.hadoop.ha.HAServiceTarget) RMHAServiceTarget(org.apache.hadoop.yarn.client.RMHAServiceTarget)

Example 5 with HAServiceState

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);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) InstanceSpec(org.apache.curator.test.InstanceSpec) HAServiceState(org.apache.hadoop.ha.HAServiceProtocol.HAServiceState) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

HAServiceState (org.apache.hadoop.ha.HAServiceProtocol.HAServiceState)7 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InstanceSpec (org.apache.curator.test.InstanceSpec)1 HAServiceProtocol (org.apache.hadoop.ha.HAServiceProtocol)1 HAServiceStatus (org.apache.hadoop.ha.HAServiceStatus)1 HAServiceTarget (org.apache.hadoop.ha.HAServiceTarget)1 ServiceFailedException (org.apache.hadoop.ha.ServiceFailedException)1 NamespaceInfoProto (org.apache.hadoop.hdfs.protocol.proto.HdfsServerProtos.NamespaceInfoProto)1 StorageInfo (org.apache.hadoop.hdfs.server.common.StorageInfo)1 RMHAServiceTarget (org.apache.hadoop.yarn.client.RMHAServiceTarget)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 Test (org.junit.Test)1