Skip to content

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 9 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .brazil.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"url-connection-client": { "packageName": "AwsJavaSdk-HttpClient-UrlConnectionClient" },
"utils": { "packageName": "AwsJavaSdk-Core-Utils" },
"imds": { "packageName": "AwsJavaSdk-Imds" },
"crt-core": { "packageName": "AwsJavaSdk-Core-CrtCore" },

"dynamodb": { "packageName": "AwsJavaSdk-DynamoDb" },
"waf": { "packageName": "AwsJavaSdk-Waf" },
Expand Down
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)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void validateBuilderConstructor(String buildableClassName, JavaClass bui
}

// Find which fields we modified in those constructors
Set<String> builderFieldsForBuilder = new HashSet<>(builderFields.get(builder));
Set<String> builderFieldsForBuilder = new HashSet<>(builderFields.getOrDefault(builder, new ArrayList<>()));
Map<String, List<String>> allConstructors = builderConstructorModifiedFields.get(builder);

allInvokedConstructors.forEach(constructorSignature -> {
Expand Down
92 changes: 92 additions & 0 deletions core/crt-core/pom.xml
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>
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);
}

}
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 {
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;
}

}
}
Loading