hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From inigo...@apache.org
Subject [hadoop] 23/45: HDFS-14191. RBF: Remove hard coded router status from FederationMetrics. Contributed by Ranith Sardar.
Date Sun, 03 Mar 2019 18:37:02 GMT
This is an automated email from the ASF dual-hosted git repository.

inigoiri pushed a commit to branch HDFS-13891
in repository https://gitbox.apache.org/repos/asf/hadoop.git

commit 8724b68c04881fa9e23a3bd7539c315e801d6d7e
Author: Surendra Singh Lilhore <surendralilhore@apache.org>
AuthorDate: Thu Jan 10 16:18:23 2019 +0530

    HDFS-14191. RBF: Remove hard coded router status from FederationMetrics. Contributed by
Ranith Sardar.
---
 .../federation/metrics/FederationMetrics.java      |  2 +-
 .../federation/metrics/NamenodeBeanMetrics.java    | 25 +++++++++++++++-
 .../hdfs/server/federation/router/Router.java      |  7 +++++
 .../src/main/webapps/router/federationhealth.js    |  2 +-
 .../federation/router/TestRouterAdminCLI.java      | 33 +++++++++++++++++++++-
 5 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/FederationMetrics.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/FederationMetrics.java
index b3fe6cc..c66910c 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/FederationMetrics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/FederationMetrics.java
@@ -582,7 +582,7 @@ public class FederationMetrics implements FederationMBean {
 
   @Override
   public String getRouterStatus() {
-    return "RUNNING";
+    return this.router.getRouterState().toString();
   }
 
   /**
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java
index 5e95606..963c6c2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/NamenodeBeanMetrics.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamespaceInfo
 import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys;
 import org.apache.hadoop.hdfs.server.federation.router.Router;
 import org.apache.hadoop.hdfs.server.federation.router.RouterRpcServer;
+import org.apache.hadoop.hdfs.server.federation.router.RouterServiceState;
 import org.apache.hadoop.hdfs.server.federation.router.SubClusterTimeoutException;
 import org.apache.hadoop.hdfs.server.federation.store.MembershipStore;
 import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
@@ -232,7 +233,29 @@ public class NamenodeBeanMetrics
 
   @Override
   public String getSafemode() {
-    // We assume that the global federated view is never in safe mode
+    try {
+      if (!getRouter().isRouterState(RouterServiceState.SAFEMODE)) {
+        return "Safe mode is ON. " + this.getSafeModeTip();
+      }
+    } catch (IOException e) {
+      return "Failed to get safemode status. Please check router"
+          + "log for more detail.";
+    }
+    return "";
+  }
+
+  private String getSafeModeTip() throws IOException {
+    Router rt = getRouter();
+    String cmd = "Use \"hdfs dfsrouteradmin -safemode leave\" "
+        + "to turn safe mode off.";
+    if (rt.isRouterState(RouterServiceState.INITIALIZING)
+        || rt.isRouterState(RouterServiceState.UNINITIALIZED)) {
+      return "Router is in" + rt.getRouterState()
+          + "mode, the router will immediately return to "
+          + "normal mode after some time. " + cmd;
+    } else if (rt.isRouterState(RouterServiceState.SAFEMODE)) {
+      return "It was turned on manually. " + cmd;
+    }
     return "";
   }
 
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java
index 6a7437f..0257162 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Router.java
@@ -585,6 +585,13 @@ public class Router extends CompositeService {
     return this.state;
   }
 
+  /**
+   * Compare router state.
+   */
+  public boolean isRouterState(RouterServiceState routerState) {
+    return routerState.equals(this.state);
+  }
+
   /////////////////////////////////////////////////////////
   // Submodule getters
   /////////////////////////////////////////////////////////
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.js
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.js
index bb8e057..5da7b07 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.js
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.js
@@ -35,7 +35,7 @@
     var BEANS = [
       {"name": "federation",  "url": "/jmx?qry=Hadoop:service=Router,name=FederationState"},
       {"name": "routerstat",  "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus"},
-      {"name": "router",      "url": "/jmx?qrt=Hadoop:service=NameNode,name=NameNodeInfo"},
+      {"name": "router",      "url": "/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo"},
       {"name": "mem",         "url": "/jmx?qry=java.lang:type=Memory"}
     ];
 
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
index 445022b..ab733dd 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
 import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext;
 import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
 import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
+import org.apache.hadoop.hdfs.server.federation.metrics.FederationMetrics;
 import org.apache.hadoop.hdfs.server.federation.resolver.ActiveNamenodeResolver;
 import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager;
 import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
@@ -66,6 +67,7 @@ public class TestRouterAdminCLI {
 
   private static RouterAdmin admin;
   private static RouterClient client;
+  private static Router router;
 
   private static final String TEST_USER = "test-user";
 
@@ -80,6 +82,7 @@ public class TestRouterAdminCLI {
     // Build and start a router with State Store + admin + RPC
     Configuration conf = new RouterConfigBuilder()
         .stateStore()
+        .metrics()
         .admin()
         .rpc()
         .safemode()
@@ -90,7 +93,7 @@ public class TestRouterAdminCLI {
     cluster.startRouters();
 
     routerContext = cluster.getRandomRouter();
-    Router router = routerContext.getRouter();
+    router = routerContext.getRouter();
     stateStore = router.getStateStore();
 
     Configuration routerConf = new Configuration();
@@ -721,6 +724,34 @@ public class TestRouterAdminCLI {
   }
 
   @Test
+  public void testSafeModeStatus() throws Exception {
+    // ensure the Router become RUNNING state
+    waitState(RouterServiceState.RUNNING);
+    assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
+    assertEquals(0,
+        ToolRunner.run(admin, new String[] {"-safemode", "enter" }));
+
+    FederationMetrics metrics = router.getMetrics();
+    String jsonString = metrics.getRouterStatus();
+
+    // verify state using FederationMetrics
+    assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString);
+    assertTrue(routerContext.getRouter().getSafemodeService().isInSafeMode());
+
+    System.setOut(new PrintStream(out));
+    assertEquals(0,
+        ToolRunner.run(admin, new String[] {"-safemode", "leave" }));
+    jsonString = metrics.getRouterStatus();
+    // verify state
+    assertEquals(RouterServiceState.RUNNING.toString(), jsonString);
+    assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode());
+
+    out.reset();
+    assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "get" }));
+    assertTrue(out.toString().contains("false"));
+  }
+
+  @Test
   public void testCreateInvalidEntry() throws Exception {
     String[] argv = new String[] {
         "-add", "test-createInvalidEntry", "ns0", "/createInvalidEntry"};


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message