HDFS-8711. setSpaceQuota command should print the available storage type when input storage type is wrong. Contributed by Brahma Reddy Battula.

This commit is contained in:
Xiaoyu Yao 2015-07-07 13:50:49 -07:00
parent 3dc92e84c2
commit b68701b7b2
3 changed files with 32 additions and 2 deletions

View File

@ -701,6 +701,9 @@ Release 2.8.0 - UNRELEASED
HDFS-8709. Clarify automatic sync in FSEditLog#logEdit. (wang) 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 OPTIMIZATIONS
HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than HDFS-8026. Trace FSOutputSummer#writeChecksumChunks rather than

View File

@ -290,9 +290,15 @@ private static class SetSpaceQuotaCommand extends DFSAdminCommand {
String storageTypeString = String storageTypeString =
StringUtils.popOptionWithArgument("-storageType", parameters); StringUtils.popOptionWithArgument("-storageType", parameters);
if (storageTypeString != null) { 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()]); this.args = parameters.toArray(new String[parameters.size()]);
} }

View File

@ -17,18 +17,22 @@
*/ */
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 static org.junit.Assert.fail; import static org.junit.Assert.fail;
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.protocol.DSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.DSQuotaExceededException;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException; import org.apache.hadoop.hdfs.protocol.NSQuotaExceededException;
@ -41,6 +45,8 @@
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 {
@ -986,4 +992,19 @@ public void testMultipleFilesSmallerThanOneBlock() throws Exception {
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()));
}
} }