Index: src/java/org/apache/hadoop/mapred/TaskTracker.java =================================================================== --- src/java/org/apache/hadoop/mapred/TaskTracker.java (revision 438557) +++ src/java/org/apache/hadoop/mapred/TaskTracker.java (working copy) @@ -154,8 +154,19 @@ * close(). */ synchronized void initialize() throws IOException { - this.localHostname = InetAddress.getLocalHost().getHostName(); + // Gets the network interface and nameserver from the cluster configuration parameters + String nif = this.fConf.get("cluster.report.nif", "default"); + String ns = this.fConf.get("cluster.report.ns", "default"); + //If default, report localHost() name, otherwise user reverse lookup from DNS and nif + if (nif.equals("default")) + this.localHostname = InetAddress.getLocalHost().getHostName(); + else + this.localHostname = ns.equals("default") ? + NetworkUtils.getDefaultHost(nif) : + NetworkUtils.getDefaultHost(nif, ns); + + //check local disk checkLocalDirs(this.fConf.getLocalDirs()); fConf.deleteLocalFiles(SUBDIR); Index: src/java/org/apache/hadoop/dfs/DataNode.java =================================================================== --- src/java/org/apache/hadoop/dfs/DataNode.java (revision 438557) +++ src/java/org/apache/hadoop/dfs/DataNode.java (working copy) @@ -15,21 +15,20 @@ */ package org.apache.hadoop.dfs; +import java.io.*; +import java.net.*; +import java.util.*; + import org.apache.commons.logging.*; - import org.apache.hadoop.ipc.*; -import org.apache.hadoop.conf.*; +import org.apache.hadoop.util.*; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.mapred.StatusHttpServer; import org.apache.hadoop.metrics.Metrics; -import org.apache.hadoop.util.*; +import org.apache.hadoop.metrics.MetricsRecord; import org.apache.hadoop.util.DiskChecker.DiskErrorException; import org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException; -import org.apache.hadoop.mapred.StatusHttpServer; -import java.io.*; -import java.net.*; -import java.util.*; -import org.apache.hadoop.metrics.MetricsRecord; - /********************************************************** * DataNode is a class (and program) that stores a set of * blocks for a DFS deployment. A single deployment can @@ -179,6 +178,20 @@ File datadir, InetSocketAddress nameNodeAddr, Configuration conf ) throws IOException { + + // Machine name is set to getlocalHost().getHostName(), so leave it unchanged unless + // the conf files contain network cluster parameters for this + + // Gets the network interface and nameserver from the cluster configuration parameters + String nif = conf.get("cluster.report.nif", "default"); + String ns = conf.get("cluster.report.ns", "default"); + + //If default, report localHost() name, otherwise user reverse lookup from DNS and nif + if (!nif.equals("default")) + machineName = ns.equals("default") ? + NetworkUtils.getDefaultHost(nif) : + NetworkUtils.getDefaultHost(nif, ns); + // get storage info and lock the data dir storage = new DataStorage( datadir ); // connect to name node Index: src/java/org/apache/hadoop/util/NetworkUtils.java =================================================================== --- src/java/org/apache/hadoop/util/NetworkUtils.java (revision 0) +++ src/java/org/apache/hadoop/util/NetworkUtils.java (revision 0) @@ -0,0 +1,93 @@ +package org.apache.hadoop.util; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.Vector; + +import org.xbill.DNS.DClass; +import org.xbill.DNS.ExtendedResolver; +import org.xbill.DNS.Message; +import org.xbill.DNS.Name; +import org.xbill.DNS.Record; +import org.xbill.DNS.Resolver; +import org.xbill.DNS.ReverseMap; +import org.xbill.DNS.Section; +import org.xbill.DNS.Type; + +public class NetworkUtils { + + public static String reverseDns(String hostIp, String ns) throws IOException { + Resolver res; + if (ns ==null) + res = new ExtendedResolver(); + else + res = new ExtendedResolver(new String[]{ns}); + + Name name = ReverseMap.fromAddress(hostIp); + int type = Type.PTR; + int dclass = DClass.IN; + Record rec = Record.newRecord(name, type, dclass); + Message query = Message.newQuery(rec); + Message response = res.send(query); + + Record[] answers = response.getSectionArray(Section.ANSWER); + if (answers.length == 0) + return hostIp; + else + return answers[0].rdataToString(); + } + + public static String[] getIPs(String strInterface) throws UnknownHostException { + try { + NetworkInterface netIF = NetworkInterface.getByName(strInterface); + if (netIF == null) + return new String[] {InetAddress.getLocalHost().getHostAddress()}; + else { + Vector ips = new Vector(); + Enumeration e = netIF.getInetAddresses(); + while (e.hasMoreElements()) + ips.add(((InetAddress)e.nextElement()).getHostAddress()); + return (String[]) ips.toArray(new String[] {}); + } + } catch (SocketException e) { + return new String[] {InetAddress.getLocalHost().getHostAddress()}; + } + } + + public static String getDefaultIP(String strInterface) throws UnknownHostException{ + String[] ips = getIPs(strInterface); + return ips[0]; + } + + public static String[] getHosts(String strInterface, String nameserver) throws UnknownHostException { + String[] ips = getIPs(strInterface); + Vector hosts = new Vector(); + for (int ctr = 0; ctr < ips.length; ctr++) + try{ + hosts.add(reverseDns(ips[ctr], nameserver)); + } catch (IOException e) { + + } + + if (hosts.size() == 0) return new String[] {InetAddress.getLocalHost().getHostName()}; + else return (String[]) hosts.toArray(new String[] {}); + } + + public static String[] getHosts(String strInterface) throws UnknownHostException { + return getHosts(strInterface,null); + } + + public static String getDefaultHost(String strInterface, String nameserver) throws UnknownHostException { + String[] hosts = getHosts(strInterface, nameserver); + return hosts[0]; + } + + public static String getDefaultHost(String strInterface) throws UnknownHostException { + return getDefaultHost(strInterface, null); + } + +} Index: lib/dnsjava-2.0.2.LICENSE.txt =================================================================== --- lib/dnsjava-2.0.2.LICENSE.txt (revision 0) +++ lib/dnsjava-2.0.2.LICENSE.txt (revision 0) @@ -0,0 +1,24 @@ +* Copyright (c) 1998, Regents of the University of California +* All rights reserved. +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the University of California, Berkeley nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY +* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file Index: conf/hadoop-default.xml =================================================================== --- conf/hadoop-default.xml (revision 438557) +++ conf/hadoop-default.xml (working copy) @@ -38,6 +38,24 @@ creations/deletions), or "all". + + + + cluster.report.nif + default + The name of the Network Interface from which a task tracker should + report its IP address. + + + + + cluster.report.ns + default + The host name or IP address of the name server (DNS) which as TaskTracker should + use to determine the host name used by the JobTracker for communication and display purposes. + + +