BlockPoolManager { void refreshNamenodes(Configuration conf) throws IOException { LOG.info("Refresh request received for nameservices: " + conf.get(DFSConfigKeys.DFS_NAMESERVICES)); Map<String, Map<String, InetSocketAddress>> newAddressMap = null; Map<String, Map<String, InetSocketAddress>> newLifelineAddressMap = null; try { newAddressMap = DFSUtil.getNNServiceRpcAddressesForCluster(conf); newLifelineAddressMap = DFSUtil.getNNLifelineRpcAddressesForCluster(conf); } catch (IOException ioe) { LOG.warn("Unable to get NameNode addresses."); } if (newAddressMap == null || newAddressMap.isEmpty()) { throw new IOException("No services to connect, missing NameNode " + "address."); } synchronized (refreshNamenodesLock) { doRefreshNamenodes(newAddressMap, newLifelineAddressMap); } } BlockPoolManager(DataNode dn);   }
@Test public void testSimpleSingleNS() throws Exception { Configuration conf = new Configuration(); conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs: bpm.refreshNamenodes(conf); assertEquals("create #1\n", log.toString()); }
@Test public void testFederationRefresh() throws Exception { Configuration conf = new Configuration(); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "ns1,ns2"); addNN(conf, "ns1", "mock1:8020"); addNN(conf, "ns2", "mock1:8020"); bpm.refreshNamenodes(conf); assertEquals( "create #1\n" + "create #2\n", log.toString()); log.setLength(0); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "ns2"); bpm.refreshNamenodes(conf); assertEquals( "stop #1\n" + "refresh #2\n", log.toString()); log.setLength(0); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "ns1,ns2"); bpm.refreshNamenodes(conf); assertEquals( "create #3\n" + "refresh #2\n", log.toString()); }
@Test public void testInternalNameService() throws Exception { Configuration conf = new Configuration(); conf.set(DFSConfigKeys.DFS_NAMESERVICES, "ns1,ns2,ns3"); addNN(conf, "ns1", "mock1:8020"); addNN(conf, "ns2", "mock1:8020"); addNN(conf, "ns3", "mock1:8020"); conf.set(DFSConfigKeys.DFS_INTERNAL_NAMESERVICES_KEY, "ns1"); bpm.refreshNamenodes(conf); assertEquals("create #1\n", log.toString()); @SuppressWarnings("unchecked") Map<String, BPOfferService> map = (Map<String, BPOfferService>) Whitebox .getInternalState(bpm, "bpByNameserviceId"); Assert.assertFalse(map.containsKey("ns2")); Assert.assertFalse(map.containsKey("ns3")); Assert.assertTrue(map.containsKey("ns1")); log.setLength(0); }