Skip to content

Commit

Permalink
refactor: replace client bean producers with synthetic beans
Browse files Browse the repository at this point in the history
  • Loading branch information
scrocquesel committed Jun 19, 2024
1 parent 4ecc717 commit afb46cd
Show file tree
Hide file tree
Showing 42 changed files with 63 additions and 1,219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import org.jboss.jandex.DotName;

import io.quarkus.amazon.cloudwatch.runtime.CloudWatchBuildTimeConfig;
import io.quarkus.amazon.cloudwatch.runtime.CloudWatchClientProducer;
import io.quarkus.amazon.cloudwatch.runtime.CloudWatchRecorder;
import io.quarkus.amazon.common.deployment.*;
import io.quarkus.amazon.common.deployment.spi.EventLoopGroupBuildItem;
import io.quarkus.amazon.common.runtime.*;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down Expand Up @@ -57,11 +55,6 @@ protected String builtinInterceptorsPath() {
return "software/amazon/awssdk/services/cloudwatch/execution.interceptors";
}

@BuildStep
AdditionalBeanBuildItem producer() {
return AdditionalBeanBuildItem.unremovableOf(CloudWatchClientProducer.class);
}

@BuildStep
void setup(
BuildProducer<ExtensionSslNativeSupportBuildItem> extensionSslNativeSupport,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import org.jboss.jandex.DotName;

import io.quarkus.amazon.cloudwatch.runtime.CloudWatchLogsBuildTimeConfig;
import io.quarkus.amazon.cloudwatch.runtime.CloudWatchLogsClientProducer;
import io.quarkus.amazon.cloudwatch.runtime.CloudWatchLogsRecorder;
import io.quarkus.amazon.common.deployment.*;
import io.quarkus.amazon.common.deployment.spi.EventLoopGroupBuildItem;
import io.quarkus.amazon.common.runtime.*;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down Expand Up @@ -57,11 +55,6 @@ protected String builtinInterceptorsPath() {
return "software/amazon/awssdk/services/cloudwatchlogs/execution.interceptors";
}

@BuildStep
AdditionalBeanBuildItem producer() {
return AdditionalBeanBuildItem.unremovableOf(CloudWatchLogsClientProducer.class);
}

@BuildStep
void setup(
BuildProducer<ExtensionSslNativeSupportBuildItem> extensionSslNativeSupport,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jboss.jandex.DotName;

import io.quarkus.amazon.cognitouserpools.runtime.CognitoUserPoolsBuildTimeConfig;
import io.quarkus.amazon.cognitouserpools.runtime.CognitoUserPoolsClientProducer;
import io.quarkus.amazon.cognitouserpools.runtime.CognitoUserPoolsRecorder;
import io.quarkus.amazon.common.deployment.AbstractAmazonServiceProcessor;
import io.quarkus.amazon.common.deployment.AmazonClientAsyncResultBuildItem;
Expand All @@ -24,7 +23,6 @@
import io.quarkus.amazon.common.runtime.AmazonClientNettyTransportRecorder;
import io.quarkus.amazon.common.runtime.AmazonClientOpenTelemetryRecorder;
import io.quarkus.amazon.common.runtime.AmazonClientUrlConnectionTransportRecorder;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
Expand Down Expand Up @@ -71,11 +69,6 @@ protected String builtinInterceptorsPath() {
return "software/amazon/awssdk/services/cognitoidentityprovider/execution.interceptors";
}

@BuildStep
AdditionalBeanBuildItem producer() {
return AdditionalBeanBuildItem.unremovableOf(CognitoUserPoolsClientProducer.class);
}

@BuildStep
void setup(
BuildProducer<ExtensionSslNativeSupportBuildItem> extensionSslNativeSupport,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.quarkus.amazon.common.runtime.AsyncHttpClientConfig;
import io.quarkus.amazon.common.runtime.AwsConfig;
import io.quarkus.amazon.common.runtime.HasSdkBuildTimeConfig;
import io.quarkus.amazon.common.runtime.SdkAutoCloseableDestroyer;
import io.quarkus.amazon.common.runtime.SdkBuildTimeConfig;
import io.quarkus.amazon.common.runtime.SdkConfig;
import io.quarkus.amazon.common.runtime.SyncHttpClientBuildTimeConfig;
Expand Down Expand Up @@ -55,6 +56,10 @@ abstract public class AbstractAmazonServiceProcessor {

abstract protected DotName asyncClientName();

protected DotName presignerClientName() {
return null;
}

abstract protected String builtinInterceptorsPath();

protected void discoverClient(BeanRegistrationPhaseBuildItem beanRegistrationPhase,
Expand Down Expand Up @@ -354,19 +359,30 @@ private void createClientBuilders(
if (addOpenTelemetry) {
syntheticBeans.produce(SyntheticBeanBuildItem
.configure(syncClientBuilderClass)
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.createWith(otelRecorder.configureSync(syncClientBuilder))
.addInjectionPoint(ClassType.create(AwsSdkTelemetry.class)).done());
} else {
syntheticBeans.produce(SyntheticBeanBuildItem.configure(syncClientBuilderClass)
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.runtimeValue(syncClientBuilder)
.done());
}
syntheticBeans.produce(SyntheticBeanBuildItem.configure(syncClientName())
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.createWith(recorder.build(syncClientBuilderClass))
.addInjectionPoint(ClassType.create(syncClientBuilderClass))
.destroyer(SdkAutoCloseableDestroyer.class)
.done());
clientSync.produce(new AmazonClientSyncResultBuildItem(configName));
}
if (asyncClientBuilder != null) {
Expand All @@ -375,30 +391,51 @@ private void createClientBuilders(
if (addOpenTelemetry) {
syntheticBeans.produce(SyntheticBeanBuildItem
.configure(asyncClientBuilderClass)
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.createWith(otelRecorder.configureAsync(asyncClientBuilder))
.addInjectionPoint(ClassType.create(AwsSdkTelemetry.class)).done());
} else {
syntheticBeans.produce(SyntheticBeanBuildItem.configure(asyncClientBuilderClass)
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.runtimeValue(asyncClientBuilder)
.done());
}
syntheticBeans.produce(SyntheticBeanBuildItem.configure(asyncClientName())
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.createWith(recorder.build(asyncClientBuilderClass))
.addInjectionPoint(ClassType.create(asyncClientBuilderClass))
.destroyer(SdkAutoCloseableDestroyer.class)
.done());
clientAsync.produce(new AmazonClientAsyncResultBuildItem(configName));
}
if (presignerBuilder != null) {
presignerBuilder = recorder.configurePresigner(presignerBuilder, awsConfigRuntime, sdkConfigRuntime,
configName());
syntheticBeans.produce(SyntheticBeanBuildItem.configure(presignerBuilderClass)
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.runtimeValue(presignerBuilder)
.done());
syntheticBeans.produce(SyntheticBeanBuildItem.configure(presignerClientName())
.unremovable()
.defaultBean()
.setRuntimeInit()
.scope(ApplicationScoped.class)
.createWith(recorder.build(presignerBuilderClass))
.addInjectionPoint(ClassType.create(presignerBuilderClass))
.destroyer(SdkAutoCloseableDestroyer.class)
.done());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Function;

import jakarta.enterprise.inject.UnsatisfiedResolutionException;
import jakarta.enterprise.inject.spi.CDI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import io.quarkus.arc.SyntheticCreationalContext;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import software.amazon.awssdk.awscore.AwsClient;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.awscore.presigner.SdkPresigner;
import software.amazon.awssdk.core.client.builder.SdkClientBuilder;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
import software.amazon.awssdk.utils.StringUtils;
import software.amazon.awssdk.utils.builder.SdkBuilder;

@Recorder
public class AmazonClientCommonRecorder {
Expand Down Expand Up @@ -122,4 +126,16 @@ private ExecutionInterceptor createInterceptor(String interceptorClassName) {
return null;
}
}

public Function<SyntheticCreationalContext<AwsClient>, AwsClient> build(Class<?> clazz) {
return new Function<SyntheticCreationalContext<AwsClient>, AwsClient>() {

@Override
public AwsClient apply(SyntheticCreationalContext<AwsClient> context) {
SdkBuilder builder = (SdkBuilder) context.getInjectedReference(clazz);

return (AwsClient) builder.build();
}
};
}
}
Loading

0 comments on commit afb46cd

Please sign in to comment.