List of usage examples for org.apache.hadoop.ha HAServiceTarget getProxy
public HAServiceProtocol getProxy(Configuration conf, int timeoutMs) throws IOException
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 w ww . j a v a 2s . c om*/ activeNamenode = DFSUtil.getNamenodeServiceAddr(hdfsConf, nameService, nnId); } if (activeNamenode == null) { throw new IllegalStateException("Could not find an active namenode"); } return rpcToHttpAddress(URI.create(activeNamenode)); }