From 14a3e74c5c701a181599b45fe39bba988f343a4a Mon Sep 17 00:00:00 2001 From: Mehakmeet Singh Date: Fri, 16 Jul 2021 19:57:00 +0530 Subject: [PATCH] HADOOP-17801. No error message reported when bucket doesn't exist in S3AFS (#3202) Contributed by: Mehakmeet Singh. Change-Id: I26c2a85ef6bbfd1b8269a23fc44d9a55d7fa091c --- .../apache/hadoop/fs/s3a/S3AFileSystem.java | 6 +++-- .../org/apache/hadoop/fs/s3a/S3AUtils.java | 2 +- .../hadoop/fs/s3a/UnknownStoreException.java | 24 +++++++++++-------- .../fs/s3a/TestS3AExceptionTranslation.java | 8 +++++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java index 5a532356f5..6f53509a41 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java @@ -681,7 +681,8 @@ protected void verifyBucketExists() trackDurationOfOperation(getDurationTrackerFactory(), STORE_EXISTS_PROBE.getSymbol(), () -> s3.doesBucketExist(bucket)))) { - throw new UnknownStoreException("Bucket " + bucket + " does not exist"); + throw new UnknownStoreException("s3a://" + bucket + "/", " Bucket does " + + "not exist"); } } @@ -699,7 +700,8 @@ protected void verifyBucketExistsV2() trackDurationOfOperation(getDurationTrackerFactory(), STORE_EXISTS_PROBE.getSymbol(), () -> s3.doesBucketExistV2(bucket)))) { - throw new UnknownStoreException("Bucket " + bucket + " does not exist"); + throw new UnknownStoreException("s3a://" + bucket + "/", " Bucket does " + + "not exist"); } } diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java index b6af8e7f27..dc9507b701 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java @@ -254,7 +254,7 @@ public static IOException translateException(@Nullable String operation, case 404: if (isUnknownBucket(ase)) { // this is a missing bucket - ioe = new UnknownStoreException(path, ase); + ioe = new UnknownStoreException(path, message, ase); } else { // a normal unknown object ioe = new FileNotFoundException(message); diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/UnknownStoreException.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/UnknownStoreException.java index 0129005e06..2ea17e0710 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/UnknownStoreException.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/UnknownStoreException.java @@ -18,10 +18,9 @@ package org.apache.hadoop.fs.s3a; -import java.io.IOException; - import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.fs.PathIOException; /** * The bucket or other AWS resource is unknown. @@ -33,23 +32,28 @@ */ @InterfaceAudience.Public @InterfaceStability.Evolving -public class UnknownStoreException extends IOException { +public class UnknownStoreException extends PathIOException { /** * Constructor. - * @param message message + * + * @param path path trying to access. + * @param message message. */ - public UnknownStoreException(final String message) { - this(message, null); + public UnknownStoreException(final String path, final String message) { + this(path, message, null); } /** * Constructor. - * @param message message - * @param cause cause (may be null) + * + * @param path path trying to access. + * @param message message. + * @param cause cause (may be null). */ - public UnknownStoreException(final String message, Throwable cause) { - super(message); + public UnknownStoreException(String path, final String message, + Throwable cause) { + super(path, message); if (cause != null) { initCause(cause); } diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java index 95bd7c21b8..fd649c436b 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AExceptionTranslation.java @@ -181,8 +181,12 @@ private static AmazonS3Exception createS3Exception(String message, int code, private static E verifyTranslated(Class clazz, AmazonClientException exception) throws Exception { - return verifyExceptionClass(clazz, - translateException("test", "/", exception)); + // Verifying that the translated exception have the correct error message. + IOException ioe = translateException("test", "/", exception); + assertExceptionContains(exception.getMessage(), ioe, + "Translated Exception should contain the error message of the " + + "actual exception"); + return verifyExceptionClass(clazz, ioe); } private void assertContainsInterrupted(boolean expected, Throwable thrown)