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

sodonnell 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 ca151a4f61 HDDS-9278. Return proper error message thrown when 
text/decimal is supplied as a parameter for namespace-quota (#5294)
ca151a4f61 is described below

commit ca151a4f61a3e81f22f0e9e0f86faf504e526e1c
Author: jyotirmoy-gh <[email protected]>
AuthorDate: Thu Sep 21 16:31:32 2023 +0530

    HDDS-9278. Return proper error message thrown when text/decimal is supplied 
as a parameter for namespace-quota (#5294)
---
 .../org/apache/hadoop/hdds/client/OzoneQuota.java  | 25 +++++----
 .../src/main/smoketest/basic/ozone-shell-lib.robot |  2 +-
 .../client/rpc/TestOzoneRpcClientAbstract.java     | 22 ++++----
 .../hadoop/ozone/shell/TestOzoneShellHA.java       | 64 ++++++++++++----------
 4 files changed, 60 insertions(+), 53 deletions(-)

diff --git 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
index 04996f10b4..8a4d75a31f 100644
--- 
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
+++ 
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/client/OzoneQuota.java
@@ -190,15 +190,13 @@ public final class OzoneQuota {
       }
       nSize = Long.parseLong(size);
     } catch (NumberFormatException e) {
-      throw new IllegalArgumentException("Invalid values for quota, to ensure" 
+
-              " that the Quota format is legal(supported values are B," +
-              " KB, MB, GB and TB with positive long values)." +
-              " And the quota value cannot be greater than " +
-              "Long.MAX_VALUE BYTES");
+      throw new IllegalArgumentException(quotaInBytes + " is invalid. " +
+          "The quota value should be a positive integer " +
+          "with byte numeration(B, KB, MB, GB and TB)");
     }
 
     if (nSize <= 0) {
-      throw new IllegalArgumentException("Invalid values for space quota: "
+      throw new IllegalArgumentException("Invalid value for space quota: "
           + nSize);
     }
 
@@ -218,12 +216,17 @@ public final class OzoneQuota {
       throw new IllegalArgumentException(
           "Quota string cannot be null or empty.");
     }
-    long nameSpaceQuota = Long.parseLong(quotaInNamespace);
-    if (nameSpaceQuota <= 0) {
-      throw new IllegalArgumentException(
-          "Invalid values for namespace quota: " + nameSpaceQuota);
+    try {
+      long nameSpaceQuota = Long.parseLong(quotaInNamespace);
+      if (nameSpaceQuota <= 0) {
+        throw new IllegalArgumentException(
+            "Invalid value for namespace quota: " + nameSpaceQuota);
+      }
+      return new OzoneQuota(nameSpaceQuota, new RawQuotaInBytes(Units.B, -1));
+    } catch (NumberFormatException e) {
+      throw new IllegalArgumentException(quotaInNamespace + " is invalid. " +
+          "The quota value should be a positive integer");
     }
-    return new OzoneQuota(nameSpaceQuota, new RawQuotaInBytes(Units.B, -1));
   }
 
   /**
diff --git a/hadoop-ozone/dist/src/main/smoketest/basic/ozone-shell-lib.robot 
b/hadoop-ozone/dist/src/main/smoketest/basic/ozone-shell-lib.robot
index 5f43ac981a..d1a6c5c7d0 100644
--- a/hadoop-ozone/dist/src/main/smoketest/basic/ozone-shell-lib.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/basic/ozone-shell-lib.robot
@@ -92,7 +92,7 @@ Test ozone shell
 Test ozone shell errors
     [arguments]     ${protocol}         ${server}       ${volume}
     ${result} =     Execute and checkrc    ozone sh volume create 
${protocol}${server}/${volume} --space-quota invalid      255
-                    Should contain      ${result}       Invalid
+                    Should contain      ${result}       invalid
                     Execute and checkrc    ozone sh volume create 
${protocol}${server}/${volume}                            0
     ${result} =     Execute and checkrc    ozone sh bucket create 
${protocol}${server}/${volume}/bucket_1                   255
                     Should contain      ${result}       INVALID_BUCKET_NAME
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
index 4bd07fbcad..000bb602e9 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClientAbstract.java
@@ -420,37 +420,37 @@ public abstract class TestOzoneRpcClientAbstract {
             () -> store.getVolume(volumeName).getBucket(bucketName)
                 .setQuota(OzoneQuota.parseQuota("0GB", "10")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for space quota"));
+        .startsWith("Invalid value for space quota"));
 
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).getBucket(bucketName).setQuota(
             OzoneQuota.parseQuota("10GB", "0")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for namespace quota"));
+        .startsWith("Invalid value for namespace quota"));
 
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).getBucket(bucketName).setQuota(
             OzoneQuota.parseQuota("1GB", "-100")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for namespace quota"));
+        .startsWith("Invalid value for namespace quota"));
 
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).getBucket(bucketName).setQuota(
             OzoneQuota.parseQuota("1TEST", "100")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for quota"));
+        .startsWith("1TEST is invalid."));
 
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).getBucket(bucketName).setQuota(
             OzoneQuota.parseQuota("9223372036854775808 BYTES", "100")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for quota"));
+        .startsWith("9223372036854775808 BYTES is invalid."));
 
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).getBucket(bucketName).setQuota(
             OzoneQuota.parseQuota("-10GB", "100")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for space quota"));
+        .startsWith("Invalid value for space quota"));
 
   }
 
@@ -491,33 +491,33 @@ public abstract class TestOzoneRpcClientAbstract {
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
             "0GB", "10")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for space quota"));
+        .startsWith("Invalid value for space quota"));
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
             "10GB", "0")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for namespace quota"));
+        .startsWith("Invalid value for namespace quota"));
 
     // The unit should be legal.
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
             "1TEST", "1000")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for quota"));
+        .startsWith("1TEST is invalid."));
 
     // The setting value cannot be greater than LONG.MAX_VALUE BYTES.
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
             "9223372036854775808 B", "1000")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for quota"));
+        .startsWith("9223372036854775808 B is invalid."));
 
     // The value cannot be negative.
     exception = assertThrows(IllegalArgumentException.class,
         () -> store.getVolume(volumeName).setQuota(OzoneQuota.parseQuota(
             "-10GB", "1000")));
     assertTrue(exception.getMessage()
-        .startsWith("Invalid values for space quota"));
+        .startsWith("Invalid value for space quota"));
   }
 
   @Test
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 73adfa300c..d28ef3b270 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
@@ -914,21 +914,19 @@ public class TestOzoneShellHA {
     out.reset();
 
     args = new String[]{"volume", "create", "vol5", "--space-quota", "-1"};
-    executeWithError(ozoneShell, args, "Invalid values for space quota: -1");
+    executeWithError(ozoneShell, args, "Invalid value for space quota: -1");
     out.reset();
 
     args = new String[]{"volume", "create", "vol5", "--space-quota", "test"};
-    executeWithError(ozoneShell, args, "Invalid values for quota, " +
-        "to ensure that the Quota format is legal(supported values are " +
-        "B, KB, MB, GB and TB with positive long values). " +
-        "And the quota value cannot be greater than Long.MAX_VALUE BYTES");
+    executeWithError(ozoneShell, args, "test is invalid. " +
+        "The quota value should be a positive integer " +
+        "with byte numeration(B, KB, MB, GB and TB)");
     out.reset();
 
     args = new String[]{"volume", "create", "vol5", "--space-quota", "1.5GB"};
-    executeWithError(ozoneShell, args, "Invalid values for quota, " +
-        "to ensure that the Quota format is legal(supported values are " +
-        "B, KB, MB, GB and TB with positive long values). " +
-        "And the quota value cannot be greater than Long.MAX_VALUE BYTES");
+    executeWithError(ozoneShell, args, "1.5GB is invalid. " +
+        "The quota value should be a positive integer " +
+        "with byte numeration(B, KB, MB, GB and TB)");
     out.reset();
 
     args = new String[]{"volume", "create", "vol5", "--namespace-quota"};
@@ -939,7 +937,7 @@ public class TestOzoneShellHA {
 
     args = new String[]{"volume", "create", "vol5", "--namespace-quota", "-1"};
     executeWithError(ozoneShell, args,
-        "Invalid values for namespace quota: -1");
+        "Invalid value for namespace quota: -1");
     out.reset();
 
     args = new String[]{"volume", "create", "vol5"};
@@ -955,23 +953,21 @@ public class TestOzoneShellHA {
     args = new String[]{"bucket", "create", "vol5/buck5",
         "--space-quota", "-1"};
     executeWithError(ozoneShell, args,
-        "Invalid values for space quota: -1");
+        "Invalid value for space quota: -1");
     out.reset();
 
     args = new String[]{"bucket", "create", "vol5/buck5",
         "--space-quota", "test"};
-    executeWithError(ozoneShell, args, "Invalid values for quota, " +
-        "to ensure that the Quota format is legal(supported values are " +
-        "B, KB, MB, GB and TB with positive long values). " +
-        "And the quota value cannot be greater than Long.MAX_VALUE BYTES");
+    executeWithError(ozoneShell, args, "test is invalid. " +
+        "The quota value should be a positive integer " +
+        "with byte numeration(B, KB, MB, GB and TB)");
     out.reset();
 
     args = new String[]{"bucket", "create", "vol5/buck5",
         "--space-quota", "1.5GB"};
-    executeWithError(ozoneShell, args, "Invalid values for quota, " +
-        "to ensure that the Quota format is legal(supported values are " +
-        "B, KB, MB, GB and TB with positive long values). " +
-        "And the quota value cannot be greater than Long.MAX_VALUE BYTES");
+    executeWithError(ozoneShell, args, "1.5GB is invalid. " +
+        "The quota value should be a positive integer " +
+        "with byte numeration(B, KB, MB, GB and TB)");
     out.reset();
 
     args = new String[]{"bucket", "create", "vol5/buck5", "--namespace-quota"};
@@ -982,7 +978,7 @@ public class TestOzoneShellHA {
 
     args = new String[]{"volume", "create", "vol5", "--namespace-quota", "-1"};
     executeWithError(ozoneShell, args,
-        "Invalid values for namespace quota: -1");
+        "Invalid value for namespace quota: -1");
     out.reset();
 
     args = new String[]{"bucket", "create", "vol5/buck5"};
@@ -1024,7 +1020,7 @@ public class TestOzoneShellHA {
     ExecutionException eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, volumeArgs1));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for space quota"));
+        .contains("Invalid value for space quota"));
     out.reset();
 
     String[] volumeArgs2 = new String[]{"volume", "setquota", "vol4",
@@ -1032,7 +1028,7 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, volumeArgs2));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for space quota"));
+        .contains("Invalid value for space quota"));
     out.reset();
 
     String[] volumeArgs3 = new String[]{"volume", "setquota", "vol4",
@@ -1040,7 +1036,9 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, volumeArgs3));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for quota"));
+        .contains("test is invalid. " +
+            "The quota value should be a positive integer " +
+            "with byte numeration(B, KB, MB, GB and TB)"));
     out.reset();
 
     String[] volumeArgs4 = new String[]{"volume", "setquota", "vol4",
@@ -1048,7 +1046,9 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, volumeArgs4));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for quota"));
+        .contains("1.5GB is invalid. " +
+            "The quota value should be a positive integer " +
+            "with byte numeration(B, KB, MB, GB and TB)"));
     out.reset();
 
     String[] volumeArgs5 = new String[]{"volume", "setquota", "vol4",
@@ -1065,7 +1065,7 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, volumeArgs6));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for namespace quota"));
+        .contains("Invalid value for namespace quota"));
     out.reset();
 
     String[] volumeArgs7 = new String[]{"volume", "setquota", "vol4",
@@ -1082,7 +1082,7 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, bucketArgs1));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for space quota"));
+        .contains("Invalid value for space quota"));
     out.reset();
 
     String[] bucketArgs2 = new String[]{"bucket", "setquota", "vol4/buck4",
@@ -1090,7 +1090,7 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, bucketArgs2));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for space quota"));
+        .contains("Invalid value for space quota"));
     out.reset();
 
     String[] bucketArgs3 = new String[]{"bucket", "setquota", "vol4/buck4",
@@ -1098,7 +1098,9 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, bucketArgs3));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for quota"));
+        .contains("test is invalid. " +
+            "The quota value should be a positive integer " +
+            "with byte numeration(B, KB, MB, GB and TB)"));
     out.reset();
 
     String[] bucketArgs4 = new String[]{"bucket", "setquota", "vol4/buck4",
@@ -1106,7 +1108,9 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, bucketArgs4));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for quota"));
+        .contains("1.5GB is invalid. " +
+            "The quota value should be a positive integer " +
+            "with byte numeration(B, KB, MB, GB and TB)"));
     out.reset();
 
     String[] bucketArgs5 = new String[]{"bucket", "setquota", "vol4/buck4",
@@ -1122,7 +1126,7 @@ public class TestOzoneShellHA {
     eException = assertThrows(ExecutionException.class,
         () -> execute(ozoneShell, bucketArgs6));
     assertTrue(eException.getMessage()
-        .contains("Invalid values for namespace quota"));
+        .contains("Invalid value for namespace quota"));
     out.reset();
 
     String[] bucketArgs7 = new String[]{"bucket", "setquota", "vol4/buck4",


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

Reply via email to