From dbcda89fefa107e413180ef3dd4305fc75fb77a5 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Wed, 17 Apr 2013 04:16:51 +0000 Subject: [PATCH] YARN-500. Fixed YARN webapps to not roll-over ports when explicitly asked to use non-ephemeral ports. Contributed by Kenji Kikushima. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1468739 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 5 +++- .../apache/hadoop/yarn/webapp/WebApps.java | 5 ++-- .../apache/hadoop/yarn/webapp/TestWebApp.java | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 631b5326d1..a94992cca7 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -237,7 +237,10 @@ Release 2.0.5-beta - UNRELEASED YARN-412. Fixed FifoScheduler to check hostname of a NodeManager rather than its host:port during scheduling which caused incorrect locality for containers. (Roger Hoover via acmurthy) - + + YARN-500. Fixed YARN webapps to not roll-over ports when explicitly asked + to use non-ephemeral ports. (Kenji Kikushima via vinodkv) + Release 2.0.4-alpha - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java index 425d45bc08..a2ffbb01af 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApps.java @@ -97,13 +97,14 @@ static class ServletStruct { public Builder at(String bindAddress) { String[] parts = StringUtils.split(bindAddress, ':'); if (parts.length == 2) { - return at(parts[0], Integer.parseInt(parts[1]), true); + int port = Integer.parseInt(parts[1]); + return at(parts[0], port, port == 0); } return at(bindAddress, 0, true); } public Builder at(int port) { - return at("0.0.0.0", port, false); + return at("0.0.0.0", port, port == 0); } public Builder at(String address, int port, boolean findPort) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java index d178dbb16c..59beab67a4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/webapp/TestWebApp.java @@ -161,6 +161,30 @@ public void render(Page.HTML<_> html) { app.stop(); } + @Test(expected=org.apache.hadoop.yarn.webapp.WebAppException.class) + public void testCreateWithBindAddressNonZeroPort() { + WebApp app = WebApps.$for(this).at("0.0.0.0:50000").start(); + int port = app.getListenerAddress().getPort(); + assertEquals(50000, port); + // start another WebApp with same NonZero port + WebApp app2 = WebApps.$for(this).at("0.0.0.0:50000").start(); + // An exception occurs (findPort disabled) + app.stop(); + app2.stop(); + } + + @Test(expected=org.apache.hadoop.yarn.webapp.WebAppException.class) + public void testCreateWithNonZeroPort() { + WebApp app = WebApps.$for(this).at(50000).start(); + int port = app.getListenerAddress().getPort(); + assertEquals(50000, port); + // start another WebApp with same NonZero port + WebApp app2 = WebApps.$for(this).at(50000).start(); + // An exception occurs (findPort disabled) + app.stop(); + app2.stop(); + } + @Test public void testServePaths() { WebApp app = WebApps.$for("test", this).start(); assertEquals("/test", app.getRedirectPath());