hadoop-yarn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject svn commit: r1575167 - in /hadoop/common/branches/branch-2/hadoop-yarn-project: ./ hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/ hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/ hadoop-yarn/hadoo...
Date Fri, 07 Mar 2014 04:35:01 GMT
Author: kasha
Date: Fri Mar  7 04:35:01 2014
New Revision: 1575167

URL: http://svn.apache.org/r1575167
Log:
YARN-1525. Web UI should redirect to active RM when HA is enabled. (Cindy Li via kasha)

Added:
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMHAUtils.java
      - copied unchanged from r1575166, hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMHAUtils.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMDispatcher.java
      - copied unchanged from r1575166, hadoop/common/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMDispatcher.java
Modified:
    hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Router.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt Fri Mar  7 04:35:01 2014
@@ -253,6 +253,9 @@ Release 2.4.0 - UNRELEASED
     YARN-1780. Improved logging in the Timeline client and server. (Zhijie Shen
     via vinodkv)
 
+    YARN-1525. Web UI should redirect to active RM when HA is enabled. (Cindy Li
+    via kasha)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/TestRMFailover.java
Fri Mar  7 04:35:01 2014
@@ -26,13 +26,14 @@ import static org.junit.Assert.fail;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.ha.ClientBaseWithFixes;
 import org.apache.hadoop.ha.HAServiceProtocol;
-import org.apache.hadoop.ha.proto.HAServiceProtocolProtos;
 import org.apache.hadoop.service.Service.STATE;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.client.api.YarnClient;
@@ -252,4 +253,37 @@ public class TestRMFailover extends Clie
         .contains("Application with id '" + fakeAppId + "' " +
             "doesn't exist in RM."));
   }
+
+  @Test
+  public void testRMWebAppRedirect() throws YarnException,
+      InterruptedException, IOException {
+    cluster = new MiniYARNCluster(TestRMFailover.class.getName(), 2, 0, 1, 1);
+    conf.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
+
+    cluster.init(conf);
+    cluster.start();
+    getAdminService(0).transitionToActive(req);
+    String rm1Url = "http://0.0.0.0:18088";
+    String rm2Url = "http://0.0.0.0:28088";
+    String header = getHeader("Refresh", rm2Url);
+    assertTrue(header.contains("; url=" + rm1Url));
+
+    header = getHeader("Refresh", rm2Url + "/cluster/cluster");
+    assertEquals(null, header);
+
+    // Due to the limitation of MiniYARNCluster and dispatcher is a singleton,
+    // we couldn't add the test case after explicitFailover();
+  }
+
+  static String getHeader(String field, String url) {
+    String fieldHeader = null;
+    try {
+      Map<String, List<String>> map =
+          new URL(url).openConnection().getHeaderFields();
+      fieldHeader = map.get(field).get(0);
+    } catch (Exception e) {
+      // throw new RuntimeException(e);
+    }
+    return fieldHeader;
+  }
 }

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Dispatcher.java
Fri Mar  7 04:35:01 2014
@@ -57,11 +57,11 @@ public class Dispatcher extends HttpServ
 
   private transient final Injector injector;
   private transient final Router router;
-  private transient final WebApp webApp;
+  protected transient final WebApp webApp;
   private volatile boolean devMode = false;
 
   @Inject
-  Dispatcher(WebApp webApp, Injector injector, Router router) {
+  protected Dispatcher(WebApp webApp, Injector injector, Router router) {
     this.webApp = webApp;
     this.injector = injector;
     this.router = router;

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Router.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Router.java?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Router.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/Router.java
Fri Mar  7 04:35:01 2014
@@ -44,7 +44,7 @@ import com.google.common.collect.Maps;
  * Manages path info to controller#action routing.
  */
 @InterfaceAudience.LimitedPrivate({"YARN", "MapReduce"})
-class Router {
+public class Router {
   static final Logger LOG = LoggerFactory.getLogger(Router.class);
   static final ImmutableList<String> EMPTY_LIST = ImmutableList.of();
   static final CharMatcher SLASH = CharMatcher.is('/');

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/WebApp.java
Fri Mar  7 04:35:01 2014
@@ -55,7 +55,7 @@ public abstract class WebApp extends Ser
 
   private volatile String name;
   private volatile List<String> servePathSpecs = new ArrayList<String>();
-  // path to redirect to if user goes to "/"
+  // path to redirect to
   private volatile String redirectPath;
   private volatile String wsName;
   private volatile Configuration conf;
@@ -134,7 +134,9 @@ public abstract class WebApp extends Ser
    * more easily differentiate the different webapps.
    * @param path  the path to redirect to
    */
-  void setRedirectPath(String path) { this.redirectPath = path; }
+  protected void setRedirectPath(String path) {
+    this.redirectPath = path;
+  }
 
   void setWebServices (String name) { this.wsName = name; }
 
@@ -158,6 +160,10 @@ public abstract class WebApp extends Ser
       serve(path).with(Dispatcher.class);
     }
 
+    configureRSServlets();
+  }
+
+  protected void configureRSServlets() {
     // Add in the web services filters/serves if app has them.
     // Using Jersey/guice integration module. If user has web services
     // they must have also bound a default one in their webapp code.

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java?rev=1575167&r1=1575166&r2=1575167&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebApp.java
Fri Mar  7 04:35:01 2014
@@ -20,10 +20,16 @@ package org.apache.hadoop.yarn.server.re
 
 import static org.apache.hadoop.yarn.util.StringHelper.pajoin;
 
+import java.net.InetSocketAddress;
+
+import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.RMHAUtils;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.security.QueueACLsManager;
 import org.apache.hadoop.yarn.server.security.ApplicationACLsManager;
+import org.apache.hadoop.yarn.webapp.Dispatcher;
 import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
 import org.apache.hadoop.yarn.webapp.WebApp;
 import org.apache.hadoop.yarn.webapp.YarnWebParams;
@@ -34,6 +40,7 @@ import org.apache.hadoop.yarn.webapp.Yar
 public class RMWebApp extends WebApp implements YarnWebParams {
 
   private final ResourceManager rm;
+  private boolean standby = false;
 
   public RMWebApp(ResourceManager rm) {
     this.rm = rm;
@@ -59,4 +66,59 @@ public class RMWebApp extends WebApp imp
     route("/scheduler", RmController.class, "scheduler");
     route(pajoin("/queue", QUEUE_NAME), RmController.class, "queue");
   }
+
+  @Override
+  public void configureServlets() {
+    setup();
+
+    serve("/").with(RMDispatcher.class);
+    serve("/__stop").with(Dispatcher.class);
+
+    for (String path : super.getServePathSpecs()) {
+      serve(path).with(RMDispatcher.class);
+    }
+
+    configureRSServlets();
+  }
+
+  public void checkIfStandbyRM() {
+    standby = (rm.getRMContext().getHAServiceState() == HAServiceState.STANDBY);
+  }
+
+  public boolean isStandby() {
+    return standby;
+  }
+
+  @Override
+  public String getRedirectPath() {
+    if (standby) {
+      return buildRedirectPath();
+    } else
+      return super.getRedirectPath();
+  }
+
+  private String buildRedirectPath() {
+    // make a copy of the original configuration so not to mutate it. Also use
+    // an YarnConfiguration to force loading of yarn-site.xml.
+    YarnConfiguration yarnConf = new YarnConfiguration(rm.getConfig());
+    String activeRMHAId = RMHAUtils.findActiveRMHAId(yarnConf);
+    String path = "";
+    if (activeRMHAId != null) {
+      yarnConf.set(YarnConfiguration.RM_HA_ID, activeRMHAId);
+
+      InetSocketAddress sock = YarnConfiguration.useHttps(yarnConf)
+          ? yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
+              YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS,
+              YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_PORT)
+          : yarnConf.getSocketAddr(YarnConfiguration.RM_WEBAPP_ADDRESS,
+              YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS,
+              YarnConfiguration.DEFAULT_RM_WEBAPP_PORT);
+
+      path = sock.getHostName() + ":" + Integer.toString(sock.getPort());
+      path = YarnConfiguration.useHttps(yarnConf)
+          ? "https://" + path
+          : "http://" + path;
+    }
+    return path;
+  }
 }



Mime
View raw message