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
This commit is contained in:
Vinod Kumar Vavilapalli 2013-12-16 19:09:44 +00:00
parent 8e32e6aff1
commit d38fb71d00
5 changed files with 25 additions and 6 deletions

View File

@ -246,6 +246,9 @@ Release 2.4.0 - UNRELEASED
YARN-1405. Fixed ResourceManager to not hang when init/start fails with an YARN-1405. Fixed ResourceManager to not hang when init/start fails with an
exception w.r.t state-store. (Jian He via vinodkv) 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 Release 2.3.0 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -33,6 +33,8 @@
import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import com.google.common.annotations.VisibleForTesting;
public class WebAppProxy extends AbstractService { public class WebAppProxy extends AbstractService {
public static final String FETCHER_ATTRIBUTE= "AppUrlFetcher"; public static final String FETCHER_ATTRIBUTE= "AppUrlFetcher";
public static final String IS_SECURITY_ENABLED_ATTRIBUTE = "IsSecurityEnabled"; public static final String IS_SECURITY_ENABLED_ATTRIBUTE = "IsSecurityEnabled";
@ -126,4 +128,9 @@ public void join() {
} }
} }
} }
@VisibleForTesting
String getBindAddress() {
return bindAddress + ":" + port;
}
} }

View File

@ -77,7 +77,8 @@ public static void main(String[] args) {
Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler());
StringUtils.startupShutdownMessage(WebAppProxyServer.class, args, LOG); StringUtils.startupShutdownMessage(WebAppProxyServer.class, args, LOG);
try { try {
WebAppProxyServer proxyServer = startServer(); YarnConfiguration configuration = new YarnConfiguration();
WebAppProxyServer proxyServer = startServer(configuration);
proxyServer.proxy.join(); proxyServer.proxy.join();
} catch (Throwable t) { } catch (Throwable t) {
LOG.fatal("Error starting Proxy server", t); LOG.fatal("Error starting Proxy server", t);
@ -90,12 +91,11 @@ public static void main(String[] args) {
* *
* @return proxy server instance. * @return proxy server instance.
*/ */
protected static WebAppProxyServer startServer() throws Exception { protected static WebAppProxyServer startServer(Configuration configuration)
throws Exception {
WebAppProxyServer proxy = new WebAppProxyServer(); WebAppProxyServer proxy = new WebAppProxyServer();
ShutdownHookManager.get().addShutdownHook( ShutdownHookManager.get().addShutdownHook(
new CompositeServiceShutdownHook(proxy), SHUTDOWN_HOOK_PRIORITY); new CompositeServiceShutdownHook(proxy), SHUTDOWN_HOOK_PRIORITY);
YarnConfiguration configuration = new YarnConfiguration();
configuration.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9099");
proxy.init(configuration); proxy.init(configuration);
proxy.start(); proxy.start();
return proxy; return proxy;

View File

@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.service.Service;
import org.apache.hadoop.service.Service.STATE; import org.apache.hadoop.service.Service.STATE;
import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer; import org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer;
@ -29,11 +30,12 @@
public class TestWebAppProxyServer { public class TestWebAppProxyServer {
private WebAppProxyServer webAppProxy = null; private WebAppProxyServer webAppProxy = null;
private final String proxyAddress = "0.0.0.0:8888";
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
YarnConfiguration conf = new YarnConfiguration(); YarnConfiguration conf = new YarnConfiguration();
conf.set(YarnConfiguration.PROXY_ADDRESS, "0.0.0.0:8888"); conf.set(YarnConfiguration.PROXY_ADDRESS, proxyAddress);
webAppProxy = new WebAppProxyServer(); webAppProxy = new WebAppProxyServer();
webAppProxy.init(conf); webAppProxy.init(conf);
} }
@ -47,6 +49,11 @@ public void tearDown() throws Exception {
public void testStart() { public void testStart() {
assertEquals(STATE.INITED, webAppProxy.getServiceState()); assertEquals(STATE.INITED, webAppProxy.getServiceState());
webAppProxy.start(); webAppProxy.start();
for (Service service : webAppProxy.getServices()) {
if (service instanceof WebAppProxy) {
assertEquals(((WebAppProxy) service).getBindAddress(), proxyAddress);
}
}
assertEquals(STATE.STARTED, webAppProxy.getServiceState()); assertEquals(STATE.STARTED, webAppProxy.getServiceState());
} }
} }

View File

@ -184,8 +184,10 @@ public void testWebAppProxyServlet() throws Exception {
@Test(timeout=5000) @Test(timeout=5000)
public void testWebAppProxyServerMainMethod() throws Exception { public void testWebAppProxyServerMainMethod() throws Exception {
WebAppProxyServer mainServer = null; WebAppProxyServer mainServer = null;
Configuration conf = new YarnConfiguration();
conf.set(YarnConfiguration.PROXY_ADDRESS, "localhost:9099");
try { try {
mainServer = WebAppProxyServer.startServer(); mainServer = WebAppProxyServer.startServer(conf);
int counter = 20; int counter = 20;
URL wrongUrl = new URL("http://localhost:9099/proxy/app"); URL wrongUrl = new URL("http://localhost:9099/proxy/app");