camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/5] camel git commit: CAMEL-11597: Polished. This closes #1857.
Date Sun, 30 Jul 2017 09:03:58 GMT
CAMEL-11597: Polished. This closes #1857.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6cc7ca4c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6cc7ca4c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6cc7ca4c

Branch: refs/heads/master
Commit: 6cc7ca4c6e6b74d50d68e3c1cb79f0c0b5b01cf4
Parents: fe99945
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jul 30 11:03:19 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jul 30 11:03:45 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/elasticsearch5-component.adoc | 22 ++++++++++++++---
 .../ElasticsearchConfiguration.java             | 26 ++++++++++----------
 .../elasticsearch5/ElasticsearchEndpoint.java   |  4 ---
 .../elasticsearch5/ElasticsearchProducer.java   | 25 ++++++++-----------
 .../ElasticsearchComponentConfiguration.java    | 17 +++++++++++++
 5 files changed, 59 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6cc7ca4c/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
index 76590b1..0210882 100644
--- a/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
+++ b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
@@ -31,7 +31,16 @@ elasticsearch5://clusterName[?options]
 
 
 // component options: START
-The Elasticsearch5 component has no options.
+The Elasticsearch5 component supports 2 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|=======================================================================
+| Name | Description | Default | Type
+| **client** (advanced) | To use an existing configured Elasticsearch client instead of creating
a client per endpoint. This allow to customize the client with specific settings. |  | TransportClient
+| **resolveProperty Placeholders** (advanced) | Whether the component should resolve property
placeholders on itself when starting. Only properties which are of String type can use property
placeholders. | true | boolean
+|=======================================================================
 // component options: END
 
 
@@ -53,20 +62,27 @@ with the following path and query parameters:
 | **clusterName** | *Required* Name of the cluster |  | String
 |=======================================================================
 
-#### Query Parameters (9 parameters):
+#### Query Parameters (16 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |=======================================================================
 | Name | Description | Default | Type
-| **clientTransportSniff** (producer) | Is the client allowed to sniff the rest of the cluster
or not (default true). This setting map to the client.transport.sniff setting. | true | Boolean
+| **clientTransportSniff** (producer) | Is the client allowed to sniff the rest of the cluster
or not (default true). This setting map to the client.transport.sniff setting. | false | boolean
 | **indexName** (producer) | The name of the index to act against |  | String
 | **indexType** (producer) | The type of the index to act against |  | String
 | **ip** (producer) | The TransportClient remote host ip to use |  | String
 | **operation** (producer) | What operation to perform |  | ElasticsearchOperation
+| **pingSchedule** (producer) | The time(in unit) the client ping the cluster. | 5s | String
+| **pingTimeout** (producer) | The time(in unit) to wait for a ping response from a node
too return. | 5s | String
 | **port** (producer) | The TransportClient remote port to use (defaults to 9300) | 9300
| int
+| **tcpCompress** (producer) | true if compression (LZF) enable between all nodes. | false
| boolean
+| **tcpConnectTimeout** (producer) | The time( in unit) to wait for connection timeout. |
30s | String
 | **transportAddresses** (producer) | Comma separated list with ip:port formatted remote
transport addresses to use. The ip and port options must be left blank for transportAddresses
to be considered instead. |  | String
 | **waitForActiveShards** (producer) | Index creation waits for the write consistency number
of shards to be available | 1 | int
 | **synchronous** (advanced) | Sets whether synchronous processing should be strictly used
or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+| **enableSSL** (security) | Enable SSL. Require XPack client jar on the classpath | false
| boolean
+| **password** (authentication) | Password for authenticate against the cluster. Require
XPack client jar on the classpath |  | String
+| **user** (authentication) | User for authenticate against the cluster. Requires transport_client
role for accessing the cluster. Require XPack client jar on the classpath |  | String
 |=======================================================================
 // endpoint options: END
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6cc7ca4c/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
index 25eddca..eff8388 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
@@ -45,22 +45,22 @@ public class ElasticsearchConfiguration {
     private String transportAddresses;
     @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_PORT)
     private int port = ElasticsearchConstants.DEFAULT_PORT;
-    @UriParam(defaultValue = "false")
-    private Boolean clientTransportSniff = false;
+    @UriParam
+    private boolean clientTransportSniff;
     @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_PING_SCHEDULE)
     private String pingSchedule = ElasticsearchConstants.DEFAULT_PING_SCHEDULE;
     @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_PING_TIMEOUT)
     private String pingTimeout = ElasticsearchConstants.DEFAULT_PING_TIMEOUT;
     @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_TCP_CONNECT_TIMEOUT)
     private String tcpConnectTimeout = ElasticsearchConstants.DEFAULT_TCP_CONNECT_TIMEOUT;
-    @UriParam(defaultValue = "false")
-    private Boolean tcpCompress = false;
     @UriParam
+    private boolean tcpCompress;
+    @UriParam(label = "authentication")
     private String user;
-    @UriParam(secret = true)
+    @UriParam(label = "authentication", secret = true)
     private String password;
-    @UriParam(defaultValue = "false")
-    private Boolean enableSSL = false;
+    @UriParam(label = "advanced,security")
+    private boolean enableSSL;
 
 
     /**
@@ -155,11 +155,11 @@ public class ElasticsearchConfiguration {
     /**
      * Is the client allowed to sniff the rest of the cluster or not (default true). This
setting map to the <tt>client.transport.sniff</tt> setting.
      */
-    public Boolean getClientTransportSniff() {
+    public boolean getClientTransportSniff() {
         return clientTransportSniff;
     }
 
-    public void setClientTransportSniff(Boolean clientTransportSniff) {
+    public void setClientTransportSniff(boolean clientTransportSniff) {
         this.clientTransportSniff = clientTransportSniff;
     }
 
@@ -196,11 +196,11 @@ public class ElasticsearchConfiguration {
     /**
      * true if compression (LZF) enable between all nodes.
      */
-    public Boolean getTcpCompress() {
+    public boolean getTcpCompress() {
         return tcpCompress;
     }
 
-    public void setTcpCompress(Boolean tcpCompress) {
+    public void setTcpCompress(boolean tcpCompress) {
         this.tcpCompress = tcpCompress;
     }
 
@@ -230,11 +230,11 @@ public class ElasticsearchConfiguration {
     /**
      * Enable SSL. Require XPack client jar on the classpath
      */
-    public Boolean getEnableSSL() {
+    public boolean getEnableSSL() {
         return enableSSL;
     }
 
-    public void setEnableSSL(Boolean enableSSL) {
+    public void setEnableSSL(boolean enableSSL) {
         this.enableSSL = enableSSL;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6cc7ca4c/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
index 9618097..5835b31 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
@@ -23,8 +23,6 @@ import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.elasticsearch.client.transport.TransportClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * The elasticsearch component is used for interfacing with ElasticSearch server using 5.x
API.
@@ -32,8 +30,6 @@ import org.slf4j.LoggerFactory;
 @UriEndpoint(firstVersion = "2.19.0", scheme = "elasticsearch5", title = "Elasticsearch5",
syntax = "elasticsearch5:clusterName", producerOnly = true, label = "monitoring,search")
 public class ElasticsearchEndpoint extends DefaultEndpoint {
 
-    private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchEndpoint.class);
-
     @UriParam
     protected final ElasticsearchConfiguration configuration;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6cc7ca4c/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
index 3830a6f..ad74f7a 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
@@ -17,7 +17,6 @@
 package org.apache.camel.component.elasticsearch5;
 
 import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.List;
@@ -83,9 +82,9 @@ public class ElasticsearchProducer extends DefaultProducer {
         } else if (request instanceof BulkRequest) {
             // do we want bulk or bulk_index?
             if (configuration.getOperation() == ElasticsearchOperation.BULK_INDEX) {
-                return configuration.getOperation().BULK_INDEX;
+                return ElasticsearchOperation.BULK_INDEX;
             } else {
-                return configuration.getOperation().BULK;
+                return ElasticsearchOperation.BULK;
             }
         } else if (request instanceof DeleteRequest) {
             return ElasticsearchOperation.DELETE;
@@ -219,16 +218,12 @@ public class ElasticsearchProducer extends DefaultProducer {
         super.doStart();
 
         if (client == null) {
-            LOG.info("Connecting to the ElasticSearch cluster: " + configuration.getClusterName());
+            LOG.info("Connecting to the ElasticSearch cluster: {}", configuration.getClusterName());
             if (configuration.getIp() != null) {
-                client = createClient()
-                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(configuration.getIp()),
configuration.getPort()));
-            } else if (configuration.getTransportAddressesList() != null
-                && !configuration.getTransportAddressesList().isEmpty()) {
+                client = createClient().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(configuration.getIp()),
configuration.getPort()));
+            } else if (configuration.getTransportAddressesList() != null && !configuration.getTransportAddressesList().isEmpty())
{
                 List<TransportAddress> addresses = new ArrayList<TransportAddress>(configuration.getTransportAddressesList().size());
-                for (TransportAddress address : configuration.getTransportAddressesList())
{
-                    addresses.add(address);
-                }
+                addresses.addAll(configuration.getTransportAddressesList());
                 client = createClient().addTransportAddresses(addresses.toArray(new TransportAddress[addresses.size()]));
             } else {
                 LOG.info("Incorrect ip address and port parameters settings for ElasticSearch
cluster");
@@ -236,7 +231,7 @@ public class ElasticsearchProducer extends DefaultProducer {
         }
     }
 
-    private TransportClient createClient() throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException, InstantiationException {
+    private TransportClient createClient() throws Exception {
         final Settings.Builder settings = getSettings();
         final CamelContext camelContext = getEndpoint().getCamelContext();
         final Class<?> clazz = camelContext.getClassResolver().resolveClass("org.elasticsearch.xpack.client.PreBuiltXPackTransportClient");
@@ -244,10 +239,10 @@ public class ElasticsearchProducer extends DefaultProducer {
             Constructor<?> ctor = clazz.getConstructor(Settings.class, Class[].class);
             settings.put("xpack.security.user", configuration.getUser() + ":" + configuration.getPassword())
                 .put("xpack.security.transport.ssl.enabled", configuration.getEnableSSL());
-            LOG.debug("XPack Client was found on the classpath");
-            return (TransportClient) ctor.newInstance(new Object[] {settings.build(), new
Class[0]});
+            LOG.info("XPack Client was found on the classpath");
+            return (TransportClient) ctor.newInstance(new Object[]{settings.build(), new
Class[0]});
         } else {
-            LOG.debug("XPack Client was not found on the classpath, using the standard client");
+            LOG.debug("XPack Client was not found on the classpath, using the standard client.");
             return new PreBuiltTransportClient(settings.build());
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6cc7ca4c/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
index ed8752c..4d87828 100644
--- a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
@@ -18,7 +18,9 @@ package org.apache.camel.component.elasticsearch5.springboot;
 
 import javax.annotation.Generated;
 import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.elasticsearch.client.transport.TransportClient;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
 
 /**
  * The elasticsearch component is used for interfacing with ElasticSearch server
@@ -33,12 +35,27 @@ public class ElasticsearchComponentConfiguration
             ComponentConfigurationPropertiesCommon {
 
     /**
+     * To use an existing configured Elasticsearch client instead of creating a
+     * client per endpoint. This allow to customize the client with specific
+     * settings.
+     */
+    @NestedConfigurationProperty
+    private TransportClient client;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
      */
     private Boolean resolvePropertyPlaceholders = true;
 
+    public TransportClient getClient() {
+        return client;
+    }
+
+    public void setClient(TransportClient client) {
+        this.client = client;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }


Mime
View raw message