Bläddra i källkod

YARN-10141.Interceptor in FederationInterceptorREST doesnt update on RM switchover. Contributed by D M Murali Krishna Reddy.

Brahma Reddy Battula 5 år sedan
förälder
incheckning
3a9ccf7f6d

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/DefaultRequestInterceptorREST.java

@@ -81,6 +81,10 @@ public class DefaultRequestInterceptorREST
     this.webAppAddress = webAppAddress;
   }
 
+  protected String getWebAppAddress() {
+    return this.webAppAddress;
+  }
+
   protected void setSubClusterId(SubClusterId scId) {
     this.subClusterId = scId;
   }

+ 5 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java

@@ -97,6 +97,7 @@ import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
 import org.apache.hadoop.yarn.util.Clock;
 import org.apache.hadoop.yarn.util.MonotonicClock;
 import org.apache.hadoop.yarn.webapp.NotFoundException;
+import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -237,7 +238,10 @@ public class FederationInterceptorREST extends AbstractRESTRequestInterceptor {
       SubClusterId subClusterId, String webAppAddress) {
     DefaultRequestInterceptorREST interceptor =
         getInterceptorForSubCluster(subClusterId);
-    if (interceptor == null) {
+    String webAppAddresswithScheme = WebAppUtils.getHttpSchemePrefix(
+            this.getConf()) + webAppAddress;
+    if (interceptor == null || !webAppAddresswithScheme.equals(interceptor.
+        getWebAppAddress())){
       interceptor = createInterceptorForSubCluster(subClusterId, webAppAddress);
     }
     return interceptor;

+ 39 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestFederationInterceptorREST.java

@@ -32,6 +32,9 @@ import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.server.federation.policies.manager.UniformBroadcastPolicyManager;
 import org.apache.hadoop.yarn.server.federation.store.impl.MemoryFederationStateStore;
 import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest;
+import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
 import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreTestUtil;
 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo;
@@ -44,6 +47,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceOptionInfo;
+import org.apache.hadoop.yarn.util.MonotonicClock;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -521,4 +525,39 @@ public class TestFederationInterceptorREST extends BaseRouterWebServicesTest {
     Assert.assertNull(response);
   }
 
+  /**
+   * This test validates the creation of new interceptor in case of a
+   * RMSwitchover in a subCluster.
+   */
+  @Test
+  public void testRMSwitchoverOfOneSC() throws Exception {
+    SubClusterId subClusterId = SubClusterId.newInstance(Integer.toString(0));
+
+    interceptor.getClusterMetricsInfo();
+    Assert.assertEquals("http://1.2.3.4:4", interceptor
+            .getInterceptorForSubCluster(subClusterId).getWebAppAddress());
+
+    //Register the first subCluster with secondRM simulating RMSwitchover
+    registerSubClusterWithSwitchoverRM(subClusterId);
+
+    interceptor.getClusterMetricsInfo();
+    Assert.assertEquals("http://5.6.7.8:8", interceptor
+            .getInterceptorForSubCluster(subClusterId).getWebAppAddress());
+  }
+
+  private void registerSubClusterWithSwitchoverRM(SubClusterId subClusterId)
+          throws YarnException {
+    String amRMAddress = "5.6.7.8:5";
+    String clientRMAddress = "5.6.7.8:6";
+    String rmAdminAddress = "5.6.7.8:7";
+    String webAppAddress = "5.6.7.8:8";
+
+    SubClusterInfo subClusterInfo = SubClusterInfo.newInstance(subClusterId,
+            amRMAddress, clientRMAddress, rmAdminAddress, webAppAddress,
+            SubClusterState.SC_RUNNING, new MonotonicClock().getTime(),
+            "capability");
+    stateStore.registerSubCluster(
+            SubClusterRegisterRequest.newInstance(subClusterInfo));
+  }
+
 }

+ 1 - 1
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/TestableFederationInterceptorREST.java

@@ -42,7 +42,7 @@ public class TestableFederationInterceptorREST
   protected void registerBadSubCluster(SubClusterId badSC) {
 
     // Adding in the cache the bad SubCluster, in this way we can stop them
-    getOrCreateInterceptorForSubCluster(badSC, "test");
+    getOrCreateInterceptorForSubCluster(badSC, "1.2.3.4:4");
 
     badSubCluster.add(badSC);
     MockDefaultRequestInterceptorREST interceptor =