diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java index 570e442c282..440d480cc90 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java @@ -68,7 +68,7 @@ class SnapshotCommands extends FsCommand { throw new IllegalArgumentException(" is missing."); } if (args.size() > 2) { - throw new IllegalArgumentException("Too many arguements."); + throw new IllegalArgumentException("Too many arguments."); } if (args.size() == 2) { snapshotName = args.removeLast(); @@ -110,7 +110,7 @@ class SnapshotCommands extends FsCommand { @Override protected void processOptions(LinkedList args) throws IOException { if (args.size() != 2) { - throw new IOException("args number not 2: " + args.size()); + throw new IllegalArgumentException("Incorrect number of arguments."); } snapshotName = args.removeLast(); } @@ -150,7 +150,7 @@ class SnapshotCommands extends FsCommand { @Override protected void processOptions(LinkedList args) throws IOException { if (args.size() != 3) { - throw new IOException("args number not 3: " + args.size()); + throw new IllegalArgumentException("Incorrect number of arguments."); } newName = args.removeLast(); oldName = args.removeLast(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index a71ec6b8331..02ce2989160 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -118,6 +118,9 @@ Release 2.2.1 - UNRELEASED IMPROVEMENTS + HDFS-5360. Improvement of usage message of renameSnapshot and + deleteSnapshot. (Shinichi Yamashita via wang) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java index 2408b4efb8f..442cc63aaee 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java @@ -23,12 +23,15 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintStream; import java.security.PrivilegedAction; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSTestUtil; @@ -921,4 +924,29 @@ public class TestSnapshotDeletion { subFile1Status = hdfs.getFileStatus(subFile1SCopy); assertEquals(REPLICATION_1, subFile1Status.getReplication()); } + + @Test + public void testDeleteSnapshotCommandWithIllegalArguments() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream psOut = new PrintStream(out); + System.setOut(psOut); + System.setErr(psOut); + FsShell shell = new FsShell(); + shell.setConf(conf); + + String[] argv1 = {"-deleteSnapshot", "/tmp"}; + int val = shell.run(argv1); + assertTrue(val == -1); + assertTrue(out.toString().contains( + argv1[0] + ": Incorrect number of arguments.")); + out.reset(); + + String[] argv2 = {"-deleteSnapshot", "/tmp", "s1", "s2"}; + val = shell.run(argv2); + assertTrue(val == -1); + assertTrue(out.toString().contains( + argv2[0] + ": Incorrect number of arguments.")); + psOut.close(); + out.close(); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java index 386563bea1f..58fa1ffc407 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java @@ -22,10 +22,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.DFSTestUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; @@ -226,4 +229,29 @@ public class TestSnapshotRename { } } } + + @Test + public void testRenameSnapshotCommandWithIllegalArguments() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintStream psOut = new PrintStream(out); + System.setOut(psOut); + System.setErr(psOut); + FsShell shell = new FsShell(); + shell.setConf(conf); + + String[] argv1 = {"-renameSnapshot", "/tmp", "s1"}; + int val = shell.run(argv1); + assertTrue(val == -1); + assertTrue(out.toString().contains( + argv1[0] + ": Incorrect number of arguments.")); + out.reset(); + + String[] argv2 = {"-renameSnapshot", "/tmp", "s1", "s2", "s3"}; + val = shell.run(argv2); + assertTrue(val == -1); + assertTrue(out.toString().contains( + argv2[0] + ": Incorrect number of arguments.")); + psOut.close(); + out.close(); + } }