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

sshenoy 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 abf3a0a2bd HDDS-10844. Clarify snapshot create error message. (#6955)
abf3a0a2bd is described below

commit abf3a0a2bd586cc223e41d6147b1c1d995cfe196
Author: Will Xiao <[email protected]>
AuthorDate: Wed Jul 17 16:11:59 2024 +0800

    HDDS-10844. Clarify snapshot create error message. (#6955)
---
 .../hadoop/hdds/scm/client/HddsClientUtils.java    | 55 ++++++++++++----------
 .../apache/hadoop/ozone/client/rpc/RpcClient.java  |  4 +-
 .../main/java/org/apache/hadoop/ozone/OmUtils.java |  8 ++--
 .../ozone/client/rpc/OzoneRpcClientTests.java      |  2 +-
 .../snapshot/TestOMSnapshotCreateRequest.java      |  4 +-
 .../snapshot/TestOMSnapshotDeleteRequest.java      |  4 +-
 .../snapshot/TestOMSnapshotRenameRequest.java      |  4 +-
 7 files changed, 42 insertions(+), 39 deletions(-)

diff --git 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java
 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java
index 2b07dacf1e..6c5f9a0a98 100644
--- 
a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java
+++ 
b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java
@@ -67,27 +67,26 @@ public final class HddsClientUtils {
           .add(NotReplicatedException.class)
           .build();
 
-  private static void doNameChecks(String resName) {
+  private static void doNameChecks(String resName, String resType) {
     if (resName == null) {
-      throw new IllegalArgumentException("Bucket or Volume name is null");
+      throw new IllegalArgumentException(resType + " name is null");
     }
 
     if (resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH ||
         resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH) {
-      throw new IllegalArgumentException(
-          "Bucket or Volume length is illegal, "
-              + "valid length is 3-63 characters");
+      throw new IllegalArgumentException(resType +
+          " length is illegal, " + "valid length is 3-63 characters");
     }
 
     if (resName.charAt(0) == '.' || resName.charAt(0) == '-') {
-      throw new IllegalArgumentException(
-          "Bucket or Volume name cannot start with a period or dash");
+      throw new IllegalArgumentException(resType +
+          " name cannot start with a period or dash");
     }
 
     if (resName.charAt(resName.length() - 1) == '.' ||
         resName.charAt(resName.length() - 1) == '-') {
-      throw new IllegalArgumentException("Bucket or Volume name "
-          + "cannot end with a period or dash");
+      throw new IllegalArgumentException(resType +
+          " name cannot end with a period or dash");
     }
   }
 
@@ -108,27 +107,27 @@ public final class HddsClientUtils {
     return false;
   }
 
-  private static void doCharacterChecks(char currChar, char prev,
+  private static void doCharacterChecks(char currChar, char prev, String 
resType,
       boolean isStrictS3) {
     if (Character.isUpperCase(currChar)) {
-      throw new IllegalArgumentException(
-          "Bucket or Volume name does not support uppercase characters");
+      throw new IllegalArgumentException(resType +
+          " name does not support uppercase characters");
     }
     if (!isSupportedCharacter(currChar, isStrictS3)) {
-      throw new IllegalArgumentException("Bucket or Volume name has an " +
-          "unsupported character : " + currChar);
+      throw new IllegalArgumentException(resType +
+          " name has an unsupported character : " + currChar);
     }
     if (prev == '.' && currChar == '.') {
-      throw new IllegalArgumentException("Bucket or Volume name should not " +
-          "have two contiguous periods");
+      throw new IllegalArgumentException(resType +
+          " name should not have two contiguous periods");
     }
     if (prev == '-' && currChar == '.') {
-      throw new IllegalArgumentException(
-          "Bucket or Volume name should not have period after dash");
+      throw new IllegalArgumentException(resType +
+          " name should not have period after dash");
     }
     if (prev == '.' && currChar == '-') {
-      throw new IllegalArgumentException(
-          "Bucket or Volume name should not have dash after period");
+      throw new IllegalArgumentException(resType +
+          " name should not have dash after period");
     }
   }
 
@@ -140,7 +139,11 @@ public final class HddsClientUtils {
    * @throws IllegalArgumentException
    */
   public static void verifyResourceName(String resName) {
-    verifyResourceName(resName, true);
+    verifyResourceName(resName, "resource", true);
+  }
+
+  public static void verifyResourceName(String resName, String resType) {
+    verifyResourceName(resName, resType, true);
   }
 
   /**
@@ -150,9 +153,9 @@ public final class HddsClientUtils {
    *
    * @throws IllegalArgumentException
    */
-  public static void verifyResourceName(String resName, boolean isStrictS3) {
+  public static void verifyResourceName(String resName, String resType, 
boolean isStrictS3) {
 
-    doNameChecks(resName);
+    doNameChecks(resName, resType);
 
     boolean isIPv4 = true;
     char prev = (char) 0;
@@ -162,13 +165,13 @@ public final class HddsClientUtils {
       if (currChar != '.') {
         isIPv4 = ((currChar >= '0') && (currChar <= '9')) && isIPv4;
       }
-      doCharacterChecks(currChar, prev, isStrictS3);
+      doCharacterChecks(currChar, prev, resType, isStrictS3);
       prev = currChar;
     }
 
     if (isIPv4) {
-      throw new IllegalArgumentException(
-          "Bucket or Volume name cannot be an IPv4 address or all numeric");
+      throw new IllegalArgumentException(resType +
+          " name cannot be an IPv4 address or all numeric");
     }
   }
 
diff --git 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
index ac0cf1d09c..97a7ac4c62 100644
--- 
a/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
+++ 
b/hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/RpcClient.java
@@ -709,7 +709,7 @@ public class RpcClient implements ClientProtocol {
 
   private static void verifyVolumeName(String volumeName) throws OMException {
     try {
-      HddsClientUtils.verifyResourceName(volumeName, false);
+      HddsClientUtils.verifyResourceName(volumeName, "volume", false);
     } catch (IllegalArgumentException e) {
       throw new OMException(e.getMessage(),
           OMException.ResultCodes.INVALID_VOLUME_NAME);
@@ -718,7 +718,7 @@ public class RpcClient implements ClientProtocol {
 
   private static void verifyBucketName(String bucketName) throws OMException {
     try {
-      HddsClientUtils.verifyResourceName(bucketName, false);
+      HddsClientUtils.verifyResourceName(bucketName, "bucket", false);
     } catch (IllegalArgumentException e) {
       throw new OMException(e.getMessage(),
           OMException.ResultCodes.INVALID_BUCKET_NAME);
diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
index 6735c0a4f0..01c95874e4 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
@@ -522,7 +522,7 @@ public final class OmUtils {
   public static void validateVolumeName(String volumeName, boolean isStrictS3)
       throws OMException {
     try {
-      HddsClientUtils.verifyResourceName(volumeName, isStrictS3);
+      HddsClientUtils.verifyResourceName(volumeName, "volume", isStrictS3);
     } catch (IllegalArgumentException e) {
       throw new OMException("Invalid volume name: " + volumeName,
           OMException.ResultCodes.INVALID_VOLUME_NAME);
@@ -535,7 +535,7 @@ public final class OmUtils {
   public static void validateBucketName(String bucketName, boolean isStrictS3)
       throws OMException {
     try {
-      HddsClientUtils.verifyResourceName(bucketName, isStrictS3);
+      HddsClientUtils.verifyResourceName(bucketName, "bucket", isStrictS3);
     } catch (IllegalArgumentException e) {
       throw new OMException("Invalid bucket name: " + bucketName,
           OMException.ResultCodes.INVALID_BUCKET_NAME);
@@ -571,9 +571,9 @@ public final class OmUtils {
       return;
     }
     try {
-      HddsClientUtils.verifyResourceName(snapshotName);
+      HddsClientUtils.verifyResourceName(snapshotName, "snapshot");
     } catch (IllegalArgumentException e) {
-      throw new OMException("Invalid snapshot name: " + snapshotName,
+      throw new OMException("Invalid snapshot name: " + snapshotName + "\n" + 
e.getMessage(),
           OMException.ResultCodes.INVALID_SNAPSHOT_ERROR);
     }
   }
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/OzoneRpcClientTests.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/OzoneRpcClientTests.java
index 84f23a9921..30597fc3e7 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/OzoneRpcClientTests.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/OzoneRpcClientTests.java
@@ -799,7 +799,7 @@ abstract class OzoneRpcClientTests extends OzoneTestBase {
     OzoneVolume volume = store.getVolume(volumeName);
     OMException omException = assertThrows(OMException.class,
         () -> volume.createBucket(bucketName));
-    assertEquals("Bucket or Volume name has an unsupported character : #",
+    assertEquals("bucket name has an unsupported character : #",
         omException.getMessage());
   }
 
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotCreateRequest.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotCreateRequest.java
index a3e83986b5..3997f39d7b 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotCreateRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotCreateRequest.java
@@ -162,8 +162,8 @@ public class TestOMSnapshotCreateRequest {
         bucketName, snapshotName);
     OMException omException =
         assertThrows(OMException.class, () -> doPreExecute(omRequest));
-    assertEquals("Invalid snapshot name: " + snapshotName,
-        omException.getMessage());
+    assertTrue(omException.getMessage()
+        .contains("Invalid snapshot name: " + snapshotName));
   }
 
   @Test
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotDeleteRequest.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotDeleteRequest.java
index 03dc7862e3..5a8bb5d7c0 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotDeleteRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotDeleteRequest.java
@@ -159,8 +159,8 @@ public class TestOMSnapshotDeleteRequest {
         bucketName, deleteSnapshotName);
     OMException omException =
         assertThrows(OMException.class, () -> doPreExecute(omRequest));
-    assertEquals("Invalid snapshot name: " + deleteSnapshotName,
-        omException.getMessage());
+    assertTrue(omException.getMessage()
+        .contains("Invalid snapshot name: " + deleteSnapshotName));
   }
 
   @Test
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotRenameRequest.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotRenameRequest.java
index 14af3e28b8..ab2bac1bd0 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotRenameRequest.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotRenameRequest.java
@@ -60,6 +60,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doNothing;
@@ -172,8 +173,7 @@ public class TestOMSnapshotRenameRequest {
         bucketName, currentSnapshotName, toSnapshotName);
     OMException omException =
         assertThrows(OMException.class, () -> doPreExecute(omRequest));
-    assertEquals("Invalid snapshot name: " + toSnapshotName,
-        omException.getMessage());
+    assertTrue(omException.getMessage().contains("Invalid snapshot name: " + 
toSnapshotName));
   }
 
   @Test


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

Reply via email to