-
Notifications
You must be signed in to change notification settings - Fork 3k
AWS: Load HttpClientBuilder dynamically to avoid runtime deps of both urlconnection and apache client #6746
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
Merged
jackye1995
merged 15 commits into
apache:master
from
JonasJ-ap:bug_fix_aws_httpclient_conflict_prefix_map
Feb 9, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
13b98b3
first draft, tested locally
JonasJ-ap e5c75a5
make new implementation package-private
JonasJ-ap 2425561
add try-catch
JonasJ-ap eef197a
add unit tests
JonasJ-ap 43983f6
rebase
JonasJ-ap 61574de
revise javadoc to get rid of importing urlconnectionhttpclient.builder
JonasJ-ap 1b242c0
restore property strings
JonasJ-ap d6e899d
switch to abstract class
JonasJ-ap d20d707
fix bug of loading unconfigred instance
JonasJ-ap 8c62f8e
fix error messages and refactor the unit test for http client configu…
JonasJ-ap d9341ec
combine two maps
JonasJ-ap b74c0cb
use static method to avoid common classes
JonasJ-ap 76a37e6
use predicate to filter properties
JonasJ-ap d446aea
rename helper method to filterProperties and parse a predicate to fil…
JonasJ-ap a12e212
add javadoc and fix the comment
JonasJ-ap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
aws/src/main/java/org/apache/iceberg/aws/ApacheHttpClientConfigurations.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * 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.time.Duration; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.iceberg.util.PropertyUtil; | ||
| import software.amazon.awssdk.awscore.client.builder.AwsSyncClientBuilder; | ||
| import software.amazon.awssdk.http.apache.ApacheHttpClient; | ||
|
|
||
| class ApacheHttpClientConfigurations { | ||
| private Long connectionTimeoutMs; | ||
| private Long socketTimeoutMs; | ||
| private Long acquisitionTimeoutMs; | ||
| private Long connectionMaxIdleTimeMs; | ||
| private Long connectionTimeToLiveMs; | ||
| private Boolean expectContinueEnabled; | ||
| private Integer maxConnections; | ||
| private Boolean tcpKeepAliveEnabled; | ||
| private Boolean useIdleConnectionReaperEnabled; | ||
|
|
||
| private ApacheHttpClientConfigurations() {} | ||
|
|
||
| public <T extends AwsSyncClientBuilder> void configureHttpClientBuilder(T awsClientBuilder) { | ||
| ApacheHttpClient.Builder apacheHttpClientBuilder = ApacheHttpClient.builder(); | ||
| configureApacheHttpClientBuilder(apacheHttpClientBuilder); | ||
| awsClientBuilder.httpClientBuilder(apacheHttpClientBuilder); | ||
| } | ||
|
|
||
| private void initialize(Map<String, String> httpClientProperties) { | ||
| this.connectionTimeoutMs = | ||
| PropertyUtil.propertyAsNullableLong( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_CONNECTION_TIMEOUT_MS); | ||
| this.socketTimeoutMs = | ||
| PropertyUtil.propertyAsNullableLong( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_SOCKET_TIMEOUT_MS); | ||
| this.acquisitionTimeoutMs = | ||
| PropertyUtil.propertyAsNullableLong( | ||
| httpClientProperties, | ||
| AwsProperties.HTTP_CLIENT_APACHE_CONNECTION_ACQUISITION_TIMEOUT_MS); | ||
| this.connectionMaxIdleTimeMs = | ||
| PropertyUtil.propertyAsNullableLong( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_CONNECTION_MAX_IDLE_TIME_MS); | ||
| this.connectionTimeToLiveMs = | ||
| PropertyUtil.propertyAsNullableLong( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_CONNECTION_TIME_TO_LIVE_MS); | ||
| this.expectContinueEnabled = | ||
| PropertyUtil.propertyAsNullableBoolean( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_EXPECT_CONTINUE_ENABLED); | ||
| this.maxConnections = | ||
| PropertyUtil.propertyAsNullableInt( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_MAX_CONNECTIONS); | ||
| this.tcpKeepAliveEnabled = | ||
| PropertyUtil.propertyAsNullableBoolean( | ||
| httpClientProperties, AwsProperties.HTTP_CLIENT_APACHE_TCP_KEEP_ALIVE_ENABLED); | ||
| this.useIdleConnectionReaperEnabled = | ||
| PropertyUtil.propertyAsNullableBoolean( | ||
| httpClientProperties, | ||
| AwsProperties.HTTP_CLIENT_APACHE_USE_IDLE_CONNECTION_REAPER_ENABLED); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| void configureApacheHttpClientBuilder(ApacheHttpClient.Builder apacheHttpClientBuilder) { | ||
| if (connectionTimeoutMs != null) { | ||
| apacheHttpClientBuilder.connectionTimeout(Duration.ofMillis(connectionTimeoutMs)); | ||
| } | ||
| if (socketTimeoutMs != null) { | ||
| apacheHttpClientBuilder.socketTimeout(Duration.ofMillis(socketTimeoutMs)); | ||
| } | ||
| if (acquisitionTimeoutMs != null) { | ||
| apacheHttpClientBuilder.connectionAcquisitionTimeout(Duration.ofMillis(acquisitionTimeoutMs)); | ||
| } | ||
| if (connectionMaxIdleTimeMs != null) { | ||
| apacheHttpClientBuilder.connectionMaxIdleTime(Duration.ofMillis(connectionMaxIdleTimeMs)); | ||
| } | ||
| if (connectionTimeToLiveMs != null) { | ||
| apacheHttpClientBuilder.connectionTimeToLive(Duration.ofMillis(connectionTimeToLiveMs)); | ||
| } | ||
| if (expectContinueEnabled != null) { | ||
| apacheHttpClientBuilder.expectContinueEnabled(expectContinueEnabled); | ||
| } | ||
| if (maxConnections != null) { | ||
| apacheHttpClientBuilder.maxConnections(maxConnections); | ||
| } | ||
| if (tcpKeepAliveEnabled != null) { | ||
| apacheHttpClientBuilder.tcpKeepAlive(tcpKeepAliveEnabled); | ||
| } | ||
| if (useIdleConnectionReaperEnabled != null) { | ||
| apacheHttpClientBuilder.useIdleConnectionReaper(useIdleConnectionReaperEnabled); | ||
| } | ||
| } | ||
|
|
||
| public static ApacheHttpClientConfigurations create(Map<String, String> properties) { | ||
| ApacheHttpClientConfigurations configurations = new ApacheHttpClientConfigurations(); | ||
| configurations.initialize(properties); | ||
| return configurations; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe add a brief Javadoc to explain why we are doing the reflection here and link to the github issue for more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1