camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [2/5] camel git commit: CAMEL-11083: camel-etcd : make it easy to configure components and service-discovery in spring-boot
Date Tue, 28 Mar 2017 15:07:28 GMT
CAMEL-11083: camel-etcd : make it easy to configure components and service-discovery in spring-boot


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

Branch: refs/heads/master
Commit: d122dadfd0b039f25e23d58d4307e9d5ca8d2088
Parents: 6f4fdf9
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Tue Mar 28 16:15:06 2017 +0200
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Tue Mar 28 17:06:47 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/etcd-component.adoc           |  15 +-
 .../camel/component/etcd/EtcdComponent.java     |  92 ++++++++-
 .../camel/component/etcd/EtcdConfiguration.java |  30 ++-
 ...CallServiceDiscoveryConfigurationCommon.java | 114 +++++++++++
 ...ServiceDiscoveryConfigurationProperties.java |  48 +++++
 .../EtcdComponentAutoConfiguration.java         |  34 +++-
 .../springboot/EtcdComponentConfiguration.java  | 202 +++++++++++++++++++
 .../cloud/EtcdCloudAutoConfiguration.java       |  15 +-
 .../cloud/EtcdCloudConfiguration.java           |  63 ------
 .../cloud/EtcdServiceDiscoveryDisabledTest.java |  64 ++++++
 .../cloud/EtcdServiceDiscoveryEnabledTest.java  |  65 ++++++
 .../src/test/resources/logback.xml              |  39 ++++
 .../SpringBootAutoConfigurationMojo.java        |  12 ++
 13 files changed, 702 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/components/camel-etcd/src/main/docs/etcd-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-etcd/src/main/docs/etcd-component.adoc b/components/camel-etcd/src/main/docs/etcd-component.adoc
index 1b45013..9dd4c5f 100644
--- a/components/camel-etcd/src/main/docs/etcd-component.adoc
+++ b/components/camel-etcd/src/main/docs/etcd-component.adoc
@@ -14,7 +14,20 @@ etcd:namespace/path[?options]
 ### URI Options
 
 // component options: START
-The etcd component has no options.
+The etcd component supports 6 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|=======================================================================
+| Name | Description | Default | Type
+| **uris** (common) | To set the URIs the client connects. |  | String
+| **sslContextParameters** (common) | To configure security using SSLContextParameters. |
 | SSLContextParameters
+| **userName** (common) | The user name to use for basic authentication. |  | String
+| **password** (common) | The password to use for basic authentication. |  | String
+| **configuration** (advanced) | Sets the common configuration shared among endpoints | 
| EtcdConfiguration
+| **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
 
 // endpoint options: START

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdComponent.java
b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdComponent.java
index 35ff2e5..fb41736 100644
--- a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdComponent.java
+++ b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdComponent.java
@@ -17,40 +17,108 @@
 package org.apache.camel.component.etcd;
 
 import java.util.Map;
+import java.util.Optional;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.jsse.SSLContextParameters;
 
 /**
  * Represents the component that manages {@link AbstractEtcdEndpoint}.
  */
-public class EtcdComponent extends UriEndpointComponent {
+public class EtcdComponent extends DefaultComponent {
+
+    @Metadata(label = "advanced")
+    private EtcdConfiguration configuration = new EtcdConfiguration();
 
     public EtcdComponent() {
-        super(AbstractEtcdEndpoint.class);
+        super();
     }
 
     public EtcdComponent(CamelContext context) {
-        super(context, AbstractEtcdEndpoint.class);
+        super(context);
+    }
+
+    // ************************************
+    // Options
+    // ************************************
+
+    public String getUris() {
+        return configuration.getUris();
+    }
+
+    /**
+     * To set the URIs the client connects.
+     * @param uris
+     */
+    public void setUris(String uris) {
+        configuration.setUris(uris);
+    }
+
+    public SSLContextParameters getSslContextParameters() {
+        return configuration.getSslContextParameters();
+    }
+
+    /**
+     * To configure security using SSLContextParameters.
+     * @param sslContextParameters
+     */
+    public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+        configuration.setSslContextParameters(sslContextParameters);
+    }
+
+    public String getUserName() {
+        return configuration.getUserName();
+    }
+
+    /**
+     * The user name to use for basic authentication.
+     * @param userName
+     */
+    public void setUserName(String userName) {
+        configuration.setUserName(userName);
+    }
+
+    public String getPassword() {
+        return configuration.getPassword();
+    }
+
+    /**
+     * The password to use for basic authentication.
+     * @param password
+     */
+    public void setPassword(String password) {
+        configuration.setPassword(password);
+    }
+
+    public EtcdConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * Sets the common configuration shared among endpoints
+     */
+    public void setConfiguration(EtcdConfiguration configuration) {
+        this.configuration = configuration;
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        String ns = ObjectHelper.before(remaining, "/");
-        String path = ObjectHelper.after(remaining, "/");
+        String ns = StringHelper.before(remaining, "/");
+        String path = StringHelper.after(remaining, "/");
 
         if (ns == null) {
             ns = remaining;
         }
-
         if (path == null) {
             path = remaining;
         }
 
         EtcdNamespace namespace = getCamelContext().getTypeConverter().mandatoryConvertTo(EtcdNamespace.class,
ns);
-        EtcdConfiguration configuration = loadConfiguration(new EtcdConfiguration(getCamelContext()),
parameters);
+        EtcdConfiguration configuration = loadConfiguration(parameters);
 
         if (namespace != null) {
             // path must start with leading slash
@@ -73,8 +141,12 @@ public class EtcdComponent extends UriEndpointComponent {
         throw new IllegalStateException("No endpoint for " + remaining);
     }
 
-    protected <T> T loadConfiguration(T configuration, Map<String, Object> parameters)
throws Exception {
+    protected EtcdConfiguration loadConfiguration(Map<String, Object> parameters) throws
Exception {
+        EtcdConfiguration configuration = Optional.ofNullable(this.configuration).orElseGet(EtcdConfiguration::new).copy();
+        configuration.setCamelContext(getCamelContext());
+
         setProperties(configuration, parameters);
+
         return configuration;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdConfiguration.java
b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdConfiguration.java
index 9ce6d2a..21ca7f6 100644
--- a/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdConfiguration.java
+++ b/components/camel-etcd/src/main/java/org/apache/camel/component/etcd/EtcdConfiguration.java
@@ -19,12 +19,14 @@ package org.apache.camel.component.etcd;
 import mousio.etcd4j.EtcdClient;
 import mousio.etcd4j.EtcdSecurityContext;
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.util.jsse.SSLContextParameters;
 
 @UriParams
-public class EtcdConfiguration {
+public class EtcdConfiguration implements CamelContextAware, Cloneable {
 
     @UriParam(defaultValue = EtcdConstants.ETCD_DEFAULT_URIS)
     private String uris = EtcdConstants.ETCD_DEFAULT_URIS;
@@ -47,18 +49,24 @@ public class EtcdConfiguration {
     @UriParam(defaultValue = "/services/")
     private String servicePath = "/services/";
 
-    private final CamelContext camelContext;
+    private CamelContext context;
 
     public EtcdConfiguration() {
-        this.camelContext = null;
+        this.context = null;
     }
 
     public EtcdConfiguration(CamelContext camelContext) {
-        this.camelContext = camelContext;
+        this.context = camelContext;
     }
 
+    @Override
+    public void setCamelContext(CamelContext context) {
+        this.context = context;
+    }
+
+    @Override
     public CamelContext getCamelContext() {
-        return this.camelContext;
+        return context;
     }
 
     public String getUris() {
@@ -179,11 +187,19 @@ public class EtcdConfiguration {
         return new EtcdClient(
             new EtcdSecurityContext(
                 sslContextParameters != null
-                    ? sslContextParameters.createSSLContext(camelContext)
+                    ? sslContextParameters.createSSLContext(context)
                     : null,
                 userName,
                 password),
-            EtcdHelper.resolveURIs(camelContext, getUris())
+            EtcdHelper.resolveURIs(context, getUris())
         );
     }
+
+    public EtcdConfiguration copy() {
+        try {
+            return (EtcdConfiguration)super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationCommon.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationCommon.java
new file mode 100644
index 0000000..e79f102
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationCommon.java
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.cloud.springboot;
+
+import java.util.List;
+import org.apache.camel.model.PropertyDefinition;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+public class EtcdServiceCallServiceDiscoveryConfigurationCommon {
+
+    /**
+     * The URIs the client can connect to.
+     */
+    private String uris;
+    /**
+     * The user name to use for basic authentication.
+     */
+    private String userName;
+    /**
+     * The password to use for basic authentication.
+     */
+    private String password;
+    /**
+     * To set the maximum time an action could take to complete.
+     */
+    private Long timeout;
+    /**
+     * The path to look for for service discovery
+     */
+    private String servicePath = "/services/";
+    /**
+     * To set the discovery type valid values are on-demand and watch.
+     */
+    private String type = "on-demand";
+    /**
+     * Set client properties to use. These properties are specific to what
+     * service call implementation are in use. For example if using ribbon then
+     * the client properties are define in
+     * com.netflix.client.config.CommonClientConfigKey.
+     */
+    private List<PropertyDefinition> properties;
+
+    public String getUris() {
+        return uris;
+    }
+
+    public void setUris(String uris) {
+        this.uris = uris;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public Long getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(Long timeout) {
+        this.timeout = timeout;
+    }
+
+    public String getServicePath() {
+        return servicePath;
+    }
+
+    public void setServicePath(String servicePath) {
+        this.servicePath = servicePath;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public List<PropertyDefinition> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(List<PropertyDefinition> properties) {
+        this.properties = properties;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationProperties.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationProperties.java
new file mode 100644
index 0000000..9d6353d
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/EtcdServiceCallServiceDiscoveryConfigurationProperties.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.cloud.springboot;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.etcd.service-discovery")
+public class EtcdServiceCallServiceDiscoveryConfigurationProperties
+        extends
+            EtcdServiceCallServiceDiscoveryConfigurationCommon {
+
+    /**
+     * Enable the component
+     */
+    private boolean enabled = true;
+    /**
+     * Define additional configuration definitions
+     */
+    private Map<String, EtcdServiceCallServiceDiscoveryConfigurationCommon> configurations
= new HashMap<>();
+
+    public Map<String, EtcdServiceCallServiceDiscoveryConfigurationCommon> getConfigurations()
{
+        return configurations;
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentAutoConfiguration.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentAutoConfiguration.java
index d55357e..26290f1 100644
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentAutoConfiguration.java
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.component.etcd.springboot;
 
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.etcd.EtcdComponent;
+import org.apache.camel.util.IntrospectionSupport;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 import org.springframework.boot.autoconfigure.condition.ConditionMessage;
 import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -26,6 +29,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
 import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ConditionContext;
 import org.springframework.context.annotation.Conditional;
@@ -40,16 +44,42 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
 @ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration")
 @Conditional(EtcdComponentAutoConfiguration.Condition.class)
 @AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@EnableConfigurationProperties(EtcdComponentConfiguration.class)
 public class EtcdComponentAutoConfiguration {
 
     @Lazy
     @Bean(name = "etcd-component")
     @ConditionalOnClass(CamelContext.class)
     @ConditionalOnMissingBean(EtcdComponent.class)
-    public EtcdComponent configureEtcdComponent(CamelContext camelContext)
-            throws Exception {
+    public EtcdComponent configureEtcdComponent(CamelContext camelContext,
+            EtcdComponentConfiguration configuration) throws Exception {
         EtcdComponent component = new EtcdComponent();
         component.setCamelContext(camelContext);
+        Map<String, Object> parameters = new HashMap<>();
+        IntrospectionSupport.getProperties(configuration, parameters, null,
+                false);
+        for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+            Object value = entry.getValue();
+            Class<?> paramClass = value.getClass();
+            if (paramClass.getName().endsWith("NestedConfiguration")) {
+                Class nestedClass = null;
+                try {
+                    nestedClass = (Class) paramClass.getDeclaredField(
+                            "CAMEL_NESTED_CLASS").get(null);
+                    HashMap<String, Object> nestedParameters = new HashMap<>();
+                    IntrospectionSupport.getProperties(value, nestedParameters,
+                            null, false);
+                    Object nestedProperty = nestedClass.newInstance();
+                    IntrospectionSupport.setProperties(camelContext,
+                            camelContext.getTypeConverter(), nestedProperty,
+                            nestedParameters);
+                    entry.setValue(nestedProperty);
+                } catch (NoSuchFieldException e) {
+                }
+            }
+        }
+        IntrospectionSupport.setProperties(camelContext,
+                camelContext.getTypeConverter(), component, parameters);
         return component;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentConfiguration.java
index 64dae7c..0ecec6b 100644
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/EtcdComponentConfiguration.java
@@ -16,7 +16,10 @@
  */
 package org.apache.camel.component.etcd.springboot;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.jsse.SSLContextParameters;
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
 
 /**
  * The camel etcd component allows you to work with Etcd a distributed reliable
@@ -28,12 +31,75 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 public class EtcdComponentConfiguration {
 
     /**
+     * To set the URIs the client connects.
+     */
+    private String uris;
+    /**
+     * To configure security using SSLContextParameters.
+     */
+    @NestedConfigurationProperty
+    private SSLContextParameters sslContextParameters;
+    /**
+     * The user name to use for basic authentication.
+     */
+    private String userName;
+    /**
+     * The password to use for basic authentication.
+     */
+    private String password;
+    /**
+     * Sets the common configuration shared among endpoints
+     */
+    private EtcdConfigurationNestedConfiguration configuration;
+    /**
      * 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 String getUris() {
+        return uris;
+    }
+
+    public void setUris(String uris) {
+        this.uris = uris;
+    }
+
+    public SSLContextParameters getSslContextParameters() {
+        return sslContextParameters;
+    }
+
+    public void setSslContextParameters(
+            SSLContextParameters sslContextParameters) {
+        this.sslContextParameters = sslContextParameters;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public EtcdConfigurationNestedConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(
+            EtcdConfigurationNestedConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }
@@ -42,4 +108,140 @@ public class EtcdComponentConfiguration {
             Boolean resolvePropertyPlaceholders) {
         this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
     }
+
+    public static class EtcdConfigurationNestedConfiguration {
+        public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.etcd.EtcdConfiguration.class;
+        private CamelContext camelContext;
+        /**
+         * To set the URIs the client connects.
+         */
+        private String uris = "http://localhost:2379,http://localhost:4001";
+        /**
+         * To configure security using SSLContextParameters.
+         */
+        @NestedConfigurationProperty
+        private SSLContextParameters sslContextParameters;
+        /**
+         * The user name to use for basic authentication.
+         */
+        private String userName;
+        /**
+         * The password to use for basic authentication.
+         */
+        private String password;
+        /**
+         * To send an empty message in case of timeout watching for a key.
+         */
+        private Boolean sendEmptyExchangeOnTimeout = false;
+        /**
+         * To apply an action recursively.
+         */
+        private Boolean recursive = false;
+        /**
+         * To set the lifespan of a key in milliseconds.
+         */
+        private Integer timeToLive;
+        /**
+         * To set the maximum time an action could take to complete.
+         */
+        private Long timeout;
+        /**
+         * The index to watch from
+         */
+        private Long fromIndex = 0L;
+        /**
+         * The path to look for for service discovery
+         */
+        private String servicePath = "/services/";
+
+        public CamelContext getCamelContext() {
+            return camelContext;
+        }
+
+        public void setCamelContext(CamelContext camelContext) {
+            this.camelContext = camelContext;
+        }
+
+        public String getUris() {
+            return uris;
+        }
+
+        public void setUris(String uris) {
+            this.uris = uris;
+        }
+
+        public SSLContextParameters getSslContextParameters() {
+            return sslContextParameters;
+        }
+
+        public void setSslContextParameters(
+                SSLContextParameters sslContextParameters) {
+            this.sslContextParameters = sslContextParameters;
+        }
+
+        public String getUserName() {
+            return userName;
+        }
+
+        public void setUserName(String userName) {
+            this.userName = userName;
+        }
+
+        public String getPassword() {
+            return password;
+        }
+
+        public void setPassword(String password) {
+            this.password = password;
+        }
+
+        public Boolean getSendEmptyExchangeOnTimeout() {
+            return sendEmptyExchangeOnTimeout;
+        }
+
+        public void setSendEmptyExchangeOnTimeout(
+                Boolean sendEmptyExchangeOnTimeout) {
+            this.sendEmptyExchangeOnTimeout = sendEmptyExchangeOnTimeout;
+        }
+
+        public Boolean getRecursive() {
+            return recursive;
+        }
+
+        public void setRecursive(Boolean recursive) {
+            this.recursive = recursive;
+        }
+
+        public Integer getTimeToLive() {
+            return timeToLive;
+        }
+
+        public void setTimeToLive(Integer timeToLive) {
+            this.timeToLive = timeToLive;
+        }
+
+        public Long getTimeout() {
+            return timeout;
+        }
+
+        public void setTimeout(Long timeout) {
+            this.timeout = timeout;
+        }
+
+        public Long getFromIndex() {
+            return fromIndex;
+        }
+
+        public void setFromIndex(Long fromIndex) {
+            this.fromIndex = fromIndex;
+        }
+
+        public String getServicePath() {
+            return servicePath;
+        }
+
+        public void setServicePath(String servicePath) {
+            this.servicePath = servicePath;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
index 1ae962d..3218cbf 100644
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java
@@ -18,13 +18,13 @@ package org.apache.camel.component.etcd.springboot.cloud;
 
 import java.util.HashMap;
 import java.util.Map;
-
 import javax.annotation.PostConstruct;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.component.etcd.EtcdConfiguration;
 import org.apache.camel.component.etcd.cloud.EtcdServiceDiscoveryFactory;
+import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationCommon;
+import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
 import org.apache.camel.spring.boot.CamelAutoConfiguration;
 import org.apache.camel.spring.boot.util.GroupCondition;
 import org.apache.camel.util.IntrospectionSupport;
@@ -44,12 +44,12 @@ import org.springframework.context.annotation.Lazy;
 @ConditionalOnBean(CamelAutoConfiguration.class)
 @Conditional(EtcdCloudAutoConfiguration.Condition.class)
 @AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties(EtcdCloudConfiguration.class)
+@EnableConfigurationProperties(EtcdServiceCallServiceDiscoveryConfigurationProperties.class)
 public class EtcdCloudAutoConfiguration {
     @Autowired
     private CamelContext camelContext;
     @Autowired
-    private EtcdCloudConfiguration configuration;
+    private EtcdServiceCallServiceDiscoveryConfigurationProperties configuration;
     @Autowired
     private ConfigurableBeanFactory beanFactory;
 
@@ -71,10 +71,9 @@ public class EtcdCloudAutoConfiguration {
     @PostConstruct
     public void postConstruct() {
         if (beanFactory != null) {
-            EtcdCloudConfiguration.ServiceDiscoveryConfiguration discovery = configuration.getServiceDiscovery();
             Map<String, Object> parameters = new HashMap<>();
 
-            for (Map.Entry<String, EtcdConfiguration> entry : discovery.getConfigurations().entrySet())
{
+            for (Map.Entry<String, EtcdServiceCallServiceDiscoveryConfigurationCommon>
entry : configuration.getConfigurations().entrySet()) {
                 // clean up params
                 parameters.clear();
 
@@ -100,8 +99,8 @@ public class EtcdCloudAutoConfiguration {
     public static class Condition extends GroupCondition {
         public Condition() {
             super(
-                "camel.cloud",
-                "camel.cloud.etcd"
+                "camel.cloud.etcd",
+                "camel.cloud.etcd.service-discovery"
             );
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
deleted file mode 100644
index e637ac4..0000000
--- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.etcd.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.component.etcd.EtcdConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.etcd")
-public class EtcdCloudConfiguration {
-    private boolean enabled = true;
-    private ServiceDiscoveryConfiguration serviceDiscovery = new ServiceDiscoveryConfiguration();
-
-    public boolean isEnabled() {
-        return enabled;
-    }
-
-    public void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-    }
-
-    public ServiceDiscoveryConfiguration getServiceDiscovery() {
-        return serviceDiscovery;
-    }
-
-    // *************************************************************************
-    //
-    // *************************************************************************
-
-    public class ServiceDiscoveryConfiguration extends EtcdConfiguration {
-        private final Map<String, EtcdConfiguration> configurations = new HashMap<>();
-
-        private String type;
-
-        public String getType() {
-            return type;
-        }
-
-        public void setType(String type) {
-            this.type = type;
-        }
-
-        public Map<String, EtcdConfiguration> getConfigurations() {
-            return configurations;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
new file mode 100644
index 0000000..5ca84bf
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryDisabledTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.etcd.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        EtcdServiceDiscoveryEnabledTest.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.cloud.etcd.service-discovery.enabled=false"
+})
+public class EtcdServiceDiscoveryDisabledTest {
+    @Autowired
+    ApplicationContext context;
+
+    @Test
+    public void testConfiguration() throws Exception {
+        Map<String, ?> beans;
+
+        beans = context.getBeansOfType(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
+        Assert.assertTrue(beans.isEmpty());
+
+        beans = context.getBeansOfType(ServiceDiscovery.class);
+        Assert.assertFalse(beans.isEmpty());
+        Assert.assertFalse(beans.containsKey("etcd-service-discovery"));
+    }
+
+    @Configuration
+    public static class TestConfiguration {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
new file mode 100644
index 0000000..f678282
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/java/org/apache/camel/component/etcd/springboot/cloud/EtcdServiceDiscoveryEnabledTest.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.etcd.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.EtcdServiceCallServiceDiscoveryConfigurationProperties;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@DirtiesContext
+@SpringBootApplication
+@SpringBootTest(
+    classes = {
+        EtcdServiceDiscoveryEnabledTest.TestConfiguration.class
+    },
+    properties = {
+        "debug=false",
+        "camel.cloud.etcd.service-discovery.enabled=true"
+})
+public class EtcdServiceDiscoveryEnabledTest {
+    @Autowired
+    ApplicationContext context;
+
+    @Test
+    public void testConfiguration() throws Exception {
+        Map<String, ?> beans;
+
+        beans = context.getBeansOfType(EtcdServiceCallServiceDiscoveryConfigurationProperties.class);
+        Assert.assertFalse(beans.isEmpty());
+        Assert.assertEquals(1, beans.size());
+
+        beans = context.getBeansOfType(ServiceDiscovery.class);
+        Assert.assertFalse(beans.isEmpty());
+        Assert.assertTrue(beans.containsKey("etcd-service-discovery"));
+    }
+
+    @Configuration
+    public static class TestConfiguration {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/resources/logback.xml
b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/resources/logback.xml
new file mode 100644
index 0000000..d78e49b
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/test/resources/logback.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <!-- encoders are assigned the type
+         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%-15.15thread] %-5level %-30.30logger - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%-15.15thread] %-5level %-30.30logger - %msg%n</pattern>
+    </encoder>
+    <file>target/camel-etcd-starter-test.log</file>
+  </appender>
+
+  <root level="INFO">
+    <appender-ref ref="FILE"/>
+  </root>
+
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/d122dadf/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 7b96fb0..033db0e 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -221,6 +221,18 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             // Generate properties, auto-configuration happens in camel-consul-starter
             createHystrixConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery");
         }
+
+        // Etcd
+        json = loadModelJson(files, "etcdServiceDiscovery");
+        if (json != null) {
+            OtherModel model = generateOtherModel(json);
+
+            int pos = model.getJavaType().lastIndexOf(".");
+            String pkg = model.getJavaType().substring(0, pos) + ".springboot";
+
+            // Generate properties, auto-configuration happens in camel-etcd-starter
+            createHystrixConfigurationSource(pkg, model, "camel.cloud.etcd.service-discovery");
+        }
     }
 
     private void createHystrixConfigurationSource(String packageName, OtherModel model, String
propertiesPrefix) throws MojoFailureException {


Mime
View raw message