This is an automated email from the ASF dual-hosted git repository.

agupta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new f1d651d0b5 HDDS-7561. Improve setquota, clrquota CLI usage (#4016)
f1d651d0b5 is described below

commit f1d651d0b5d87339e8bc698466216bc7862f48b9
Author: Sumit Agrawal <[email protected]>
AuthorDate: Thu Dec 1 00:35:59 2022 +0530

    HDDS-7561. Improve setquota, clrquota CLI usage (#4016)
---
 .../hadoop/ozone/shell/TestOzoneShellHA.java       | 22 ++++++++++++++++++++++
 .../ozone/shell/bucket/ClearQuotaHandler.java      | 12 ++++++++++--
 .../hadoop/ozone/shell/bucket/SetQuotaHandler.java | 12 ++++++++++--
 .../ozone/shell/volume/ClearQuotaHandler.java      | 12 ++++++++++--
 .../hadoop/ozone/shell/volume/SetQuotaHandler.java | 11 ++++++++++-
 5 files changed, 62 insertions(+), 7 deletions(-)

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 88f387afee..8c1653426b 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 class TestOzoneShellHA {
             .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 class TestOzoneShellHA {
         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 class TestOzoneShellHA {
     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 class TestOzoneShellHA {
     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 160475e193..103f13841d 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 @@ import java.io.IOException;
  * 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 @@ public class ClearQuotaHandler extends BucketHandler {
     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 7df37a3272..68d1bee178 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 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OLD_QUOTA_DEFAULT;
  * 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 class SetQuotaHandler extends BucketHandler {
         .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 fc5dc96150..b36e77e908 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 @@ import java.io.IOException;
  * 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 @@ public class ClearQuotaHandler extends VolumeHandler {
       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 018a213ecb..40d4b9f193 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 @@ import static 
org.apache.hadoop.ozone.OzoneConsts.OLD_QUOTA_DEFAULT;
  * 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 @@ public class SetQuotaHandler extends VolumeHandler {
 
     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) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to