Skip to content

Commit 5fdb23d

Browse files
committed
addendum - ignore region configured for central endpoint + tests
1 parent 2b89855 commit 5fdb23d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/DefaultS3ClientFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,11 @@ private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> void
293293
boolean overrideEndpoint = true;
294294
checkArgument(!fipsEnabled,
295295
"%s : %s", ERROR_ENDPOINT_WITH_FIPS, endpoint);
296-
// No region was configured, try to determine it from the endpoint.
297-
if (region == null) {
298-
boolean endpointEndsWithCentral =
299-
endpointStr.endsWith(CENTRAL_ENDPOINT);
296+
boolean endpointEndsWithCentral =
297+
endpointStr.endsWith(CENTRAL_ENDPOINT);
298+
// No region was configured or the endpoint is central,
299+
// determine the region from the endpoint.
300+
if (region == null || endpointEndsWithCentral) {
300301
region = getS3RegionFromEndpoint(endpointStr,
301302
endpointEndsWithCentral);
302303
if (region != null) {

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AEndpointRegion.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ public void testCentralEndpointWithRegion() throws Throwable {
160160
describe("Create a client with the central endpoint but also specify region");
161161
Configuration conf = getConfiguration();
162162

163-
S3Client client = createS3Client(conf, CENTRAL_ENDPOINT, US_WEST_2, US_WEST_2, false);
163+
S3Client client = createS3Client(conf, CENTRAL_ENDPOINT, US_WEST_2, US_EAST_2, false);
164164

165165
expectInterceptorException(client);
166166

167-
client = createS3Client(conf, CENTRAL_ENDPOINT, US_EAST_1, US_EAST_1, false);
167+
client = createS3Client(conf, CENTRAL_ENDPOINT, US_EAST_1, US_EAST_2, false);
168168

169169
expectInterceptorException(client);
170170
}
@@ -279,6 +279,23 @@ public void testWithVPCE() throws Throwable {
279279
public void testCentralEndpointCrossRegionAccess() throws Throwable {
280280
describe("Create bucket on different region and access it using central endpoint");
281281
final Configuration conf = getConfiguration();
282+
removeBaseAndBucketOverrides(conf, ENDPOINT);
283+
284+
final Configuration newConf = new Configuration(conf);
285+
286+
newConf.set(ENDPOINT, CENTRAL_ENDPOINT);
287+
288+
newFS = new S3AFileSystem();
289+
newFS.initialize(getFileSystem().getUri(), newConf);
290+
291+
assertOpsUsingNewFs();
292+
}
293+
294+
@Test
295+
public void testCentralEndpointWithNullRegionCrossRegionAccess() throws Throwable {
296+
describe(
297+
"Create bucket on different region and access it using central endpoint and null region");
298+
final Configuration conf = getConfiguration();
282299
removeBaseAndBucketOverrides(conf, ENDPOINT, AWS_REGION);
283300

284301
final Configuration newConf = new Configuration(conf);
@@ -288,6 +305,10 @@ public void testCentralEndpointCrossRegionAccess() throws Throwable {
288305
newFS = new S3AFileSystem();
289306
newFS.initialize(getFileSystem().getUri(), newConf);
290307

308+
assertOpsUsingNewFs();
309+
}
310+
311+
private void assertOpsUsingNewFs() throws IOException {
291312
final String file = getMethodName();
292313
final Path basePath = methodPath();
293314
final Path srcDir = new Path(basePath, "srcdir");
@@ -328,7 +349,7 @@ private final class RegionInterceptor implements ExecutionInterceptor {
328349
public void beforeExecution(Context.BeforeExecution context,
329350
ExecutionAttributes executionAttributes) {
330351

331-
if (endpoint != null && (!endpoint.endsWith(CENTRAL_ENDPOINT) || !US_EAST_2.equals(region))) {
352+
if (endpoint != null && !endpoint.endsWith(CENTRAL_ENDPOINT)) {
332353
Assertions.assertThat(
333354
executionAttributes.getAttribute(AwsExecutionAttribute.ENDPOINT_OVERRIDDEN))
334355
.describedAs("Endpoint not overridden").isTrue();

0 commit comments

Comments
 (0)