From 0d5b0143cc003e132ce454415e35d55d46311416 Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Mon, 27 Apr 2015 12:23:34 -0700 Subject: [PATCH] HDFS-8205. CommandFormat#parse() should not parse option as value of option. (Contributed by Peter Shi and Xiaoyu Yao) --- .../apache/hadoop/fs/shell/CommandFormat.java | 3 +- .../org/apache/hadoop/fs/shell/TestCount.java | 28 ++++++++++++++ hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 ++ .../apache/hadoop/hdfs/tools/DFSAdmin.java | 4 +- .../src/test/resources/testHDFSConf.xml | 38 +++++++++++++++++++ 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java index 371168d991..0aa3d654f2 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandFormat.java @@ -114,7 +114,8 @@ public void parse(List args) { options.put(opt, Boolean.TRUE); } else if (optionsWithValue.containsKey(opt)) { args.remove(pos); - if (pos < args.size() && (args.size() > minPar)) { + if (pos < args.size() && (args.size() > minPar) + && !args.get(pos).startsWith("-")) { arg = args.get(pos); args.remove(pos); } else { diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java index 22d9a21b97..44fc1e6821 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCount.java @@ -315,6 +315,34 @@ public void processPathWithQuotasBySSDStorageTypesHeader() throws Exception { verifyNoMoreInteractions(out); } + @Test + public void processPathWithQuotasByQTVH() throws Exception { + Path path = new Path("mockfs:/test"); + + when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); + + PrintStream out = mock(PrintStream.class); + + Count count = new Count(); + count.out = out; + + LinkedList options = new LinkedList(); + options.add("-q"); + options.add("-t"); + options.add("-v"); + options.add("-h"); + options.add("dummy"); + count.processOptions(options); + String withStorageTypeHeader = + // <----13---> <-------17------> + " DISK_QUOTA REM_DISK_QUOTA " + + " SSD_QUOTA REM_SSD_QUOTA " + + "ARCHIVE_QUOTA REM_ARCHIVE_QUOTA " + + "PATHNAME"; + verify(out).println(withStorageTypeHeader); + verifyNoMoreInteractions(out); + } + @Test public void processPathWithQuotasByMultipleStorageTypesContent() throws Exception { Path path = new Path("mockfs:/test"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index b7199c7675..00b5db5689 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -618,6 +618,9 @@ Release 2.7.1 - UNRELEASED HDFS-8070. Pre-HDFS-7915 DFSClient cannot use short circuit on post-HDFS-7915 DataNode (cmccabe) + HDFS-8205. CommandFormat#parse() should not parse option as + value of option. (Peter Shi and Xiaoyu Yao via Arpit Agarwal) + Release 2.7.0 - 2015-04-20 INCOMPATIBLE CHANGES 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 d608281aa3..11f2c3281a 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 @@ -221,9 +221,9 @@ private static class ClearSpaceQuotaCommand extends DFSAdminCommand { ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) { super(fs); CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE); + c.addOptionWithValue("storageType"); List parameters = c.parse(args, pos); - String storageTypeString = - StringUtils.popOptionWithArgument("-storageType", parameters); + String storageTypeString = c.getOptValue("storageType"); if (storageTypeString != null) { this.type = StorageType.parseStorageType(storageTypeString); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml index 2d3de1f99b..56713f5521 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testHDFSConf.xml @@ -7721,6 +7721,44 @@ + + setSpaceQuota -storageType: directory with quota by storage type + + -fs NAMENODE -mkdir /ttt + -fs NAMENODE -setSpaceQuota 1m -storageType DISK /ttt + -fs NAMENODE -count -q -t DISK /ttt + + + -fs NAMENODE -rm -r /ttt + + + + RegexpComparator + ( |\t)*1048576( |\t)*1048576 /ttt + + + + + + clrSpaceQuota -storageType: directory quota by storage type + + -fs NAMENODE -mkdir /ttt + -fs NAMENODE -setSpaceQuota 1m -storageType DISK /ttt + -fs NAMENODE -count -q -t DISK /ttt + -fs NAMENODE -clrSpaceQuota -storageType DISK /ttt + -fs NAMENODE -count -q -t DISK /ttt + + + -fs NAMENODE -rm -r /ttt + + + + RegexpComparator + ( |\t)*none( |\t)*inf /ttt + + + + count: directory using relative path with -q option