-
Notifications
You must be signed in to change notification settings - Fork 3.4k
AWS: create HttpClientProperties, move s3 related methods into S3FileIOProperties #7562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1b74bca
5f50536
65891ad
7769028
5601d12
74876a0
4c7494b
c59b956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg.aws; | ||
|
|
||
| import java.util.Map; | ||
| import org.apache.iceberg.common.DynClasses; | ||
| import org.apache.iceberg.common.DynMethods; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Strings; | ||
| import org.apache.iceberg.util.PropertyUtil; | ||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
| import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; | ||
| import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
|
|
||
| public class AwsClientProperties { | ||
| /** | ||
| * Configure the AWS credentials provider used to create AWS clients. A fully qualified concrete | ||
| * class with package that implements the {@link AwsCredentialsProvider} interface is required. | ||
| * | ||
| * <p>Additionally, the implementation class must also have a create() or create(Map) method | ||
| * implemented, which returns an instance of the class that provides aws credentials provider. | ||
| * | ||
| * <p>Example: | ||
| * client.credentials-provider=software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider | ||
| * | ||
| * <p>When set, the default client factory {@link | ||
| * org.apache.iceberg.aws.AwsClientFactories#defaultFactory()} and other AWS client factory | ||
| * classes will use this provider to get AWS credentials provided instead of reading the default | ||
| * credential chain to get AWS access credentials. | ||
| */ | ||
| public static final String CLIENT_CREDENTIALS_PROVIDER = "client.credentials-provider"; | ||
|
|
||
| /** | ||
| * Used by the client.credentials-provider configured value that will be used by {@link | ||
| * org.apache.iceberg.aws.AwsClientFactories#defaultFactory()} and other AWS client factory | ||
| * classes to pass provider-specific properties. Each property consists of a key name and an | ||
| * associated value. | ||
| */ | ||
| private static final String CLIENT_CREDENTIAL_PROVIDER_PREFIX = "client.credentials-provider."; | ||
|
|
||
| private String clientCredentialsProvider; | ||
| private final Map<String, String> clientCredentialsProviderProperties; | ||
|
|
||
| public AwsClientProperties() { | ||
| this.clientCredentialsProvider = null; | ||
| this.clientCredentialsProviderProperties = null; | ||
| } | ||
|
|
||
| public AwsClientProperties(Map<String, String> properties) { | ||
| this.clientCredentialsProvider = properties.get(CLIENT_CREDENTIALS_PROVIDER); | ||
| this.clientCredentialsProviderProperties = | ||
| PropertyUtil.propertiesWithPrefix(properties, CLIENT_CREDENTIAL_PROVIDER_PREFIX); | ||
| } | ||
|
|
||
| @SuppressWarnings("checkstyle:HiddenField") | ||
| public AwsCredentialsProvider credentialsProvider( | ||
|
jackye1995 marked this conversation as resolved.
|
||
| String accessKeyId, String secretAccessKey, String sessionToken) { | ||
| if (accessKeyId != null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that's probably a miss we can fix here |
||
| if (sessionToken == null) { | ||
| return StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create(accessKeyId, secretAccessKey)); | ||
| } else { | ||
| return StaticCredentialsProvider.create( | ||
| AwsSessionCredentials.create(accessKeyId, secretAccessKey, sessionToken)); | ||
| } | ||
| } | ||
|
|
||
| if (!Strings.isNullOrEmpty(this.clientCredentialsProvider)) { | ||
| return credentialsProvider(this.clientCredentialsProvider); | ||
| } | ||
|
|
||
| return DefaultCredentialsProvider.create(); | ||
| } | ||
|
|
||
| private AwsCredentialsProvider credentialsProvider(String credentialsProviderClass) { | ||
| Class<?> providerClass; | ||
| try { | ||
| providerClass = DynClasses.builder().impl(credentialsProviderClass).buildChecked(); | ||
| } catch (ClassNotFoundException e) { | ||
| throw new IllegalArgumentException( | ||
| String.format( | ||
| "Cannot load class %s, it does not exist in the classpath", credentialsProviderClass), | ||
| e); | ||
| } | ||
|
|
||
| Preconditions.checkArgument( | ||
| AwsCredentialsProvider.class.isAssignableFrom(providerClass), | ||
| String.format( | ||
| "Cannot initialize %s, it does not implement %s.", | ||
| credentialsProviderClass, AwsCredentialsProvider.class.getName())); | ||
|
|
||
| AwsCredentialsProvider provider; | ||
| try { | ||
| try { | ||
| provider = | ||
| DynMethods.builder("create") | ||
| .hiddenImpl(providerClass, Map.class) | ||
| .buildStaticChecked() | ||
| .invoke(clientCredentialsProviderProperties); | ||
| } catch (NoSuchMethodException e) { | ||
| provider = | ||
| DynMethods.builder("create").hiddenImpl(providerClass).buildStaticChecked().invoke(); | ||
| } | ||
|
|
||
| return provider; | ||
| } catch (NoSuchMethodException e) { | ||
| throw new IllegalArgumentException( | ||
| String.format( | ||
| "Cannot create an instance of %s, it does not contain a static 'create' or 'create(Map<String, String>)' method", | ||
| credentialsProviderClass), | ||
| e); | ||
| } | ||
|
Comment on lines
+111
to
+165
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block is a bit hard to read imo, I got what's going on but while we're at this refactoring we can take the opportunity to do some cleanup. For this could we have a separate helper for obtaining the provider with some inline comment on our "fallback" behavior. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,24 +493,37 @@ public class AwsProperties implements Serializable { | |
| * AwsClientFactory} If set, all AWS clients will use this specified HTTP client. If not set, | ||
| * {@link #HTTP_CLIENT_TYPE_DEFAULT} will be used. For specific types supported, see | ||
| * HTTP_CLIENT_TYPE_* defined below. | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| public static final String HTTP_CLIENT_TYPE = "http-client.type"; | ||
| @Deprecated public static final String HTTP_CLIENT_TYPE = "http-client.type"; | ||
|
|
||
| /** | ||
| * If this is set under {@link #HTTP_CLIENT_TYPE}, {@link | ||
| * software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient} will be used as the HTTP | ||
| * Client in {@link AwsClientFactory} | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| public static final String HTTP_CLIENT_TYPE_URLCONNECTION = "urlconnection"; | ||
| @Deprecated public static final String HTTP_CLIENT_TYPE_URLCONNECTION = "urlconnection"; | ||
|
|
||
| /** | ||
| * If this is set under {@link #HTTP_CLIENT_TYPE}, {@link | ||
| * software.amazon.awssdk.http.apache.ApacheHttpClient} will be used as the HTTP Client in {@link | ||
| * AwsClientFactory} | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| public static final String HTTP_CLIENT_TYPE_APACHE = "apache"; | ||
| @Deprecated public static final String HTTP_CLIENT_TYPE_APACHE = "apache"; | ||
|
|
||
| public static final String HTTP_CLIENT_TYPE_DEFAULT = HTTP_CLIENT_TYPE_APACHE; | ||
| /** | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup |
||
| */ | ||
| @Deprecated public static final String HTTP_CLIENT_TYPE_DEFAULT = HTTP_CLIENT_TYPE_APACHE; | ||
|
|
||
| /** | ||
| * Used to configure the connection timeout in milliseconds for {@link | ||
|
|
@@ -519,7 +532,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_URLCONNECTION_CONNECTION_TIMEOUT_MS = | ||
| "http-client.urlconnection.connection-timeout-ms"; | ||
|
|
||
|
|
@@ -530,7 +547,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_URLCONNECTION_SOCKET_TIMEOUT_MS = | ||
| "http-client.urlconnection.socket-timeout-ms"; | ||
|
|
||
|
|
@@ -541,7 +562,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_CONNECTION_TIMEOUT_MS = | ||
| "http-client.apache.connection-timeout-ms"; | ||
|
|
||
|
|
@@ -552,7 +577,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_SOCKET_TIMEOUT_MS = | ||
| "http-client.apache.socket-timeout-ms"; | ||
|
|
||
|
|
@@ -563,7 +592,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_CONNECTION_ACQUISITION_TIMEOUT_MS = | ||
| "http-client.apache.connection-acquisition-timeout-ms"; | ||
|
|
||
|
|
@@ -574,7 +607,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_CONNECTION_MAX_IDLE_TIME_MS = | ||
| "http-client.apache.connection-max-idle-time-ms"; | ||
|
|
||
|
|
@@ -585,7 +622,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_CONNECTION_TIME_TO_LIVE_MS = | ||
| "http-client.apache.connection-time-to-live-ms"; | ||
|
|
||
|
|
@@ -598,7 +639,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_EXPECT_CONTINUE_ENABLED = | ||
| "http-client.apache.expect-continue-enabled"; | ||
|
|
||
|
|
@@ -609,7 +654,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_MAX_CONNECTIONS = | ||
| "http-client.apache.max-connections"; | ||
|
|
||
|
|
@@ -622,7 +671,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_TCP_KEEP_ALIVE_ENABLED = | ||
| "http-client.apache.tcp-keep-alive-enabled"; | ||
|
|
||
|
|
@@ -635,7 +688,11 @@ public class AwsProperties implements Serializable { | |
| * | ||
| * <p>For more details, see | ||
| * https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.Builder.html | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public static final String HTTP_CLIENT_APACHE_USE_IDLE_CONNECTION_REAPER_ENABLED = | ||
| "http-client.apache.use-idle-connection-reaper-enabled"; | ||
| /** | ||
|
|
@@ -1505,7 +1562,11 @@ public void setClientRegion(String clientRegion) { | |
| * <pre> | ||
| * S3Client.builder().applyMutation(awsProperties::applyS3CredentialConfigurations) | ||
| * </pre> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.s3.S3FileIOProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public <T extends S3ClientBuilder> void applyS3CredentialConfigurations(T builder) { | ||
| builder.credentialsProvider( | ||
| s3RemoteSigningEnabled | ||
|
|
@@ -1552,7 +1613,11 @@ public <T extends AwsClientBuilder> void applyClientCredentialConfigurations(T b | |
| * <pre> | ||
| * S3Client.builder().applyMutation(awsProperties::applyS3ServiceConfigurations) | ||
| * </pre> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.s3.S3FileIOProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public <T extends S3ClientBuilder> void applyS3ServiceConfigurations(T builder) { | ||
| builder | ||
| .dualstackEnabled(s3DualStackEnabled) | ||
|
|
@@ -1572,7 +1637,11 @@ public <T extends S3ClientBuilder> void applyS3ServiceConfigurations(T builder) | |
| * <pre> | ||
| * S3Client.builder().applyMutation(awsProperties::applyS3SignerConfiguration) | ||
| * </pre> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.s3.S3FileIOProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public <T extends S3ClientBuilder> void applyS3SignerConfiguration(T builder) { | ||
| if (s3RemoteSigningEnabled) { | ||
| builder.overrideConfiguration( | ||
|
|
@@ -1591,7 +1660,11 @@ public <T extends S3ClientBuilder> void applyS3SignerConfiguration(T builder) { | |
| * <pre> | ||
| * S3Client.builder().applyMutation(awsProperties::applyHttpClientConfigurations) | ||
| * </pre> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public <T extends AwsSyncClientBuilder> void applyHttpClientConfigurations(T builder) { | ||
| if (Strings.isNullOrEmpty(httpClientType)) { | ||
| httpClientType = HTTP_CLIENT_TYPE_DEFAULT; | ||
|
|
@@ -1620,7 +1693,11 @@ public <T extends AwsSyncClientBuilder> void applyHttpClientConfigurations(T bui | |
| * <pre> | ||
| * S3Client.builder().applyMutation(awsProperties::applyS3EndpointConfigurations) | ||
| * </pre> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.s3.S3FileIOProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| public <T extends S3ClientBuilder> void applyS3EndpointConfigurations(T builder) { | ||
| configureEndpoint(builder, s3Endpoint); | ||
| } | ||
|
|
@@ -1760,7 +1837,11 @@ private <T extends SdkClientBuilder> void configureEndpoint(T builder, String en | |
| * software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient} and {@link | ||
| * software.amazon.awssdk.http.apache.ApacheHttpClient}, since including both will cause error | ||
| * described in <a href="https://github.com/apache/iceberg/issues/6715">issue#6715</a> | ||
| * | ||
| * @deprecated will be removed in 1.4.0, use {@link org.apache.iceberg.aws.HttpClientProperties} | ||
| * instead | ||
| */ | ||
| @Deprecated | ||
| private <T> T loadHttpClientConfigurations(String impl) { | ||
| Object httpClientConfigurations; | ||
| try { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.