Browse Source

HADOOP-14110. In S3AFileSystem, make getAmazonClient() package private; export getBucketLocation(). Contributed by Steve Loughran

Mingliang Liu 8 years ago
parent
commit
dd2a9cfc3e

+ 25 - 1
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java

@@ -390,10 +390,34 @@ public class S3AFileSystem extends FileSystem {
    * Returns the S3 client used by this filesystem.
    * @return AmazonS3Client
    */
-  public AmazonS3 getAmazonS3Client() {
+  AmazonS3 getAmazonS3Client() {
     return s3;
   }
 
+  /**
+   * Get the region of a bucket.
+   * @return the region in which a bucket is located
+   * @throws IOException on any failure.
+   */
+  public String getBucketLocation() throws IOException {
+    return getBucketLocation(bucket);
+  }
+
+  /**
+   * Get the region of a bucket.
+   * @param bucketName the name of the bucket
+   * @return the region in which a bucket is located
+   * @throws IOException on any failure.
+   */
+  public String getBucketLocation(String bucketName) throws IOException {
+    try {
+      return s3.getBucketLocation(bucketName);
+    } catch (AmazonClientException e) {
+      throw translateException("getBucketLocation()",
+          bucketName, e);
+    }
+  }
+
   /**
    * Returns the read ahead range value used by this filesystem
    * @return

+ 2 - 15
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/DynamoDBMetadataStore.java

@@ -199,14 +199,7 @@ public class DynamoDBMetadataStore implements MetadataStore {
   @VisibleForTesting
   static DynamoDB createDynamoDB(S3AFileSystem fs) throws IOException {
     Preconditions.checkNotNull(fs);
-    String region;
-    try {
-      region = fs.getAmazonS3Client().getBucketLocation(fs.getBucket());
-    } catch (AmazonClientException e) {
-      throw translateException("Determining bucket location",
-          fs.getUri().toString(), e);
-    }
-    return createDynamoDB(fs, region);
+    return createDynamoDB(fs, fs.getBucketLocation());
   }
 
   /**
@@ -236,13 +229,7 @@ public class DynamoDBMetadataStore implements MetadataStore {
         "DynamoDBMetadataStore only supports S3A filesystem.");
     final S3AFileSystem s3afs = (S3AFileSystem) fs;
     final String bucket = s3afs.getBucket();
-    try {
-      region = s3afs.getAmazonS3Client().getBucketLocation(bucket);
-    } catch (AmazonClientException e) {
-      throw translateException("Determining bucket location",
-          fs.getUri().toString(), e);
-    }
-
+    region = s3afs.getBucketLocation();
     username = s3afs.getUsername();
     conf = s3afs.getConf();
     Class<? extends DynamoDBClientFactory> cls = conf.getClass(

+ 1 - 1
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/TestDynamoDBMetadataStore.java

@@ -216,7 +216,7 @@ public class TestDynamoDBMetadataStore extends MetadataStoreTestBase {
       assertNotNull(ddbms.getTable());
       assertEquals(tableName, ddbms.getTable().getTableName());
       assertEquals("DynamoDB table should be in the same region as S3 bucket",
-          s3afs.getAmazonS3Client().getBucketLocation(tableName),
+          s3afs.getBucketLocation(tableName),
           ddbms.getRegion());
     }
   }