HADOOP-12474. MiniKMS should use random ports for Jetty server by default. Contributed by Mingliang Liu.

This commit is contained in:
Haohui Mai 2015-10-13 13:07:57 -07:00
parent 6716f15964
commit 7f00fcac77
2 changed files with 6 additions and 9 deletions

View File

@ -1283,6 +1283,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

View File

@ -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 @@ private static URL getJettyURL(Server server) {
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 static class Builder {
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();