List of usage examples for org.apache.hadoop.hdfs DFSUtil getNamenodeServiceAddr
public static String getNamenodeServiceAddr(final Configuration conf, String nsId, String nnId)
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 a v a 2 s . com*/ 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.hdfs.HDFSNodes.java
License:Apache License
private List<String> getNameNodes() throws IOException { List<String> namenodes = new ArrayList<>(); if (!HAUtil.isHAEnabled(conf, getNameService())) { try (FileSystem fs = FileSystem.get(conf)) { return Collections.singletonList(fs.getUri().toString()); }/*from w ww .j a v a 2 s. c om*/ } String nameService = getNameService(); for (String nnId : DFSUtil.getNameNodeIds(conf, nameService)) { namenodes.add(DFSUtil.getNamenodeServiceAddr(conf, nameService, nnId)); } return namenodes; }