@Override public int doWorkInternal(GetConf tool, String []args) throws IOException { Configuration config = tool.getConf(); List<ConfiguredNNAddress> cnnlist = DFSUtil.flattenAddressMap( DFSUtil.getNNServiceRpcAddressesForCluster(config)); if (!cnnlist.isEmpty()) { for (ConfiguredNNAddress cnn : cnnlist) { InetSocketAddress rpc = cnn.getAddress(); tool.printOut(rpc.getHostName()+":"+rpc.getPort()); } return 0; } tool.printError("Did not get namenode service rpc addresses."); return -1; }
void printMap(Map<String, Map<String, InetSocketAddress>> map) { StringBuilder buffer = new StringBuilder(); List<ConfiguredNNAddress> cnns = DFSUtil.flattenAddressMap(map); for (ConfiguredNNAddress cnn : cnns) { InetSocketAddress address = cnn.getAddress(); if (buffer.length() > 0) { buffer.append(" "); } buffer.append(address.getHostName()); } printOut(buffer.toString()); }
private String[] toStringArray(List<ConfiguredNNAddress> list) { String[] ret = new String[list.size()]; for (int i = 0; i < list.size(); i++) { ret[i] = NetUtils.getHostPortString(list.get(i).getAddress()); } return ret; }
/** * Using {@link GetConf} methods get the list of given {@code type} of * addresses * * @param type, TestType * @param conf, configuration * @param checkPort, If checkPort is true, verify NNPRCADDRESSES whose * expected value is hostname:rpc-port. If checkPort is false, the * expected is hostname only. * @param expected, expected addresses */ private void getAddressListFromTool(TestType type, HdfsConfiguration conf, boolean checkPort, List<ConfiguredNNAddress> expected) throws Exception { String out = getAddressListFromTool(type, conf, expected.size() != 0); List<String> values = new ArrayList<String>(); // Convert list of addresses returned to an array of string StringTokenizer tokenizer = new StringTokenizer(out); while (tokenizer.hasMoreTokens()) { String s = tokenizer.nextToken().trim(); values.add(s); } String[] actual = values.toArray(new String[values.size()]); // Convert expected list to String[] of hosts int i = 0; String[] expectedHosts = new String[expected.size()]; for (ConfiguredNNAddress cnn : expected) { InetSocketAddress addr = cnn.getAddress(); if (!checkPort) { expectedHosts[i++] = addr.getHostName(); }else { expectedHosts[i++] = addr.getHostName()+":"+addr.getPort(); } } // Compare two arrays assertTrue(Arrays.equals(expectedHosts, actual)); }
private void verifyAddresses(HdfsConfiguration conf, TestType type, boolean checkPort, String... expected) throws Exception { // Ensure DFSUtil returned the right set of addresses Map<String, Map<String, InetSocketAddress>> map = getAddressListFromConf(type, conf); List<ConfiguredNNAddress> list = DFSUtil.flattenAddressMap(map); String[] actual = toStringArray(list); Arrays.sort(actual); Arrays.sort(expected); assertArrayEquals(expected, actual); // Test GetConf returned addresses getAddressListFromTool(type, conf, checkPort, list); }
@Override public int doWorkInternal(GetConf tool, String []args) throws IOException { Configuration config = tool.getConf(); List<ConfiguredNNAddress> cnnlist = DFSUtil.flattenAddressMap( DFSUtil.getNNServiceRpcAddresses(config)); if (!cnnlist.isEmpty()) { for (ConfiguredNNAddress cnn : cnnlist) { InetSocketAddress rpc = cnn.getAddress(); tool.printOut(rpc.getHostName()+":"+rpc.getPort()); } return 0; } tool.printError("Did not get namenode service rpc addresses."); return -1; }
private void verifyAddresses(HdfsConfiguration conf, TestType type, boolean checkPort, String... expected) throws Exception { // Ensure DFSUtil returned the right set of addresses Map<String, Map<String, InetSocketAddress>> map = getAddressListFromConf(type, conf); List<ConfiguredNNAddress> list = DFSUtil.flattenAddressMap(map); String[] actual = toStringArray(list); Arrays.sort(actual); Arrays.sort(expected); assertTrue(Arrays.equals(expected, actual)); // Test GetConf returned addresses getAddressListFromTool(type, conf, checkPort, list); }