Ver código fonte

commit 20a207b2cca1a68e148fc20f8f2b7257dc2700bf
Author: Jitendra Nath Pandey <jitendra@yahoo-inc.com>
Date: Thu Sep 3 10:54:21 2009 -0700

Merged from jira Hadoop-5363.
Removed pickOneAddress function.


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1076992 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 anos atrás
pai
commit
63bbf1275e

+ 3 - 16
src/hdfs/org/apache/hadoop/hdfs/HftpFileSystem.java

@@ -28,7 +28,6 @@ import java.net.InetSocketAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.UnknownHostException;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -76,7 +75,6 @@ public class HftpFileSystem extends FileSystem {
 
   protected InetSocketAddress nnAddr;
   protected UserGroupInformation ugi; 
-  protected final Random ran = new Random();
 
   public static final String HFTP_TIMEZONE = "UTC";
   public static final String HFTP_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
@@ -107,26 +105,15 @@ public class HftpFileSystem extends FileSystem {
     nnAddr = NetUtils.createSocketAddr(name.toString());
   }
   
-  /** randomly pick one from all available IP addresses of a given hostname */
-  protected String pickOneAddress(String hostname) throws UnknownHostException {
-    if ("localhost".equals(hostname))
-      return hostname;
-    InetAddress[] addrs = InetAddress.getAllByName(hostname);
-    if (addrs.length > 1)
-      return addrs[ran.nextInt(addrs.length)].getHostAddress();
-    return addrs[0].getHostAddress();
-  }
 
   @Override
   public URI getUri() {
     try {
-      return new URI("hftp", null, pickOneAddress(nnAddr.getHostName()), nnAddr.getPort(),
+      return new URI("hftp", null, nnAddr.getHostName(), nnAddr.getPort(),
                      null, null, null);
     } catch (URISyntaxException e) {
       return null;
-    } catch (UnknownHostException e) {
-      return null;
-    }
+    } 
   }
 
   /**
@@ -137,7 +124,7 @@ public class HftpFileSystem extends FileSystem {
   protected HttpURLConnection openConnection(String path, String query)
       throws IOException {
     try {
-      final URL url = new URI("http", null, pickOneAddress(nnAddr.getHostName()),
+      final URL url = new URI("http", null, nnAddr.getHostName(),
           nnAddr.getPort(), path, query, null).toURL();
       if (LOG.isTraceEnabled()) {
         LOG.trace("url=" + url);

+ 3 - 6
src/hdfs/org/apache/hadoop/hdfs/HsftpFileSystem.java

@@ -23,7 +23,6 @@ import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.UnknownHostException;
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLSession;
@@ -69,7 +68,7 @@ public class HsftpFileSystem extends HftpFileSystem {
   protected HttpURLConnection openConnection(String path, String query)
       throws IOException {
     try {
-      final URL url = new URI("https", null, pickOneAddress(nnAddr.getHostName()),
+      final URL url = new URI("https", null, nnAddr.getHostName(),
           nnAddr.getPort(), path, query, null).toURL();
       HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
       // bypass hostname verification
@@ -83,13 +82,11 @@ public class HsftpFileSystem extends HftpFileSystem {
   @Override
   public URI getUri() {
     try {
-      return new URI("hsftp", null, pickOneAddress(nnAddr.getHostName()), nnAddr.getPort(),
+      return new URI("hsftp", null, nnAddr.getHostName(), nnAddr.getPort(),
                      null, null, null);
     } catch (URISyntaxException e) {
       return null;
-    } catch (UnknownHostException e) {
-      return null;
-    }
+    } 
   }
 
   /**