当前位置: 首页>>代码示例>>Java>>正文


Java NetUtils.normalizeHostName方法代码示例

本文整理汇总了Java中org.apache.hadoop.net.NetUtils.normalizeHostName方法的典型用法代码示例。如果您正苦于以下问题:Java NetUtils.normalizeHostName方法的具体用法?Java NetUtils.normalizeHostName怎么用?Java NetUtils.normalizeHostName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.net.NetUtils的用法示例。


在下文中一共展示了NetUtils.normalizeHostName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValidNode

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
public boolean isValidNode(String hostName) {
  synchronized (hostsReader) {
    Set<String> hostsList = hostsReader.getHosts();
    Set<String> excludeList = hostsReader.getExcludedHosts();
    String ip = NetUtils.normalizeHostName(hostName);
    return (hostsList.isEmpty() || hostsList.contains(hostName) || hostsList
        .contains(ip))
        && !(excludeList.contains(hostName) || excludeList.contains(ip));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:NodesListManager.java

示例2: testDecomissionedNMsMetricsOnRMRestart

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test (timeout = 60000)
public void testDecomissionedNMsMetricsOnRMRestart() throws Exception {
  YarnConfiguration conf = new YarnConfiguration();
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH,
    hostFile.getAbsolutePath());
  writeToHostsFile("");
  final DrainDispatcher dispatcher = new DrainDispatcher();
  MockRM rm1 = null, rm2 = null;
  try {
    rm1 = new MockRM(conf) {
      @Override
      protected Dispatcher createDispatcher() {
        return dispatcher;
      }
    };
    rm1.start();
    MockNM nm1 = rm1.registerNode("localhost:1234", 8000);
    MockNM nm2 = rm1.registerNode("host2:1234", 8000);
    Assert
        .assertEquals(0,
            ClusterMetrics.getMetrics().getNumDecommisionedNMs());
    String ip = NetUtils.normalizeHostName("localhost");
    // Add 2 hosts to exclude list.
    writeToHostsFile("host2", ip);

    // refresh nodes
    rm1.getNodesListManager().refreshNodes(conf);
    NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
    Assert
        .assertTrue(
            NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()));
    nodeHeartbeat = nm2.nodeHeartbeat(true);
    Assert.assertTrue("The decommisioned metrics are not updated",
        NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()));

    dispatcher.await();
    Assert
        .assertEquals(2,
            ClusterMetrics.getMetrics().getNumDecommisionedNMs());
    rm1.stop();
    rm1 = null;
    Assert
        .assertEquals(0,
            ClusterMetrics.getMetrics().getNumDecommisionedNMs());

    // restart RM.
    rm2 = new MockRM(conf);
    rm2.start();
    Assert
        .assertEquals(2,
            ClusterMetrics.getMetrics().getNumDecommisionedNMs());
  } finally {
    if (rm1 != null) {
      rm1.stop();
    }
    if (rm2 != null) {
      rm2.stop();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:61,代码来源:TestRMRestart.java

示例3: testDecommissionWithIncludeHosts

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Decommissioning using a pre-configured include hosts file
 */
@Test
public void testDecommissionWithIncludeHosts() throws Exception {

  writeToHostsFile("localhost", "host1", "host2");
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NODES_INCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());

  rm = new MockRM(conf);
  rm.start();

  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  MockNM nm3 = rm.registerNode("localhost:4433", 1024);
  
  ClusterMetrics metrics = ClusterMetrics.getMetrics();
  assert(metrics != null);
  int metricCount = metrics.getNumDecommisionedNMs();

  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  nodeHeartbeat = nm3.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));

  // To test that IPs also work
  String ip = NetUtils.normalizeHostName("localhost");
  writeToHostsFile("host1", ip);

  rm.getNodesListManager().refreshNodes(conf);

  checkDecommissionedNMCount(rm, ++metricCount);

  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  Assert
      .assertEquals(1, ClusterMetrics.getMetrics().getNumDecommisionedNMs());

  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertTrue("Node is not decommisioned.", NodeAction.SHUTDOWN
      .equals(nodeHeartbeat.getNodeAction()));

  nodeHeartbeat = nm3.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  Assert.assertEquals(metricCount, ClusterMetrics.getMetrics()
    .getNumDecommisionedNMs());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:52,代码来源:TestResourceTrackerService.java

示例4: testDecommissionWithExcludeHosts

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Decommissioning using a pre-configured exclude hosts file
 */
@Test
public void testDecommissionWithExcludeHosts() throws Exception {
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.RM_NODES_EXCLUDE_FILE_PATH, hostFile
      .getAbsolutePath());

  writeToHostsFile("");
  final DrainDispatcher dispatcher = new DrainDispatcher();
  rm = new MockRM(conf) {
    @Override
    protected Dispatcher createDispatcher() {
      return dispatcher;
    }
  };
  rm.start();

  MockNM nm1 = rm.registerNode("host1:1234", 5120);
  MockNM nm2 = rm.registerNode("host2:5678", 10240);
  MockNM nm3 = rm.registerNode("localhost:4433", 1024);

  dispatcher.await();

  int metricCount = ClusterMetrics.getMetrics().getNumDecommisionedNMs();
  NodeHeartbeatResponse nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  dispatcher.await();

  // To test that IPs also work
  String ip = NetUtils.normalizeHostName("localhost");
  writeToHostsFile("host2", ip);

  rm.getNodesListManager().refreshNodes(conf);

  checkDecommissionedNMCount(rm, metricCount + 2);

  nodeHeartbeat = nm1.nodeHeartbeat(true);
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  nodeHeartbeat = nm2.nodeHeartbeat(true);
  Assert.assertTrue("The decommisioned metrics are not updated",
      NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()));

  nodeHeartbeat = nm3.nodeHeartbeat(true);
  Assert.assertTrue("The decommisioned metrics are not updated",
      NodeAction.SHUTDOWN.equals(nodeHeartbeat.getNodeAction()));
  dispatcher.await();

  writeToHostsFile("");
  rm.getNodesListManager().refreshNodes(conf);

  nm3 = rm.registerNode("localhost:4433", 1024);
  dispatcher.await();
  nodeHeartbeat = nm3.nodeHeartbeat(true);
  dispatcher.await();
  Assert.assertTrue(NodeAction.NORMAL.equals(nodeHeartbeat.getNodeAction()));
  // decommissined node is 1 since 1 node is rejoined after updating exclude
  // file
  checkDecommissionedNMCount(rm, metricCount + 1);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:64,代码来源:TestResourceTrackerService.java


注:本文中的org.apache.hadoop.net.NetUtils.normalizeHostName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。