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:46:35 UTC

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

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

    CAMEL-14690 - Camel-AWS2: Better logging when checking client instance in the registry, EC2
---
 .../camel/component/aws2/ec2/AWS2EC2Component.java | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Component.java b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Component.java
index 2f8c3cb..dd6de4c 100644
--- a/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Component.java
+++ b/components/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Component.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.ec2.Ec2Client;
 
 /**
@@ -32,6 +36,8 @@ import software.amazon.awssdk.services.ec2.Ec2Client;
 @Component("aws2-ec2")
 public class AWS2EC2Component extends DefaultComponent {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AWS2EC2Component.class);
+
     @Metadata
     private AWS2EC2Configuration configuration = new AWS2EC2Configuration();
 
@@ -51,7 +57,7 @@ public class AWS2EC2Component extends DefaultComponent {
         AWS2EC2Configuration configuration = this.configuration != null ? this.configuration.copy() : new AWS2EC2Configuration();
         AWS2EC2Endpoint endpoint = new AWS2EC2Endpoint(uri, this, configuration);
         setProperties(endpoint, parameters);
-        checkAndSetRegistryClient(configuration);
+        checkAndSetRegistryClient(configuration, endpoint);
         if (configuration.getAmazonEc2Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("amazonEC2Client or accessKey and secretKey must be specified");
         }
@@ -70,10 +76,18 @@ public class AWS2EC2Component extends DefaultComponent {
         this.configuration = configuration;
     }
 
-    private void checkAndSetRegistryClient(AWS2EC2Configuration configuration) {
-        Set<Ec2Client> clients = getCamelContext().getRegistry().findByType(Ec2Client.class);
-        if (clients.size() == 1) {
-            configuration.setAmazonEc2Client(clients.stream().findFirst().get());
+    private void checkAndSetRegistryClient(AWS2EC2Configuration configuration, AWS2EC2Endpoint endpoint) {
+        if (ObjectHelper.isEmpty(endpoint.getConfiguration().getAmazonEc2Client())) {
+            LOG.debug("Looking for an Ec2Client instance in the registry");
+            Set<Ec2Client> clients = getCamelContext().getRegistry().findByType(Ec2Client.class);
+            if (clients.size() == 1) {
+                LOG.debug("Found exactly one Ec2Client instance in the registry");
+                configuration.setAmazonEc2Client(clients.stream().findFirst().get());
+            } else {
+                LOG.debug("No Ec2Client instance in the registry");
+            }
+        } else {
+            LOG.debug("Ec2Client instance is already set at endpoint level: skipping the check in the registry");
         }
     }
 }