This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch ra
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 07299ad471ea51219b9df76b12f0801baa6ff7dc
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun May 26 10:27:09 2024 +0200

    CAMEL-20798: Add RemoteAddress to endpoints so they can tell the 
url/hostname etc for the system it connects. This is needed for better 
monitoring, tracing and management. Add this information into camel-tracer as 
tags.
---
 .../component/file/remote/RemoteFileEndpoint.java   | 16 +++++++++++++++-
 .../remote/InfinispanRemoteConfiguration.java       |  4 ++--
 .../infinispan/remote/InfinispanRemoteEndpoint.java | 13 ++++++++++++-
 .../component/kudu/KuduEndpointUriFactory.java      |  4 ++--
 .../org/apache/camel/component/kudu/kudu.json       |  4 ++--
 .../apache/camel/component/kudu/KuduEndpoint.java   | 11 ++++++++++-
 .../camel/component/lucene/LuceneEndpoint.java      | 17 ++++++++++++++---
 .../apache/camel/component/mail/MailEndpoint.java   | 21 ++++++++++++++++++++-
 8 files changed, 77 insertions(+), 13 deletions(-)

diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
index fb15509cf2f..9f201a6640f 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
@@ -26,6 +26,7 @@ import org.apache.camel.component.file.GenericFileEndpoint;
 import org.apache.camel.component.file.GenericFileExist;
 import org.apache.camel.component.file.GenericFilePollingConsumer;
 import org.apache.camel.component.file.GenericFileProducer;
+import org.apache.camel.spi.EndpointLocationAddress;
 import org.apache.camel.spi.UriParam;
 import 
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
 import org.apache.camel.util.StringHelper;
@@ -35,7 +36,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Remote file endpoint.
  */
-public abstract class RemoteFileEndpoint<T> extends GenericFileEndpoint<T> {
+public abstract class RemoteFileEndpoint<T> extends GenericFileEndpoint<T> 
implements EndpointLocationAddress {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(RemoteFileEndpoint.class);
 
@@ -104,6 +105,19 @@ public abstract class RemoteFileEndpoint<T> extends 
GenericFileEndpoint<T> {
         return (RemoteFileConfiguration) this.configuration;
     }
 
+    @Override
+    public String getAddress() {
+        return getConfiguration().getProtocol() + ":" + 
getConfiguration().getHost() + ":" + getConfiguration().getPort();
+    }
+
+    @Override
+    public Map<String, String> getAddressMetadata() {
+        if (getConfiguration().getUsername() != null) {
+            return Map.of("username", getConfiguration().getUsername());
+        }
+        return null;
+    }
+
     @Override
     public Exchange createExchange(GenericFile<T> file) {
         Exchange answer = super.createExchange();
diff --git 
a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteConfiguration.java
 
b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteConfiguration.java
index cccdfd84a76..bc05ac240da 100644
--- 
a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteConfiguration.java
+++ 
b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteConfiguration.java
@@ -32,7 +32,7 @@ import 
org.infinispan.client.hotrod.configuration.Configuration;
 public class InfinispanRemoteConfiguration extends InfinispanConfiguration 
implements Cloneable {
     @UriParam
     private String hosts;
-    @UriParam(label = "common", defaultValue = "false")
+    @UriParam(label = "common,security", defaultValue = "false")
     private boolean secure;
     @UriParam(label = "common,security")
     private String username;
@@ -82,7 +82,7 @@ public class InfinispanRemoteConfiguration extends 
InfinispanConfiguration imple
     }
 
     /**
-     * Specifies the host of the cache on Infinispan instance
+     * Specifies the host of the cache on Infinispan instance. Multiple hosts 
can be separated by semicolon.
      */
     public String getHosts() {
         return hosts;
diff --git 
a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteEndpoint.java
 
b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteEndpoint.java
index efcc763c8d6..a6be6293c9c 100644
--- 
a/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteEndpoint.java
+++ 
b/components/camel-infinispan/camel-infinispan/src/main/java/org/apache/camel/component/infinispan/remote/InfinispanRemoteEndpoint.java
@@ -23,12 +23,15 @@ import org.apache.camel.Producer;
 import org.apache.camel.component.infinispan.InfinispanComponent;
 import org.apache.camel.component.infinispan.InfinispanConstants;
 import org.apache.camel.component.infinispan.InfinispanEndpoint;
+import org.apache.camel.spi.EndpointLocationAddress;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.support.service.ServiceHelper;
 
+import java.util.StringJoiner;
+
 import static 
org.apache.camel.component.infinispan.InfinispanConstants.SCHEME_INFINISPAN;
 
 /**
@@ -36,7 +39,7 @@ import static 
org.apache.camel.component.infinispan.InfinispanConstants.SCHEME_I
  */
 @UriEndpoint(firstVersion = "2.13.0", scheme = SCHEME_INFINISPAN, title = 
"Infinispan", syntax = "infinispan:cacheName",
              category = { Category.CACHE, Category.CLUSTERING }, headersClass 
= InfinispanConstants.class)
-public class InfinispanRemoteEndpoint extends InfinispanEndpoint {
+public class InfinispanRemoteEndpoint extends InfinispanEndpoint implements 
EndpointLocationAddress {
 
     @UriPath(description = "The name of the cache to use. Use current to use 
the existing cache name from the currently configured cached manager. Or use 
default for the default cache manager name.")
     @Metadata(required = true)
@@ -55,6 +58,14 @@ public class InfinispanRemoteEndpoint extends 
InfinispanEndpoint {
         this.manager = new 
InfinispanRemoteManager(component.getCamelContext(), configuration);
     }
 
+    @Override
+    public String getAddress() {
+        if (configuration.getHosts() != null) {
+            return configuration.getHosts();
+        }
+        return null;
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
diff --git 
a/components/camel-kudu/src/generated/java/org/apache/camel/component/kudu/KuduEndpointUriFactory.java
 
b/components/camel-kudu/src/generated/java/org/apache/camel/component/kudu/KuduEndpointUriFactory.java
index d260fc02fe0..4737640d09a 100644
--- 
a/components/camel-kudu/src/generated/java/org/apache/camel/component/kudu/KuduEndpointUriFactory.java
+++ 
b/components/camel-kudu/src/generated/java/org/apache/camel/component/kudu/KuduEndpointUriFactory.java
@@ -46,8 +46,8 @@ public class KuduEndpointUriFactory extends 
org.apache.camel.support.component.E
 
         Map<String, Object> copy = new HashMap<>(properties);
 
-        uri = buildPathParameter(syntax, uri, "host", null, false, copy);
-        uri = buildPathParameter(syntax, uri, "port", null, false, copy);
+        uri = buildPathParameter(syntax, uri, "host", null, true, copy);
+        uri = buildPathParameter(syntax, uri, "port", null, true, copy);
         uri = buildPathParameter(syntax, uri, "tableName", null, false, copy);
         uri = buildQueryParameters(uri, copy, encode);
         return uri;
diff --git 
a/components/camel-kudu/src/generated/resources/META-INF/org/apache/camel/component/kudu/kudu.json
 
b/components/camel-kudu/src/generated/resources/META-INF/org/apache/camel/component/kudu/kudu.json
index 7d9401c167d..d0309c30780 100644
--- 
a/components/camel-kudu/src/generated/resources/META-INF/org/apache/camel/component/kudu/kudu.json
+++ 
b/components/camel-kudu/src/generated/resources/META-INF/org/apache/camel/component/kudu/kudu.json
@@ -35,8 +35,8 @@
     "CamelKuduScanLimit": { "index": 4, "kind": "header", "displayName": "", 
"group": "producer", "label": "", "required": false, "javaType": "long", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The limit on the number of rows for scan operation", 
"constantName": 
"org.apache.camel.component.kudu.KuduConstants#CAMEL_KUDU_SCAN_LIMIT" }
   },
   "properties": {
-    "host": { "index": 0, "kind": "path", "displayName": "Host", "group": 
"common", "label": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Host of the server to connect to" },
-    "port": { "index": 1, "kind": "path", "displayName": "Port", "group": 
"common", "label": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Port of the server to connect to" },
+    "host": { "index": 0, "kind": "path", "displayName": "Host", "group": 
"common", "label": "common", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Host of the server to connect to" },
+    "port": { "index": 1, "kind": "path", "displayName": "Port", "group": 
"common", "label": "common", "required": true, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Port of the server to connect to" },
     "tableName": { "index": 2, "kind": "path", "displayName": "Table Name", 
"group": "common", "label": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "Table to connect to" },
     "operation": { "index": 3, "kind": "parameter", "displayName": 
"Operation", "group": "producer", "label": "", "required": false, "type": 
"object", "javaType": "org.apache.camel.component.kudu.KuduOperations", "enum": 
[ "INSERT", "DELETE", "UPDATE", "UPSERT", "CREATE_TABLE", "SCAN" ], 
"deprecated": false, "autowired": false, "secret": false, "description": 
"Operation to perform" },
     "lazyStartProducer": { "index": 4, "kind": "parameter", "displayName": 
"Lazy Start Producer", "group": "producer (advanced)", "label": 
"producer,advanced", "required": false, "type": "boolean", "javaType": 
"boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": false, "description": "Whether the producer should be started 
lazy (on the first message). By starting lazy you can use this to allow 
CamelContext and routes to startup in situations where a produc [...]
diff --git 
a/components/camel-kudu/src/main/java/org/apache/camel/component/kudu/KuduEndpoint.java
 
b/components/camel-kudu/src/main/java/org/apache/camel/component/kudu/KuduEndpoint.java
index a2658ba7c1f..1213e3b2837 100644
--- 
a/components/camel-kudu/src/main/java/org/apache/camel/component/kudu/KuduEndpoint.java
+++ 
b/components/camel-kudu/src/main/java/org/apache/camel/component/kudu/KuduEndpoint.java
@@ -23,6 +23,8 @@ import org.apache.camel.Category;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.spi.EndpointLocationAddress;
+import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
@@ -40,16 +42,18 @@ import org.slf4j.LoggerFactory;
              title = "Kudu", syntax = "kudu:host:port/tableName",
              category = { Category.DATABASE, Category.IOT, Category.CLOUD }, 
producerOnly = true,
              headersClass = KuduConstants.class)
-public class KuduEndpoint extends DefaultEndpoint {
+public class KuduEndpoint extends DefaultEndpoint implements 
EndpointLocationAddress {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(KuduEndpoint.class);
     private KuduClient kuduClient;
     private boolean userManagedClient;
 
     @UriPath(name = "host", displayName = "Host", label = "common", 
description = "Host of the server to connect to")
+    @Metadata(required = true)
     private String host;
 
     @UriPath(name = "port", displayName = "Port", label = "common", 
description = "Port of the server to connect to")
+    @Metadata(required = true)
     private String port;
 
     @UriParam(description = "Operation to perform")
@@ -72,6 +76,11 @@ public class KuduEndpoint extends DefaultEndpoint {
         this.setTableName(m.group(3));
     }
 
+    @Override
+    public String getAddress() {
+        return host + ":" + port;
+    }
+
     @Override
     protected void doStart() throws Exception {
         LOG.trace("Connection: {}, {}", getHost(), getPort());
diff --git 
a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
 
b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
index 2ef4f041d49..de8212905ec 100644
--- 
a/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
+++ 
b/components/camel-lucene/src/main/java/org/apache/camel/component/lucene/LuceneEndpoint.java
@@ -21,6 +21,7 @@ import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.spi.EndpointLocationAddress;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.DefaultEndpoint;
@@ -30,11 +31,13 @@ import org.apache.camel.support.DefaultEndpoint;
  */
 @UriEndpoint(firstVersion = "2.2.0", scheme = "lucene", title = "Lucene", 
syntax = "lucene:host:operation", producerOnly = true,
              category = { Category.DATABASE, Category.SEARCH }, headersClass = 
LuceneConstants.class)
-public class LuceneEndpoint extends DefaultEndpoint {
+public class LuceneEndpoint extends DefaultEndpoint implements 
EndpointLocationAddress {
+
+    private LuceneIndexer indexer;
+    private boolean insertFlag;
+
     @UriParam
     LuceneConfiguration config;
-    LuceneIndexer indexer;
-    boolean insertFlag;
 
     public LuceneEndpoint() {
     }
@@ -52,6 +55,14 @@ public class LuceneEndpoint extends DefaultEndpoint {
         }
     }
 
+    @Override
+    public String getAddress() {
+        if (config != null) {
+            return config.getHost();
+        }
+        return null;
+    }
+
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
         throw new UnsupportedOperationException("Consumer not supported for 
Lucene endpoint");
diff --git 
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
 
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
index ffae7d927b6..09a55767a18 100644
--- 
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
+++ 
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailEndpoint.java
@@ -24,6 +24,7 @@ import org.apache.camel.Consumer;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.spi.EndpointLocationAddress;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.camel.spi.IdempotentRepository;
@@ -32,6 +33,8 @@ import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.ScheduledPollEndpoint;
 import org.eclipse.angus.mail.imap.SortTerm;
 
+import java.util.Map;
+
 import static 
org.apache.camel.component.mail.MailConstants.MAIL_GENERATE_MISSING_ATTACHMENT_NAMES_NEVER;
 import static 
org.apache.camel.component.mail.MailConstants.MAIL_HANDLE_DUPLICATE_ATTACHMENT_NAMES_NEVER;
 
@@ -41,7 +44,7 @@ import static 
org.apache.camel.component.mail.MailConstants.MAIL_HANDLE_DUPLICAT
 @UriEndpoint(firstVersion = "1.0.0", scheme = 
"imap,imaps,pop3,pop3s,smtp,smtps", title = "IMAP,IMAPS,POP3,POP3S,SMTP,SMTPS",
              syntax = "imap:host:port", alternativeSyntax = 
"imap:username:password@host:port",
              category = { Category.MAIL }, headersClass = MailConstants.class)
-public class MailEndpoint extends ScheduledPollEndpoint implements 
HeaderFilterStrategyAware {
+public class MailEndpoint extends ScheduledPollEndpoint implements 
HeaderFilterStrategyAware, EndpointLocationAddress {
 
     @UriParam(defaultValue = "" + MailConsumer.DEFAULT_CONSUMER_DELAY, 
javaType = "java.time.Duration",
               label = "consumer,scheduler",
@@ -87,6 +90,22 @@ public class MailEndpoint extends ScheduledPollEndpoint 
implements HeaderFilterS
         setDelay(MailConsumer.DEFAULT_CONSUMER_DELAY);
     }
 
+    @Override
+    public String getAddress() {
+        if (configuration != null) {
+            return configuration.getProtocol() + ":" + configuration.getHost() 
+ ":" + configuration.getPort();
+        }
+        return null;
+    }
+
+    @Override
+    public Map<String, String> getAddressMetadata() {
+        if (configuration != null && configuration.getUsername() != null) {
+            return Map.of("username", configuration.getUsername());
+        }
+        return null;
+    }
+
     @Override
     public Producer createProducer() throws Exception {
         JavaMailSender sender = configuration.getJavaMailSender();

Reply via email to