HDFS-8711. setSpaceQuota command should print the available storage type when input storage type is wrong. Contributed by Brahma Reddy Battula.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/15a136dd Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/15a136dd Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/15a136dd Branch: refs/heads/YARN-2928 Commit: 15a136ddc8b9990fd72330519254006a0331d01e Parents: 68b59eb Author: Xiaoyu Yao <[email protected]> Authored: Tue Jul 7 13:50:49 2015 -0700 Committer: Zhijie Shen <[email protected]> Committed: Mon Jul 13 11:43:27 2015 -0700 ---------------------------------------------------------------------- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../org/apache/hadoop/hdfs/tools/DFSAdmin.java | 10 ++++++++-- .../java/org/apache/hadoop/hdfs/TestQuota.java | 21 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/15a136dd/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 7294cab..1e1e6bb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -701,6 +701,9 @@ Release 2.8.0 - UNRELEASED HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang) + HDFS-8711. setSpaceQuota command should print the available storage type + when input storage type is wrong. (Brahma Reddy Battula via xyao) + OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than http://git-wip-us.apache.org/repos/asf/hadoop/blob/15a136dd/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java ---------------------------------------------------------------------- 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 4640bb3..014637b 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 @@ -290,9 +290,15 @@ public class DFSAdmin extends FsShell { String storageTypeString = StringUtils.popOptionWithArgument("-storageType", parameters); if (storageTypeString != null) { - this.type = StorageType.parseStorageType(storageTypeString); + try { + this.type = StorageType.parseStorageType(storageTypeString); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Storage type " + + storageTypeString + + " is not available. Available storage types are " + + StorageType.getTypesSupportingQuota()); + } } - this.args = parameters.toArray(new String[parameters.size()]); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/15a136dd/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java index 4541e69..e339049 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java @@ -17,18 +17,22 @@ */ package org.apache.hadoop.hdfs; +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY; import static org.junit.Assert.assertEquals; 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.OutputStream; +import java.io.PrintStream; import java.security.PrivilegedExceptionAction; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException; @@ -41,6 +45,8 @@ import org.apache.hadoop.security.UserGroupInformation; import org.junit.Assert; import org.junit.Test; +import com.google.common.base.Charsets; + /** A class for testing quota-related commands */ public class TestQuota { @@ -986,4 +992,19 @@ public class TestQuota { cluster.shutdown(); } } + + @Test + public void testSetSpaceQuotaWhenStorageTypeIsWrong() throws Exception { + Configuration conf = new HdfsConfiguration(); + conf.set(FS_DEFAULT_NAME_KEY, "hdfs://127.0.0.1:8020"); + DFSAdmin admin = new DFSAdmin(conf); + ByteArrayOutputStream err = new ByteArrayOutputStream(); + System.setErr(new PrintStream(err)); + String[] args = { "-setSpaceQuota", "100", "-storageType", "COLD", + "/testDir" }; + admin.run(args); + String errOutput = new String(err.toByteArray(), Charsets.UTF_8); + assertTrue(errOutput.contains(StorageType.getTypesSupportingQuota() + .toString())); + } }
