From 874a004347c82539b4b69987b79d93e8a59bdd05 Mon Sep 17 00:00:00 2001 From: slfan1989 <55643692+slfan1989@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:18:01 +0800 Subject: [PATCH] YARN-11318. Improve FederationInterceptorREST#createInterceptorForSubCluster Use WebAppUtils. (#4939) --- .../webapp/FederationInterceptorREST.java | 4 ++- .../webapp/TestFederationInterceptorREST.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java index 4756da4fa8..b8c55cf6ee 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java @@ -248,7 +248,9 @@ private DefaultRequestInterceptorREST createInterceptorForSubCluster( e); } - interceptorInstance.setWebAppAddress("http://" + webAppAddress); + String webAppAddresswithScheme = + WebAppUtils.getHttpSchemePrefix(this.getConf()) + webAppAddress; + interceptorInstance.setWebAppAddress(webAppAddresswithScheme); interceptorInstance.setSubClusterId(subClusterId); interceptors.put(subClusterId, interceptorInstance); return interceptorInstance; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java index c617f8612e..596f210528 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java @@ -30,6 +30,8 @@ import javax.ws.rs.core.Response; 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.yarn.api.records.ApplicationId; 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.MonotonicClock; import org.apache.hadoop.yarn.util.Times; +import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; @@ -1127,4 +1130,28 @@ public void testListReservation() throws Exception { Assert.assertEquals(1, vCore); 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 Https,at 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); + } }