Skip to content

Commit 7fb9c30

Browse files
authored
HADOOP-18382. AWS SDK v2 upgrade prerequisites (#4698)
This patch prepares the hadoop-aws module for a future migration to using the v2 AWS SDK (HADOOP-18073) That upgrade will be incompatible; this patch prepares for it: -marks some credential providers and other classes and methods as @deprecated. -updates site documentation -reduces the visibility of the s3 client; other than for testing, it is kept private to the S3AFileSystem class. -logs some warnings when deprecated APIs are used. The warning messages are printed only once per JVM's life. To disable them, set the log level of org.apache.hadoop.fs.s3a.SDKV2Upgrade to ERROR Contributed by Ahmar Suhail
1 parent 1691ccc commit 7fb9c30

38 files changed

+440
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
*/
6262
@InterfaceAudience.Private
6363
@InterfaceStability.Evolving
64-
public class AWSCredentialProviderList implements AWSCredentialsProvider,
64+
public final class AWSCredentialProviderList implements AWSCredentialsProvider,
6565
AutoCloseable {
6666

6767
private static final Logger LOG = LoggerFactory.getLogger(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
* Please note that users may reference this class name from configuration
3535
* property fs.s3a.aws.credentials.provider. Therefore, changing the class name
3636
* would be a backward-incompatible change.
37+
*
38+
* @deprecated This class will be replaced by one that implements AWS SDK V2's AwsCredentialProvider
39+
* as part of upgrading S3A to SDK V2. See HADOOP-18073.
3740
*/
3841
@InterfaceAudience.Private
3942
@InterfaceStability.Stable
43+
@Deprecated
4044
public class AnonymousAWSCredentialsProvider implements AWSCredentialsProvider {
4145

4246
public static final String NAME

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ private Constants() {
140140
public static final String ASSUMED_ROLE_POLICY =
141141
"fs.s3a.assumed.role.policy";
142142

143+
@SuppressWarnings("deprecation")
143144
public static final String ASSUMED_ROLE_CREDENTIALS_DEFAULT =
144145
SimpleAWSCredentialsProvider.NAME;
145146

@@ -732,6 +733,7 @@ private Constants() {
732733

733734
@InterfaceAudience.Private
734735
@InterfaceStability.Unstable
736+
@SuppressWarnings("deprecation")
735737
public static final Class<? extends S3ClientFactory>
736738
DEFAULT_S3_CLIENT_FACTORY_IMPL =
737739
DefaultS3ClientFactory.class;
@@ -1204,6 +1206,11 @@ private Constants() {
12041206
*/
12051207
public static final int DEFAULT_AWS_S3_VECTOR_READS_MAX_MERGED_READ_SIZE = 1253376; //1M
12061208

1209+
/**
1210+
* Prefix of auth classes in AWS SDK V1.
1211+
*/
1212+
public static final String AWS_AUTH_CLASS_PREFIX = "com.amazonaws.auth";
1213+
12071214
/**
12081215
* Controls whether the prefetching input stream is enabled.
12091216
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
*/
7272
@InterfaceAudience.Private
7373
@InterfaceStability.Unstable
74+
@SuppressWarnings("deprecation")
7475
public class DefaultS3ClientFactory extends Configured
7576
implements S3ClientFactory {
7677

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import com.amazonaws.services.s3.AmazonS3;
5555
import com.amazonaws.services.s3.Headers;
5656
import com.amazonaws.services.s3.model.CannedAccessControlList;
57+
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
58+
import com.amazonaws.services.s3.model.CompleteMultipartUploadResult;
5759
import com.amazonaws.services.s3.model.CopyObjectRequest;
5860
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
5961
import com.amazonaws.services.s3.model.DeleteObjectsResult;
@@ -70,6 +72,8 @@
7072
import com.amazonaws.services.s3.model.PutObjectRequest;
7173
import com.amazonaws.services.s3.model.PutObjectResult;
7274
import com.amazonaws.services.s3.model.S3Object;
75+
import com.amazonaws.services.s3.model.SelectObjectContentRequest;
76+
import com.amazonaws.services.s3.model.SelectObjectContentResult;
7377
import com.amazonaws.services.s3.model.StorageClass;
7478
import com.amazonaws.services.s3.model.UploadPartRequest;
7579
import com.amazonaws.services.s3.model.UploadPartResult;
@@ -127,6 +131,7 @@
127131
import org.apache.hadoop.fs.s3a.impl.StatusProbeEnum;
128132
import org.apache.hadoop.fs.s3a.impl.StoreContext;
129133
import org.apache.hadoop.fs.s3a.impl.StoreContextBuilder;
134+
import org.apache.hadoop.fs.s3a.impl.V2Migration;
130135
import org.apache.hadoop.fs.s3a.prefetch.S3APrefetchingInputStream;
131136
import org.apache.hadoop.fs.s3a.tools.MarkerToolOperations;
132137
import org.apache.hadoop.fs.s3a.tools.MarkerToolOperationsImpl;
@@ -882,6 +887,7 @@ public Listing getListing() {
882887
* @param dtEnabled are delegation tokens enabled?
883888
* @throws IOException failure.
884889
*/
890+
@SuppressWarnings("deprecation")
885891
private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
886892
Configuration conf = getConf();
887893
credentials = null;
@@ -894,6 +900,7 @@ private void bindAWSClient(URI name, boolean dtEnabled) throws IOException {
894900
// with it if so.
895901

896902
LOG.debug("Using delegation tokens");
903+
V2Migration.v1DelegationTokenCredentialProvidersUsed();
897904
S3ADelegationTokens tokens = new S3ADelegationTokens();
898905
this.delegationTokens = Optional.of(tokens);
899906
tokens.bindToFileSystem(getCanonicalUri(),
@@ -1221,7 +1228,7 @@ public int getDefaultPort() {
12211228
* This is for internal use within the S3A code itself.
12221229
* @return AmazonS3Client
12231230
*/
1224-
AmazonS3 getAmazonS3Client() {
1231+
private AmazonS3 getAmazonS3Client() {
12251232
return s3;
12261233
}
12271234

@@ -1235,6 +1242,7 @@ AmazonS3 getAmazonS3Client() {
12351242
@VisibleForTesting
12361243
public AmazonS3 getAmazonS3ClientForTesting(String reason) {
12371244
LOG.warn("Access to S3A client requested, reason {}", reason);
1245+
V2Migration.v1S3ClientRequested();
12381246
return s3;
12391247
}
12401248

@@ -1619,6 +1627,25 @@ public <T> CompletableFuture<T> submit(final CallableRaisingIOE<T> operation) {
16191627
}
16201628
}
16211629

1630+
/**
1631+
* Callbacks for WriteOperationHelper.
1632+
*/
1633+
private final class WriteOperationHelperCallbacksImpl
1634+
implements WriteOperationHelper.WriteOperationHelperCallbacks {
1635+
1636+
@Override
1637+
public SelectObjectContentResult selectObjectContent(SelectObjectContentRequest request) {
1638+
return s3.selectObjectContent(request);
1639+
}
1640+
1641+
@Override
1642+
public CompleteMultipartUploadResult completeMultipartUpload(
1643+
CompleteMultipartUploadRequest request) {
1644+
return s3.completeMultipartUpload(request);
1645+
}
1646+
}
1647+
1648+
16221649
/**
16231650
* Create the read context for reading from the referenced file,
16241651
* using FS state as well as the status.
@@ -1843,7 +1870,8 @@ public WriteOperationHelper createWriteOperationHelper(AuditSpan auditSpan) {
18431870
getConf(),
18441871
statisticsContext,
18451872
getAuditSpanSource(),
1846-
auditSpan);
1873+
auditSpan,
1874+
new WriteOperationHelperCallbacksImpl());
18471875
}
18481876

18491877
/**
@@ -2324,6 +2352,7 @@ public int getMaxKeys() {
23242352
@Retries.RetryTranslated
23252353
@InterfaceStability.Evolving
23262354
public ObjectMetadata getObjectMetadata(Path path) throws IOException {
2355+
V2Migration.v1GetObjectMetadataCalled();
23272356
return trackDurationAndSpan(INVOCATION_GET_FILE_STATUS, path, () ->
23282357
getObjectMetadata(makeQualified(path), null, invoker,
23292358
"getObjectMetadata"));

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.hadoop.fs.s3a.auth.delegation.EncryptionSecrets;
4747
import org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider;
4848
import org.apache.hadoop.fs.s3a.impl.NetworkBinding;
49+
import org.apache.hadoop.fs.s3a.impl.V2Migration;
4950
import org.apache.hadoop.fs.s3native.S3xLoginHelper;
5051
import org.apache.hadoop.net.ConnectTimeoutException;
5152
import org.apache.hadoop.security.ProviderUtils;
@@ -551,6 +552,7 @@ public static long dateToLong(final Date date) {
551552
/**
552553
* The standard AWS provider list for AWS connections.
553554
*/
555+
@SuppressWarnings("deprecation")
554556
public static final List<Class<?>>
555557
STANDARD_AWS_PROVIDERS = Collections.unmodifiableList(
556558
Arrays.asList(
@@ -637,6 +639,10 @@ public static AWSCredentialProviderList buildAWSProviderList(
637639
AWSCredentialProviderList providers = new AWSCredentialProviderList();
638640
for (Class<?> aClass : awsClasses) {
639641

642+
if (aClass.getName().contains(AWS_AUTH_CLASS_PREFIX)) {
643+
V2Migration.v1ProviderReferenced(aClass.getName());
644+
}
645+
640646
if (forbidden.contains(aClass)) {
641647
throw new IOException(E_FORBIDDEN_AWS_PROVIDER
642648
+ " in option " + key + ": " + aClass);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@
4444
* implementing only the deprecated method will work.
4545
* See https://github.com/apache/hbase-filesystem
4646
*
47+
* @deprecated This interface will be replaced by one which uses the AWS SDK V2 S3 client as part of
48+
* upgrading S3A to SDK V2. See HADOOP-18073.
4749
*/
4850
@InterfaceAudience.LimitedPrivate("HBoss")
4951
@InterfaceStability.Evolving
52+
@Deprecated
5053
public interface S3ClientFactory {
5154

5255
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
*/
4040
@InterfaceAudience.Public
4141
@InterfaceStability.Evolving
42-
public final class SharedInstanceCredentialProvider extends
43-
IAMInstanceCredentialsProvider {
42+
@SuppressWarnings("deprecation")
43+
public final class SharedInstanceCredentialProvider extends IAMInstanceCredentialsProvider {
4444
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@
4141
* Please note that users may reference this class name from configuration
4242
* property fs.s3a.aws.credentials.provider. Therefore, changing the class name
4343
* would be a backward-incompatible change.
44+
*
45+
* @deprecated This class will be replaced by one that implements AWS SDK V2's AwsCredentialProvider
46+
* as part of upgrading S3A to SDK V2. See HADOOP-18073.
4447
*/
4548
@InterfaceAudience.Public
4649
@InterfaceStability.Stable
50+
@Deprecated
4751
public class SimpleAWSCredentialsProvider implements AWSCredentialsProvider {
4852

4953
public static final String NAME

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@
4343
*
4444
* This credential provider must not fail in creation because that will
4545
* break a chain of credential providers.
46+
*
47+
* @deprecated This class will be replaced by one that implements AWS SDK V2's AwsCredentialProvider
48+
* as part of upgrading S3A to SDK V2. See HADOOP-18073.
4649
*/
4750
@InterfaceAudience.Public
4851
@InterfaceStability.Stable
49-
public class TemporaryAWSCredentialsProvider extends
50-
AbstractSessionCredentialsProvider {
52+
@Deprecated
53+
public class TemporaryAWSCredentialsProvider extends AbstractSessionCredentialsProvider {
5154

5255
public static final String NAME
5356
= "org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider";

0 commit comments

Comments
 (0)