diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 86c2256c03..9f695c57c9 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -310,6 +310,8 @@ Release 0.23.3 - UNRELEASED MAPREDUCE-4079. Allow MR AppMaster to limit ephemeral port range. (bobby via tgraves) + MAPREDUCE-4210. Expose listener address for WebApp (Daryn Sharp via bobby) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java index 72dd53fb6f..cb2dbb5b8d 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -75,6 +76,14 @@ void setHttpServer(HttpServer server) { @Provides public HttpServer httpServer() { return httpServer; } + /** + * Get the address the http server is bound to + * @return InetSocketAddress + */ + public InetSocketAddress getListenerAddress() { + return checkNotNull(httpServer, "httpServer").getListenerAddress(); + } + public int port() { return checkNotNull(httpServer, "httpServer").getPort(); } diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java index 31b2aaa2ed..d178dbb16c 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java @@ -149,6 +149,18 @@ public void render(Page.HTML<_> html) { app.stop(); } + @Test public void testCreateWithPort() { + // see if the ephemeral port is updated + WebApp app = WebApps.$for(this).at(0).start(); + int port = app.getListenerAddress().getPort(); + assertTrue(port > 0); + app.stop(); + // try to reuse the port + app = WebApps.$for(this).at(port).start(); + assertEquals(port, app.getListenerAddress().getPort()); + app.stop(); + } + @Test public void testServePaths() { WebApp app = WebApps.$for("test", this).start(); assertEquals("/test", app.getRedirectPath());