Skip to content

Commit 34beeea

Browse files
committed
HADOOP-18820. checkstyle and minor code cleanups
biggest change is that S3AInternals exports getBucketMetadata(), this was used in a test, and its output indirectly available on getXattrs(/). Change-Id: Iaf45ccbdd778be474e6ece07275ba179c215cf83
1 parent 99273eb commit 34beeea

File tree

10 files changed

+59
-39
lines changed

10 files changed

+59
-39
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,17 @@ public HeadObjectResponse getObjectMetadata(Path path) throws IOException {
14441444
"getObjectMetadata"));
14451445
}
14461446

1447+
/**
1448+
* S3AInternals method.
1449+
* {@inheritDoc}.
1450+
*/
1451+
@Override
1452+
@AuditEntryPoint
1453+
@Retries.RetryTranslated
1454+
public HeadBucketResponse getBucketMetadata() throws IOException {
1455+
return S3AFileSystem.this.getBucketMetadata();
1456+
}
1457+
14471458
/**
14481459
* Get a shared copy of the AWS credentials, with its reference
14491460
* counter updated.
@@ -2821,7 +2832,8 @@ protected HeadObjectResponse getObjectMetadata(String key,
28212832
* @throws UnknownStoreException the bucket is absent
28222833
* @throws IOException any other problem talking to S3
28232834
*/
2824-
@Retries.RetryRaw
2835+
@AuditEntryPoint
2836+
@Retries.RetryTranslated
28252837
protected HeadBucketResponse getBucketMetadata() throws IOException {
28262838
final HeadBucketResponse response = trackDurationAndSpan(STORE_EXISTS_PROBE, bucket, null,
28272839
() -> invoker.retry("getBucketMetadata()", bucket, true, () -> {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.file.AccessDeniedException;
2323

2424
import software.amazon.awssdk.services.s3.S3Client;
25+
import software.amazon.awssdk.services.s3.model.HeadBucketResponse;
2526
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
2627

2728
import org.apache.hadoop.classification.InterfaceAudience;
@@ -96,4 +97,14 @@ public interface S3AInternals {
9697
* @return a reference to shared credentials.
9798
*/
9899
AWSCredentialProviderList shareCredentials(String purpose);
100+
101+
/**
102+
* Request bucket metadata.
103+
* @return the metadata
104+
* @throws UnknownStoreException the bucket is absent
105+
* @throws IOException any other problem talking to S3
106+
*/
107+
@AuditEntryPoint
108+
@Retries.RetryTranslated
109+
HeadBucketResponse getBucketMetadata() throws IOException;
99110
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class SimpleAWSCredentialsProvider implements AwsCredentialsProvider {
6161
*/
6262
public SimpleAWSCredentialsProvider(final URI uri, final Configuration conf)
6363
throws IOException {
64-
this(getAWSAccessKeys(uri, conf));
64+
this(getAWSAccessKeys(uri, conf));
6565
}
6666

6767
/**
@@ -73,8 +73,8 @@ public SimpleAWSCredentialsProvider(final URI uri, final Configuration conf)
7373
@VisibleForTesting
7474
SimpleAWSCredentialsProvider(final S3xLoginHelper.Login login)
7575
throws IOException {
76-
this.accessKey = login.getUser();
77-
this.secretKey = login.getPassword();
76+
this.accessKey = login.getUser();
77+
this.secretKey = login.getPassword();
7878
}
7979

8080
@Override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
import software.amazon.awssdk.services.s3.model.StorageClass;
4242
import software.amazon.awssdk.services.s3.model.UploadPartRequest;
4343

44+
import org.apache.hadoop.classification.InterfaceAudience;
45+
import org.apache.hadoop.classification.InterfaceStability;
4446
import org.apache.hadoop.fs.PathIOException;
4547
import org.apache.hadoop.fs.s3a.S3AEncryptionMethods;
4648
import org.apache.hadoop.fs.s3a.auth.delegation.EncryptionSecrets;
4749
import org.apache.hadoop.fs.s3a.impl.PutObjectOptions;
4850

4951
/**
50-
* Factory for S3 objects.
52+
* Factory for S3 request objects.
5153
*
5254
* This is where the owner FS's {@code prepareRequest()}
5355
* callback is invoked to mark up a request for this span.
@@ -61,6 +63,8 @@
6163
* as there are no guarantees how they are processed.
6264
* That is: no guarantees of retry or translation.
6365
*/
66+
@InterfaceStability.Unstable
67+
@InterfaceAudience.LimitedPrivate("testing/diagnostics")
6468
public interface RequestFactory {
6569

6670
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static class BadCredentialsProviderConstructor
8080
implements AwsCredentialsProvider {
8181

8282
@SuppressWarnings("unused")
83-
public BadCredentialsProviderConstructor(String fsUri, Configuration conf) {
83+
BadCredentialsProviderConstructor(String fsUri, Configuration conf) {
8484
}
8585

8686
@Override
@@ -125,7 +125,7 @@ private void createFailingFS(Configuration conf) throws IOException {
125125
static class BadCredentialsProvider implements AwsCredentialsProvider {
126126

127127
@SuppressWarnings("unused")
128-
public BadCredentialsProvider(Configuration conf) {
128+
BadCredentialsProvider(Configuration conf) {
129129
}
130130

131131
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private Configuration createConfigurationWithProbe(final int probe) {
131131
ENDPOINT,
132132
AWS_REGION);
133133
conf.setInt(S3A_BUCKET_PROBE, probe);
134-
conf.set(AWS_REGION, "eu-west-1");
134+
conf.set(AWS_REGION, EU_WEST_1);
135135
return conf;
136136
}
137137

@@ -210,7 +210,7 @@ public void testAccessPointRequired() throws Exception {
210210
*/
211211
private Configuration createArnConfiguration() {
212212
Configuration configuration = createConfigurationWithProbe(2);
213-
configuration.set(AWS_REGION, "eu-west-1");
213+
configuration.set(AWS_REGION, EU_WEST_1);
214214
return configuration;
215215
}
216216

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package org.apache.hadoop.fs.s3a;
2020

2121
import java.io.File;
22-
import java.io.IOException;
2322
import java.net.URI;
23+
import java.nio.file.AccessDeniedException;
2424
import java.security.PrivilegedExceptionAction;
2525

2626
import org.assertj.core.api.Assertions;
@@ -38,7 +38,6 @@
3838
import software.amazon.awssdk.services.s3.S3Client;
3939
import software.amazon.awssdk.services.s3.S3Configuration;
4040
import software.amazon.awssdk.services.s3.model.HeadBucketRequest;
41-
import software.amazon.awssdk.services.s3.model.S3Exception;
4241
import software.amazon.awssdk.services.sts.StsClient;
4342
import software.amazon.awssdk.services.sts.model.StsException;
4443

@@ -60,6 +59,7 @@
6059

6160
import static java.util.Objects.requireNonNull;
6261
import static org.apache.hadoop.fs.s3a.Constants.*;
62+
import static org.apache.hadoop.fs.s3a.S3ATestConstants.EU_WEST_1;
6363
import static org.apache.hadoop.fs.s3a.S3AUtils.*;
6464
import static org.apache.hadoop.fs.s3a.S3ATestUtils.*;
6565
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
@@ -134,7 +134,6 @@ public void testEndpoint() throws Exception {
134134
} else {
135135
conf.set(Constants.ENDPOINT, endpoint);
136136
fs = S3ATestUtils.createTestFileSystem(conf);
137-
S3Client s3 = getS3Client("test endpoint");
138137
String endPointRegion = "";
139138
// Differentiate handling of "s3-" and "s3." based endpoint identifiers
140139
String[] endpointParts = StringUtils.split(endpoint, '.');
@@ -173,7 +172,7 @@ protected void useFailFastConfiguration() {
173172
}
174173

175174
/**
176-
* Expect a filesystem to not be created from a configuration
175+
* Expect a filesystem to not be created from a configuration.
177176
* @return the exception intercepted
178177
* @throws Exception any other exception
179178
*/
@@ -540,36 +539,34 @@ public void testConfOptionPropagationToFS() throws Exception {
540539
}
541540

542541
@Test(timeout = 10_000L)
543-
public void testS3SpecificSignerOverride() throws IOException {
542+
public void testS3SpecificSignerOverride() throws Exception {
544543
Configuration config = new Configuration();
544+
removeBaseAndBucketOverrides(config,
545+
CUSTOM_SIGNERS, SIGNING_ALGORITHM_S3, SIGNING_ALGORITHM_STS, AWS_REGION);
545546

546547
config.set(CUSTOM_SIGNERS,
547-
"CustomS3Signer:" + CustomS3Signer.class.getName() + ",CustomSTSSigner:"
548-
+ CustomSTSSigner.class.getName());
548+
"CustomS3Signer:" + CustomS3Signer.class.getName()
549+
+ ",CustomSTSSigner:" + CustomSTSSigner.class.getName());
549550

550551
config.set(SIGNING_ALGORITHM_S3, "CustomS3Signer");
551552
config.set(SIGNING_ALGORITHM_STS, "CustomSTSSigner");
552553

553-
config.set(AWS_REGION, "eu-west-1");
554+
config.set(AWS_REGION, EU_WEST_1);
554555
fs = S3ATestUtils.createTestFileSystem(config);
555556

556557
S3Client s3Client = getS3Client("testS3SpecificSignerOverride");
557558

559+
final String bucket = fs.getBucket();
558560
StsClient stsClient =
559-
STSClientFactory.builder(config, fs.getBucket(), new AnonymousAWSCredentialsProvider(), "",
561+
STSClientFactory.builder(config, bucket, new AnonymousAWSCredentialsProvider(), "",
560562
"").build();
561563

562-
try {
563-
stsClient.getSessionToken();
564-
} catch (StsException exception) {
565-
// Expected 403, as credentials are not provided.
566-
}
564+
intercept(StsException.class, "", () ->
565+
stsClient.getSessionToken());
567566

568-
try {
569-
s3Client.headBucket(HeadBucketRequest.builder().bucket(fs.getBucket()).build());
570-
} catch (S3Exception exception) {
571-
// Expected 403, as credentials are not provided.
572-
}
567+
intercept(AccessDeniedException.class, "", () ->
568+
Invoker.once("head", bucket, () ->
569+
s3Client.headBucket(HeadBucketRequest.builder().bucket(bucket).build())));
573570

574571
Assertions.assertThat(CustomS3Signer.isS3SignerCalled())
575572
.describedAs("Custom S3 signer not called").isTrue();

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626

2727
import org.assertj.core.api.Assertions;
28-
import org.junit.Assert;
2928
import org.junit.Test;
3029
import software.amazon.awssdk.awscore.AwsExecutionAttribute;
3130
import software.amazon.awssdk.awscore.exception.AwsServiceException;
@@ -34,14 +33,12 @@
3433
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
3534
import software.amazon.awssdk.services.s3.S3Client;
3635
import software.amazon.awssdk.services.s3.model.HeadBucketRequest;
37-
import software.amazon.awssdk.services.s3.model.S3Exception;
3836

3937
import org.apache.hadoop.conf.Configuration;
4038
import org.apache.hadoop.fs.s3a.statistics.impl.EmptyS3AStatisticsContext;
4139

4240
import static org.apache.hadoop.fs.s3a.Constants.AWS_REGION;
4341
import static org.apache.hadoop.fs.s3a.Statistic.STORE_REGION_PROBE;
44-
import static org.apache.hadoop.fs.s3a.impl.InternalConstants.SC_301_MOVED_PERMANENTLY;
4542
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
4643

4744
/**
@@ -68,13 +65,7 @@ public void testWithoutRegionConfig() throws IOException {
6865
S3AFileSystem fs = new S3AFileSystem();
6966
fs.initialize(getFileSystem().getUri(), conf);
7067

71-
try {
72-
fs.getBucketMetadata();
73-
} catch (S3Exception exception) {
74-
if (exception.statusCode() == SC_301_MOVED_PERMANENTLY) {
75-
Assert.fail(exception.toString());
76-
}
77-
}
68+
fs.getS3AInternals().getBucketMetadata();
7869

7970
Assertions.assertThat(fs.getInstrumentation().getCounterValue(STORE_REGION_PROBE))
8071
.describedAs("Region is not configured, region probe should have been made").isEqualTo(1);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ private static <T> T verifyNoTrailingSlash(String role, T o) {
412412
private GetBucketEncryptionResponse getDefaultEncryption() throws IOException {
413413
S3AFileSystem fs = getFileSystem();
414414
S3Client s3 = getS3AInternals().getAmazonS3V2ClientForTesting("check default encryption");
415-
try {
415+
try (AuditSpan s = span()){
416416
return Invoker.once("getBucketEncryption()",
417417
fs.getBucket(),
418418
() -> s3.getBucketEncryption(GetBucketEncryptionRequest.builder()

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,9 @@ public interface S3ATestConstants {
251251
* Value: {@value}.
252252
*/
253253
String PROJECT_BUILD_DIRECTORY_PROPERTY = "project.build.directory";
254+
255+
/**
256+
* AWS ireland region.
257+
*/
258+
String EU_WEST_1 = "eu-west-1";
254259
}

0 commit comments

Comments
 (0)