From c7b5f858a00ece19e6ee22e9cb09080dfd419a56 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Wed, 10 Jul 2019 20:57:02 +0100 Subject: [PATCH] HADOOP-16393. S3Guard init command uses global settings, not those of target bucket. Contributed by Steve Loughran. Change-Id: I226a91ab8d7758340f8d221aa80a7abf9a0d3e8f --- .../org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java | 8 ++++++++ .../hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java index b013a0d65f3..c9fd6731a0f 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/s3guard/S3GuardTool.java @@ -65,6 +65,7 @@ import org.apache.hadoop.util.ToolRunner; import static org.apache.hadoop.fs.s3a.Constants.*; import static org.apache.hadoop.fs.s3a.Invoker.LOG_EVENT; import static org.apache.hadoop.fs.s3a.S3AUtils.clearBucketOption; +import static org.apache.hadoop.fs.s3a.S3AUtils.propagateBucketOptions; import static org.apache.hadoop.service.launcher.LauncherExitCodes.*; /** @@ -480,6 +481,13 @@ public abstract class S3GuardTool extends Configured implements Tool { int writeCapacity = Integer.parseInt(writeCap); getConf().setInt(S3GUARD_DDB_TABLE_CAPACITY_WRITE_KEY, writeCapacity); } + if (!paths.isEmpty()) { + String s3path = paths.get(0); + URI fsURI = new URI(s3path); + Configuration bucketConf = propagateBucketOptions(getConf(), + fsURI.getHost()); + setConf(bucketConf); + } String tags = getCommandFormat().getOptValue(TAG_FLAG); if (tags != null && !tags.isEmpty()) { diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java index d0304f7b4d6..f774bbb58ca 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/s3guard/ITestS3GuardToolDynamoDB.java @@ -45,6 +45,7 @@ import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.Init; import static org.apache.hadoop.fs.s3a.Constants.S3GUARD_DDB_REGION_KEY; import static org.apache.hadoop.fs.s3a.Constants.S3GUARD_DDB_TABLE_NAME_KEY; import static org.apache.hadoop.fs.s3a.Constants.S3GUARD_DDB_TABLE_TAG; +import static org.apache.hadoop.fs.s3a.S3ATestUtils.removeBucketOverrides; import static org.apache.hadoop.fs.s3a.S3AUtils.setBucketOption; import static org.apache.hadoop.fs.s3a.s3guard.DynamoDBMetadataStore.*; import static org.apache.hadoop.fs.s3a.s3guard.S3GuardTool.*; @@ -120,6 +121,11 @@ public class ITestS3GuardToolDynamoDB extends AbstractS3GuardToolTestBase { conf.set(S3GUARD_DDB_TABLE_NAME_KEY, getTestTableName("testDynamoTableTagging-" + UUID.randomUUID())); + String bucket = getFileSystem().getBucket(); + removeBucketOverrides(bucket, conf, + S3GUARD_DDB_TABLE_NAME_KEY, + S3GUARD_DDB_REGION_KEY); + S3GuardTool.Init cmdR = new S3GuardTool.Init(conf); Map tagMap = new HashMap<>(); tagMap.put("hello", "dynamo"); @@ -128,7 +134,7 @@ public class ITestS3GuardToolDynamoDB extends AbstractS3GuardToolTestBase { String[] argsR = new String[]{ cmdR.getName(), "-tag", tagMapToStringParams(tagMap), - getFileSystem().getBucket() + "s3a://" + bucket + "/" }; // run