DFSUtil { public static List<InetSocketAddress> getNameNodesRPCAddresses( Configuration conf) { return getNameNodesRPCAddresses(conf, DFSConfigKeys.DFS_NAMENODES_RPC_ADDRESS_KEY, DFS_NAMENODE_RPC_ADDRESS_KEY); } private  DFSUtil(); static Random getRandom(); static SecureRandom getSecureRandom(); static T[] shuffle(final T[] array); static boolean isValidName(String src); static String bytes2String(byte[] bytes); static byte[] string2Bytes(String str); static String byteArray2PathString(byte[][] pathComponents,
      int offset, int length); static String byteArray2PathString(byte[][] pathComponents); static String strings2PathString(String[] components); static String path2String(final Object path); static byte[][] bytes2byteArray(byte[] bytes, byte separator); static byte[][] bytes2byteArray(byte[] bytes, int len,
      byte separator); static String addKeySuffixes(String key, String... suffixes); static int roundBytesToGB(long bytes); static ClientDatanodeProtocol createClientDatanodeProtocolProxy(
      DatanodeID datanodeid, Configuration conf, int socketTimeout,
      boolean connectToDnViaHostname, LocatedBlock locatedBlock); static ClientDatanodeProtocol createClientDatanodeProtocolProxy(
      DatanodeID datanodeid, Configuration conf, int socketTimeout,
      boolean connectToDnViaHostname); static ClientDatanodeProtocol createClientDatanodeProtocolProxy(
      InetSocketAddress addr, UserGroupInformation ticket, Configuration conf,
      SocketFactory factory); static URI createUri(String scheme, InetSocketAddress address); static void addPBProtocol(Configuration conf, Class<?> protocol,
      BlockingService service, RPC.Server server); static boolean parseHelpArgument(String[] args, String helpDescription,
      PrintStream out, boolean printGenericCommandUsage); static float getInvalidateWorkPctPerIteration(Configuration conf); static int getReplWorkMultiplier(Configuration conf); static String getSpnegoKeytabKey(Configuration conf,
      String defaultKey); static HttpConfig.Policy getHttpPolicy(Configuration conf); static HttpServer2.Builder loadSslConfToHttpServerBuilder(HttpServer2.Builder builder, Configuration sslConf); static HttpServer2.Builder loadSslConfToHttpServerBuilder(HttpServer2.Builder builder,
      Configuration sslConf, Configuration systemConf); static List<InetSocketAddress> getNameNodesServiceRpcAddresses(
      Configuration conf); static List<InetSocketAddress> getNameNodesRPCAddresses(
      Configuration conf); static List<URI> getNameNodesRPCAddressesAsURIs(Configuration conf); static String joinNameNodesRpcAddresses(
      List<InetSocketAddress> namenodes); static String joinNameNodesHostPortString(List<String> namenodes); static URI getInfoServer(InetSocketAddress namenodeAddr,
      Configuration conf, String scheme); static URI getInfoServerWithDefaultHost(String defaultHost,
      Configuration conf, final String scheme); static String getHttpClientScheme(Configuration conf); static List<URI> getNsServiceRpcUris(Configuration conf); static boolean isLogicalUri(Configuration conf, URI nameNodeUri); static URI createHDFSUri(String server); static Configuration loadSslConfiguration(Configuration conf); static HttpServer2.Builder httpServerTemplateForNNAndJN(
      Configuration conf, final InetSocketAddress httpAddr,
      final InetSocketAddress httpsAddr, String name, String spnegoUserNameKey,
      String spnegoKeytabFileKey); static Map<String, Map<String, InetSocketAddress>> getHaNnRpcAddresses(Configuration conf); static String dateToIso8601String(Date date); static String durationToString(long durationMs); static long parseRelativeTime(String relTime); static KeyProvider createKeyProvider(
      final Configuration conf); static KeyProviderCryptoExtension createKeyProviderCryptoExtension(
      final Configuration conf); static final Log LOG; static final Comparator<DatanodeInfo> DECOM_COMPARATOR; static Options helpOptions; static Option helpOpt; }
@Test public void testNamenodeURIsFromServiceDiscovery() throws Exception { Set<Service> nns = Sets.newHashSet( Service.of("namenode.service.consul", "10.0.0.1", 8020), Service.of("namenode.service.consul", "10.0.0.2", 8020), Service.of("namenode.service.consul", "10.0.0.1", 50470), Service.of("namenode.service.consul", "10.0.0.2", 50470)); List<InetSocketAddress> expected = Lists.newArrayList( new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 8020), new InetSocketAddress(InetAddress.getByName("10.0.0.2"), 8020)); DnsResolver dnsResolver = Mockito.mock(DnsResolver.class); when(dnsResolver.getService(any(ServiceQuery.class))).thenReturn(nns.stream()); ServiceDiscoveryClientFactory.getInstance().setClient(dnsResolver); Configuration conf = new Configuration(false); conf.setBoolean(CommonConfigurationKeysPublic.SERVICE_DISCOVERY_ENABLED_KEY, true); conf.set(DFSConfigKeys.DFS_NAMENODES_RPC_ADDRESS_KEY, "namenode.service.lc:8020"); List<InetSocketAddress> nnIps = DFSUtil.getNameNodesRPCAddresses(conf); assertNotNull(nnIps); assertEquals(2, nnIps.size()); assertThat(nnIps, Matchers.equalTo(expected)); when(dnsResolver.getService(any(ServiceQuery.class))).thenReturn(nns.stream()); conf = new Configuration(false); conf.setBoolean(CommonConfigurationKeysPublic.SERVICE_DISCOVERY_ENABLED_KEY, true); conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "namenode.service.lc:8020"); nnIps = DFSUtil.getNameNodesRPCAddresses(conf); assertNotNull(nnIps); assertEquals(2, nnIps.size()); assertThat(nnIps, Matchers.equalTo(expected)); when(dnsResolver.getService(any(ServiceQuery.class))).thenThrow(new ServiceNotFoundException("Service not found")); conf = new Configuration(false); conf.setBoolean(CommonConfigurationKeysPublic.SERVICE_DISCOVERY_ENABLED_KEY, true); conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "namenode.service.lc:8020"); nnIps = DFSUtil.getNameNodesRPCAddresses(conf); assertNotNull(nnIps); assertTrue(nnIps.isEmpty()); }