HDFS-5331 make SnapshotDiff.java to a o.a.h.util.Tool interface implementation. Contributed by Vinay.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1533917 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uma Maheswara Rao G 2013-10-20 15:23:10 +00:00
parent 7f97fd1319
commit 7fd9148800
2 changed files with 19 additions and 7 deletions

View File

@ -380,6 +380,9 @@ Release 2.2.1 - UNRELEASED
HDFS-5360. Improvement of usage message of renameSnapshot and HDFS-5360. Improvement of usage message of renameSnapshot and
deleteSnapshot. (Shinichi Yamashita via wang) deleteSnapshot. (Shinichi Yamashita via wang)
HDFS-5331. make SnapshotDiff.java to a o.a.h.util.Tool interface implementation.
(Vinayakumar B via umamahesh)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -20,12 +20,14 @@ package org.apache.hadoop.hdfs.tools.snapshot;
import java.io.IOException; import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience; 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.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport; import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
/** /**
* A tool used to get the difference report between two snapshots, or between * A tool used to get the difference report between two snapshots, or between
@ -38,7 +40,7 @@ import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
* </pre> * </pre>
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public class SnapshotDiff { public class SnapshotDiff extends Configured implements Tool {
private static String getSnapshotName(String name) { private static String getSnapshotName(String name) {
if (Path.CUR_DIR.equals(name)) { // current directory if (Path.CUR_DIR.equals(name)) { // current directory
return ""; return "";
@ -57,7 +59,8 @@ public class SnapshotDiff {
return name.substring(i + HdfsConstants.DOT_SNAPSHOT_DIR.length() + 1); return name.substring(i + HdfsConstants.DOT_SNAPSHOT_DIR.length() + 1);
} }
public static void main(String[] argv) throws IOException { @Override
public int run(String[] argv) throws Exception {
String description = "SnapshotDiff <snapshotDir> <from> <to>:\n" + String description = "SnapshotDiff <snapshotDir> <from> <to>:\n" +
"\tGet the difference between two snapshots, \n" + "\tGet the difference between two snapshots, \n" +
"\tor between a snapshot and the current tree of a directory.\n" + "\tor between a snapshot and the current tree of a directory.\n" +
@ -67,15 +70,14 @@ public class SnapshotDiff {
if(argv.length != 3) { if(argv.length != 3) {
System.err.println("Usage: \n" + description); System.err.println("Usage: \n" + description);
System.exit(1); return 1;
} }
Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(getConf());
FileSystem fs = FileSystem.get(conf);
if (! (fs instanceof DistributedFileSystem)) { if (! (fs instanceof DistributedFileSystem)) {
System.err.println( System.err.println(
"SnapshotDiff can only be used in DistributedFileSystem"); "SnapshotDiff can only be used in DistributedFileSystem");
System.exit(1); return 1;
} }
DistributedFileSystem dfs = (DistributedFileSystem) fs; DistributedFileSystem dfs = (DistributedFileSystem) fs;
@ -89,7 +91,14 @@ public class SnapshotDiff {
} catch (IOException e) { } catch (IOException e) {
String[] content = e.getLocalizedMessage().split("\n"); String[] content = e.getLocalizedMessage().split("\n");
System.err.println("snapshotDiff: " + content[0]); System.err.println("snapshotDiff: " + content[0]);
return 1;
} }
return 0;
}
public static void main(String[] argv) throws Exception {
int rc = ToolRunner.run(new SnapshotDiff(), argv);
System.exit(rc);
} }
} }