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.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 @@ * 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 String getCanonicalServiceName() { 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.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 void setSafeMode(String[] argv, int idx) throws IOException { } 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 void testDatanodeThreshold() throws IOException { 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()); + } }