hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [2/2] hadoop git commit: HADOOP-12656. MiniKdc throws "address in use" BindException. (Contributed by Wei-Chiu Chuang)
Date Sat, 19 Dec 2015 00:08:53 GMT
HADOOP-12656. MiniKdc throws "address in use" BindException. (Contributed by Wei-Chiu Chuang)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/8fb70a03
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/8fb70a03
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/8fb70a03

Branch: refs/heads/trunk
Commit: 8fb70a031b323634ddc51ff6aff4f376baef68c8
Parents: ef3f3f6
Author: Arpit Agarwal <arp@apache.org>
Authored: Fri Dec 18 16:06:03 2015 -0800
Committer: Arpit Agarwal <arp@apache.org>
Committed: Fri Dec 18 16:08:26 2015 -0800

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |  3 +++
 .../java/org/apache/hadoop/minikdc/MiniKdc.java | 22 +++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/8fb70a03/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index 5a2e836..64cb7fd 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -1406,6 +1406,9 @@ Release 2.8.0 - UNRELEASED
     HADOOP-12468. Partial group resolution failure should not result in user
     lockout. (Wei-Chiu Chuang via Yongjun Zhang)
 
+    HADOOP-12656. MiniKdc throws "address in use" BindException.
+    (Wei-Chiu Chuang via Arpit Agarwal)
+
   OPTIMIZATIONS
 
     HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

http://git-wip-us.apache.org/repos/asf/hadoop/blob/8fb70a03/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
b/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
index a5253c4..b089e0e 100644
--- a/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
+++ b/hadoop-common-project/hadoop-minikdc/src/main/java/org/apache/hadoop/minikdc/MiniKdc.java
@@ -41,6 +41,7 @@ import org.apache.directory.server.kerberos.kdc.KdcServer;
 import org.apache.directory.server.kerberos.shared.crypto.encryption.KerberosKeyFactory;
 import org.apache.directory.server.kerberos.shared.keytab.Keytab;
 import org.apache.directory.server.kerberos.shared.keytab.KeytabEntry;
+import org.apache.directory.server.protocol.shared.transport.AbstractTransport;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
 import org.apache.directory.server.protocol.shared.transport.UdpTransport;
 import org.apache.directory.server.xdbm.Index;
@@ -64,8 +65,7 @@ import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.StringReader;
 import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.ServerSocket;
+import java.net.InetSocketAddress;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -265,12 +265,6 @@ public class MiniKdc {
     LOG.info("---------------------------------------------------------------");
     this.conf = conf;
     port = Integer.parseInt(conf.getProperty(KDC_PORT));
-    if (port == 0) {
-      ServerSocket ss = new ServerSocket(0, 1, InetAddress.getByName
-              (conf.getProperty(KDC_BIND_ADDRESS)));
-      port = ss.getLocalPort();
-      ss.close();
-    }
     String orgName= conf.getProperty(ORG_NAME);
     String orgDomain = conf.getProperty(ORG_DOMAIN);
     realm = orgName.toUpperCase(Locale.ENGLISH) + "."
@@ -458,15 +452,23 @@ public class MiniKdc {
 
     // transport
     String transport = conf.getProperty(TRANSPORT);
+    AbstractTransport absTransport;
     if (transport.trim().equals("TCP")) {
-      kdc.addTransports(new TcpTransport(bindAddress, port, 3, 50));
+      absTransport = new TcpTransport(bindAddress, port, 3, 50);
     } else if (transport.trim().equals("UDP")) {
-      kdc.addTransports(new UdpTransport(port));
+      absTransport = new UdpTransport(port);
     } else {
       throw new IllegalArgumentException("Invalid transport: " + transport);
     }
+    kdc.addTransports(absTransport);
     kdc.setServiceName(conf.getProperty(INSTANCE));
     kdc.start();
+    // if using ephemeral port, update port number for binding
+    if (port == 0) {
+      InetSocketAddress addr =
+          (InetSocketAddress)absTransport.getAcceptor().getLocalAddress();
+      port = addr.getPort();
+    }
 
     StringBuilder sb = new StringBuilder();
     InputStream is2 = getResourceAsStream("minikdc-krb5.conf");


Mime
View raw message