From 950e8a459ea8ec3785f07ba67540eb6dac217ffd Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Tue, 13 Oct 2015 13:07:57 -0700 Subject: [PATCH] HADOOP-12474. MiniKMS should use random ports for Jetty server by default. Contributed by Mingliang Liu. --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../apache/hadoop/crypto/key/kms/server/MiniKMS.java | 12 +++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index c1649a7e455..5f28a27e1a2 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -701,6 +701,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12441. Fixed shell-kill command behaviour to work correctly on some Linux distributions after HADOOP-12317. (Wangda Tan via vinodkv) + HADOOP-12474. MiniKMS should use random ports for Jetty server by default. + (Mingliang Liu via wheat9) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/MiniKMS.java b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/MiniKMS.java index 4f802ccd608..eb640bbba72 100644 --- a/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/MiniKMS.java +++ b/hadoop-common-project/hadoop-kms/src/test/java/org/apache/hadoop/crypto/key/kms/server/MiniKMS.java @@ -47,19 +47,13 @@ public class MiniKMS { private static Server createJettyServer(String keyStore, String password, int inPort) { try { boolean ssl = keyStore != null; - InetAddress localhost = InetAddress.getByName("localhost"); String host = "localhost"; - ServerSocket ss = new ServerSocket((inPort < 0) ? 0 : inPort, 50, localhost); - int port = ss.getLocalPort(); - ss.close(); - Server server = new Server(0); + Server server = new Server(inPort); if (!ssl) { server.getConnectors()[0].setHost(host); - server.getConnectors()[0].setPort(port); } else { SslSocketConnector c = new SslSocketConnectorSecure(); c.setHost(host); - c.setPort(port); c.setNeedClientAuth(false); c.setKeystore(keyStore); c.setKeystoreType("jks"); @@ -80,7 +74,7 @@ public class MiniKMS { String scheme = (ssl) ? "https" : "http"; return new URL(scheme + "://" + server.getConnectors()[0].getHost() + ":" + - server.getConnectors()[0].getPort()); + server.getConnectors()[0].getLocalPort()); } catch (MalformedURLException ex) { throw new RuntimeException("It should never happen, " + ex.getMessage(), ex); @@ -92,7 +86,7 @@ public class MiniKMS { private String log4jConfFile; private File keyStoreFile; private String keyStorePassword; - private int inPort = -1; + private int inPort; public Builder() { kmsConfDir = new File("target/test-classes").getAbsoluteFile();