Search in sources :

Example 1 with ConfiguredNNAddress

use of org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress in project hadoop by apache.

the class TestGetConf method getAddressListFromTool.

/**
   * 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));
}
Also used : StringTokenizer(java.util.StringTokenizer) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) ConfiguredNNAddress(org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress)

Example 2 with ConfiguredNNAddress

use of org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress in project hadoop by apache.

the class GetConf method printMap.

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConfiguredNNAddress(org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 ConfiguredNNAddress (org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1