You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/03/11 10:40:01 UTC

[camel] 01/04: CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, DynamoDB

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 db9993116ee350a6d9a108fd359d34c46372cbd5
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 11 11:33:51 2020 +0100

    CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, DynamoDB
---
 .../camel/component/aws2/ddb/Ddb2Component.java    | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java
index a56bafa..abb8578 100644
--- a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java
+++ b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java
@@ -24,10 +24,15 @@ 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.dynamodb.DynamoDbClient;
 
 @Component("aws2-ddb")
 public class Ddb2Component extends DefaultComponent {
+	
+    private static final Logger LOG = LoggerFactory.getLogger(Ddb2Component.class);
 
     @Metadata
     private Ddb2Configuration configuration = new Ddb2Configuration();
@@ -52,7 +57,7 @@ public class Ddb2Component extends DefaultComponent {
         configuration.setTableName(remaining);
         Ddb2Endpoint endpoint = new Ddb2Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (configuration.getAmazonDDBClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonDDBClient or accessKey and secretKey must be specified");
         }
@@ -71,10 +76,18 @@ public class Ddb2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(Ddb2Configuration configuration) {
-        Set<DynamoDbClient> clients = getCamelContext().getRegistry().findByType(DynamoDbClient.class);
-        if (clients.size() == 1) {
-            configuration.setAmazonDDBClient(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(Ddb2Configuration configuration, Ddb2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonDDBClient())) {
+            LOG.debug("Looking for an CloudWatchClient instance in the registry");
+            Set<DynamoDbClient> clients = getCamelContext().getRegistry().findByType(DynamoDbClient.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one CloudWatchClient instance in the registry");
+                configuration.setAmazonDDBClient(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No CloudWatchClient instance in the registry");
+            }
+        } else {
+            LOG.debug("CloudWatchClient instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }