This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit df1edfb1785084fb6d10a8de4feb1ff06925f5c1 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Mar 10 16:30:47 2020 +0100 CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, Lambda --- .../component/aws2/lambda/Lambda2Component.java | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Component.java b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Component.java index a86b8d4..f5cc874 100644 --- a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Component.java +++ b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Component.java @@ -24,6 +24,10 @@ import org.apache.camel.Endpoint; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import software.amazon.awssdk.services.lambda.LambdaClient; /** @@ -31,6 +35,8 @@ import software.amazon.awssdk.services.lambda.LambdaClient; */ @Component("aws2-lambda") public class Lambda2Component extends DefaultComponent { + + private static final Logger LOG = LoggerFactory.getLogger(Lambda2Component.class); @Metadata private Lambda2Configuration configuration = new Lambda2Configuration(); @@ -51,7 +57,7 @@ public class Lambda2Component extends DefaultComponent { Lambda2Endpoint endpoint = new Lambda2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); endpoint.setFunction(remaining); - checkAndSetRegistryClient(configuration); + checkAndSetRegistryClient(configuration, endpoint); if (configuration.getAwsLambdaClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("accessKey/secretKey or awsLambdaClient must be specified"); } @@ -70,10 +76,18 @@ public class Lambda2Component extends DefaultComponent { this.configuration = configuration; } - private void checkAndSetRegistryClient(Lambda2Configuration configuration) { - Set<LambdaClient> clients = getCamelContext().getRegistry().findByType(LambdaClient.class); - if (clients.size() == 1) { - configuration.setAwsLambdaClient(clients.stream().findFirst().get()); + private void checkAndSetRegistryClient(Lambda2Configuration configuration, Lambda2Endpoint endpoint) { + if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAwsLambdaClient())) { + LOG.debug("Looking for an LambdaClient instance in the registry"); + Set<LambdaClient> clients = getCamelContext().getRegistry().findByType(LambdaClient.class); + if (clients.size() == 1) { + LOG.debug("Found exactly one LambdaClient instance in the registry"); + configuration.setAwsLambdaClient(clients.stream().findFirst().get()); + } else { + LOG.debug("No LambdaClient instance in the registry"); + } + } else { + LOG.debug("LambdaClient instance is already set at endpoint level: skipping the check in the registry"); } } }