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


Java NetUtils.getHostNameOfIP方法代码示例

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


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

示例1: printTopology

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Display each rack and the nodes assigned to that rack, as determined
 * by the NameNode, in a hierarchical manner.  The nodes and racks are
 * sorted alphabetically.
 * 
 * @throws IOException If an error while getting datanode report
 */
public int printTopology() throws IOException {
    DistributedFileSystem dfs = getDFS();
    final DatanodeInfo[] report = dfs.getDataNodeStats();

    // Build a map of rack -> nodes from the datanode report
    HashMap<String, TreeSet<String> > tree = new HashMap<String, TreeSet<String>>();
    for(DatanodeInfo dni : report) {
      String location = dni.getNetworkLocation();
      String name = dni.getName();
      
      if(!tree.containsKey(location)) {
        tree.put(location, new TreeSet<String>());
      }
      
      tree.get(location).add(name);
    }
    
    // Sort the racks (and nodes) alphabetically, display in order
    ArrayList<String> racks = new ArrayList<String>(tree.keySet());
    Collections.sort(racks);
    
    for(String r : racks) {
      System.out.println("Rack: " + r);
      TreeSet<String> nodes = tree.get(r);

      for(String n : nodes) {
        System.out.print("   " + n);
        String hostname = NetUtils.getHostNameOfIP(n);
        if(hostname != null)
          System.out.print(" (" + hostname + ")");
        System.out.println();
      }

      System.out.println();
    }
  return 0;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:45,代码来源:DFSAdmin.java

示例2: getDatanodeReport

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/** A formatted string for reporting the status of the DataNode. */
public String getDatanodeReport() {
  StringBuilder buffer = new StringBuilder();
  long c = getCapacity();
  long r = getRemaining();
  long u = getDfsUsed();
  long nonDFSUsed = getNonDfsUsed();
  float usedPercent = getDfsUsedPercent();
  float remainingPercent = getRemainingPercent();
  long cc = getCacheCapacity();
  long cr = getCacheRemaining();
  long cu = getCacheUsed();
  float cacheUsedPercent = getCacheUsedPercent();
  float cacheRemainingPercent = getCacheRemainingPercent();
  String lookupName = NetUtils.getHostNameOfIP(getName());

  buffer.append("Name: "+ getName());
  if (lookupName != null) {
    buffer.append(" (" + lookupName + ")");
  }
  buffer.append("\n");
  buffer.append("Hostname: " + getHostName() + "\n");

  if (!NetworkTopology.DEFAULT_RACK.equals(location)) {
    buffer.append("Rack: "+location+"\n");
  }
  buffer.append("Decommission Status : ");
  if (isDecommissioned()) {
    buffer.append("Decommissioned\n");
  } else if (isDecommissionInProgress()) {
    buffer.append("Decommission in progress\n");
  } else {
    buffer.append("Normal\n");
  }
  buffer.append("Configured Capacity: "+c+" ("+StringUtils.byteDesc(c)+")"+"\n");
  buffer.append("DFS Used: "+u+" ("+StringUtils.byteDesc(u)+")"+"\n");
  buffer.append("Non DFS Used: "+nonDFSUsed+" ("+StringUtils.byteDesc(nonDFSUsed)+")"+"\n");
  buffer.append("DFS Remaining: " +r+ " ("+StringUtils.byteDesc(r)+")"+"\n");
  buffer.append("DFS Used%: "+percent2String(usedPercent) + "\n");
  buffer.append("DFS Remaining%: "+percent2String(remainingPercent) + "\n");
  buffer.append("Configured Cache Capacity: "+cc+" ("+StringUtils.byteDesc(cc)+")"+"\n");
  buffer.append("Cache Used: "+cu+" ("+StringUtils.byteDesc(cu)+")"+"\n");
  buffer.append("Cache Remaining: " +cr+ " ("+StringUtils.byteDesc(cr)+")"+"\n");
  buffer.append("Cache Used%: "+percent2String(cacheUsedPercent) + "\n");
  buffer.append("Cache Remaining%: "+percent2String(cacheRemainingPercent) + "\n");
  buffer.append("Xceivers: "+getXceiverCount()+"\n");
  buffer.append("Last contact: "+new Date(lastUpdate)+"\n");
  return buffer.toString();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:DatanodeInfo.java


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