You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/03/28 15:07:27 UTC
[1/5] camel git commit: CAMEL-11084: camel-dns : make it easy to
configure components and service-discovery in spring-boot
Repository: camel
Updated Branches:
refs/heads/master ea3a02e97 -> 365ac51a0
CAMEL-11084: camel-dns : 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/46dc46b0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/46dc46b0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/46dc46b0
Branch: refs/heads/master
Commit: 46dc46b06ce537e9d59f3a6bbdfa387e6cc809e2
Parents: d122dad
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 28 16:33:44 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 28 17:06:47 2017 +0200
----------------------------------------------------------------------
...CallServiceDiscoveryConfigurationCommon.java | 66 ++++++++++++++++++++
...ServiceDiscoveryConfigurationProperties.java | 48 ++++++++++++++
.../cloud/DnsCloudAutoConfiguration.java | 15 +++--
.../springboot/cloud/DnsCloudConfiguration.java | 53 ----------------
.../cloud/DnsServiceDiscoveryDisabledTest.java | 64 +++++++++++++++++++
.../cloud/DnsServiceDiscoveryEnabledTest.java | 65 +++++++++++++++++++
.../src/test/resources/logback.xml | 39 ++++++++++++
.../SpringBootAutoConfigurationMojo.java | 20 ++++--
8 files changed, 305 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/46dc46b0/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
new file mode 100644
index 0000000..8515557
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
@@ -0,0 +1,66 @@
+/**
+ * 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 DnsServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * The transport protocol of the desired service.
+ */
+ private String proto = "_tcp";
+ /**
+ * The domain name;
+ */
+ private String domain;
+ /**
+ * 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 getProto() {
+ return proto;
+ }
+
+ public void setProto(String proto) {
+ this.proto = proto;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ 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/46dc46b0/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationProperties.java
new file mode 100644
index 0000000..76f9c7a
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationProperties.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.dns.service-discovery")
+public class DnsServiceCallServiceDiscoveryConfigurationProperties
+ extends
+ DnsServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * Enable the component
+ */
+ private boolean enabled = true;
+ /**
+ * Define additional configuration definitions
+ */
+ private Map<String, DnsServiceCallServiceDiscoveryConfigurationCommon> configurations = new HashMap<>();
+
+ public Map<String, DnsServiceCallServiceDiscoveryConfigurationCommon> 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/46dc46b0/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
index 57fbed3..b0ee4c0 100644
--- a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudAutoConfiguration.java
@@ -18,13 +18,13 @@ package org.apache.camel.component.dns.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.dns.DnsConfiguration;
import org.apache.camel.component.dns.cloud.DnsServiceDiscoveryFactory;
+import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationCommon;
+import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
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(DnsCloudAutoConfiguration.Condition.class)
@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties(DnsCloudConfiguration.class)
+@EnableConfigurationProperties(DnsServiceCallServiceDiscoveryConfigurationProperties.class)
public class DnsCloudAutoConfiguration {
@Autowired
private CamelContext camelContext;
@Autowired
- private DnsCloudConfiguration configuration;
+ private DnsServiceCallServiceDiscoveryConfigurationProperties configuration;
@Autowired
private ConfigurableBeanFactory beanFactory;
@@ -71,10 +71,9 @@ public class DnsCloudAutoConfiguration {
@PostConstruct
public void postConstruct() {
if (beanFactory != null) {
- DnsCloudConfiguration.ServiceDiscoveryConfiguration discovery = configuration.getServiceDiscovery();
Map<String, Object> parameters = new HashMap<>();
- for (Map.Entry<String, DnsConfiguration> entry : discovery.getConfigurations().entrySet()) {
+ for (Map.Entry<String, DnsServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
// clean up params
parameters.clear();
@@ -100,8 +99,8 @@ public class DnsCloudAutoConfiguration {
public static class Condition extends GroupCondition {
public Condition() {
super(
- "camel.cloud",
- "camel.cloud.dns"
+ "camel.cloud.dns",
+ "camel.cloud.dns.service-discovery"
);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/46dc46b0/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
deleted file mode 100644
index 789315e..0000000
--- a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java
+++ /dev/null
@@ -1,53 +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.dns.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.component.dns.DnsConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.dns")
-public class DnsCloudConfiguration {
- 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 DnsConfiguration {
- private final Map<String, DnsConfiguration> configurations = new HashMap<>();
-
- public Map<String, DnsConfiguration> getConfigurations() {
- return configurations;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/46dc46b0/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.java
new file mode 100644
index 0000000..cc967c0
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryDisabledTest.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.dns.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ DnsServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.dns.service-discovery.enabled=false"
+})
+public class DnsServiceDiscoveryDisabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertTrue(beans.isEmpty());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertFalse(beans.containsKey("dns-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/46dc46b0/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.java
new file mode 100644
index 0000000..bc1bcc7
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/java/org/apache/camel/component/dns/springboot/cloud/DnsServiceDiscoveryEnabledTest.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.dns.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.DnsServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ DnsServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.dns.service-discovery.enabled=true"
+})
+public class DnsServiceDiscoveryEnabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(DnsServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertEquals(1, beans.size());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertTrue(beans.containsKey("dns-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/46dc46b0/platforms/spring-boot/components-starter/camel-dns-starter/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/test/resources/logback.xml b/platforms/spring-boot/components-starter/camel-dns-starter/src/test/resources/logback.xml
new file mode 100644
index 0000000..55e0b6b
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-dns-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-dns-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/46dc46b0/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 033db0e..e31d1ba 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
@@ -207,7 +207,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration happens in camel-hystrix-starter
- createHystrixConfigurationSource(pkg, model, "camel.hystrix");
+ createOtherModelConfigurationSource(pkg, model, "camel.hystrix");
}
// Consul
@@ -219,7 +219,19 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration happens in camel-consul-starter
- createHystrixConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery");
+ createOtherModelConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery");
+ }
+
+ // DNS
+ json = loadModelJson(files, "dnsServiceDiscovery");
+ 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-consul-starter
+ createOtherModelConfigurationSource(pkg, model, "camel.cloud.dns.service-discovery");
}
// Etcd
@@ -231,11 +243,11 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
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");
+ createOtherModelConfigurationSource(pkg, model, "camel.cloud.etcd.service-discovery");
}
}
- private void createHystrixConfigurationSource(String packageName, OtherModel model, String propertiesPrefix) throws MojoFailureException {
+ private void createOtherModelConfigurationSource(String packageName, OtherModel model, String propertiesPrefix) throws MojoFailureException {
final int pos = model.getJavaType().lastIndexOf(".");
final String commonName = model.getJavaType().substring(pos + 1) + "Common";
final String configName = model.getJavaType().substring(pos + 1) + "Properties";
[3/5] camel git commit: CAMEL-11082: camel-consul : make it easy to
configure components and service-discovery in spring-boot
Posted by lb...@apache.org.
CAMEL-11082: camel-consul : 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/6f4fdf9e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6f4fdf9e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6f4fdf9e
Branch: refs/heads/master
Commit: 6f4fdf9e05f437a1f2d7a608131ceda55f28deb9
Parents: ea3a02e
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 28 14:27:47 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 28 17:06:47 2017 +0200
----------------------------------------------------------------------
...erviceCallServiceDiscoveryConfiguration.java | 24 +-
.../src/main/docs/consul-component.adoc | 19 +-
.../camel/component/consul/ConsulComponent.java | 127 +++++--
.../component/consul/ConsulConfiguration.java | 50 ++-
.../camel/component/consul/ConsulEndpoint.java | 26 +-
.../consul/cloud/ConsulServiceDiscovery.java | 10 +-
.../cloud/ConsulServiceDiscoveryFactory.java | 19 +-
.../src/main/resources/application.properties | 8 +-
.../ConsulComponentAutoConfiguration.java | 34 +-
.../ConsulComponentConfiguration.java | 333 +++++++++++++++++++
.../cloud/ConsulCloudAutoConfiguration.java | 105 ------
.../cloud/ConsulCloudConfiguration.java | 53 ---
...ConsulServiceDiscoveryAutoConfiguration.java | 106 ++++++
.../main/resources/META-INF/spring.factories | 2 +-
.../ConsulServiceDiscoveryDisabledTest.java | 64 ++++
.../ConsulServiceDiscoveryEnabledTest.java | 65 ++++
.../src/test/resources/logback.xml | 39 +++
...CallServiceDiscoveryConfigurationCommon.java | 150 +++++++++
...ServiceDiscoveryConfigurationProperties.java | 48 +++
...ystrixConfigurationDefinitionProperties.java | 2 +-
.../SpringBootAutoConfigurationMojo.java | 28 +-
21 files changed, 1091 insertions(+), 221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
index b30f871..bd7d27e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/ConsulServiceCallServiceDiscoveryConfiguration.java
@@ -32,7 +32,7 @@ public class ConsulServiceCallServiceDiscoveryConfiguration extends ServiceCallS
@XmlAttribute
private String url;
@XmlAttribute
- private String dc;
+ private String datacenter;
@XmlAttribute @Metadata(label = "security")
private String aclToken;
@XmlAttribute @Metadata(label = "security")
@@ -73,15 +73,33 @@ public class ConsulServiceCallServiceDiscoveryConfiguration extends ServiceCallS
this.url = url;
}
+ /**
+ * @deprecated replaced by {@link #getDatacenter()} ()}
+ */
+ @Deprecated
public String getDc() {
- return dc;
+ return datacenter;
}
/**
* The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
*/
+ @Deprecated
public void setDc(String dc) {
- this.dc = dc;
+ this.datacenter = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ /**
+ * The data center
+ */
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
}
public String getAclToken() {
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/docs/consul-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/docs/consul-component.adoc b/components/camel-consul/src/main/docs/consul-component.adoc
index 8c8823f..9d7080f 100644
--- a/components/camel-consul/src/main/docs/consul-component.adoc
+++ b/components/camel-consul/src/main/docs/consul-component.adoc
@@ -35,7 +35,22 @@ You can append query options to the URI in the following format:
// component options: START
-The Consul component has no options.
+The Consul component supports 8 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|=======================================================================
+| Name | Description | Default | Type
+| **url** (common) | The Consul agent URL | | String
+| **datacenter** (common) | The data center | | String
+| **sslContextParameters** (common) | SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters instance. | | SSLContextParameters
+| **aclToken** (common) | Sets the ACL token to be used with Consul | | String
+| **userName** (common) | Sets the username to be used for basic authentication | | String
+| **password** (common) | Sets the password to be used for basic authentication | | String
+| **configuration** (advanced) | Sets the common configuration shared among endpoints | | ConsulConfiguration
+| **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
@@ -64,7 +79,6 @@ with the following path and query parameters:
|=======================================================================
| Name | Description | Default | Type
| **connectTimeoutMillis** (common) | Connect timeout for OkHttpClient | | Long
-| **dc** (common) | The data center | | String
| **key** (common) | The default key. Can be overridden by CamelConsulKey | | String
| **pingInstance** (common) | Configure if the AgentClient should attempt a ping before returning the Consul instance | true | boolean
| **readTimeoutMillis** (common) | Read timeout for OkHttpClient | | Long
@@ -76,6 +90,7 @@ with the following path and query parameters:
| **exchangePattern** (consumer) | Sets the exchange pattern when the consumer creates an exchange. | | ExchangePattern
| **action** (producer) | The default action. Can be overridden by CamelConsulAction | | String
| **valueAsString** (producer) | Default to transform values retrieved from Consul i.e. on KV endpoint to string. | false | boolean
+| **datacenter** (advanced) | The data center | | String
| **synchronous** (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
| **blockSeconds** (watch) | The second to wait for a watch event default 10 seconds | 10 | Integer
| **firstIndex** (watch) | The first index for watch for default 0 | 0 | long
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
index 83887e3..ccacf8a 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulComponent.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.consul;
import java.util.Map;
+import java.util.Optional;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
@@ -25,53 +26,137 @@ import org.apache.camel.component.consul.enpoint.ConsulEventConsumer;
import org.apache.camel.component.consul.enpoint.ConsulEventProducer;
import org.apache.camel.component.consul.enpoint.ConsulKeyValueConsumer;
import org.apache.camel.component.consul.enpoint.ConsulKeyValueProducer;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.jsse.SSLContextParameters;
/**
* Represents the component that manages {@link ConsulEndpoint}.
*/
-public class ConsulComponent extends UriEndpointComponent {
+public class ConsulComponent extends DefaultComponent {
+
+ @Metadata(label = "advanced")
+ private ConsulConfiguration configuration = new ConsulConfiguration();
public ConsulComponent() {
- super(ConsulEndpoint.class);
+ super();
}
public ConsulComponent(CamelContext context) {
- super(context, ConsulEndpoint.class);
+ super(context);
+ }
+
+ // ************************************
+ // Options
+ // ************************************
+
+
+ public String getUrl() {
+ return this.configuration.getUrl();
+ }
+
+ /**
+ * The Consul agent URL
+ */
+ public void setUrl(String url) {
+ this.configuration.setUrl(url);
+ }
+
+ public String getDatacenter() {
+ return configuration.getDatacenter();
+ }
+
+ /**
+ * The data center
+ * @param datacenter
+ */
+ public void setDatacenter(String datacenter) {
+ configuration.setDatacenter(datacenter);
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return configuration.getSslContextParameters();
+ }
+
+ /**
+ * SSL configuration using an org.apache.camel.util.jsse.SSLContextParameters
+ * instance.
+ * @param sslContextParameters
+ */
+ public void setSslContextParameters(SSLContextParameters sslContextParameters) {
+ configuration.setSslContextParameters(sslContextParameters);
+ }
+
+ public String getAclToken() {
+ return configuration.getAclToken();
+ }
+
+ /**
+ * Sets the ACL token to be used with Consul
+ * @param aclToken
+ */
+ public void setAclToken(String aclToken) {
+ configuration.setAclToken(aclToken);
+ }
+
+ public String getUserName() {
+ return configuration.getUserName();
+ }
+
+ /**
+ * Sets the username to be used for basic authentication
+ * @param userName
+ */
+ public void setUserName(String userName) {
+ configuration.setUserName(userName);
+ }
+
+ public String getPassword() {
+ return configuration.getPassword();
+ }
+
+ /**
+ * Sets the password to be used for basic authentication
+ * @param password
+ */
+ public void setPassword(String password) {
+ configuration.setPassword(password);
}
+ public ConsulConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * Sets the common configuration shared among endpoints
+ */
+ public void setConfiguration(ConsulConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- return ConsulApiEndpoint.valueOf(remaining).create(
- remaining,
- uri,
- this,
- createConfiguration(parameters)
- );
- }
+ ConsulConfiguration configuration = Optional.ofNullable(this.configuration).orElseGet(ConsulConfiguration::new).copy();
+ configuration.setCamelContext(getCamelContext());
- private ConsulConfiguration createConfiguration(Map<String, Object> parameters) throws Exception {
- ConsulConfiguration configuration = new ConsulConfiguration(getCamelContext());
setProperties(configuration, parameters);
- return configuration;
+ return ConsulApiEndpoint.valueOf(remaining).create(remaining, uri, this, configuration);
}
- // *************************************************************************
// Consul Api Enpoints (see https://www.consul.io/docs/agent/http.html)
- // *************************************************************************
-
private enum ConsulApiEndpoint {
kv(ConsulKeyValueProducer::new, ConsulKeyValueConsumer::new),
event(ConsulEventProducer::new, ConsulEventConsumer::new),
agent(ConsulAgentProducer::new, null);
- private final ConsulEndpoint.ProducerFactory producerFactory;
- private final ConsulEndpoint.ConsumerFactory consumerFactory;
+ private final Optional<ConsulEndpoint.ProducerFactory> producerFactory;
+ private final Optional<ConsulEndpoint.ConsumerFactory> consumerFactory;
ConsulApiEndpoint(ConsulEndpoint.ProducerFactory producerFactory, ConsulEndpoint.ConsumerFactory consumerFactory) {
- this.producerFactory = producerFactory;
- this.consumerFactory = consumerFactory;
+ this.producerFactory = Optional.ofNullable(producerFactory);
+ this.consumerFactory = Optional.ofNullable(consumerFactory);
}
public Endpoint create(String apiEndpoint, String uri, ConsulComponent component, ConsulConfiguration configuration) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
index dbf1466..34fa757 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulConfiguration.java
@@ -22,17 +22,19 @@ import java.util.Set;
import com.orbitz.consul.Consul;
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.ObjectHelper;
import org.apache.camel.util.jsse.SSLContextParameters;
@UriParams
-public class ConsulConfiguration {
+public class ConsulConfiguration implements CamelContextAware, Cloneable {
@UriParam
private String url;
- @UriParam
- private String dc;
+ @UriParam(label = "advanced")
+ private String datacenter;
@UriParam(javaType = "java.lang.String")
private Set<String> tags;
@@ -68,7 +70,7 @@ public class ConsulConfiguration {
@UriParam(label = "consumer,watch", defaultValue = "false")
private boolean recursive;
- private final CamelContext context;
+ private CamelContext context;
public ConsulConfiguration() {
this.context = null;
@@ -78,8 +80,14 @@ public class ConsulConfiguration {
this.context = context;
}
- public CamelContext getContext() {
- return this.context;
+ @Override
+ public void setCamelContext(CamelContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return context;
}
public String getUrl() {
@@ -93,15 +101,33 @@ public class ConsulConfiguration {
this.url = url;
}
+ /**
+ * @deprecated replaced by {@link #getDatacenter()} ()}
+ */
+ @Deprecated
public String getDc() {
- return dc;
+ return datacenter;
}
/**
* The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
*/
+ @Deprecated
public void setDc(String dc) {
- this.dc = dc;
+ this.datacenter = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ /**
+ * The data center
+ */
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
}
public Set<String> getTags() {
@@ -311,4 +337,12 @@ public class ConsulConfiguration {
return builder.build();
}
+
+ public ConsulConfiguration copy() {
+ try {
+ return (ConsulConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
index b17177c..0399830 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulEndpoint.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.consul;
+import java.util.Optional;
+
import com.orbitz.consul.Consul;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
@@ -41,8 +43,8 @@ public class ConsulEndpoint extends DefaultEndpoint {
@Metadata(required = "true")
private final String apiEndpoint;
- private final ProducerFactory producerFactory;
- private final ConsumerFactory consumerFactory;
+ private final Optional<ProducerFactory> producerFactory;
+ private final Optional<ConsumerFactory> consumerFactory;
private Consul consul;
@@ -51,8 +53,8 @@ public class ConsulEndpoint extends DefaultEndpoint {
String uri,
ConsulComponent component,
ConsulConfiguration configuration,
- ProducerFactory producerFactory,
- ConsumerFactory consumerFactory) {
+ Optional<ProducerFactory> producerFactory,
+ Optional<ConsumerFactory> consumerFactory) {
super(uri, component);
@@ -69,20 +71,20 @@ public class ConsulEndpoint extends DefaultEndpoint {
@Override
public Producer createProducer() throws Exception {
- if (producerFactory == null) {
- throw new IllegalArgumentException("No producer for " + apiEndpoint);
- }
+ ProducerFactory factory = producerFactory.orElseThrow(
+ () -> new IllegalArgumentException("No producer for " + apiEndpoint)
+ );
- return producerFactory.create(this, configuration);
+ return factory.create(this, configuration);
}
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- if (consumerFactory == null) {
- throw new IllegalArgumentException("No consumer for " + apiEndpoint);
- }
+ ConsumerFactory factory = consumerFactory.orElseThrow(
+ () -> new IllegalArgumentException("No consumer for " + apiEndpoint)
+ );
- return consumerFactory.create(this, configuration, processor);
+ return factory.create(this, configuration, processor);
}
// *************************************************************************
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
index c09d211..fd3fe60 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
@@ -36,17 +36,15 @@ import org.apache.camel.impl.cloud.DefaultServiceHealth;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.function.Suppliers;
-;
-
public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
private final Supplier<Consul> client;
private final CatalogOptions catalogOptions;
public ConsulServiceDiscovery(ConsulConfiguration configuration) throws Exception {
- this.client = Suppliers.memorize(configuration::createConsulClient, e -> { throw new RuntimeCamelException(e); });
+ this.client = Suppliers.memorize(configuration::createConsulClient, this::rethrowAsRuntimeCamelException);
ImmutableCatalogOptions.Builder builder = ImmutableCatalogOptions.builder();
- ObjectHelper.ifNotEmpty(configuration.getDc(), builder::datacenter);
+ ObjectHelper.ifNotEmpty(configuration.getDatacenter(), builder::datacenter);
ObjectHelper.ifNotEmpty(configuration.getTags(), tags -> tags.forEach(builder::tag));
catalogOptions = builder.build();
@@ -70,6 +68,10 @@ public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
// Helpers
// *************************
+ private void rethrowAsRuntimeCamelException(Exception e) {
+ throw new RuntimeCamelException(e);
+ }
+
private boolean isHealthy(ServiceHealth serviceHealth) {
return serviceHealth.getChecks().stream().allMatch(
check -> ObjectHelper.equal(check.getStatus(), "passing", true)
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
index 04215ef..0c032af 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryFactory.java
@@ -45,14 +45,31 @@ public class ConsulServiceDiscoveryFactory implements ServiceDiscoveryFactory {
configuration.setUrl(url);
}
+ /**
+ * @deprecated, @deprecated replaced by {@link #getDatacenter()} ()}
+ * @return
+ */
+ @Deprecated
public String getDc() {
- return configuration.getDc();
+ return configuration.getDatacenter();
}
+ /**
+ * @deprecated, @deprecated replaced by {@link #setDatacenter(String)}} ()}
+ */
+ @Deprecated
public void setDc(String dc) {
configuration.setDc(dc);
}
+ public void setDatacenter(String dc) {
+ configuration.setDatacenter(dc);
+ }
+
+ public String getDatacenter() {
+ return configuration.getDatacenter();
+ }
+
public SSLContextParameters getSslContextParameters() {
return configuration.getSslContextParameters();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties b/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
index bfe3682..6684b24 100644
--- a/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-servicecall/consumer/src/main/resources/application.properties
@@ -13,4 +13,10 @@ camel.rest.binding-mode=auto
camel.cloud.service-filter.blacklist[service-1] = localhost:9012
# Configure additional services
-camel.cloud.service-discovery.services[service-2] = localhost:9021,localhost:9022,localhost:9023
\ No newline at end of file
+camel.cloud.service-discovery.services[service-2] = localhost:9021,localhost:9022,localhost:9023
+
+# Consul
+#
+# this property is not mandatory and it has been included to show how to configure
+# the service discovery implementation provided by camel-consul
+camel.cloud.consul.service-discovery.url=http://localhost:8500
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
index 1ddca31..cd7fbbf 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentAutoConfiguration.java
@@ -16,8 +16,11 @@
*/
package org.apache.camel.component.consul.springboot;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.component.consul.ConsulComponent;
+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(ConsulComponentAutoConfiguration.Condition.class)
@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@EnableConfigurationProperties(ConsulComponentConfiguration.class)
public class ConsulComponentAutoConfiguration {
@Lazy
@Bean(name = "consul-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ConsulComponent.class)
- public ConsulComponent configureConsulComponent(CamelContext camelContext)
- throws Exception {
+ public ConsulComponent configureConsulComponent(CamelContext camelContext,
+ ConsulComponentConfiguration configuration) throws Exception {
ConsulComponent component = new ConsulComponent();
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/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
index 19877ec..519a1b6 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
@@ -16,7 +16,12 @@
*/
package org.apache.camel.component.consul.springboot;
+import java.util.Set;
+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.DeprecatedConfigurationProperty;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* The camel consul component allows you to work with Consul a distributed
@@ -28,12 +33,100 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class ConsulComponentConfiguration {
/**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * SSL configuration using an
+ * org.apache.camel.util.jsse.SSLContextParameters instance.
+ */
+ @NestedConfigurationProperty
+ private SSLContextParameters sslContextParameters;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Sets the common configuration shared among endpoints
+ */
+ private ConsulConfigurationNestedConfiguration 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 getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return sslContextParameters;
+ }
+
+ public void setSslContextParameters(
+ SSLContextParameters sslContextParameters) {
+ this.sslContextParameters = sslContextParameters;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ 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 ConsulConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ ConsulConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
@@ -42,4 +135,244 @@ public class ConsulComponentConfiguration {
Boolean resolvePropertyPlaceholders) {
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
+
+ public static class ConsulConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.consul.ConsulConfiguration.class;
+ private CamelContext camelContext;
+ /**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ *
+ * @deprecated replaced by {@link #setDatacenter(String)} ()}
+ */
+ @Deprecated
+ private String dc;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * Set tags. You can separate multiple tags by comma.
+ */
+ private Set tags;
+ /**
+ * SSL configuration using an
+ * org.apache.camel.util.jsse.SSLContextParameters instance.
+ */
+ @NestedConfigurationProperty
+ private SSLContextParameters sslContextParameters;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * The default action. Can be overridden by CamelConsulAction
+ */
+ private String action;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Connect timeout for OkHttpClient
+ */
+ private Long connectTimeoutMillis;
+ /**
+ * Read timeout for OkHttpClient
+ */
+ private Long readTimeoutMillis;
+ /**
+ * Write timeout for OkHttpClient
+ */
+ private Long writeTimeoutMillis;
+ /**
+ * Configure if the AgentClient should attempt a ping before returning
+ * the Consul instance
+ */
+ private Boolean pingInstance = true;
+ /**
+ * Default to transform values retrieved from Consul i.e. on KV endpoint
+ * to string.
+ */
+ private Boolean valueAsString = false;
+ /**
+ * The default key. Can be overridden by CamelConsulKey
+ */
+ private String key;
+ /**
+ * The second to wait for a watch event, default 10 seconds
+ */
+ private Integer blockSeconds = 10;
+ /**
+ * The first index for watch for, default 0
+ */
+ private Long firstIndex = 0L;
+ /**
+ * Recursively watch, default false
+ */
+ private Boolean recursive = false;
+
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @Deprecated
+ @DeprecatedConfigurationProperty
+ public String getDc() {
+ return dc;
+ }
+
+ @Deprecated
+ public void setDc(String dc) {
+ this.dc = dc;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public Set getTags() {
+ return tags;
+ }
+
+ public void setTags(Set tags) {
+ this.tags = tags;
+ }
+
+ public SSLContextParameters getSslContextParameters() {
+ return sslContextParameters;
+ }
+
+ public void setSslContextParameters(
+ SSLContextParameters sslContextParameters) {
+ this.sslContextParameters = sslContextParameters;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ 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 getConnectTimeoutMillis() {
+ return connectTimeoutMillis;
+ }
+
+ public void setConnectTimeoutMillis(Long connectTimeoutMillis) {
+ this.connectTimeoutMillis = connectTimeoutMillis;
+ }
+
+ public Long getReadTimeoutMillis() {
+ return readTimeoutMillis;
+ }
+
+ public void setReadTimeoutMillis(Long readTimeoutMillis) {
+ this.readTimeoutMillis = readTimeoutMillis;
+ }
+
+ public Long getWriteTimeoutMillis() {
+ return writeTimeoutMillis;
+ }
+
+ public void setWriteTimeoutMillis(Long writeTimeoutMillis) {
+ this.writeTimeoutMillis = writeTimeoutMillis;
+ }
+
+ public Boolean getPingInstance() {
+ return pingInstance;
+ }
+
+ public void setPingInstance(Boolean pingInstance) {
+ this.pingInstance = pingInstance;
+ }
+
+ public Boolean getValueAsString() {
+ return valueAsString;
+ }
+
+ public void setValueAsString(Boolean valueAsString) {
+ this.valueAsString = valueAsString;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Integer getBlockSeconds() {
+ return blockSeconds;
+ }
+
+ public void setBlockSeconds(Integer blockSeconds) {
+ this.blockSeconds = blockSeconds;
+ }
+
+ public Long getFirstIndex() {
+ return firstIndex;
+ }
+
+ public void setFirstIndex(Long firstIndex) {
+ this.firstIndex = firstIndex;
+ }
+
+ public Boolean getRecursive() {
+ return recursive;
+ }
+
+ public void setRecursive(Boolean recursive) {
+ this.recursive = recursive;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
deleted file mode 100644
index 22fb21a..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudAutoConfiguration.java
+++ /dev/null
@@ -1,105 +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.consul.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.consul.ConsulConfiguration;
-import org.apache.camel.component.consul.cloud.ConsulServiceDiscoveryFactory;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.util.IntrospectionSupport;
-import org.springframework.beans.factory.BeanCreationException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-@Configuration
-@ConditionalOnBean({ CamelAutoConfiguration.class, CamelContext.class })
-@Conditional(ConsulCloudAutoConfiguration.Condition.class)
-@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties(ConsulCloudConfiguration.class)
-public class ConsulCloudAutoConfiguration {
- @Autowired
- private CamelContext camelContext;
- @Autowired
- private ConsulCloudConfiguration configuration;
- @Autowired
- private ConfigurableBeanFactory beanFactory;
-
- @Lazy
- @Bean(name = "consul-service-discovery")
- public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
- ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
-
- IntrospectionSupport.setProperties(
- camelContext,
- camelContext.getTypeConverter(),
- factory,
- IntrospectionSupport.getNonNullProperties(configuration));
-
- return factory.newInstance(camelContext);
- }
-
- @PostConstruct
- public void postConstruct() {
- if (beanFactory != null) {
- ConsulCloudConfiguration.ServiceDiscoveryConfiguration discovery = configuration.getServiceDiscovery();
- Map<String, Object> parameters = new HashMap<>();
-
- for (Map.Entry<String, ConsulConfiguration> entry : discovery.getConfigurations().entrySet()) {
- // clean up params
- parameters.clear();
-
- // The instance factory
- ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
-
- try {
- IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
- IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
-
- beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
- } catch (Exception e) {
- throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
- }
- }
- }
- }
-
- // *******************************
- // Condition
- // *******************************
-
- public static class Condition extends GroupCondition {
- public Condition() {
- super(
- "camel.cloud",
- "camel.cloud.consul"
- );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
deleted file mode 100644
index da94b19..0000000
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulCloudConfiguration.java
+++ /dev/null
@@ -1,53 +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.consul.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.component.consul.ConsulConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.consul")
-public class ConsulCloudConfiguration {
- 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 ConsulConfiguration {
- private final Map<String, ConsulConfiguration> configurations = new HashMap<>();
-
- public Map<String, ConsulConfiguration> getConfigurations() {
- return configurations;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
new file mode 100644
index 0000000..ec4e9d3
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryAutoConfiguration.java
@@ -0,0 +1,106 @@
+/**
+ * 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.consul.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.consul.cloud.ConsulServiceDiscoveryFactory;
+import org.apache.camel.component.consul.springboot.ConsulComponentConfiguration;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationCommon;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.util.IntrospectionSupport;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+@Configuration
+@ConditionalOnBean({ CamelAutoConfiguration.class, CamelContext.class })
+@Conditional(ConsulServiceDiscoveryAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(ConsulServiceCallServiceDiscoveryConfigurationProperties.class)
+public class ConsulServiceDiscoveryAutoConfiguration {
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private ConsulServiceCallServiceDiscoveryConfigurationProperties configuration;
+ @Autowired
+ private ConfigurableBeanFactory beanFactory;
+
+ @Lazy
+ @Bean(name = "consul-service-discovery")
+ public ServiceDiscovery configureServiceDiscoveryFactory() throws Exception {
+ ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
+
+ IntrospectionSupport.setProperties(
+ camelContext,
+ camelContext.getTypeConverter(),
+ factory,
+ IntrospectionSupport.getNonNullProperties(configuration));
+
+ return factory.newInstance(camelContext);
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ if (beanFactory != null) {
+ Map<String, Object> parameters = new HashMap<>();
+
+ for (Map.Entry<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
+ // clean up params
+ parameters.clear();
+
+ // The instance factory
+ ConsulServiceDiscoveryFactory factory = new ConsulServiceDiscoveryFactory();
+
+ try {
+ IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
+ IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters);
+
+ beanFactory.registerSingleton(entry.getKey(), factory.newInstance(camelContext));
+ } catch (Exception e) {
+ throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ // *******************************
+ // Condition
+ // *******************************
+
+ public static class Condition extends GroupCondition {
+ public Condition() {
+ super(
+ "camel.cloud.consul",
+ "camel.cloud.consul.service-discovery"
+ );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
index 4517ac3..fcc6bf8 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/resources/META-INF/spring.factories
@@ -17,4 +17,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.camel.component.consul.springboot.ConsulComponentAutoConfiguration,\
-org.apache.camel.component.consul.springboot.cloud.ConsulCloudAutoConfiguration
+org.apache.camel.component.consul.springboot.cloud.ConsulServiceDiscoveryAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.java
new file mode 100644
index 0000000..01cc252
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryDisabledTest.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.consul.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.consul.service-discovery.enabled=false"
+})
+public class ConsulServiceDiscoveryDisabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertTrue(beans.isEmpty());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertFalse(beans.containsKey("consul-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.java
new file mode 100644
index 0000000..cedfde5
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceDiscoveryEnabledTest.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.consul.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.ConsulServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ ConsulServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.consul.service-discovery.enabled=true"
+})
+public class ConsulServiceDiscoveryEnabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(ConsulServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertEquals(1, beans.size());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertTrue(beans.containsKey("consul-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/resources/logback.xml
new file mode 100644
index 0000000..93d5a0c
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-consul-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-consul-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/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
new file mode 100644
index 0000000..23df276
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
@@ -0,0 +1,150 @@
+/**
+ * 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 ConsulServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * The Consul agent URL
+ */
+ private String url;
+ /**
+ * The data center
+ */
+ private String datacenter;
+ /**
+ * Sets the ACL token to be used with Consul
+ */
+ private String aclToken;
+ /**
+ * Sets the username to be used for basic authentication
+ */
+ private String userName;
+ /**
+ * Sets the password to be used for basic authentication
+ */
+ private String password;
+ /**
+ * Connect timeout for OkHttpClient
+ */
+ private Long connectTimeoutMillis;
+ /**
+ * Read timeout for OkHttpClient
+ */
+ private Long readTimeoutMillis;
+ /**
+ * Write timeout for OkHttpClient
+ */
+ private Long writeTimeoutMillis;
+ /**
+ * The seconds to wait for a watch event default 10 seconds
+ */
+ private Integer blockSeconds = 10;
+ /**
+ * 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 getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getDatacenter() {
+ return datacenter;
+ }
+
+ public void setDatacenter(String datacenter) {
+ this.datacenter = datacenter;
+ }
+
+ public String getAclToken() {
+ return aclToken;
+ }
+
+ public void setAclToken(String aclToken) {
+ this.aclToken = aclToken;
+ }
+
+ 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 getConnectTimeoutMillis() {
+ return connectTimeoutMillis;
+ }
+
+ public void setConnectTimeoutMillis(Long connectTimeoutMillis) {
+ this.connectTimeoutMillis = connectTimeoutMillis;
+ }
+
+ public Long getReadTimeoutMillis() {
+ return readTimeoutMillis;
+ }
+
+ public void setReadTimeoutMillis(Long readTimeoutMillis) {
+ this.readTimeoutMillis = readTimeoutMillis;
+ }
+
+ public Long getWriteTimeoutMillis() {
+ return writeTimeoutMillis;
+ }
+
+ public void setWriteTimeoutMillis(Long writeTimeoutMillis) {
+ this.writeTimeoutMillis = writeTimeoutMillis;
+ }
+
+ public Integer getBlockSeconds() {
+ return blockSeconds;
+ }
+
+ public void setBlockSeconds(Integer blockSeconds) {
+ this.blockSeconds = blockSeconds;
+ }
+
+ 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/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.java
new file mode 100644
index 0000000..57d2588
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationProperties.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.consul.service-discovery")
+public class ConsulServiceCallServiceDiscoveryConfigurationProperties
+ extends
+ ConsulServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * Enable the component
+ */
+ private boolean enabled = true;
+ /**
+ * Define additional configuration definitions
+ */
+ private Map<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> configurations = new HashMap<>();
+
+ public Map<String, ConsulServiceCallServiceDiscoveryConfigurationCommon> 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/6f4fdf9e/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
index 0daa611..5cf7c99 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/springboot/HystrixConfigurationDefinitionProperties.java
@@ -26,7 +26,7 @@ public class HystrixConfigurationDefinitionProperties
HystrixConfigurationDefinitionCommon {
/**
- * Enable camel-hystrix
+ * Enable the component
*/
private boolean enabled = true;
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/6f4fdf9e/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 0ffa9a4..7b96fb0 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
@@ -196,8 +196,10 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
private void executeModels() throws MojoExecutionException, MojoFailureException {
final Set<File> files = PackageHelper.findJsonFiles(buildDir, p -> p.isDirectory() || p.getName().endsWith(".json"));
+ String json;
+
// Hystrix
- final String json = loadModelJson(files, "hystrixConfiguration");
+ json = loadModelJson(files, "hystrixConfiguration");
if (json != null) {
OtherModel model = generateOtherModel(json);
@@ -205,11 +207,23 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration happens in camel-hystrix-starter
- createHystrixConfigurationSource(pkg, model);
+ createHystrixConfigurationSource(pkg, model, "camel.hystrix");
+ }
+
+ // Consul
+ json = loadModelJson(files, "consulServiceDiscovery");
+ 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-consul-starter
+ createHystrixConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery");
}
}
- private void createHystrixConfigurationSource(String packageName, OtherModel model) throws MojoFailureException {
+ private void createHystrixConfigurationSource(String packageName, OtherModel model, String propertiesPrefix) throws MojoFailureException {
final int pos = model.getJavaType().lastIndexOf(".");
final String commonName = model.getJavaType().substring(pos + 1) + "Common";
final String configName = model.getJavaType().substring(pos + 1) + "Properties";
@@ -229,8 +243,8 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
String type = option.getJavaType();
String name = option.getName();
- if ("id".equalsIgnoreCase(name) || "parent".equalsIgnoreCase(name)) {
- // Skip it as it should not be set via spring boot
+ if ("id".equalsIgnoreCase(name) || "parent".equalsIgnoreCase(name) || "camelContext".equalsIgnoreCase(name)) {
+ // Skip them as they should not be set via spring boot
continue;
}
@@ -261,7 +275,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
configClass.setPackage(packageName);
configClass.setName(configName);
configClass.extendSuperType(commonClass);
- configClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", "camel.hystrix");
+ configClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", propertiesPrefix);
configClass.addImport(Map.class);
configClass.addImport(HashMap.class);
configClass.removeImport(commonClass);
@@ -271,7 +285,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
.setType(boolean.class)
.setPrivate()
.setLiteralInitializer("true")
- .getJavaDoc().setFullText("Enable camel-hystrix");
+ .getJavaDoc().setFullText("Enable the component");
configClass.addField("Map<String, " + commonName + "> configurations = new HashMap<>()")
.setPrivate()
.getJavaDoc().setFullText("Define additional configuration definitions");
[5/5] camel git commit: Translate List to
Map in spring-boot configuration classes
Posted by lb...@apache.org.
Translate List<PropertyDefinition> to Map<String, String> in spring-boot configuration classes
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/365ac51a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/365ac51a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/365ac51a
Branch: refs/heads/master
Commit: 365ac51a0289c6c9758a83b2074c88b3574d5fb9
Parents: 9bab0d0
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 28 17:06:11 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 28 17:06:48 2017 +0200
----------------------------------------------------------------------
...onsulServiceCallServiceDiscoveryConfigurationCommon.java | 9 ++++-----
.../DnsServiceCallServiceDiscoveryConfigurationCommon.java | 9 ++++-----
.../EtcdServiceCallServiceDiscoveryConfigurationCommon.java | 9 ++++-----
...netesServiceCallServiceDiscoveryConfigurationCommon.java | 9 ++++-----
.../maven/packaging/SpringBootAutoConfigurationMojo.java | 8 ++++++--
5 files changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/365ac51a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
index 23df276..cc8ae52 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/ConsulServiceCallServiceDiscoveryConfigurationCommon.java
@@ -16,8 +16,7 @@
*/
package org.apache.camel.model.cloud.springboot;
-import java.util.List;
-import org.apache.camel.model.PropertyDefinition;
+import java.util.Map;
/**
* Generated by camel-package-maven-plugin - do not edit this file!
@@ -66,7 +65,7 @@ public class ConsulServiceCallServiceDiscoveryConfigurationCommon {
* the client properties are define in
* com.netflix.client.config.CommonClientConfigKey.
*/
- private List<PropertyDefinition> properties;
+ private Map<String, String> properties;
public String getUrl() {
return url;
@@ -140,11 +139,11 @@ public class ConsulServiceCallServiceDiscoveryConfigurationCommon {
this.blockSeconds = blockSeconds;
}
- public List<PropertyDefinition> getProperties() {
+ public Map<String, String> getProperties() {
return properties;
}
- public void setProperties(List<PropertyDefinition> properties) {
+ public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/365ac51a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
index 8515557..42fe393 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/DnsServiceCallServiceDiscoveryConfigurationCommon.java
@@ -16,8 +16,7 @@
*/
package org.apache.camel.model.cloud.springboot;
-import java.util.List;
-import org.apache.camel.model.PropertyDefinition;
+import java.util.Map;
/**
* Generated by camel-package-maven-plugin - do not edit this file!
@@ -38,7 +37,7 @@ public class DnsServiceCallServiceDiscoveryConfigurationCommon {
* the client properties are define in
* com.netflix.client.config.CommonClientConfigKey.
*/
- private List<PropertyDefinition> properties;
+ private Map<String, String> properties;
public String getProto() {
return proto;
@@ -56,11 +55,11 @@ public class DnsServiceCallServiceDiscoveryConfigurationCommon {
this.domain = domain;
}
- public List<PropertyDefinition> getProperties() {
+ public Map<String, String> getProperties() {
return properties;
}
- public void setProperties(List<PropertyDefinition> properties) {
+ public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/365ac51a/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
index e79f102..0109284 100644
--- 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
@@ -16,8 +16,7 @@
*/
package org.apache.camel.model.cloud.springboot;
-import java.util.List;
-import org.apache.camel.model.PropertyDefinition;
+import java.util.Map;
/**
* Generated by camel-package-maven-plugin - do not edit this file!
@@ -54,7 +53,7 @@ public class EtcdServiceCallServiceDiscoveryConfigurationCommon {
* the client properties are define in
* com.netflix.client.config.CommonClientConfigKey.
*/
- private List<PropertyDefinition> properties;
+ private Map<String, String> properties;
public String getUris() {
return uris;
@@ -104,11 +103,11 @@ public class EtcdServiceCallServiceDiscoveryConfigurationCommon {
this.type = type;
}
- public List<PropertyDefinition> getProperties() {
+ public Map<String, String> getProperties() {
return properties;
}
- public void setProperties(List<PropertyDefinition> properties) {
+ public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/365ac51a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
index 9763c5b..5ffac09 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
@@ -16,8 +16,7 @@
*/
package org.apache.camel.model.cloud.springboot;
-import java.util.List;
-import org.apache.camel.model.PropertyDefinition;
+import java.util.Map;
/**
* Generated by camel-package-maven-plugin - do not edit this file!
@@ -108,7 +107,7 @@ public class KubernetesServiceCallServiceDiscoveryConfigurationCommon {
* the client properties are define in
* com.netflix.client.config.CommonClientConfigKey.
*/
- private List<PropertyDefinition> properties;
+ private Map<String, String> properties;
public String getLookup() {
return lookup;
@@ -246,11 +245,11 @@ public class KubernetesServiceCallServiceDiscoveryConfigurationCommon {
this.trustCerts = trustCerts;
}
- public List<PropertyDefinition> getProperties() {
+ public Map<String, String> getProperties() {
return properties;
}
- public void setProperties(List<PropertyDefinition> properties) {
+ public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/365ac51a/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 76c1057..4af0892 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
@@ -284,15 +284,19 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
continue;
}
+ if ("java.util.List<org.apache.camel.model.PropertyDefinition>".equalsIgnoreCase(type)) {
+ type = "java.util.Map<java.lang.String, java.lang.String>";
+ }
+
// generate inner class for non-primitive options
PropertySource<JavaClassSource> prop = commonClass.addProperty(type, option.getName());
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
- if ("java.lang.String".equals(option.getJavaType())) {
+ if ("java.lang.String".equals(type)) {
prop.getField().setStringInitializer(option.getDefaultValue());
- } else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) {
+ } else if ("long".equals(type) || "java.lang.Long".equals(type)) {
// the value should be a Long number
String value = option.getDefaultValue() + "L";
prop.getField().setLiteralInitializer(value);
[4/5] camel git commit: CAMEL-11085: camel-kubernetes : make it easy
to configure components and service-discovery in spring-boot
Posted by lb...@apache.org.
CAMEL-11085: camel-kubernetes : 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/9bab0d08
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9bab0d08
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9bab0d08
Branch: refs/heads/master
Commit: 9bab0d088c4930c1e2aec58745e59f56d9df8d61
Parents: 46dc46b
Author: lburgazzoli <lb...@gmail.com>
Authored: Tue Mar 28 16:46:30 2017 +0200
Committer: lburgazzoli <lb...@gmail.com>
Committed: Tue Mar 28 17:06:48 2017 +0200
----------------------------------------------------------------------
...CallServiceDiscoveryConfigurationCommon.java | 256 +++++++++++++++++++
...ServiceDiscoveryConfigurationProperties.java | 48 ++++
.../cloud/KubernetesCloudAutoConfiguration.java | 15 +-
.../cloud/KubernetesCloudConfiguration.java | 62 -----
.../KubernetesServiceDiscoveryDisabledTest.java | 64 +++++
.../KubernetesServiceDiscoveryEnabledTest.java | 65 +++++
.../src/test/resources/logback.xml | 39 +++
.../SpringBootAutoConfigurationMojo.java | 14 +-
8 files changed, 492 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9bab0d08/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
new file mode 100644
index 0000000..9763c5b
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationCommon.java
@@ -0,0 +1,256 @@
+/**
+ * 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 KubernetesServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * How to perform service lookup. Possible values: client dns environment.
+ * When using client then the client queries the kubernetes master to obtain
+ * a list of active pods that provides the service and then random (or round
+ * robin) select a pod. When using dns the service name is resolved as
+ * name.namespace.service.dnsDomain. When using environment then environment
+ * variables are used to lookup the service. By default environment is used.
+ */
+ private String lookup = "environment";
+ /**
+ * Sets the DNS domain to use for DNS lookup.
+ */
+ private String dnsDomain;
+ /**
+ * Sets the namespace to use. Will by default use namespace from the ENV
+ * variable KUBERNETES_MASTER.
+ */
+ private String namespace;
+ /**
+ * Sets the API version when using client lookup
+ */
+ private String apiVersion;
+ /**
+ * Sets the URL to the master when using client lookup
+ */
+ private String masterUrl;
+ /**
+ * Sets the username for authentication when using client lookup
+ */
+ private String username;
+ /**
+ * Sets the password for authentication when using client lookup
+ */
+ private String password;
+ /**
+ * Sets the OAUTH token for authentication (instead of username/password)
+ * when using client lookup
+ */
+ private String oauthToken;
+ /**
+ * Sets the Certificate Authority data when using client lookup
+ */
+ private String caCertData;
+ /**
+ * Sets the Certificate Authority data that are loaded from the file when
+ * using client lookup
+ */
+ private String caCertFile;
+ /**
+ * Sets the Client Certificate data when using client lookup
+ */
+ private String clientCertData;
+ /**
+ * Sets the Client Certificate data that are loaded from the file when using
+ * client lookup
+ */
+ private String clientCertFile;
+ /**
+ * Sets the Client Keystore algorithm such as RSA when using client lookup
+ */
+ private String clientKeyAlgo;
+ /**
+ * Sets the Client Keystore data when using client lookup
+ */
+ private String clientKeyData;
+ /**
+ * Sets the Client Keystore data that are loaded from the file when using
+ * client lookup
+ */
+ private String clientKeyFile;
+ /**
+ * Sets the Client Keystore passphrase when using client lookup
+ */
+ private String clientKeyPassphrase;
+ /**
+ * Sets whether to turn on trust certificate check when using client lookup
+ */
+ private Boolean trustCerts = false;
+ /**
+ * 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 getLookup() {
+ return lookup;
+ }
+
+ public void setLookup(String lookup) {
+ this.lookup = lookup;
+ }
+
+ public String getDnsDomain() {
+ return dnsDomain;
+ }
+
+ public void setDnsDomain(String dnsDomain) {
+ this.dnsDomain = dnsDomain;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public String getApiVersion() {
+ return apiVersion;
+ }
+
+ public void setApiVersion(String apiVersion) {
+ this.apiVersion = apiVersion;
+ }
+
+ public String getMasterUrl() {
+ return masterUrl;
+ }
+
+ public void setMasterUrl(String masterUrl) {
+ this.masterUrl = masterUrl;
+ }
+
+ 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 String getOauthToken() {
+ return oauthToken;
+ }
+
+ public void setOauthToken(String oauthToken) {
+ this.oauthToken = oauthToken;
+ }
+
+ public String getCaCertData() {
+ return caCertData;
+ }
+
+ public void setCaCertData(String caCertData) {
+ this.caCertData = caCertData;
+ }
+
+ public String getCaCertFile() {
+ return caCertFile;
+ }
+
+ public void setCaCertFile(String caCertFile) {
+ this.caCertFile = caCertFile;
+ }
+
+ public String getClientCertData() {
+ return clientCertData;
+ }
+
+ public void setClientCertData(String clientCertData) {
+ this.clientCertData = clientCertData;
+ }
+
+ public String getClientCertFile() {
+ return clientCertFile;
+ }
+
+ public void setClientCertFile(String clientCertFile) {
+ this.clientCertFile = clientCertFile;
+ }
+
+ public String getClientKeyAlgo() {
+ return clientKeyAlgo;
+ }
+
+ public void setClientKeyAlgo(String clientKeyAlgo) {
+ this.clientKeyAlgo = clientKeyAlgo;
+ }
+
+ public String getClientKeyData() {
+ return clientKeyData;
+ }
+
+ public void setClientKeyData(String clientKeyData) {
+ this.clientKeyData = clientKeyData;
+ }
+
+ public String getClientKeyFile() {
+ return clientKeyFile;
+ }
+
+ public void setClientKeyFile(String clientKeyFile) {
+ this.clientKeyFile = clientKeyFile;
+ }
+
+ public String getClientKeyPassphrase() {
+ return clientKeyPassphrase;
+ }
+
+ public void setClientKeyPassphrase(String clientKeyPassphrase) {
+ this.clientKeyPassphrase = clientKeyPassphrase;
+ }
+
+ public Boolean getTrustCerts() {
+ return trustCerts;
+ }
+
+ public void setTrustCerts(Boolean trustCerts) {
+ this.trustCerts = trustCerts;
+ }
+
+ 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/9bab0d08/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationProperties.java b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationProperties.java
new file mode 100644
index 0000000..4807d33
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/cloud/springboot/KubernetesServiceCallServiceDiscoveryConfigurationProperties.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.kubernetes.service-discovery")
+public class KubernetesServiceCallServiceDiscoveryConfigurationProperties
+ extends
+ KubernetesServiceCallServiceDiscoveryConfigurationCommon {
+
+ /**
+ * Enable the component
+ */
+ private boolean enabled = true;
+ /**
+ * Define additional configuration definitions
+ */
+ private Map<String, KubernetesServiceCallServiceDiscoveryConfigurationCommon> configurations = new HashMap<>();
+
+ public Map<String, KubernetesServiceCallServiceDiscoveryConfigurationCommon> 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/9bab0d08/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
index b3ced3e..0124e32 100644
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java
@@ -18,13 +18,13 @@ package org.apache.camel.component.kubernetes.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.kubernetes.KubernetesConfiguration;
import org.apache.camel.component.kubernetes.cloud.KubernetesServiceDiscoveryFactory;
+import org.apache.camel.model.cloud.springboot.KubernetesServiceCallServiceDiscoveryConfigurationCommon;
+import org.apache.camel.model.cloud.springboot.KubernetesServiceCallServiceDiscoveryConfigurationProperties;
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(KubernetesCloudAutoConfiguration.Condition.class)
@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties(KubernetesCloudConfiguration.class)
+@EnableConfigurationProperties(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class)
public class KubernetesCloudAutoConfiguration {
@Autowired
private CamelContext camelContext;
@Autowired
- private KubernetesCloudConfiguration configuration;
+ private KubernetesServiceCallServiceDiscoveryConfigurationProperties configuration;
@Autowired
private ConfigurableBeanFactory beanFactory;
@@ -71,10 +71,9 @@ public class KubernetesCloudAutoConfiguration {
@PostConstruct
public void postConstruct() {
if (beanFactory != null) {
- KubernetesCloudConfiguration.ServiceDiscoveryConfiguration discovery = configuration.getServiceDiscovery();
Map<String, Object> parameters = new HashMap<>();
- for (Map.Entry<String, KubernetesConfiguration> entry : discovery.getConfigurations().entrySet()) {
+ for (Map.Entry<String, KubernetesServiceCallServiceDiscoveryConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
// clean up params
parameters.clear();
@@ -100,8 +99,8 @@ public class KubernetesCloudAutoConfiguration {
public static class Condition extends GroupCondition {
public Condition() {
super(
- "camel.cloud",
- "camel.cloud.kubernetes"
+ "camel.cloud.kubernetes",
+ "camel.cloud.kubernetes.service-discovery"
);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9bab0d08/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
deleted file mode 100644
index 832b0e7..0000000
--- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java
+++ /dev/null
@@ -1,62 +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.kubernetes.springboot.cloud;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.component.kubernetes.KubernetesConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.cloud.kubernetes")
-public class KubernetesCloudConfiguration {
- 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 KubernetesConfiguration {
- private final Map<String, KubernetesConfiguration> configurations = new HashMap<>();
- private String lookup;
-
- public String getLookup() {
- return lookup;
- }
-
- public void setLookup(String lookup) {
- this.lookup = lookup;
- }
-
- public Map<String, KubernetesConfiguration> getConfigurations() {
- return configurations;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/9bab0d08/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryDisabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryDisabledTest.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryDisabledTest.java
new file mode 100644
index 0000000..79f7a84
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryDisabledTest.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.kubernetes.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.KubernetesServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ KubernetesServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.kubernetes.service-discovery.enabled=false"
+})
+public class KubernetesServiceDiscoveryDisabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertTrue(beans.isEmpty());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertFalse(beans.containsKey("kubernetes-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9bab0d08/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryEnabledTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryEnabledTest.java b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryEnabledTest.java
new file mode 100644
index 0000000..19e4c80
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesServiceDiscoveryEnabledTest.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.kubernetes.springboot.cloud;
+
+import java.util.Map;
+
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.model.cloud.springboot.KubernetesServiceCallServiceDiscoveryConfigurationProperties;
+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 = {
+ KubernetesServiceDiscoveryEnabledTest.TestConfiguration.class
+ },
+ properties = {
+ "debug=false",
+ "camel.cloud.kubernetes.service-discovery.enabled=true"
+})
+public class KubernetesServiceDiscoveryEnabledTest {
+ @Autowired
+ ApplicationContext context;
+
+ @Test
+ public void testConfiguration() throws Exception {
+ Map<String, ?> beans;
+
+ beans = context.getBeansOfType(KubernetesServiceCallServiceDiscoveryConfigurationProperties.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertEquals(1, beans.size());
+
+ beans = context.getBeansOfType(ServiceDiscovery.class);
+ Assert.assertFalse(beans.isEmpty());
+ Assert.assertTrue(beans.containsKey("kubernetes-service-discovery"));
+ }
+
+ @Configuration
+ public static class TestConfiguration {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9bab0d08/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/resources/logback.xml b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/test/resources/logback.xml
new file mode 100644
index 0000000..a6fb347
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-kubernetes-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-kubernetes-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/9bab0d08/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 e31d1ba..76c1057 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
@@ -230,7 +230,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
- // Generate properties, auto-configuration happens in camel-consul-starter
+ // Generate properties, auto-configuration happens in camel-dns-starter
createOtherModelConfigurationSource(pkg, model, "camel.cloud.dns.service-discovery");
}
@@ -245,6 +245,18 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
// Generate properties, auto-configuration happens in camel-etcd-starter
createOtherModelConfigurationSource(pkg, model, "camel.cloud.etcd.service-discovery");
}
+
+ // Kubernetes
+ json = loadModelJson(files, "kubernetesServiceDiscovery");
+ 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-kubernetes-starter
+ createOtherModelConfigurationSource(pkg, model, "camel.cloud.kubernetes.service-discovery");
+ }
}
private void createOtherModelConfigurationSource(String packageName, OtherModel model, String propertiesPrefix) throws MojoFailureException {
[2/5] camel git commit: CAMEL-11083: camel-etcd : make it easy to
configure components and service-discovery in spring-boot
Posted by lb...@apache.org.
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 <lb...@gmail.com>
Authored: Tue Mar 28 16:15:06 2017 +0200
Committer: lburgazzoli <lb...@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 {