From 2fb3d51edb1083d4bbc1c7379fa18ee069a47bc6 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Sun, 22 Nov 2020 23:55:38 +0530 Subject: [PATCH 1/2] HDDS-4492. CLI flag --quota should default to 'spaceQuota' to preserve backward compatibility. --- .../hadoop/ozone/shell/TestOzoneShellHA.java | 42 +++++++++++++++++++ .../ozone/shell/SetSpaceQuotaOptions.java | 8 +++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java index 513049d3a441..830a3d652f99 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneShellHA.java @@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; import java.util.List; @@ -36,6 +37,7 @@ import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl; import org.apache.hadoop.ozone.OmUtils; import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.client.ObjectStore; import org.apache.hadoop.ozone.om.OMConfigKeys; import org.apache.hadoop.ozone.om.OzoneManager; import org.apache.hadoop.test.GenericTestUtils; @@ -48,6 +50,8 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; + +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; @@ -525,4 +529,42 @@ public void testDeleteToTrashOrSkipTrash() throws Exception { } } + @Test + public void testShQuota() throws IOException { + ObjectStore objectStore = cluster.getClient().getObjectStore(); + try { + // Test --quota option. + + String[] args = + new String[] {"volume", "create", "vol1", "--quota", "100BYTES"}; + execute(ozoneShell, args); + assertEquals(100, objectStore.getVolume("vol1").getQuotaInBytes()); + out.reset(); + + args = + new String[] {"bucket", "create", "vol1/buck1", "--quota", "10BYTES"}; + execute(ozoneShell, args); + assertEquals(10, + objectStore.getVolume("vol1").getBucket("buck1").getQuotaInBytes()); + + // Test --space-quota option. + + args = new String[] {"volume", "create", "vol2", "--space-quota", + "100BYTES"}; + execute(ozoneShell, args); + assertEquals(100, objectStore.getVolume("vol2").getQuotaInBytes()); + out.reset(); + + args = new String[] {"bucket", "create", "vol2/buck2", "--space-quota", + "10BYTES"}; + execute(ozoneShell, args); + assertEquals(10, + objectStore.getVolume("vol2").getBucket("buck2").getQuotaInBytes()); + } finally { + objectStore.getVolume("vol1").deleteBucket("buck1"); + objectStore.deleteVolume("vol1"); + objectStore.getVolume("vol2").deleteBucket("buck2"); + objectStore.deleteVolume("vol2"); + } + } } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java index 364efc5fb406..daa92028f372 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java @@ -26,6 +26,7 @@ public class SetSpaceQuotaOptions { @CommandLine.Option(names = {"--space-quota"}, description = "The maximum space quota can be used (eg. 1GB)") + private String quotaInBytes; @CommandLine.Option(names = {"--count-quota"}, @@ -33,8 +34,13 @@ public class SetSpaceQuotaOptions { "buckets, and for buckets represents the number of keys (eg. 5)") private long quotaInCounts; + // Hidden option, added for backward compatibility. + @CommandLine.Option(names = {"--quota"}, hidden = true, + description = "Deprecated use --space-quota") + private String quotaInBytesDep; + public String getQuotaInBytes() { - return quotaInBytes; + return quotaInBytes != null ? quotaInBytes : quotaInBytesDep; } public long getQuotaInCounts() { From 703098e41d2a5abec581e5319da869c2d488e9fc Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Tue, 24 Nov 2020 16:28:55 +0530 Subject: [PATCH 2/2] Add to --quota to names. --- .../hadoop/ozone/shell/SetSpaceQuotaOptions.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java index daa92028f372..8dea3a9b0afc 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/SetSpaceQuotaOptions.java @@ -24,9 +24,9 @@ */ public class SetSpaceQuotaOptions { - @CommandLine.Option(names = {"--space-quota"}, + // Added --quota for backward compatibility. + @CommandLine.Option(names = {"--space-quota", "--quota"}, description = "The maximum space quota can be used (eg. 1GB)") - private String quotaInBytes; @CommandLine.Option(names = {"--count-quota"}, @@ -34,13 +34,8 @@ public class SetSpaceQuotaOptions { "buckets, and for buckets represents the number of keys (eg. 5)") private long quotaInCounts; - // Hidden option, added for backward compatibility. - @CommandLine.Option(names = {"--quota"}, hidden = true, - description = "Deprecated use --space-quota") - private String quotaInBytesDep; - public String getQuotaInBytes() { - return quotaInBytes != null ? quotaInBytes : quotaInBytesDep; + return quotaInBytes; } public long getQuotaInCounts() {