-
Notifications
You must be signed in to change notification settings - Fork 910
Expose S3CrtHttpConfiguration #3824
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bbbdcb1
Expose S3CrtHttpConfiguration to allow users to configure HTTP settin…
zoewangg dc87509
Fix checkstyle errors and spotbug issue
zoewangg b99ce98
Address feedback
zoewangg e08c468
close clientTlsContextOptions
zoewangg 3466563
Merge branch 'master' into zoewang/crtS3Client-httpConfig
zoewangg 9690ab6
Revert "close clientTlsContextOptions"
zoewangg 35a8f71
Fix version
zoewangg c602540
Merge branch 'master' into zoewang/crtS3Client-httpConfig
zoewangg a998a5b
Update version
zoewangg 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
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
6 changes: 6 additions & 0 deletions
6
.changes/next-release/feature-AWSCRTbasedS3client-b387f9c.json
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,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS CRT-based S3 client", | ||
"contributor": "", | ||
"description": "Exposes `S3CrtHttpConfiguration` to allow users to configure HTTP settings such as proxy and connection timeout on AWS CRT-based S3 client. [#3262](https://github.com/aws/aws-sdk-java-v2/issues/3262)" | ||
} |
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
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,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"). | ||
~ You may not use this file except in compliance with the License. | ||
~ A copy of the License is located at | ||
~ | ||
~ http://aws.amazon.com/apache2.0 | ||
~ | ||
~ or in the "license" file accompanying this file. This file 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>core</artifactId> | ||
<version>2.20.28-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>crt-core</artifactId> | ||
<name>AWS Java SDK :: AWS CRT Core</name> | ||
<description>The AWS SDK for Java - AWS CRT Core holds common types that are built on the AWS Common Runtime | ||
</description> | ||
<url>https://aws.amazon.com/sdkforjava</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk.crt</groupId> | ||
<artifactId>aws-crt</artifactId> | ||
<version>${awscrt.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>test-utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.crtcore</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
69 changes: 69 additions & 0 deletions
69
core/crt-core/src/main/java/software/amazon/awssdk/crtcore/CrtConfigurationUtils.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,69 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.crtcore; | ||
|
||
import java.util.Optional; | ||
import software.amazon.awssdk.annotations.SdkProtectedApi; | ||
import software.amazon.awssdk.crt.http.HttpMonitoringOptions; | ||
import software.amazon.awssdk.crt.http.HttpProxyOptions; | ||
import software.amazon.awssdk.crt.io.TlsContext; | ||
import software.amazon.awssdk.utils.NumericUtils; | ||
|
||
@SdkProtectedApi | ||
public final class CrtConfigurationUtils { | ||
|
||
private CrtConfigurationUtils() { | ||
} | ||
|
||
public static Optional<HttpProxyOptions> resolveProxy(CrtProxyConfiguration proxyConfiguration, | ||
TlsContext tlsContext) { | ||
if (proxyConfiguration == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
HttpProxyOptions clientProxyOptions = new HttpProxyOptions(); | ||
|
||
clientProxyOptions.setHost(proxyConfiguration.host()); | ||
clientProxyOptions.setPort(proxyConfiguration.port()); | ||
|
||
if ("https".equalsIgnoreCase(proxyConfiguration.scheme())) { | ||
clientProxyOptions.setTlsContext(tlsContext); | ||
} | ||
|
||
if (proxyConfiguration.username() != null && proxyConfiguration.password() != null) { | ||
clientProxyOptions.setAuthorizationUsername(proxyConfiguration.username()); | ||
clientProxyOptions.setAuthorizationPassword(proxyConfiguration.password()); | ||
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.Basic); | ||
} else { | ||
clientProxyOptions.setAuthorizationType(HttpProxyOptions.HttpProxyAuthorizationType.None); | ||
} | ||
|
||
return Optional.of(clientProxyOptions); | ||
} | ||
|
||
public static Optional<HttpMonitoringOptions> resolveHttpMonitoringOptions(CrtConnectionHealthConfiguration config) { | ||
if (config == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
HttpMonitoringOptions httpMonitoringOptions = new HttpMonitoringOptions(); | ||
httpMonitoringOptions.setMinThroughputBytesPerSecond(config.minimumThroughputInBps()); | ||
int seconds = NumericUtils.saturatedCast(config.minimumThroughputTimeout().getSeconds()); | ||
httpMonitoringOptions.setAllowableThroughputFailureIntervalSeconds(seconds); | ||
return Optional.of(httpMonitoringOptions); | ||
} | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
...t-core/src/main/java/software/amazon/awssdk/crtcore/CrtConnectionHealthConfiguration.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,132 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.crtcore; | ||
|
||
import java.time.Duration; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.utils.Validate; | ||
|
||
/** | ||
* The base class for CRT connection health configuration | ||
*/ | ||
@SdkPublicApi | ||
public abstract class CrtConnectionHealthConfiguration { | ||
L-Applin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final long minimumThroughputInBps; | ||
private final Duration minimumThroughputTimeout; | ||
|
||
protected CrtConnectionHealthConfiguration(DefaultBuilder<?> builder) { | ||
this.minimumThroughputInBps = Validate.paramNotNull(builder.minimumThroughputInBps, | ||
"minimumThroughputInBps"); | ||
this.minimumThroughputTimeout = Validate.isPositive(builder.minimumThroughputTimeout, | ||
"minimumThroughputTimeout"); | ||
} | ||
|
||
/** | ||
* @return the minimum amount of throughput, in bytes per second, for a connection to be considered healthy. | ||
*/ | ||
public final long minimumThroughputInBps() { | ||
return minimumThroughputInBps; | ||
} | ||
|
||
/** | ||
* @return How long a connection is allowed to be unhealthy before getting shut down. | ||
*/ | ||
public final Duration minimumThroughputTimeout() { | ||
return minimumThroughputTimeout; | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
CrtConnectionHealthConfiguration that = (CrtConnectionHealthConfiguration) o; | ||
|
||
if (minimumThroughputInBps != that.minimumThroughputInBps) { | ||
return false; | ||
} | ||
return minimumThroughputTimeout.equals(that.minimumThroughputTimeout); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = (int) (minimumThroughputInBps ^ (minimumThroughputInBps >>> 32)); | ||
result = 31 * result + minimumThroughputTimeout.hashCode(); | ||
return result; | ||
} | ||
|
||
/** | ||
* A builder for {@link CrtConnectionHealthConfiguration}. | ||
* | ||
* <p>All implementations of this interface are mutable and not thread safe.</p> | ||
*/ | ||
public interface Builder { | ||
|
||
/** | ||
* Sets a throughput threshold for connections. Throughput below this value will be considered unhealthy. | ||
* | ||
* @param minimumThroughputInBps minimum amount of throughput, in bytes per second, for a connection to be | ||
* considered healthy. | ||
* @return Builder | ||
*/ | ||
Builder minimumThroughputInBps(Long minimumThroughputInBps); | ||
|
||
/** | ||
* Sets how long a connection is allowed to be unhealthy before getting shut down. | ||
* | ||
* <p> | ||
* It only supports seconds precision | ||
* | ||
* @param minimumThroughputTimeout How long a connection is allowed to be unhealthy | ||
* before getting shut down. | ||
* @return Builder | ||
*/ | ||
Builder minimumThroughputTimeout(Duration minimumThroughputTimeout); | ||
|
||
CrtConnectionHealthConfiguration build(); | ||
} | ||
|
||
protected abstract static class DefaultBuilder<B extends Builder> implements Builder { | ||
private Long minimumThroughputInBps; | ||
private Duration minimumThroughputTimeout; | ||
|
||
protected DefaultBuilder() { | ||
} | ||
|
||
protected DefaultBuilder(CrtConnectionHealthConfiguration configuration) { | ||
this.minimumThroughputInBps = configuration.minimumThroughputInBps; | ||
this.minimumThroughputTimeout = configuration.minimumThroughputTimeout; | ||
} | ||
|
||
@Override | ||
public B minimumThroughputInBps(Long minimumThroughputInBps) { | ||
this.minimumThroughputInBps = minimumThroughputInBps; | ||
return (B) this; | ||
} | ||
|
||
@Override | ||
public B minimumThroughputTimeout(Duration minimumThroughputTimeout) { | ||
this.minimumThroughputTimeout = minimumThroughputTimeout; | ||
return (B) this; | ||
} | ||
|
||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.