Example usage for org.apache.hadoop.hdfs.tools NNHAServiceTarget NNHAServiceTarget

List of usage examples for org.apache.hadoop.hdfs.tools NNHAServiceTarget NNHAServiceTarget

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.tools NNHAServiceTarget NNHAServiceTarget.

Prototype

public NNHAServiceTarget(Configuration conf, String nsId, String nnId) 

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;
        }/*w ww  . ja v a 2  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));
}