From 28c307519ad9f3519d10627bd4f690c7959cf051 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Mon, 26 Mar 2012 22:19:30 +0000 Subject: [PATCH] svn merge -c 1305632 from trunk for HDFS-2413. Add an API DistributedFileSystem.isInSafeMode() and change DistributedFileSystem to @InterfaceAudience.LimitedPrivate. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1305633 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 4 ++++ .../apache/hadoop/hdfs/DistributedFileSystem.java | 15 +++++++++++++-- .../org/apache/hadoop/hdfs/tools/DFSAdmin.java | 4 ++-- .../java/org/apache/hadoop/hdfs/TestSafeMode.java | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index d36bff04273..41f14b2049e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -58,6 +58,10 @@ Release 0.23.3 - UNRELEASED HDFS-2941. Add an administrative command to download a copy of the fsimage from the NN. (atm) + HDFS-2413. Add an API DistributedFileSystem.isInSafeMode() and change + DistributedFileSystem to @InterfaceAudience.LimitedPrivate. + (harsh via szetszwo) + IMPROVEMENTS HDFS-2018. Move all journal stream management code into one place. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java index 0e8e5adbf5c..7fe6a40a8af 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java @@ -51,6 +51,7 @@ import org.apache.hadoop.hdfs.protocol.DirectoryListing; import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; +import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.protocol.HdfsConstants.UpgradeAction; import org.apache.hadoop.hdfs.protocol.HdfsFileStatus; import org.apache.hadoop.hdfs.protocol.HdfsLocatedFileStatus; @@ -71,8 +72,8 @@ import org.apache.hadoop.util.Progressable; * DistributedFileSystem. * *****************************************************************/ -@InterfaceAudience.Private -@InterfaceStability.Evolving +@InterfaceAudience.LimitedPrivate({ "MapReduce", "HBase" }) +@InterfaceStability.Unstable public class DistributedFileSystem extends FileSystem { private Path workingDir; private URI uri; @@ -854,4 +855,14 @@ public class DistributedFileSystem extends FileSystem { return super.getCanonicalServiceName(); } } + + /** + * Utility function that returns if the NameNode is in safemode or not. + * + * @return true if NameNode is in safemode, false otherwise. + * @throws IOException when there is an issue communicating with the NameNode + */ + public boolean isInSafeMode() throws IOException { + return setSafeMode(SafeModeAction.SAFEMODE_GET); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java index dccd2f459a9..9c49654c471 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java @@ -59,7 +59,7 @@ import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.ToolRunner; /** - * This class provides some DFS administrative access. + * This class provides some DFS administrative access shell commands. */ @InterfaceAudience.Private public class DFSAdmin extends FsShell { @@ -396,7 +396,7 @@ public class DFSAdmin extends FsShell { } catch (java.lang.InterruptedException e) { throw new IOException("Wait Interrupted"); } - inSafeMode = dfs.setSafeMode(action); + inSafeMode = dfs.isInSafeMode(); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java index 50a26f9eaf1..3c25a61e725 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSafeMode.java @@ -357,4 +357,19 @@ public class TestSafeMode { assertEquals("", cluster.getNamesystem().getSafemode()); } + /* + * Tests some utility methods that surround the SafeMode's state. + * @throws IOException when there's an issue connecting to the test DFS. + */ + public void testSafeModeUtils() throws IOException { + dfs = (DistributedFileSystem)cluster.getFileSystem(); + + // Enter safemode. + dfs.setSafeMode(SafeModeAction.SAFEMODE_ENTER); + assertTrue("State was expected to be in safemode.", dfs.isInSafeMode()); + + // Exit safemode. + dfs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE); + assertFalse("State was expected to be out of safemode.", dfs.isInSafeMode()); + } }