From 907abdca73809b80c473a6fb70f4d9c6f83b7423 Mon Sep 17 00:00:00 2001 From: Xiaoyu Yao Date: Tue, 7 Jul 2015 13:50:49 -0700 Subject: [PATCH] HDFS-8711. setSpaceQuota command should print the available storage type when input storage type is wrong. Contributed by Brahma Reddy Battula. (cherry picked from commit b68701b7b2a9597b4183e0ba19b1551680d543a1) Conflicts: hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 --- .../apache/hadoop/hdfs/tools/DFSAdmin.java | 10 +++++++-- .../org/apache/hadoop/hdfs/TestQuota.java | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index e12c156a1e0..ac5887f0e0e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -362,15 +362,12 @@ Release 2.8.0 - UNRELEASED HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang) -<<<<<<< HEAD -======= HDFS-8711. setSpaceQuota command should print the available storage type when input storage type is wrong. (Brahma Reddy Battula via xyao) HDFS-8620. Clean up the checkstyle warinings about ClientProtocol. (Takanobu Asanuma via wheat9) ->>>>>>> c0b8e4e... HDFS-8620. Clean up the checkstyle warinings about ClientProtocol. Contributed by Takanobu Asanuma. OPTIMIZATIONS HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than 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 9305c5d7714..6f7d8bff537 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 @@ -291,9 +291,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()]); } 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 bb182d110d0..f41893bc460 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,17 +17,21 @@ */ 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 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.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.HdfsConstants; @@ -40,6 +44,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 { @@ -922,4 +928,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())); + } }