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 b68701b7b2)

Conflicts:
	hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
	hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestQuota.java
This commit is contained in:
Xiaoyu Yao 2015-07-07 13:50:49 -07:00 committed by Vinayakumar B
parent d260478d3a
commit 907abdca73
3 changed files with 29 additions and 5 deletions

View File

@ -362,15 +362,12 @@ Release 2.8.0 - UNRELEASED
HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang) HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang)
<<<<<<< HEAD
=======
HDFS-8711. setSpaceQuota command should print the available storage type HDFS-8711. setSpaceQuota command should print the available storage type
when input storage type is wrong. (Brahma Reddy Battula via xyao) when input storage type is wrong. (Brahma Reddy Battula via xyao)
HDFS-8620. Clean up the checkstyle warinings about ClientProtocol. HDFS-8620. Clean up the checkstyle warinings about ClientProtocol.
(Takanobu Asanuma via wheat9) (Takanobu Asanuma via wheat9)
>>>>>>> c0b8e4e... HDFS-8620. Clean up the checkstyle warinings about ClientProtocol. Contributed by Takanobu Asanuma.
OPTIMIZATIONS OPTIMIZATIONS
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

View File

@ -291,9 +291,15 @@ public class DFSAdmin extends FsShell {
String storageTypeString = String storageTypeString =
StringUtils.popOptionWithArgument("-storageType", parameters); StringUtils.popOptionWithArgument("-storageType", parameters);
if (storageTypeString != null) { if (storageTypeString != null) {
try {
this.type = StorageType.parseStorageType(storageTypeString); 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()]); this.args = parameters.toArray(new String[parameters.size()]);
} }

View File

@ -17,17 +17,21 @@
*/ */
package org.apache.hadoop.hdfs; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.ContentSummary;
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.fs.StorageType;
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
@ -40,6 +44,8 @@ import org.apache.hadoop.security.UserGroupInformation;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import com.google.common.base.Charsets;
/** A class for testing quota-related commands */ /** A class for testing quota-related commands */
public class TestQuota { public class TestQuota {
@ -922,4 +928,19 @@ public class TestQuota {
cluster.shutdown(); 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()));
}
} }