YARN-9130. Add Bind_HOST configuration for Yarn Web Proxy. Contributed by Rong Tang.
This commit is contained in:
parent
499c70eda5
commit
5df9fb16b9
@ -2310,6 +2310,10 @@ public static boolean isAclEnabled(Configuration conf) {
|
|||||||
public static final String DEFAULT_PROXY_ADDRESS =
|
public static final String DEFAULT_PROXY_ADDRESS =
|
||||||
"0.0.0.0:" + DEFAULT_PROXY_PORT;
|
"0.0.0.0:" + DEFAULT_PROXY_PORT;
|
||||||
|
|
||||||
|
/** Binding address for the web proxy. */
|
||||||
|
public static final String PROXY_BIND_HOST =
|
||||||
|
PROXY_PREFIX + "bind-host";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YARN Service Level Authorization
|
* YARN Service Level Authorization
|
||||||
*/
|
*/
|
||||||
|
@ -2157,6 +2157,15 @@
|
|||||||
<value/>
|
<value/>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<description>The actual address the web proxy will bind to. If this optional
|
||||||
|
address is set, it overrides only the hostname portion of yarn.web-proxy.address.
|
||||||
|
This is useful for making the web proxy server listen on all interfaces by setting
|
||||||
|
it to 0.0.0.0 </description>
|
||||||
|
<name>yarn.web-proxy.bind-host</name>
|
||||||
|
<value/>
|
||||||
|
</property>
|
||||||
|
|
||||||
<!-- Applications' Configuration -->
|
<!-- Applications' Configuration -->
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
|
@ -77,13 +77,23 @@ protected void serviceInit(Configuration conf) throws Exception {
|
|||||||
throw new YarnRuntimeException(YarnConfiguration.PROXY_ADDRESS +
|
throw new YarnRuntimeException(YarnConfiguration.PROXY_ADDRESS +
|
||||||
" is not set so the proxy will not run.");
|
" is not set so the proxy will not run.");
|
||||||
}
|
}
|
||||||
LOG.info("Instantiating Proxy at " + bindAddress);
|
|
||||||
String[] parts = StringUtils.split(bindAddress, ':');
|
String[] parts = StringUtils.split(bindAddress, ':');
|
||||||
port = 0;
|
port = 0;
|
||||||
if (parts.length == 2) {
|
if (parts.length == 2) {
|
||||||
bindAddress = parts[0];
|
bindAddress = parts[0];
|
||||||
port = Integer.parseInt(parts[1]);
|
port = Integer.parseInt(parts[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String bindHost = conf.getTrimmed(YarnConfiguration.PROXY_BIND_HOST, null);
|
||||||
|
if (bindHost != null) {
|
||||||
|
LOG.debug("{} is set, will be used to run proxy.",
|
||||||
|
YarnConfiguration.PROXY_BIND_HOST);
|
||||||
|
bindAddress = bindHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Instantiating Proxy at {}:{}", bindAddress, port);
|
||||||
|
|
||||||
acl = new AccessControlList(conf.get(YarnConfiguration.YARN_ADMIN_ACL,
|
acl = new AccessControlList(conf.get(YarnConfiguration.YARN_ADMIN_ACL,
|
||||||
YarnConfiguration.DEFAULT_YARN_ADMIN_ACL));
|
YarnConfiguration.DEFAULT_YARN_ADMIN_ACL));
|
||||||
super.serviceInit(conf);
|
super.serviceInit(conf);
|
||||||
|
@ -103,7 +103,9 @@ protected void doSecureLogin(Configuration conf) throws IOException {
|
|||||||
* @return InetSocketAddress
|
* @return InetSocketAddress
|
||||||
*/
|
*/
|
||||||
public static InetSocketAddress getBindAddress(Configuration conf) {
|
public static InetSocketAddress getBindAddress(Configuration conf) {
|
||||||
return conf.getSocketAddr(YarnConfiguration.PROXY_ADDRESS,
|
return conf.getSocketAddr(
|
||||||
|
YarnConfiguration.PROXY_BIND_HOST,
|
||||||
|
YarnConfiguration.PROXY_ADDRESS,
|
||||||
YarnConfiguration.DEFAULT_PROXY_ADDRESS,
|
YarnConfiguration.DEFAULT_PROXY_ADDRESS,
|
||||||
YarnConfiguration.DEFAULT_PROXY_PORT);
|
YarnConfiguration.DEFAULT_PROXY_PORT);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
import org.apache.hadoop.service.Service;
|
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.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -33,14 +32,15 @@
|
|||||||
|
|
||||||
public class TestWebAppProxyServer {
|
public class TestWebAppProxyServer {
|
||||||
private WebAppProxyServer webAppProxy = null;
|
private WebAppProxyServer webAppProxy = null;
|
||||||
private final String proxyAddress = "0.0.0.0:8888";
|
private final String port = "8888";
|
||||||
|
private final String proxyAddress = "localhost:" + port;
|
||||||
|
private YarnConfiguration conf = null;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
YarnConfiguration conf = new YarnConfiguration();
|
conf = new YarnConfiguration();
|
||||||
conf.set(YarnConfiguration.PROXY_ADDRESS, proxyAddress);
|
conf.set(YarnConfiguration.PROXY_ADDRESS, proxyAddress);
|
||||||
webAppProxy = new WebAppProxyServer();
|
webAppProxy = new WebAppProxyServer();
|
||||||
webAppProxy.init(conf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -50,19 +50,38 @@ public void tearDown() throws Exception {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStart() {
|
public void testStart() {
|
||||||
|
webAppProxy.init(conf);
|
||||||
assertEquals(STATE.INITED, webAppProxy.getServiceState());
|
assertEquals(STATE.INITED, webAppProxy.getServiceState());
|
||||||
webAppProxy.start();
|
webAppProxy.start();
|
||||||
for (Service service : webAppProxy.getServices()) {
|
for (Service service : webAppProxy.getServices()) {
|
||||||
if (service instanceof WebAppProxy) {
|
if (service instanceof WebAppProxy) {
|
||||||
assertEquals(((WebAppProxy) service).getBindAddress(), proxyAddress);
|
assertEquals(proxyAddress, ((WebAppProxy) service).getBindAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(STATE.STARTED, webAppProxy.getServiceState());
|
assertEquals(STATE.STARTED, webAppProxy.getServiceState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartWithBindHost() {
|
||||||
|
String bindHost = "0.0.0.0";
|
||||||
|
conf.set(YarnConfiguration.PROXY_BIND_HOST, bindHost);
|
||||||
|
webAppProxy.init(conf);
|
||||||
|
|
||||||
|
assertEquals(STATE.INITED, webAppProxy.getServiceState());
|
||||||
|
webAppProxy.start();
|
||||||
|
for (Service service : webAppProxy.getServices()) {
|
||||||
|
if (service instanceof WebAppProxy) {
|
||||||
|
assertEquals(bindHost + ":" + port,
|
||||||
|
((WebAppProxy) service).getBindAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(STATE.STARTED, webAppProxy.getServiceState());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindAddress() {
|
public void testBindAddress() {
|
||||||
YarnConfiguration conf = new YarnConfiguration();
|
conf = new YarnConfiguration();
|
||||||
|
|
||||||
InetSocketAddress defaultBindAddress = WebAppProxyServer.getBindAddress(conf);
|
InetSocketAddress defaultBindAddress = WebAppProxyServer.getBindAddress(conf);
|
||||||
Assert.assertEquals("Web Proxy default bind address port is incorrect",
|
Assert.assertEquals("Web Proxy default bind address port is incorrect",
|
||||||
|
Loading…
Reference in New Issue
Block a user