From 7d86f491099e45ba22149c553c74829019437917 Mon Sep 17 00:00:00 2001 From: Uma Maheswara Rao G Date: Sat, 2 Nov 2013 09:07:59 +0000 Subject: [PATCH] Merge HDFS-5344. Make LsSnapshottableDir as Tool interface implementation. Contributed by Sathish. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1538158 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 2 ++ .../tools/snapshot/LsSnapshottableDir.java | 22 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 37b7fedd1e1..da39fa5c1d0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -155,6 +155,8 @@ Release 2.2.1 - UNRELEASED report to a configurable value. (Aaron T. Myers via Colin Patrick McCabe) + HDFS-5344. Make LsSnapshottableDir as Tool interface implementation. (Sathish via umamahesh) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/snapshot/LsSnapshottableDir.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/snapshot/LsSnapshottableDir.java index d7621794391..b2b9ce19376 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/snapshot/LsSnapshottableDir.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/snapshot/LsSnapshottableDir.java @@ -21,9 +21,12 @@ import java.io.IOException; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; /** * A tool used to list all snapshottable directories that are owned by the @@ -31,23 +34,23 @@ import org.apache.hadoop.hdfs.protocol.SnapshottableDirectoryStatus; * is a super user. */ @InterfaceAudience.Private -public class LsSnapshottableDir { - public static void main(String[] argv) throws IOException { +public class LsSnapshottableDir extends Configured implements Tool { + @Override + public int run(String[] argv) throws Exception { String description = "LsSnapshottableDir: \n" + "\tGet the list of snapshottable directories that are owned by the current user.\n" + "\tReturn all the snapshottable directories if the current user is a super user.\n"; if(argv.length != 0) { System.err.println("Usage: \n" + description); - System.exit(1); + return 1; } - Configuration conf = new Configuration(); - FileSystem fs = FileSystem.get(conf); + FileSystem fs = FileSystem.get(getConf()); if (! (fs instanceof DistributedFileSystem)) { System.err.println( "LsSnapshottableDir can only be used in DistributedFileSystem"); - System.exit(1); + return 1; } DistributedFileSystem dfs = (DistributedFileSystem) fs; @@ -57,7 +60,12 @@ public class LsSnapshottableDir { } catch (IOException e) { String[] content = e.getLocalizedMessage().split("\n"); System.err.println("lsSnapshottableDir: " + content[0]); + return 1; } + return 0; + } + public static void main(String[] argv) throws Exception { + int rc = ToolRunner.run(new LsSnapshottableDir(), argv); + System.exit(rc); } - }