From 997d749f8a78a0d86eef26ed722ad80b4e8515ea 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. --- .../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 1a5d6353fbc..e30ad5c0842 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 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities, 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 @@ public class S3AFileSystem extends FileSystem implements StreamCapabilities, 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 220355aaa3f..859f71a1815 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 final class S3AUtils { 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 0129005e067..2ea17e07105 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 @@ import org.apache.hadoop.classification.InterfaceStability; */ @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 95bd7c21b85..fd649c436bf 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 @@ public class TestS3AExceptionTranslation { 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)