This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5cc6a823989491dec65f5b7cd4d9b712ec5d49f8 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Tue May 29 16:48:19 2018 +0200 service registry --- .../cloud/ConsulServiceDiscoveryDisabledTest.java | 64 ++++++++++++++++++ .../cloud/ConsulServiceDiscoveryEnabledTest.java | 65 ++++++++++++++++++ .../camel-zookeeper-starter/pom.xml | 7 -- .../ZooKeeperClusterServiceAutoConfiguration.java | 53 +++++++++++++++ .../ZooKeeperClusterServiceConfiguration.java | 77 ++++++++++++++++++++++ .../src/main/resources/META-INF/spring.factories | 5 +- 6 files changed, 261 insertions(+), 10 deletions(-) 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 { + } +} 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 { + } +} diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml b/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml index f6996a0..7c274d2 100644 --- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml +++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml @@ -39,13 +39,6 @@ <artifactId>camel-zookeeper</artifactId> <version>${project.version}</version> </dependency> - <!-- testing --> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-jetty</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> <!--START OF GENERATED CODE--> <dependency> <groupId>org.apache.camel</groupId> diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java new file mode 100644 index 0000000..c34d82e --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java @@ -0,0 +1,53 @@ +/** + * 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.zookeeper.cluster.springboot; + +import org.apache.camel.cluster.CamelClusterService; +import org.apache.camel.component.zookeeper.cluster.ZooKeeperClusterService; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration; +import org.apache.camel.util.IntrospectionSupport; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +@Configuration +@AutoConfigureBefore({ ClusteredRouteControllerAutoConfiguration.class, CamelAutoConfiguration.class }) +@ConditionalOnProperty(prefix = "camel.component.zookeeper.cluster.service", name = "enabled") +@EnableConfigurationProperties(ZooKeeperClusterServiceConfiguration.class) +public class ZooKeeperClusterServiceAutoConfiguration { + @Autowired + private ZooKeeperClusterServiceConfiguration configuration; + + @Bean(name = "zookeeper-cluster-service") + @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) + public CamelClusterService zookeeperClusterService() throws Exception { + ZooKeeperClusterService service = new ZooKeeperClusterService(); + + IntrospectionSupport.setProperties( + service, + IntrospectionSupport.getNonNullProperties(configuration) + ); + + return service; + } +} diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java new file mode 100644 index 0000000..1feb5af --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java @@ -0,0 +1,77 @@ +/** + * 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.zookeeper.cluster.springboot; + +import java.util.Map; + +import org.apache.camel.component.zookeeper.ZooKeeperCuratorConfiguration; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "camel.component.zookeeper.cluster.service") +public class ZooKeeperClusterServiceConfiguration extends ZooKeeperCuratorConfiguration { + /** + * Sets if the zookeeper cluster service should be enabled or not, default is false. + */ + private boolean enabled; + + /** + * Cluster Service ID + */ + private String id; + + /** + * Custom service attributes. + */ + private Map<String, Object> attributes; + + /** + * Service lookup order/priority. + */ + private Integer order; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Map<String, Object> getAttributes() { + return attributes; + } + + public void setAttributes(Map<String, Object> attributes) { + this.attributes = attributes; + } + + public Integer getOrder() { + return order; + } + + public void setOrder(Integer order) { + this.order = order; + } +} diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/resources/META-INF/spring.factories index 383172c..f3a7b4b 100644 --- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/resources/META-INF/spring.factories @@ -15,6 +15,5 @@ ## limitations under the License. ## --------------------------------------------------------------------------- org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - org.apache.camel.component.zookeeper.springboot.ZooKeeperComponentAutoConfiguration,\ - org.apache.camel.component.zookeeper.springboot.cloud.ZooKeeperServiceRegistryAutoConfiguration,\ - org.apache.camel.component.zookeeper.springboot.cluster.ZooKeeperClusterServiceAutoConfiguration +org.apache.camel.component.zookeeper.springboot.ZooKeeperComponentAutoConfiguration,\ +org.apache.camel.component.zookeeper.cluster.springboot.ZooKeeperClusterServiceAutoConfiguration -- To stop receiving notification emails like this one, please contact lburgazz...@apache.org.