From eb53d6b9679f1ce483201b85c48728f5e2ffee01 Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Wed, 8 Apr 2015 15:59:55 -0700 Subject: [PATCH] Revert HDFS-7808. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 --- .../apache/hadoop/hdfs/tools/DFSHAAdmin.java | 20 +++++++++++++++++++ .../hadoop/hdfs/tools/TestDFSHAAdmin.java | 20 +++++++++++++++++++ .../hdfs/tools/TestDFSHAAdminMiniCluster.java | 3 +++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 3fe17cdb5aa..8f0d80d6069 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -793,9 +793,6 @@ Release 2.7.0 - UNRELEASED HDFS-6662. WebHDFS cannot open a file if its path contains "%". (Gerson Carlos via wheat9) - HDFS-7808. Remove obsolete -ns options in in DFSHAAdmin.java. - (Arshad Mohammad via wheat9) - HDFS-7788. Post-2.6 namenode may not start up with an image containing inodes created with an old release. (Rushabh Shah via kihwal) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java index 6b6fb302f86..e9c611d8aa3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSHAAdmin.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hdfs.tools; import java.io.PrintStream; +import java.util.Arrays; import java.util.Collection; import org.apache.commons.logging.Log; @@ -97,6 +98,25 @@ public class DFSHAAdmin extends HAAdmin { printUsage(errOut); return -1; } + + int i = 0; + String cmd = argv[i++]; + + if ("-ns".equals(cmd)) { + if (i == argv.length) { + errOut.println("Missing nameservice ID"); + printUsage(errOut); + return -1; + } + nameserviceId = argv[i++]; + if (i >= argv.length) { + errOut.println("Missing command"); + printUsage(errOut); + return -1; + } + argv = Arrays.copyOfRange(argv, i, argv.length); + } + return super.runCmd(argv); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java index 8ecc71a86cc..33da4d4946f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdmin.java @@ -146,6 +146,17 @@ public class TestDFSHAAdmin { } } + @Test + public void testNameserviceOption() throws Exception { + assertEquals(-1, runTool("-ns")); + assertOutputContains("Missing nameservice ID"); + assertEquals(-1, runTool("-ns", "ns1")); + assertOutputContains("Missing command"); + // "ns1" isn't defined but we check this lazily and help doesn't use the ns + assertEquals(0, runTool("-ns", "ns1", "-help", "transitionToActive")); + assertOutputContains("Transitions the service into Active"); + } + @Test public void testNamenodeResolution() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); @@ -267,6 +278,15 @@ public class TestDFSHAAdmin { assertEquals(0, runTool("-failover", "nn1", "nn2")); } + @Test + public void testFailoverWithFencerAndNameservice() throws Exception { + Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); + HdfsConfiguration conf = getHAConf(); + conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand()); + tool.setConf(conf); + assertEquals(0, runTool("-ns", "ns1", "-failover", "nn1", "nn2")); + } + @Test public void testFailoverWithFencerConfiguredAndForce() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java index 904727937c8..2910004f943 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSHAAdminMiniCluster.java @@ -157,6 +157,9 @@ public class TestDFSHAAdminMiniCluster { assertEquals(0, runTool("-failover", "nn1", "nn2")); assertEquals(0, runTool("-failover", "nn2", "nn1")); + // Test failover with fencer and nameservice + assertEquals(0, runTool("-ns", "minidfs-ns", "-failover", "nn2", "nn1")); + // Fencer has not run yet, since none of the above required fencing assertEquals("", Files.toString(tmpFile, Charsets.UTF_8));