From 7bbe01a1960f1f4168b30545d448ff58ff557de4 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Sat, 2 Mar 2019 17:17:34 -0800 Subject: [PATCH] HDFS-14259. RBF: Fix safemode message for Router. Contributed by Ranith Sadar. --- .../server/federation/metrics/NamenodeBeanMetrics.java | 2 +- .../hdfs/server/federation/router/TestRouterAdminCLI.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 b08d9608c0..9687af0236 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 @@ -234,7 +234,7 @@ public long getProvidedCapacity() { @Override public String getSafemode() { try { - if (!getRouter().isRouterState(RouterServiceState.SAFEMODE)) { + if (getRouter().isRouterState(RouterServiceState.SAFEMODE)) { return "Safe mode is ON. " + this.getSafeModeTip(); } } catch (IOException e) { 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 9f53dd4458..486d4a09b7 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 @@ -747,6 +747,9 @@ public void testSafeModeStatus() throws Exception { FederationMetrics metrics = router.getMetrics(); String jsonString = metrics.getRouterStatus(); + String result = router.getNamenodeMetrics().getSafemode(); + assertTrue("Wrong safe mode message: " + result, + result.startsWith("Safe mode is ON.")); // verify state using FederationMetrics assertEquals(RouterServiceState.SAFEMODE.toString(), jsonString); @@ -756,6 +759,9 @@ public void testSafeModeStatus() throws Exception { assertEquals(0, ToolRunner.run(admin, new String[] {"-safemode", "leave" })); jsonString = metrics.getRouterStatus(); + result = router.getNamenodeMetrics().getSafemode(); + assertEquals("Wrong safe mode message: " + result, "", result); + // verify state assertEquals(RouterServiceState.RUNNING.toString(), jsonString); assertFalse(routerContext.getRouter().getSafemodeService().isInSafeMode()); @@ -1153,4 +1159,4 @@ public void testGetDestination() throws Exception { argv = new String[] {"-getDestination /file1.txt /file2.txt"}; assertEquals(-1, ToolRunner.run(admin, argv)); } -} \ No newline at end of file +}