camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject camel git commit: CAMEL-10686: service-call eip : generate service-call auto configurations for spring-boot
Date Wed, 22 Feb 2017 10:07:45 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5350f010f -> f13acd39a


CAMEL-10686: service-call eip : generate service-call auto configurations for spring-boot


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

Branch: refs/heads/master
Commit: f13acd39a791893c1e79428931755a0729856898
Parents: 5350f01
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Wed Feb 22 11:06:42 2017 +0100
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Wed Feb 22 11:07:25 2017 +0100

----------------------------------------------------------------------
 ...bonServiceCallLoadBalancerConfiguration.java | 77 +++++++++++++++++++
 .../ribbon/cloud/RibbonLoadBalancerFactory.java | 34 ++++++++-
 .../cloud/RibbonCloudAutoConfiguration.java     | 79 ++++++++++++++++++++
 .../cloud/RibbonCloudConfiguration.java         | 45 +++++++++++
 .../main/resources/META-INF/spring.factories    | 18 +++++
 .../src/main/resources/application.properties   |  1 +
 6 files changed, 251 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f13acd39/camel-core/src/main/java/org/apache/camel/model/cloud/RibbonServiceCallLoadBalancerConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/RibbonServiceCallLoadBalancerConfiguration.java
b/camel-core/src/main/java/org/apache/camel/model/cloud/RibbonServiceCallLoadBalancerConfiguration.java
index 05f2523..b605890 100644
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/RibbonServiceCallLoadBalancerConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/RibbonServiceCallLoadBalancerConfiguration.java
@@ -16,11 +16,13 @@
  */
 package org.apache.camel.model.cloud;
 
+import java.util.Map;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.spi.Metadata;
 
 @Metadata(label = "routing,cloud,load-balancing")
@@ -28,6 +30,12 @@ import org.apache.camel.spi.Metadata;
 @XmlAccessorType(XmlAccessType.FIELD)
 public class RibbonServiceCallLoadBalancerConfiguration extends ServiceCallLoadBalancerConfiguration
{
     @XmlAttribute
+    private String namespace;
+    @XmlAttribute
+    private String username;
+    @XmlAttribute
+    private String password;
+    @XmlAttribute
     private String clientName;
 
     public RibbonServiceCallLoadBalancerConfiguration() {
@@ -42,6 +50,39 @@ public class RibbonServiceCallLoadBalancerConfiguration extends ServiceCallLoadB
     // Properties
     // *************************************************************************
 
+    public String getNamespace() {
+        return namespace;
+    }
+
+    /**
+     * The namespace
+     */
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    /**
+     * The username
+     */
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * The password
+     */
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
     public String getClientName() {
         return clientName;
     }
@@ -58,10 +99,46 @@ public class RibbonServiceCallLoadBalancerConfiguration extends ServiceCallLoadB
     // *************************************************************************
 
     /**
+     * Sets the namespace
+     */
+    public RibbonServiceCallLoadBalancerConfiguration namespace(String namespace) {
+        setNamespace(namespace);
+        return this;
+    }
+
+    /**
+     * Sets the username
+     */
+    public RibbonServiceCallLoadBalancerConfiguration username(String username) {
+        setUsername(username);
+        return this;
+    }
+
+    /**
+     * Sets the password
+     */
+    public RibbonServiceCallLoadBalancerConfiguration password(String password) {
+        setPassword(password);
+        return this;
+    }
+
+    /**
      * Sets the Ribbon client name
      */
     public RibbonServiceCallLoadBalancerConfiguration clientName(String clientName) {
         setClientName(clientName);
         return this;
     }
+
+    // *************************************************************************
+    // Helpers
+    // *************************************************************************
+
+    @Override
+    protected void postProcessFactoryParameters(CamelContext camelContext, Map<String,
Object> parameters) throws Exception  {
+        Map<String, Object> properties = (Map<String, Object>)parameters.get("properties");
+        if (properties != null) {
+            parameters.put("clientConfig", properties);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/f13acd39/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancerFactory.java
b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancerFactory.java
index 86874f0..5a211fc 100644
--- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancerFactory.java
+++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancerFactory.java
@@ -27,13 +27,41 @@ public class RibbonLoadBalancerFactory implements LoadBalancerFactory
{
     private final RibbonConfiguration configuration;
 
     public RibbonLoadBalancerFactory() {
-        this.configuration = new RibbonConfiguration();
+        this(new RibbonConfiguration());
+    }
+
+    public RibbonLoadBalancerFactory(RibbonConfiguration configuration) {
+        this.configuration = configuration;
     }
 
     // *************************************************************************
     // Properties
     // *************************************************************************
 
+    public String getNamespace() {
+        return configuration.getNamespace();
+    }
+
+    public void setNamespace(String namespace) {
+        configuration.setNamespace(namespace);
+    }
+
+    public String getUsername() {
+        return configuration.getUsername();
+    }
+
+    public void setUsername(String username) {
+        configuration.setUsername(username);
+    }
+
+    public String getPassword() {
+        return configuration.getPassword();
+    }
+
+    public void setPassword(String password) {
+        configuration.setPassword(password);
+    }
+
     public String getClientName() {
         return configuration.getClientName();
     }
@@ -42,11 +70,11 @@ public class RibbonLoadBalancerFactory implements LoadBalancerFactory
{
         configuration.setClientName(clientName);
     }
 
-    public Map<String, String> getProperies() {
+    public Map<String, String> getClientConfig() {
         return configuration.getClientConfig();
     }
 
-    public void setProperties(Map<String, String> clientConfig) {
+    public void setClientConfig(Map<String, String> clientConfig) {
         configuration.setClientConfig(clientConfig);
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/f13acd39/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudAutoConfiguration.java
b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudAutoConfiguration.java
new file mode 100644
index 0000000..cfb7f88
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudAutoConfiguration.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.ribbon.springboot.cloud;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.LoadBalancer;
+import org.apache.camel.component.ribbon.cloud.RibbonLoadBalancerFactory;
+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(RibbonCloudAutoConfiguration.Condition.class)
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties(RibbonCloudConfiguration.class)
+public class RibbonCloudAutoConfiguration {
+    @Lazy
+    @Bean(name = "ribbon-load-balancer")
+    @ConditionalOnClass(CamelContext.class)
+    public LoadBalancer configureServiceDiscoveryFactory(CamelContext camelContext, RibbonCloudConfiguration
configuration) throws Exception {
+        RibbonLoadBalancerFactory factory = new RibbonLoadBalancerFactory();
+
+        Map<String, Object> 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.ribbon");
+            if (isEnabled(conditionContext, "camel.cloud.ribbon.", 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/f13acd39/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudConfiguration.java
b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudConfiguration.java
new file mode 100644
index 0000000..dd31bea
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/java/org/apache/camel/component/ribbon/springboot/cloud/RibbonCloudConfiguration.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.ribbon.springboot.cloud;
+
+import org.apache.camel.component.ribbon.RibbonConfiguration;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.cloud.ribbon")
+public class RibbonCloudConfiguration {
+    private boolean enabled = true;
+    private LoadBalancerConfiguration loadBalancer = new LoadBalancerConfiguration();
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public LoadBalancerConfiguration getLoadBalancer() {
+        return loadBalancer;
+    }
+
+    // *************************************************************************
+    //
+    // *************************************************************************
+
+    public class LoadBalancerConfiguration extends RibbonConfiguration {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f13acd39/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/META-INF/spring.factories
b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..567d3d4
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,18 @@
+#
+# 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.
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.ribbon.springboot.cloud.RibbonCloudAutoConfiguration
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/f13acd39/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/application.properties
b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/application.properties
new file mode 100644
index 0000000..024710e
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-ribbon-starter/src/main/resources/application.properties
@@ -0,0 +1 @@
+camel.cloud.ribbon.load-balancer.
\ No newline at end of file


Mime
View raw message