Skip to content

Commit

Permalink
Cleaned apache config section, http client dependencies as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinczeczko committed Oct 17, 2019
1 parent 0733c45 commit 5d68871
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 135 deletions.
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/dynamodb-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -326,24 +326,24 @@ If you're going to use a local DynamoDB instance, configure it as follows:
quarkus.dynamodb.endpoint-override=http://localhost:8000
quarkus.dynamodb.aws.region=eu-central-1
quarkus.dynamodb.aws.credentials.type=STATIC
quarkus.dynamodb.aws.credentials.type=static
quarkus.dynamodb.aws.credentials.static-provider.access-key-id=test-key
quarkus.dynamodb.aws.credentials.static-provider.secret-access-key=test-secret
----

- `quarkus.dynamodb.aws.region` - It's required by the client, but since you're using a local DynamoDB instance you can pick any valid AWS region.
- `quarkus.dynamodb.aws.credentials.type` - Set `STATIC` credentials provider with any values for `access-key-id` and `secret-access-key`
- `quarkus.dynamodb.aws.credentials.type` - Set `static` credentials provider with any values for `access-key-id` and `secret-access-key`
- `quarkus.dynamodb.endpoint-override` - Override the DynamoDB client to use a local instance instead of an AWS service

If you want to work with an AWS account, you'd need to set it with:
[source,properties]
----
quarkus.dynamodb.aws.region=<YOUR_REGION>
quarkus.dynamodb.aws.credentials.type=DEFAULT
quarkus.dynamodb.aws.credentials.type=default
----

- `quarkus.dynamodb.aws.region` you should set it to the region where you provisioned the DynamoDB table,
- `quarkus.dynamodb.aws.credentials.type` - use the `DEFAULT` credentials provider chain that looks for credentials in this order:
- `quarkus.dynamodb.aws.credentials.type` - use the `default` credentials provider chain that looks for credentials in this order:
- Java System Properties - `aws.accessKeyId` and `aws.secretKey`
* Environment Variables - `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
* Credential profiles file at the default location (`~/.aws/credentials`) shared by all AWS SDKs and the AWS CLI
Expand Down
21 changes: 21 additions & 0 deletions extensions/amazon-dynamodb/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.stream.Collectors;

import javax.enterprise.inject.spi.DeploymentException;

import org.jboss.jandex.DotName;
import org.jboss.jandex.Type;

Expand All @@ -17,6 +19,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ApplicationIndexBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
Expand All @@ -38,17 +41,18 @@
import io.quarkus.dynamodb.runtime.TlsManagersProviderType;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.http.SdkHttpService;
import software.amazon.awssdk.http.apache.ApacheSdkHttpService;
import software.amazon.awssdk.http.async.SdkAsyncHttpService;
import software.amazon.awssdk.http.nio.netty.NettySdkAsyncHttpService;
import software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService;
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.utils.StringUtils;

public class DynamodbProcessor {
public static final String AWS_SDK_APPLICATION_ARCHIVE_MARKERS = "software/amazon/awssdk";

private static final String APACHE_HTTP_SERVICE = "software.amazon.awssdk.http.apache.ApacheSdkHttpService";
private static final String NETTY_HTTP_SERVICE = "software.amazon.awssdk.http.nio.netty.NettySdkAsyncHttpService";
private static final String URL_HTTP_SERVICE = "software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService";

private static final List<String> INTERCEPTOR_PATHS = Arrays.asList(
"software/amazon/awssdk/global/handlers/execution.interceptors",
"software/amazon/awssdk/services/dynamodb/execution.interceptors");
Expand Down Expand Up @@ -95,7 +99,8 @@ void setup(CombinedIndexBuildItem combinedIndexBuildItem,
@BuildStep
DynamodbClientBuildItem analyzeDynamodbClientInjectionPoints(BeanRegistrationPhaseBuildItem beanRegistrationPhase,
BuildProducer<ServiceProviderBuildItem> serviceProvider,
BuildProducer<SubstrateProxyDefinitionBuildItem> proxyDefinition) {
BuildProducer<SubstrateProxyDefinitionBuildItem> proxyDefinition,
ApplicationIndexBuildItem appIndex) {

boolean createSyncClient = false;
boolean createAsyncClient = false;
Expand All @@ -115,31 +120,39 @@ DynamodbClientBuildItem analyzeDynamodbClientInjectionPoints(BeanRegistrationPha

if (createSyncClient) {
if (config.syncClient.type == SyncClientType.APACHE) {
checkClasspath(APACHE_HTTP_SERVICE, "apache-client");

//Register Apache client as sync client
proxyDefinition
.produce(new SubstrateProxyDefinitionBuildItem("org.apache.http.conn.HttpClientConnectionManager",
proxyDefinition.produce(
new SubstrateProxyDefinitionBuildItem("org.apache.http.conn.HttpClientConnectionManager",
"org.apache.http.pool.ConnPoolControl",
"software.amazon.awssdk.http.apache.internal.conn.Wrapped"));

serviceProvider.produce(
new ServiceProviderBuildItem(SdkHttpService.class.getName(), ApacheSdkHttpService.class.getName()));
serviceProvider.produce(new ServiceProviderBuildItem(SdkHttpService.class.getName(), APACHE_HTTP_SERVICE));
} else {
serviceProvider.produce(
new ServiceProviderBuildItem(SdkHttpService.class.getName(),
UrlConnectionSdkHttpService.class.getName()));
checkClasspath(URL_HTTP_SERVICE, "url-connection-client");
serviceProvider.produce(new ServiceProviderBuildItem(SdkHttpService.class.getName(), URL_HTTP_SERVICE));
}
}

if (createAsyncClient) {
checkClasspath(NETTY_HTTP_SERVICE, "netty-nio-client");
//Register netty as async client
serviceProvider.produce(
new ServiceProviderBuildItem(SdkAsyncHttpService.class.getName(),
NettySdkAsyncHttpService.class.getName()));
serviceProvider.produce(new ServiceProviderBuildItem(SdkAsyncHttpService.class.getName(), NETTY_HTTP_SERVICE));
}

return new DynamodbClientBuildItem(createSyncClient, createAsyncClient);
}

private void checkClasspath(String className, String dependencyName) {
try {
Class.forName(className, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new DeploymentException(
"Missing 'software.amazon.awssdk:" + dependencyName + "' dependency on the classpath");
}
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void buildClients(DynamodbClientBuildItem clientBuildItem, DynamodbRecorder recorder,
Expand Down Expand Up @@ -203,16 +216,16 @@ private static void checkConfig(DynamodbConfig config, List<String> knownInterce

private static void checkSyncClientConfig(SyncHttpClientConfig syncClient) {
if (syncClient.type == SyncClientType.APACHE) {
if (syncClient.apacheHttp.maxConnections <= 0) {
if (syncClient.apache.maxConnections <= 0) {
throw new ConfigurationError("quarkus.dynamodb.sync-client.max-connections may not be negative or zero.");
}
if (syncClient.apacheHttp.proxy != null && syncClient.apacheHttp.proxy.enabled) {
URI proxyEndpoint = syncClient.apacheHttp.proxy.endpoint;
if (syncClient.apache.proxy != null && syncClient.apache.proxy.enabled) {
URI proxyEndpoint = syncClient.apache.proxy.endpoint;
if (proxyEndpoint != null) {
validateProxyEndpoint(proxyEndpoint, "sync");
}
}
validateTlsManagersProvider(syncClient.apacheHttp.tlsManagersProvider, "sync");
validateTlsManagersProvider(syncClient.apache.tlsManagersProvider, "sync");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ quarkus.dynamodb.enable-endpoint-discovery=false
quarkus.dynamodb.endpoint-override=http://localhost:8000

quarkus.dynamodb.aws.region=us-east-1
quarkus.dynamodb.aws.credentials.type=STATIC
quarkus.dynamodb.aws.credentials.type=static
quarkus.dynamodb.aws.credentials.static-provider.access-key-id=test-key
quarkus.dynamodb.aws.credentials.static-provider.secret-access-key=test-secret

Expand All @@ -15,13 +15,13 @@ quarkus.dynamodb.async-client.connection-acquisition-timeout=0.01S
quarkus.dynamodb.async-client.connection-time-to-live=0.01S
quarkus.dynamodb.async-client.connection-max-idle-time=0.01S
quarkus.dynamodb.async-client.use-idle-connection-reaper=false
quarkus.dynamodb.async-client.protocol = HTTP1_1
quarkus.dynamodb.async-client.protocol = http1-1
quarkus.dynamodb.async-client.max-http2-streams = 10
quarkus.dynamodb.async-client.ssl-provider = JDK
quarkus.dynamodb.async-client.ssl-provider = jdk
quarkus.dynamodb.async-client.event-loop.override = true
quarkus.dynamodb.async-client.event-loop.number-of-threads = 5
quarkus.dynamodb.async-client.event-loop.thread-name-prefix = Quarkus-Netty-EventLoop-
quarkus.dynamodb.async-client.proxy.enabled = true
quarkus.dynamodb.async-client.proxy.endpoint = http://127.1.1.1
quarkus.dynamodb.async-client.proxy.non-proxy-hosts = localhost, hostlocal
quarkus.dynamodb.async-client.tls-managers-provider.type=SYSTEM_PROPERTY
quarkus.dynamodb.async-client.tls-managers-provider.type=system-property
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
quarkus.dynamodb.aws.region=us-east-1

quarkus.dynamodb.async-client.tls-managers-provider.type=FILE_STORE
quarkus.dynamodb.async-client.tls-managers-provider.type=file-store
quarkus.dynamodb.async-client.tls-managers-provider.file-store.path=/tmp/file.key
quarkus.dynamodb.async-client.tls-managers-provider.file-store.type=pkcs11
quarkus.dynamodb.async-client.tls-managers-provider.file-store.password=thePassword
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
quarkus.dynamodb.aws.region=us-east-2

quarkus.dynamodb.aws.credentials.type=DEFAULT
quarkus.dynamodb.aws.credentials.type=default
quarkus.dynamodb.aws.credentials.default-provider.async-credential-update-enabled=true
quarkus.dynamodb.aws.credentials.default-provider.reuse-last-provider-enabled=true

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
quarkus.dynamodb.aws.credentials.type=PROCESS
quarkus.dynamodb.aws.credentials.type=process

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
quarkus.dynamodb.aws.region=us-east-2

quarkus.dynamodb.aws.credentials.type=PROFILE
quarkus.dynamodb.aws.credentials.type=profile
quarkus.dynamodb.aws.credentials.profile-provider.profile-name=myprofile

Original file line number Diff line number Diff line change
@@ -1 +1 @@
quarkus.dynamodb.aws.credentials.type=STATIC
quarkus.dynamodb.aws.credentials.type=static
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
quarkus.dynamodb.sync-client.type = APACHE
quarkus.dynamodb.sync-client.max-connections = -10
quarkus.dynamodb.sync-client.type = apache
quarkus.dynamodb.sync-client.apache.max-connections = -10


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
quarkus.dynamodb.sync-client.type = APACHE
quarkus.dynamodb.sync-client.proxy.enabled = true
quarkus.dynamodb.sync-client.proxy.endpoint = http://user:[email protected]?foo=bar
quarkus.dynamodb.sync-client.type = apache
quarkus.dynamodb.sync-client.apache.proxy.enabled = true
quarkus.dynamodb.sync-client.apache.proxy.endpoint = http://user:[email protected]?foo=bar



Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ quarkus.dynamodb.enable-endpoint-discovery=false
quarkus.dynamodb.endpoint-override=http://localhost:8000

quarkus.dynamodb.aws.region=us-east-2
quarkus.dynamodb.aws.credentials.type=STATIC
quarkus.dynamodb.aws.credentials.type=static
quarkus.dynamodb.aws.credentials.static-provider.access-key-id=test-key
quarkus.dynamodb.aws.credentials.static-provider.secret-access-key=test-secret

quarkus.dynamodb.sync-client.type = APACHE
quarkus.dynamodb.sync-client.type=apache
quarkus.dynamodb.sync-client.socket-timeout = 0.100S
quarkus.dynamodb.sync-client.connection-timeout = 0.100S

quarkus.dynamodb.sync-client.connection-acquisition-timeout = 0.100S
quarkus.dynamodb.sync-client.connection-max-idle-time = 0.100S
quarkus.dynamodb.sync-client.connection-time-to-live = 0.100S
quarkus.dynamodb.sync-client.max-connections = 10
quarkus.dynamodb.sync-client.expect-continue-enabled = true
quarkus.dynamodb.sync-client.use-idle-connection-reaper = true
quarkus.dynamodb.sync-client.proxy.enabled = true
quarkus.dynamodb.sync-client.proxy.endpoint = http://127.1.1.1
quarkus.dynamodb.sync-client.proxy.username = foo
quarkus.dynamodb.sync-client.proxy.password = bar
quarkus.dynamodb.sync-client.proxy.ntlm-domain = foo-domainn
quarkus.dynamodb.sync-client.proxy.ntlm-workstation = foo-workstation
quarkus.dynamodb.sync-client.proxy.preemptive-basic-authentication-enabled = true
quarkus.dynamodb.sync-client.proxy.non-proxy-hosts = localhost, hostlocal
quarkus.dynamodb.sync-client.tls-managers-provider.type=SYSTEM_PROPERTY
quarkus.dynamodb.sync-client.apache.connection-acquisition-timeout = 0.100S
quarkus.dynamodb.sync-client.apache.connection-max-idle-time = 0.100S
quarkus.dynamodb.sync-client.apache.connection-time-to-live = 0.100S
quarkus.dynamodb.sync-client.apache.max-connections = 10
quarkus.dynamodb.sync-client.apache.expect-continue-enabled = true
quarkus.dynamodb.sync-client.apache.use-idle-connection-reaper = true
quarkus.dynamodb.sync-client.apache.proxy.enabled = true
quarkus.dynamodb.sync-client.apache.proxy.endpoint = http://127.1.1.1
quarkus.dynamodb.sync-client.apache.proxy.username = foo
quarkus.dynamodb.sync-client.apache.proxy.password = bar
quarkus.dynamodb.sync-client.apache.proxy.ntlm-domain = foo-domainn
quarkus.dynamodb.sync-client.apache.proxy.ntlm-workstation = foo-workstation
quarkus.dynamodb.sync-client.apache.proxy.preemptive-basic-authentication-enabled = true
quarkus.dynamodb.sync-client.apache.proxy.non-proxy-hosts = localhost, hostlocal
quarkus.dynamodb.sync-client.apache.tls-managers-provider.type=system-property

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ quarkus.dynamodb.enable-endpoint-discovery=false
quarkus.dynamodb.endpoint-override=http://localhost:8000

quarkus.dynamodb.aws.region=us-east-2
quarkus.dynamodb.aws.credentials.type=STATIC
quarkus.dynamodb.aws.credentials.type=static
quarkus.dynamodb.aws.credentials.static-provider.access-key-id=test-key
quarkus.dynamodb.aws.credentials.static-provider.secret-access-key=test-secret

quarkus.dynamodb.sync-client.type = URL
quarkus.dynamodb.sync-client.socket-timeout = 0.100S
quarkus.dynamodb.sync-client.connection-timeout = 0.100S
quarkus.dynamodb.sync-client.type=url
quarkus.dynamodb.sync-client.socket-timeout=0.100S
quarkus.dynamodb.sync-client.connection-timeout=0.100S


3 changes: 3 additions & 0 deletions extensions/amazon-dynamodb/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import io.quarkus.dynamodb.runtime.SyncHttpClientConfig.ApacheHttpClientConfig;
import io.quarkus.dynamodb.runtime.SyncHttpClientConfig.SyncClientType;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.core.client.builder.SdkClientBuilder;
Expand Down Expand Up @@ -128,31 +127,29 @@ private ApacheHttpClient.Builder createApacheClientBuilder(SyncHttpClientConfig
builder.connectionTimeout(config.connectionTimeout);
builder.socketTimeout(config.socketTimeout);

ApacheHttpClientConfig apacheHttpClientConfig = config.apacheHttp;
builder.connectionAcquisitionTimeout(config.apache.connectionAcquisitionTimeout);
builder.connectionMaxIdleTime(config.apache.connectionMaxIdleTime);
config.apache.connectionTimeToLive.ifPresent(builder::connectionTimeToLive);
builder.expectContinueEnabled(config.apache.expectContinueEnabled);
builder.maxConnections(config.apache.maxConnections);
builder.useIdleConnectionReaper(config.apache.useIdleConnectionReaper);

builder.connectionAcquisitionTimeout(apacheHttpClientConfig.connectionAcquisitionTimeout);
builder.connectionMaxIdleTime(apacheHttpClientConfig.connectionMaxIdleTime);
apacheHttpClientConfig.connectionTimeToLive.ifPresent(builder::connectionTimeToLive);
builder.expectContinueEnabled(apacheHttpClientConfig.expectContinueEnabled);
builder.maxConnections(apacheHttpClientConfig.maxConnections);
builder.useIdleConnectionReaper(apacheHttpClientConfig.useIdleConnectionReaper);

if (apacheHttpClientConfig.proxy.enabled) {
if (config.apache.proxy.enabled) {
ProxyConfiguration.Builder proxyBuilder = ProxyConfiguration.builder()
.endpoint(apacheHttpClientConfig.proxy.endpoint);
apacheHttpClientConfig.proxy.username.ifPresent(proxyBuilder::username);
apacheHttpClientConfig.proxy.password.ifPresent(proxyBuilder::password);
apacheHttpClientConfig.proxy.nonProxyHosts.forEach(proxyBuilder::addNonProxyHost);
apacheHttpClientConfig.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain);
apacheHttpClientConfig.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation);
apacheHttpClientConfig.proxy.preemptiveBasicAuthenticationEnabled
.endpoint(config.apache.proxy.endpoint);
config.apache.proxy.username.ifPresent(proxyBuilder::username);
config.apache.proxy.password.ifPresent(proxyBuilder::password);
config.apache.proxy.nonProxyHosts.forEach(proxyBuilder::addNonProxyHost);
config.apache.proxy.ntlmDomain.ifPresent(proxyBuilder::ntlmDomain);
config.apache.proxy.ntlmWorkstation.ifPresent(proxyBuilder::ntlmWorkstation);
config.apache.proxy.preemptiveBasicAuthenticationEnabled
.ifPresent(proxyBuilder::preemptiveBasicAuthenticationEnabled);

builder.proxyConfiguration(proxyBuilder.build());
}

builder.tlsKeyManagersProvider(
apacheHttpClientConfig.tlsManagersProvider.type.create(apacheHttpClientConfig.tlsManagersProvider));
config.apache.tlsManagersProvider.type.create(config.apache.tlsManagersProvider));

return builder;
}
Expand Down
Loading

0 comments on commit 5d68871

Please sign in to comment.