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 88f387afee0f..8c1653426bf0 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 @@ -820,6 +820,11 @@ public void testShQuota() throws Exception { .getQuotaInNamespace()); // Test clrquota option. + args = new String[]{"volume", "clrquota", "vol4"}; + executeWithError(ozoneShell, args, "At least one of the quota clear" + + " flag is required"); + out.reset(); + args = new String[]{"volume", "clrquota", "vol4", "--space-quota", "--namespace-quota"}; execute(ozoneShell, args); @@ -828,6 +833,11 @@ public void testShQuota() throws Exception { objectStore.getVolume("vol4").getQuotaInNamespace()); out.reset(); + args = new String[]{"bucket", "clrquota", "vol4/buck4"}; + executeWithError(ozoneShell, args, "At least one of the quota clear" + + " flag is required"); + out.reset(); + args = new String[]{"bucket", "clrquota", "vol4/buck4", "--space-quota", "--namespace-quota"}; execute(ozoneShell, args); @@ -870,6 +880,12 @@ public void testShQuota() throws Exception { assertEquals(100, objectStore.getVolume("vol4").getQuotaInNamespace()); + // Test set volume quota without quota flag + String[] volumeArgs5 = new String[]{"volume", "setquota", "vol4"}; + executeWithError(ozoneShell, volumeArgs5, + "At least one of the quota set flag is required"); + out.reset(); + // Test set bucket quota to 0. String[] bucketArgs1 = new String[]{"bucket", "setquota", "vol4/buck4", "--space-quota", "0GB"}; @@ -914,6 +930,12 @@ public void testShQuota() throws Exception { assertEquals(100, objectStore.getVolume("vol4") .getBucket("buck4").getQuotaInNamespace()); + // Test set volume quota without quota flag + String[] bucketArgs6 = new String[]{"bucket", "setquota", "vol4/buck4"}; + executeWithError(ozoneShell, bucketArgs6, + "At least one of the quota set flag is required"); + out.reset(); + objectStore.getVolume("vol").deleteBucket("buck"); objectStore.deleteVolume("vol"); objectStore.getVolume("vol1").deleteBucket("buck1"); diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/ClearQuotaHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/ClearQuotaHandler.java index 160475e19340..103f13841db9 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/ClearQuotaHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/ClearQuotaHandler.java @@ -31,7 +31,8 @@ * clean quota of the bucket. */ @Command(name = "clrquota", - description = "clear quota of the bucket") + description = "clear quota of the bucket. At least one of the " + + "quota clear flag is mandatory.") public class ClearQuotaHandler extends BucketHandler { @CommandLine.Mixin @@ -44,12 +45,19 @@ protected void execute(OzoneClient client, OzoneAddress address) String bucketName = address.getBucketName(); OzoneBucket bucket = client.getObjectStore().getVolume(volumeName) .getBucket(bucketName); - + boolean isOptionPresent = false; if (clrSpaceQuota.getClrSpaceQuota()) { bucket.clearSpaceQuota(); + isOptionPresent = true; } if (clrSpaceQuota.getClrNamespaceQuota()) { bucket.clearNamespaceQuota(); + isOptionPresent = true; + } + + if (!isOptionPresent) { + throw new IOException( + "At least one of the quota clear flag is required."); } } } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/SetQuotaHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/SetQuotaHandler.java index 7df37a327276..68d1bee1784d 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/SetQuotaHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/bucket/SetQuotaHandler.java @@ -34,7 +34,8 @@ * set quota of the bucket. */ @Command(name = "setquota", - description = "Set quota of the buckets") + description = "Set quota of the buckets. At least one of the " + + "quota set flag is mandatory.") public class SetQuotaHandler extends BucketHandler { @CommandLine.Mixin @@ -50,15 +51,22 @@ public void execute(OzoneClient client, OzoneAddress address) .getBucket(bucketName); long spaceQuota = bucket.getQuotaInBytes(); long namespaceQuota = bucket.getQuotaInNamespace(); - + boolean isOptionPresent = false; if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInBytes())) { spaceQuota = OzoneQuota.parseSpaceQuota( quotaOptions.getQuotaInBytes()).getQuotaInBytes(); + isOptionPresent = true; } if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInNamespace())) { namespaceQuota = OzoneQuota.parseNameSpaceQuota( quotaOptions.getQuotaInNamespace()).getQuotaInNamespace(); + isOptionPresent = true; + } + + if (!isOptionPresent) { + throw new IOException( + "At least one of the quota set flag is required."); } if (bucket.getQuotaInNamespace() == OLD_QUOTA_DEFAULT || diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ClearQuotaHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ClearQuotaHandler.java index fc5dc9615023..b36e77e90867 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ClearQuotaHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/ClearQuotaHandler.java @@ -31,7 +31,8 @@ * clear quota of the volume. */ @Command(name = "clrquota", - description = "clear quota of the volume") + description = "clear quota of the volume. At least one of the " + + "quota clear flag is mandatory.") public class ClearQuotaHandler extends VolumeHandler { @CommandLine.Mixin @@ -42,12 +43,19 @@ protected void execute(OzoneClient client, OzoneAddress address) throws IOException { String volumeName = address.getVolumeName(); OzoneVolume volume = client.getObjectStore().getVolume(volumeName); - + boolean isOptionPresent = false; if (clrSpaceQuota.getClrSpaceQuota()) { volume.clearSpaceQuota(); + isOptionPresent = true; } if (clrSpaceQuota.getClrNamespaceQuota()) { volume.clearNamespaceQuota(); + isOptionPresent = true; + } + + if (!isOptionPresent) { + throw new IOException( + "At least one of the quota clear flag is required."); } } } diff --git a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/SetQuotaHandler.java b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/SetQuotaHandler.java index 018a213ecb53..40d4b9f19324 100644 --- a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/SetQuotaHandler.java +++ b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/volume/SetQuotaHandler.java @@ -35,7 +35,8 @@ * Executes set volume quota calls. */ @Command(name = "setquota", - description = "Set quota of the volumes") + description = "Set quota of the volumes. At least one of the " + + "quota set flag is mandatory.") public class SetQuotaHandler extends VolumeHandler { @CommandLine.Mixin @@ -49,14 +50,22 @@ protected void execute(OzoneClient client, OzoneAddress address) long spaceQuota = volume.getQuotaInBytes(); long namespaceQuota = volume.getQuotaInNamespace(); + boolean isOptionPresent = false; if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInBytes())) { spaceQuota = OzoneQuota.parseSpaceQuota( quotaOptions.getQuotaInBytes()).getQuotaInBytes(); + isOptionPresent = true; } if (!Strings.isNullOrEmpty(quotaOptions.getQuotaInNamespace())) { namespaceQuota = OzoneQuota.parseNameSpaceQuota( quotaOptions.getQuotaInNamespace()).getQuotaInNamespace(); + isOptionPresent = true; + } + + if (!isOptionPresent) { + throw new IOException( + "At least one of the quota set flag is required."); } if (volume.getQuotaInNamespace() == OLD_QUOTA_DEFAULT) {