Example usage for org.apache.hadoop.ha HAServiceStatus getState

List of usage examples for org.apache.hadoop.ha HAServiceStatus getState

Introduction

In this page you can find the example usage for org.apache.hadoop.ha HAServiceStatus getState.

Prototype

public HAServiceState getState() 

Source Link

Usage

From source file:co.cask.cdap.operations.hdfs.HDFSInfo.java

License:Apache License

@Nullable
private URL getHAWebURL() throws IOException {
    String activeNamenode = null;
    String nameService = getNameService();
    HdfsConfiguration hdfsConf = new HdfsConfiguration(conf);
    String nameNodePrincipal = conf.get(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY, "");

    hdfsConf.set(CommonConfigurationKeys.HADOOP_SECURITY_SERVICE_USER_NAME_KEY, nameNodePrincipal);

    for (String nnId : DFSUtil.getNameNodeIds(conf, nameService)) {
        HAServiceTarget haServiceTarget = new NNHAServiceTarget(hdfsConf, nameService, nnId);
        HAServiceProtocol proxy = haServiceTarget.getProxy(hdfsConf, 10000);
        HAServiceStatus serviceStatus = proxy.getServiceStatus();
        if (HAServiceProtocol.HAServiceState.ACTIVE != serviceStatus.getState()) {
            continue;
        }/*from   ww  w.j  av a2 s.c  o m*/
        activeNamenode = DFSUtil.getNamenodeServiceAddr(hdfsConf, nameService, nnId);
    }
    if (activeNamenode == null) {
        throw new IllegalStateException("Could not find an active namenode");
    }
    return rpcToHttpAddress(URI.create(activeNamenode));
}

From source file:co.cask.cdap.operations.yarn.YarnInfo.java

License:Apache License

/**
 * Should only be called when HA is enabled.
 *///from  ww  w  . j a  v a 2s . co m
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) {
        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();
    }
    if (activeRM == null) {
        throw new IllegalStateException("Could not find an active resource manager");
    }
    return adminToWebappAddress(activeRM);
}