hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ayushsax...@apache.org
Subject [hadoop] branch trunk updated: HDFS-14711. RBF: RBFMetrics throws NullPointerException if stateStore disabled. Contributed by Chen Zhang.
Date Sun, 01 Sep 2019 07:23:38 GMT
This is an automated email from the ASF dual-hosted git repository.

ayushsaxena pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 18d74fe  HDFS-14711. RBF: RBFMetrics throws NullPointerException if stateStore disabled.
Contributed by Chen Zhang.
18d74fe is described below

commit 18d74fe41c0982dc1540367805b0c3d0d4fc29d3
Author: Ayush Saxena <ayushsaxena@apache.org>
AuthorDate: Sun Sep 1 12:41:17 2019 +0530

    HDFS-14711. RBF: RBFMetrics throws NullPointerException if stateStore disabled. Contributed
by Chen Zhang.
---
 .../hdfs/server/federation/metrics/RBFMetrics.java | 25 +++++++++++++++++++++-
 .../server/federation/router/TestRouterRpc.java    | 22 +++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/RBFMetrics.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/RBFMetrics.java
index 4b33f80..86599c7 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/RBFMetrics.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/metrics/RBFMetrics.java
@@ -31,6 +31,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
@@ -183,6 +184,10 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
   @Override
   public String getNamenodes() {
     final Map<String, Map<String, Object>> info = new LinkedHashMap<>();
+    if (membershipStore == null) {
+      return "{}";
+    }
+
     try {
       // Get the values from the store
       GetNamenodeRegistrationsRequest request =
@@ -252,6 +257,9 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
   @Override
   public String getMountTable() {
     final List<Map<String, Object>> info = new LinkedList<>();
+    if (mountTableStore == null) {
+      return "[]";
+    }
 
     try {
       // Get all the mount points in order
@@ -302,6 +310,9 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
   @Override
   public String getRouters() {
     final Map<String, Map<String, Object>> info = new LinkedHashMap<>();
+    if (routerStore == null) {
+      return "{}";
+    }
     try {
       // Get all the routers in order
       GetRouterRegistrationsRequest request =
@@ -391,6 +402,9 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
 
   @Override
   public int getNumNamenodes() {
+    if (membershipStore == null) {
+      return 0;
+    }
     try {
       GetNamenodeRegistrationsRequest request =
           GetNamenodeRegistrationsRequest.newInstance();
@@ -406,6 +420,9 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
 
   @Override
   public int getNumExpiredNamenodes() {
+    if (membershipStore == null) {
+      return 0;
+    }
     try {
       GetNamenodeRegistrationsRequest request =
           GetNamenodeRegistrationsRequest.newInstance();
@@ -670,6 +687,9 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
    */
   private Collection<String> getNamespaceInfo(
       Function<FederationNamespaceInfo, String> f) throws IOException {
+    if (membershipStore == null) {
+      return new HashSet<>();
+    }
     GetNamespaceInfoRequest request = GetNamespaceInfoRequest.newInstance();
     GetNamespaceInfoResponse response =
         membershipStore.getNamespaceInfo(request);
@@ -719,8 +739,11 @@ public class RBFMetrics implements RouterMBean, FederationMBean {
    */
   private List<MembershipState> getActiveNamenodeRegistrations()
       throws IOException {
-
     List<MembershipState> resultList = new ArrayList<>();
+    if (membershipStore == null) {
+      return resultList;
+    }
+
     GetNamespaceInfoRequest request = GetNamespaceInfoRequest.newInstance();
     GetNamespaceInfoResponse response =
         membershipStore.getNamespaceInfo(request);
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
index 8ec87cb..3767d93 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterRpc.java
@@ -101,6 +101,7 @@ import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterConte
 import org.apache.hadoop.hdfs.server.federation.MockResolver;
 import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
 import org.apache.hadoop.hdfs.server.federation.metrics.NamenodeBeanMetrics;
+import org.apache.hadoop.hdfs.server.federation.metrics.RBFMetrics;
 import org.apache.hadoop.hdfs.server.federation.resolver.FileSubclusterResolver;
 import org.apache.hadoop.hdfs.server.namenode.FSDirectory;
 import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
@@ -1619,6 +1620,27 @@ public class TestRouterRpc {
   }
 
   @Test
+  public void testRBFMetricsMethodsRelayOnStateStore() {
+    assertNull(router.getRouter().getStateStore());
+
+    RBFMetrics metrics = router.getRouter().getMetrics();
+    assertEquals("{}", metrics.getNamenodes());
+    assertEquals("[]", metrics.getMountTable());
+    assertEquals("{}", metrics.getRouters());
+    assertEquals(0, metrics.getNumNamenodes());
+    assertEquals(0, metrics.getNumExpiredNamenodes());
+
+    // These 2 methods relays on {@link RBFMetrics#getNamespaceInfo()}
+    assertEquals("[]", metrics.getClusterId());
+    assertEquals("[]", metrics.getBlockPoolId());
+
+    // These methods relays on
+    // {@link RBFMetrics#getActiveNamenodeRegistration()}
+    assertEquals("{}", metrics.getNameservices());
+    assertEquals(0, metrics.getNumLiveNodes());
+  }
+
+  @Test
   public void testCacheAdmin() throws Exception {
     DistributedFileSystem routerDFS = (DistributedFileSystem) routerFS;
     // Verify cache directive commands.


---------------------------------------------------------------------
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