From d38fb71d00f1016a171ac39ff4949eadd602147e Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Mon, 16 Dec 2013 19:09:44 +0000 Subject: [PATCH] YARN-1505. Fixed Webapplication proxy server to not hardcode its bind address. Contributed by Xuan Gong. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1551314 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../apache/hadoop/yarn/server/webproxy/WebAppProxy.java | 7 +++++++ .../hadoop/yarn/server/webproxy/WebAppProxyServer.java | 8 ++++---- .../yarn/server/webproxy/TestWebAppProxyServer.java | 9 ++++++++- .../yarn/server/webproxy/TestWebAppProxyServlet.java | 4 +++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 17111bca53..e03de63ec4 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -246,6 +246,9 @@ Release 2.4.0 - UNRELEASED YARN-1405. Fixed ResourceManager to not hang when init/start fails with an exception w.r.t state-store. (Jian He via vinodkv) + YARN-1505. Fixed Webapplication proxy server to not hardcode its bind + address. (Xuan Gong via vinodkv) + Release 2.3.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxy.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxy.java index d66571e762..2fbb0b886f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxy.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxy.java @@ -33,6 +33,8 @@ import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.fs.CommonConfigurationKeys; +import com.google.common.annotations.VisibleForTesting; + public class WebAppProxy extends AbstractService { public static final String FETCHER_ATTRIBUTE= "AppUrlFetcher"; public static final String IS_SECURITY_ENABLED_ATTRIBUTE = "IsSecurityEnabled"; @@ -126,4 +128,9 @@ public void join() { } } } + + @VisibleForTesting + String getBindAddress() { + return bindAddress + ":" + port; + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServer.java index ce9003d1d1..c8474a54ef 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServer.java @@ -77,7 +77,8 @@ public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); StringUtils.startupShutdownMessage(WebAppProxyServer.class, args, LOG); try { - WebAppProxyServer proxyServer = startServer(); + YarnConfiguration configuration = new YarnConfiguration(); + WebAppProxyServer proxyServer = startServer(configuration); proxyServer.proxy.join(); } catch (Throwable t) { LOG.fatal("Error starting Proxy server", t); @@ -90,12 +91,11 @@ public static void main(String[] args) { * * @return proxy server instance. */ - protected static WebAppProxyServer startServer() throws Exception { + protected static WebAppProxyServer startServer(Configuration configuration) + throws Exception { WebAppProxyServer proxy = new WebAppProxyServer(); ShutdownHookManager.get().addShutdownHook( new CompositeServiceShutdownHook(proxy), SHUTDOWN_HOOK_PRIORITY); - YarnConfiguration configuration = new YarnConfiguration(); - configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9099"); proxy.init(configuration); proxy.start(); return proxy; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServer.java index 0981c8d3c0..feed9fe361 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServer.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; +import org.apache.hadoop.service.Service; import org.apache.hadoop.service.Service.STATE; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer; @@ -29,11 +30,12 @@ public class TestWebAppProxyServer { private WebAppProxyServer webAppProxy = null; + private final String proxyAddress = "0.0.0.0:8888"; @Before public void setUp() throws Exception { YarnConfiguration conf = new YarnConfiguration(); - conf.set(YarnConfiguration.PROXY_ADDRESS, "0.0.0.0:8888"); + conf.set(YarnConfiguration.PROXY_ADDRESS, proxyAddress); webAppProxy = new WebAppProxyServer(); webAppProxy.init(conf); } @@ -47,6 +49,11 @@ public void tearDown() throws Exception { public void testStart() { assertEquals(STATE.INITED, webAppProxy.getServiceState()); webAppProxy.start(); + for (Service service : webAppProxy.getServices()) { + if (service instanceof WebAppProxy) { + assertEquals(((WebAppProxy) service).getBindAddress(), proxyAddress); + } + } assertEquals(STATE.STARTED, webAppProxy.getServiceState()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java index 47f4e09d75..58a7ff0023 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java @@ -184,8 +184,10 @@ public void testWebAppProxyServlet() throws Exception { @Test(timeout=5000) public void testWebAppProxyServerMainMethod() throws Exception { WebAppProxyServer mainServer = null; + Configuration conf = new YarnConfiguration(); + conf.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9099"); try { - mainServer = WebAppProxyServer.startServer(); + mainServer = WebAppProxyServer.startServer(conf); int counter = 20; URL wrongUrl = new URL("http://localhost:9099/proxy/app");