public static String getNamenodeWebAddr(final Configuration conf, String nsId,
      String nnId) {

    if (nsId == null) {
      nsId = getOnlyNameServiceIdOrNull(conf);
    }

    String webAddrBaseKey = DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY;
    String webAddrDefault = DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_DEFAULT;
    if (getHttpPolicy(conf) == HttpConfig.Policy.HTTPS_ONLY) {
      webAddrBaseKey = DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY;
      webAddrDefault = DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_DEFAULT;
    }
    String webAddrKey = DFSUtilClient.concatSuffixes(
        webAddrBaseKey, nsId, nnId);
    String webAddr = conf.get(webAddrKey, webAddrDefault);
    return webAddr;
  }
@Test
  public void testGetNamenodeWebAddr() {
    HdfsConfiguration conf = new HdfsConfiguration();

    conf.set(DFSUtil.addKeySuffixes(
        DFS_NAMENODE_HTTPS_ADDRESS_KEY, "ns1", "nn1"), NS1_NN1_HTTPS_ADDR);
    conf.set(DFSUtil.addKeySuffixes(
        DFS_NAMENODE_HTTP_ADDRESS_KEY, "ns1", "nn1"), NS1_NN1_HTTP_ADDR);

    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTPS_ONLY.name());
    String httpsOnlyWebAddr = DFSUtil.getNamenodeWebAddr(
        conf, "ns1", "nn1");
    assertEquals(NS1_NN1_HTTPS_ADDR, httpsOnlyWebAddr);

    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTP_ONLY.name());
    String httpOnlyWebAddr = DFSUtil.getNamenodeWebAddr(
        conf, "ns1", "nn1");
    assertEquals(NS1_NN1_HTTP_ADDR, httpOnlyWebAddr);

    conf.set(DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTP_AND_HTTPS.name());
    String httpAndHttpsWebAddr = DFSUtil.getNamenodeWebAddr(
        conf, "ns1", "nn1");
    assertEquals(NS1_NN1_HTTP_ADDR, httpAndHttpsWebAddr);

  }