Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7AD66200C22 for ; Tue, 21 Feb 2017 12:17:52 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 79734160B74; Tue, 21 Feb 2017 11:17:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 530F2160B3E for ; Tue, 21 Feb 2017 12:17:51 +0100 (CET) Received: (qmail 68484 invoked by uid 500); 21 Feb 2017 11:17:50 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 68475 invoked by uid 99); 21 Feb 2017 11:17:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Feb 2017 11:17:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6E3D7DFEF5; Tue, 21 Feb 2017 11:17:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lburgazzoli@apache.org To: commits@camel.apache.org Date: Tue, 21 Feb 2017 11:17:50 -0000 Message-Id: <5c8038c476ac4d87be7bc7a7afedda35@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] camel git commit: CAMEL-10686: service-call eip : generate service-call auto configurations for spring-boot archived-at: Tue, 21 Feb 2017 11:17:52 -0000 Repository: camel Updated Branches: refs/heads/master 2c3fa6c4b -> 615314557 http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 new file mode 100644 index 0000000..3d2d7b7 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/java/org/apache/camel/component/dns/springboot/cloud/DnsCloudConfiguration.java @@ -0,0 +1,45 @@ +/** + * 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 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 { + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories index fef7327..f078ff9 100644 --- a/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-dns-starter/src/main/resources/META-INF/spring.factories @@ -16,4 +16,5 @@ # org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.camel.component.dns.springboot.DnsComponentAutoConfiguration +org.apache.camel.component.dns.springboot.DnsComponentAutoConfiguration,\ +org.apache.camel.component.dns.springboot.cloud.DnsCloudAutoConfiguration \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 new file mode 100644 index 0000000..9af3218 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudAutoConfiguration.java @@ -0,0 +1,83 @@ +/** + * 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.CamelContext; +import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.component.etcd.cloud.EtcdOnDemandServiceDiscovery; +import org.apache.camel.component.etcd.cloud.EtcdServiceDiscoveryFactory; +import org.apache.camel.component.etcd.cloud.EtcdWatchServiceDiscovery; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.ObjectHelper; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionMessage; +import org.springframework.boot.autoconfigure.condition.ConditionOutcome; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +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; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@Configuration +@ConditionalOnBean(CamelAutoConfiguration.class) +@Conditional(EtcdCloudAutoConfiguration.Condition.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties(EtcdCloudConfiguration.class) +public class EtcdCloudAutoConfiguration { + @Lazy + @Bean(name = "etcd-service-discovery") + @ConditionalOnClass(CamelContext.class) + public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, EtcdCloudConfiguration configuration) throws Exception { + EtcdServiceDiscoveryFactory factory = new EtcdServiceDiscoveryFactory(); + + Map parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, false); + IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters); + + return factory.newInstance(camelContext); + } + + public static class Condition extends SpringBootCondition { + @Override + public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { + boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true); + + ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.etcd"); + if (isEnabled(conditionContext, "camel.cloud.etcd.", groupEnabled)) { + return ConditionOutcome.match(message.because("enabled")); + } + + return ConditionOutcome.noMatch(message.because("not enabled")); + } + + private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) { + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix); + return resolver.getProperty("enabled", Boolean.class, defaultValue); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 new file mode 100644 index 0000000..42d4e92 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/java/org/apache/camel/component/etcd/springboot/cloud/EtcdCloudConfiguration.java @@ -0,0 +1,54 @@ +/** + * 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 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 String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories index d3e9b9a..1358d3e 100644 --- a/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-etcd-starter/src/main/resources/META-INF/spring.factories @@ -16,4 +16,5 @@ # org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.camel.component.etcd.springboot.EtcdComponentAutoConfiguration +org.apache.camel.component.etcd.springboot.EtcdComponentAutoConfiguration,\ +org.apache.camel.component.etcd.springboot.cloud.EtcdCloudAutoConfiguration http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 new file mode 100644 index 0000000..6527ba4 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudAutoConfiguration.java @@ -0,0 +1,79 @@ +/** + * 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.CamelContext; +import org.apache.camel.cloud.ServiceDiscovery; +import org.apache.camel.component.kubernetes.cloud.KubernetesServiceDiscoveryFactory; +import org.apache.camel.spring.boot.CamelAutoConfiguration; +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; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +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; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@Configuration +@ConditionalOnBean(CamelAutoConfiguration.class) +@Conditional(KubernetesCloudAutoConfiguration.Condition.class) +@AutoConfigureAfter(CamelAutoConfiguration.class) +@EnableConfigurationProperties(KubernetesCloudConfiguration.class) +public class KubernetesCloudAutoConfiguration { + @Lazy + @Bean(name = "kubernetes-service-discovery") + @ConditionalOnClass(CamelContext.class) + public ServiceDiscovery configureServiceDiscoveryFactory(CamelContext camelContext, KubernetesCloudConfiguration configuration) throws Exception { + KubernetesServiceDiscoveryFactory factory = new KubernetesServiceDiscoveryFactory(); + + Map parameters = new HashMap<>(); + IntrospectionSupport.getProperties(configuration, parameters, null, false); + IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), factory, parameters); + + return factory.newInstance(camelContext); + } + + public static class Condition extends SpringBootCondition { + @Override + public ConditionOutcome getMatchOutcome(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { + boolean groupEnabled = isEnabled(conditionContext, "camel.cloud.", true); + + ConditionMessage.Builder message = ConditionMessage.forCondition("camel.cloud.kubernetes"); + if (isEnabled(conditionContext, "camel.cloud.kubernetes.", groupEnabled)) { + return ConditionOutcome.match(message.because("enabled")); + } + + return ConditionOutcome.noMatch(message.because("not enabled")); + } + + private boolean isEnabled(ConditionContext context, String prefix, boolean defaultValue) { + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(), prefix); + return resolver.getProperty("enabled", Boolean.class, defaultValue); + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/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 new file mode 100644 index 0000000..5dd6902 --- /dev/null +++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/java/org/apache/camel/component/kubernetes/springboot/cloud/KubernetesCloudConfiguration.java @@ -0,0 +1,54 @@ +/** + * 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 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 String lookup; + + public String getLookup() { + return lookup; + } + + public void setLookup(String lookup) { + this.lookup = lookup; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/61531455/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories index 5ef2258..310e1fe 100644 --- a/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories +++ b/platforms/spring-boot/components-starter/camel-kubernetes-starter/src/main/resources/META-INF/spring.factories @@ -16,4 +16,5 @@ # org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.camel.component.kubernetes.springboot.KubernetesComponentAutoConfiguration +org.apache.camel.component.kubernetes.springboot.KubernetesComponentAutoConfiguration,\ +org.apache.camel.component.kubernetes.springboot.cloud.KubernetesCloudAutoConfiguration