YARN-11318. Improve FederationInterceptorREST#createInterceptorForSubCluster Use WebAppUtils. (#4939)

This commit is contained in:
slfan1989 2022-10-05 00:18:01 +08:00 committed by GitHub
parent 22bd5e3b53
commit 874a004347
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -248,7 +248,9 @@ private DefaultRequestInterceptorREST createInterceptorForSubCluster(
e); e);
} }
interceptorInstance.setWebAppAddress("http://" + webAppAddress); String webAppAddresswithScheme =
WebAppUtils.getHttpSchemePrefix(this.getConf()) + webAppAddress;
interceptorInstance.setWebAppAddress(webAppAddresswithScheme);
interceptorInstance.setSubClusterId(subClusterId); interceptorInstance.setSubClusterId(subClusterId);
interceptors.put(subClusterId, interceptorInstance); interceptors.put(subClusterId, interceptorInstance);
return interceptorInstance; return interceptorInstance;

View File

@ -30,6 +30,8 @@
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.http.HttpConfig;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ReservationId; import org.apache.hadoop.yarn.api.records.ReservationId;
@ -89,6 +91,7 @@
import org.apache.hadoop.yarn.util.LRUCacheHashMap; import org.apache.hadoop.yarn.util.LRUCacheHashMap;
import org.apache.hadoop.yarn.util.MonotonicClock; import org.apache.hadoop.yarn.util.MonotonicClock;
import org.apache.hadoop.yarn.util.Times; import org.apache.hadoop.yarn.util.Times;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -1127,4 +1130,28 @@ public void testListReservation() throws Exception {
Assert.assertEquals(1, vCore); Assert.assertEquals(1, vCore);
Assert.assertEquals(1024, memory); Assert.assertEquals(1024, memory);
} }
@Test
public void testWebAddressWithScheme() {
// The style of the web address reported by the subCluster in the heartbeat is 0.0.0.0:8000
// We design the following 2 test cases:
String webAppAddress = "0.0.0.0:8000";
// 1. We try to disable Https, at this point we should get the following link:
// http://0.0.0.0:8000
String expectedHttpWebAddress = "http://0.0.0.0:8000";
String webAppAddressWithScheme =
WebAppUtils.getHttpSchemePrefix(this.getConf()) + webAppAddress;
Assert.assertEquals(expectedHttpWebAddress, webAppAddressWithScheme);
// 2. We try to enable Httpsat this point we should get the following link:
// https://0.0.0.0:8000
Configuration configuration = this.getConf();
configuration.set(YarnConfiguration.YARN_HTTP_POLICY_KEY,
HttpConfig.Policy.HTTPS_ONLY.name());
String expectedHttpsWebAddress = "https://0.0.0.0:8000";
String webAppAddressWithScheme2 =
WebAppUtils.getHttpSchemePrefix(this.getConf()) + webAppAddress;
Assert.assertEquals(expectedHttpsWebAddress, webAppAddressWithScheme2);
}
} }