priyeshkaratha commented on code in PR #10097:
URL: https://github.com/apache/ozone/pull/10097#discussion_r3115023943
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java:
##########
@@ -193,27 +195,87 @@ public int getHttpCode() {
return httpCode;
}
- public static OS3Exception newError(S3ErrorTable e, String resource) {
- return newError(e, resource, null);
+ /** Converts result code of @{code OMException} to {@code S3ErrorTable},
which
+ * should be thrown via {@link #newError(S3ErrorTable, String, Exception)}.
*/
+ public static S3ErrorTable translateResultCode(OMException ex) {
+ switch (ex.getResult()) {
+ case ACCESS_DENIED:
+ case INVALID_TOKEN:
+ case PERMISSION_DENIED:
+ return ACCESS_DENIED;
+ case ATOMIC_WRITE_CONFLICT:
+ return CONDITIONAL_REQUEST_CONFLICT;
+ case BUCKET_ALREADY_EXISTS:
+ return BUCKET_ALREADY_EXISTS;
+ case BUCKET_NOT_EMPTY:
+ return BUCKET_NOT_EMPTY;
+ case BUCKET_NOT_FOUND:
+ case VOLUME_NOT_FOUND:
+ return NO_SUCH_BUCKET;
+ case ENTITY_TOO_SMALL:
+ return ENTITY_TOO_SMALL;
+ case ETAG_MISMATCH:
+ case ETAG_NOT_AVAILABLE:
+ case KEY_ALREADY_EXISTS:
+ return PRECOND_FAILED;
+ case FILE_ALREADY_EXISTS:
+ return NO_OVERWRITE;
+ case INVALID_BUCKET_NAME:
+ return INVALID_BUCKET_NAME;
+ case INVALID_PART:
+ return INVALID_PART;
+ case INVALID_PART_ORDER:
+ return INVALID_PART_ORDER;
+ case INVALID_REQUEST:
+ return INVALID_REQUEST;
+ case KEY_NOT_FOUND:
+ return NO_SUCH_KEY;
+ case NOT_SUPPORTED_OPERATION:
+ return NOT_IMPLEMENTED;
+ case QUOTA_EXCEEDED:
+ return QUOTA_EXCEEDED;
+ default:
+ return INTERNAL_ERROR;
+ }
+ }
+
+ /** Same as {@link #newError(String, OMException)}, but uses {@code bucket}
as the {@code resource}
+ * in case of {@link #NO_SUCH_BUCKET} error. */
+ public static OS3Exception newError(String bucket, String resource,
OMException cause) {
+ S3ErrorTable errorCode = translateResultCode(cause);
+ return new OS3Exception(errorCode, cause, NO_SUCH_BUCKET == errorCode ?
bucket : resource);
+ }
+
+ /** Creates new {@link OS3Exception} for {@link OMException} and {@code
resource}. */
+ public static OS3Exception newError(@Nullable String resource, OMException
cause) {
+ return new OS3Exception(translateResultCode(cause), cause, resource);
+ }
+
+ /** Creates new {@link OS3Exception} for {@link S3ErrorTable}. */
+ public static OS3Exception newError(S3ErrorTable errorCode) {
+ return new OS3Exception(errorCode, null, null);
+ }
+
+ /** Creates new {@link OS3Exception} for {@link S3ErrorTable} and {@code
resource}. */
+ public static OS3Exception newError(S3ErrorTable errorCode, @Nullable String
resource) {
+ return new OS3Exception(errorCode, null, resource);
+ }
+
+ /** Creates new {@link OS3Exception} for {@link S3ErrorTable}, {@code
resource} and {@code cause}. */
Review Comment:
The Javadoc comment for this method is inaccurate as it mentions a resource
parameter which is not present in this specific overload.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/exception/S3ErrorTable.java:
##########
@@ -193,27 +195,87 @@ public int getHttpCode() {
return httpCode;
}
- public static OS3Exception newError(S3ErrorTable e, String resource) {
- return newError(e, resource, null);
+ /** Converts result code of @{code OMException} to {@code S3ErrorTable},
which
Review Comment:
There is a typo in the Javadoc tag. It should be {@code instead of @{code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]