HDDS-10844. Clarify snapshot create error message #6955
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
HDDS-10844. Clarify snapshot create error message
Please describe your PR in detail:
Show the specific reason why the snapshot name is invalid by throwing the specific IllegalArgumentException using
e.getMessage()Enhance HddsClientUtils.verifyResourceName to support validation for volumes, buckets, and snapshots by introducing a resType parameter. This modification allows specifying the resource type in error messages, making them more context-specific.
Usage examples:
Example output:
If don't pass resType into verifyResourceName, it will show default resType as string "resource"
Previously, the method generated fixed error messages such as "Bucket or Volume name has an unsupported character". This update ensures the error messages are relevant to the type of resource being validated, addressing inaccuracies when used with volumes, buckets, and snapshots.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-10844
How was this patch tested?
Tested below scenarios in local docker according to hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/client/HddsClientUtils.java
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket s1"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s1
snapshot length is illegal, valid length is 3-63 characters
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 .s1"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: .s1
snapshot name cannot start with a period or dash
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s1."
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s1.
snapshot name cannot end with a period or dash
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s1-"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s1-
snapshot name cannot end with a period or dash
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 ssA"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: ssA
snapshot name does not support uppercase characters
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s%s"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s%s
snapshot name has an unsupported character : %
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s..s"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s..s
snapshot name should not have two contiguous periods
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s-.s"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s-.s
snapshot name should not have period after dash
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 s.-s"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: s.-s
snapshot name should not have dash after period
docker exec -it ozone-om-1 sh -c "ozone sh snapshot create /s3v/bucket1 192.168.1.1"
INVALID_SNAPSHOT_ERROR Invalid snapshot name: 192.168.1.1
snapshotBucket or Volume name cannot be an IPv4 address or all numeric