public static Map<String, Map<String, InetSocketAddress>>
    getNNServiceRpcAddressesForCluster(Configuration conf) throws IOException {
    // Use default address as fall back
    String defaultAddress;
    try {
      defaultAddress = NetUtils.getHostPortString(
          DFSUtilClient.getNNAddress(conf));
    } catch (IllegalArgumentException e) {
      defaultAddress = null;
    }

    Collection<String> parentNameServices = getParentNameServices(conf);

    Map<String, Map<String, InetSocketAddress>> addressList =
            getAddressesForNsIds(conf, parentNameServices,
                                               defaultAddress,
                                               DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY,
                                               DFS_NAMENODE_RPC_ADDRESS_KEY);
    if (addressList.isEmpty()) {
      throw new IOException("Incorrect configuration: namenode address "
              + DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY + "." + parentNameServices
              + " or "
              + DFS_NAMENODE_RPC_ADDRESS_KEY + "." + parentNameServices
              + " is not configured.");
    }
    return addressList;
  }
@Test
  public void testErrorMessageForInvalidNameservice() throws Exception {
    Configuration conf = new HdfsConfiguration();
    conf.set(DFSConfigKeys.DFS_NAMESERVICES, "ns1, ns2");
    String expectedErrorMessage = "Incorrect configuration: namenode address "
            + DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY + ".[ns1, ns2]"
            + " or "
            + DFS_NAMENODE_RPC_ADDRESS_KEY + ".[ns1, ns2]"
            + " is not configured.";
    LambdaTestUtils.intercept(IOException.class, expectedErrorMessage,
        ()->DFSUtil.getNNServiceRpcAddressesForCluster(conf));
  }