From 33608c3bd4d73996e4b1f022f36c44b380e0d83c Mon Sep 17 00:00:00 2001 From: Petre Bogdan Stolojan Date: Mon, 4 Oct 2021 20:58:22 +0100 Subject: [PATCH] HADOOP-17951. Improve S3A checking of S3 Access Point existence (#3516) Follow-on to HADOOP-17198. Support S3 Access Points Contributed by Bogdan Stolojan --- .../main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java | 4 +++- .../org/apache/hadoop/fs/s3a/impl/InternalConstants.java | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 a7dc3f9f7f..3e6dacad1d 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 @@ -216,6 +216,7 @@ import static org.apache.hadoop.fs.s3a.impl.CallableSupplier.waitForCompletionIgnoringExceptions; import static org.apache.hadoop.fs.s3a.impl.ErrorTranslation.isObjectNotFound; import static org.apache.hadoop.fs.s3a.impl.ErrorTranslation.isUnknownBucket; +import static org.apache.hadoop.fs.s3a.impl.InternalConstants.AP_INACCESSIBLE; import static org.apache.hadoop.fs.s3a.impl.InternalConstants.AP_REQUIRED_EXCEPTION; import static org.apache.hadoop.fs.s3a.impl.InternalConstants.AP_S3GUARD_INCOMPATIBLE; import static org.apache.hadoop.fs.s3a.impl.InternalConstants.ARN_BUCKET_OPTION; @@ -785,7 +786,8 @@ protected void verifyBucketExistsV2() s3.getBucketAcl(bucket); } catch (AmazonServiceException ex) { int statusCode = ex.getStatusCode(); - if (statusCode == SC_404 || (statusCode == SC_403 && accessPoint != null)) { + if (statusCode == SC_404 || + (statusCode == SC_403 && ex.getMessage().contains(AP_INACCESSIBLE))) { return false; } } diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/InternalConstants.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/InternalConstants.java index 501460de07..286ec2125a 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/InternalConstants.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/InternalConstants.java @@ -154,6 +154,11 @@ private InternalConstants() { public static final String AP_REQUIRED_EXCEPTION = "Access Points usage is required" + " but not configured for the bucket."; + /** + * Error message to indicate Access Points are not accessible or don't exist. + */ + public static final String AP_INACCESSIBLE = "Could not access through this access point"; + /** * AccessPoint ARN for the bucket. When set as a bucket override the requests for that bucket * will go through the AccessPoint.