Repository: camel
Updated Branches:
  refs/heads/master 0df901540 -> 7dd45d915


CAMEL-10801: ServiceCall : add the option to force the service call to use the 
default load balancer


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

Branch: refs/heads/master
Commit: 7dd45d91542ecd6c5bdc3ce2073a2cbe3a3b356f
Parents: 0df9015
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Tue Feb 7 17:57:29 2017 +0100
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Tue Feb 7 17:57:29 2017 +0100

----------------------------------------------------------------------
 .../impl/cloud/DefaultLoadBalancerFactory.java  | 32 +++++++++++++
 ...ultServiceCallLoadBalancerConfiguration.java | 47 ++++++++++++++++++++
 .../ServiceCallConfigurationDefinition.java     | 10 ++++-
 .../camel/model/cloud/ServiceCallConstants.java |  8 +---
 .../model/cloud/ServiceCallDefinition.java      | 12 ++++-
 .../apache/camel/cloud/default-load-balancer    | 17 +++++++
 .../ConsulDefaultServiceCallRouteTest.java      |  7 ++-
 .../cloud/ConsulRibbonServiceCallRouteTest.java |  4 +-
 .../cloud/ServiceCallConfigurationTest.java     |  5 +++
 .../cloud/ServiceCallConfigurationTest.xml      |  1 +
 10 files changed, 127 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultLoadBalancerFactory.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultLoadBalancerFactory.java
 
b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultLoadBalancerFactory.java
new file mode 100644
index 0000000..c12497e
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultLoadBalancerFactory.java
@@ -0,0 +1,32 @@
+/**
+ * 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.impl.cloud;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.LoadBalancer;
+import org.apache.camel.cloud.LoadBalancerFactory;
+
+public class DefaultLoadBalancerFactory implements LoadBalancerFactory {
+    @Override
+    public LoadBalancer newInstance(CamelContext camelContext) throws 
Exception {
+        DefaultLoadBalancer loadBalancer = new DefaultLoadBalancer();
+        loadBalancer.setCamelContext(camelContext);
+
+        return loadBalancer;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/java/org/apache/camel/model/cloud/DefaultServiceCallLoadBalancerConfiguration.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/cloud/DefaultServiceCallLoadBalancerConfiguration.java
 
b/camel-core/src/main/java/org/apache/camel/model/cloud/DefaultServiceCallLoadBalancerConfiguration.java
new file mode 100644
index 0000000..4c3dae4
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/model/cloud/DefaultServiceCallLoadBalancerConfiguration.java
@@ -0,0 +1,47 @@
+/**
+ * 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;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "routing,cloud,load-balancing")
+@XmlRootElement(name = "defaultLoadBalancer")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DefaultServiceCallLoadBalancerConfiguration extends 
ServiceCallLoadBalancerConfiguration {
+    public DefaultServiceCallLoadBalancerConfiguration() {
+        this(null);
+    }
+
+    public DefaultServiceCallLoadBalancerConfiguration(ServiceCallDefinition 
parent) {
+        super(parent, "default-load-balancer");
+    }
+
+    // 
*************************************************************************
+    // Properties
+    // 
*************************************************************************
+
+
+    // 
*************************************************************************
+    // Fluent API
+    // 
*************************************************************************
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConfigurationDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConfigurationDefinition.java
 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConfigurationDefinition.java
index aec0291..82b2603 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConfigurationDefinition.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConfigurationDefinition.java
@@ -87,7 +87,8 @@ public class ServiceCallConfigurationDefinition extends 
IdentifiedType {
     private ServiceCallServiceFilterConfiguration serviceFilterConfiguration;
 
     @XmlElements({
-        @XmlElement(name = "ribbonLoadBalancer", type = 
RibbonServiceCallLoadBalancerConfiguration.class)}
+        @XmlElement(name = "ribbonLoadBalancer", type = 
RibbonServiceCallLoadBalancerConfiguration.class),
+        @XmlElement(name = "defaultLoadBalancer", type = 
DefaultServiceCallLoadBalancerConfiguration.class) }
     )
     private ServiceCallLoadBalancerConfiguration loadBalancerConfiguration;
 
@@ -583,6 +584,13 @@ public class ServiceCallConfigurationDefinition extends 
IdentifiedType {
     // Shortcuts - LoadBalancer
     // *****************************
 
+    public ServiceCallConfigurationDefinition defaultLoadBalancer() {
+        DefaultServiceCallLoadBalancerConfiguration conf = new 
DefaultServiceCallLoadBalancerConfiguration();
+        setLoadBalancerConfiguration(conf);
+
+        return this;
+    }
+
     public ServiceCallConfigurationDefinition ribbonLoadBalancer() {
         RibbonServiceCallLoadBalancerConfiguration conf = new 
RibbonServiceCallLoadBalancerConfiguration();
         setLoadBalancerConfiguration(conf);

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConstants.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConstants.java
 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConstants.java
index 1c535f2..04ee654 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConstants.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallConstants.java
@@ -21,8 +21,6 @@ import java.util.List;
 
 final class ServiceCallConstants {
     public static final List<ServiceCallServiceDiscoveryConfiguration> 
SERVICE_DISCOVERY_CONFIGURATIONS = Arrays.asList(
-        new CachingServiceCallServiceDiscoveryConfiguration(),
-        new ChainedServiceCallServiceDiscoveryConfiguration(),
         new ConsulServiceCallServiceDiscoveryConfiguration(),
         new DnsServiceCallServiceDiscoveryConfiguration(),
         new EtcdServiceCallServiceDiscoveryConfiguration(),
@@ -30,15 +28,13 @@ final class ServiceCallConstants {
     );
 
     public static final List<ServiceCallServiceFilterConfiguration> 
SERVICE_FILTER_CONFIGURATIONS = Arrays.asList(
-        new BlacklistServiceCallServiceFilterConfiguration(),
-        new ChainedServiceCallServiceFilterConfiguration(),
-        new CustomServiceCallServiceFilterConfiguration(),
         new HealthyServiceCallServiceFilterConfiguration(),
         new PassThroughServiceCallServiceFilterConfiguration()
     );
 
     public static final List<ServiceCallLoadBalancerConfiguration> 
LOAD_BALANCER_CONFIGURATIONS = Arrays.asList(
-        new RibbonServiceCallLoadBalancerConfiguration()
+        new RibbonServiceCallLoadBalancerConfiguration(),
+        new DefaultServiceCallLoadBalancerConfiguration()
     );
 
     private ServiceCallConstants() {

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
index f51bbc4..5d8fe91 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/cloud/ServiceCallDefinition.java
@@ -111,7 +111,8 @@ public class ServiceCallDefinition extends 
NoOutputDefinition<ServiceCallDefinit
     private ServiceCallServiceFilterConfiguration serviceFilterConfiguration;
 
     @XmlElements({
-        @XmlElement(name = "ribbonLoadBalancer", type = 
RibbonServiceCallLoadBalancerConfiguration.class)}
+        @XmlElement(name = "ribbonLoadBalancer", type = 
RibbonServiceCallLoadBalancerConfiguration.class),
+        @XmlElement(name = "defaultLoadBalancer", type = 
DefaultServiceCallLoadBalancerConfiguration.class) }
     )
     private ServiceCallLoadBalancerConfiguration loadBalancerConfiguration;
 
@@ -651,6 +652,13 @@ public class ServiceCallDefinition extends 
NoOutputDefinition<ServiceCallDefinit
     // Shortcuts - LoadBalancer
     // *****************************
 
+    public ServiceCallDefinition defaultLoadBalancer() {
+        DefaultServiceCallLoadBalancerConfiguration conf = new 
DefaultServiceCallLoadBalancerConfiguration();
+        setLoadBalancerConfiguration(conf);
+
+        return this;
+    }
+
     public ServiceCallDefinition ribbonLoadBalancer() {
         RibbonServiceCallLoadBalancerConfiguration conf = new 
RibbonServiceCallLoadBalancerConfiguration(this);
         setLoadBalancerConfiguration(conf);
@@ -773,7 +781,7 @@ public class ServiceCallDefinition extends 
NoOutputDefinition<ServiceCallDefinit
 
         if (serviceFilterConfiguration != null) {
             answer = serviceFilterConfiguration.newInstance(camelContext);
-        } else if (config != null && config.getLoadBalancerConfiguration() != 
null) {
+        } else if (config != null && config.getServiceFilterConfiguration() != 
null) {
             answer = 
config.getServiceFilterConfiguration().newInstance(camelContext);
         } else {
             answer = retrieve(ServiceFilter.class, camelContext, 
this::getServiceFilter, this::getServiceFilterRef);

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/default-load-balancer
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/default-load-balancer
 
b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/default-load-balancer
new file mode 100644
index 0000000..f8c9ddb
--- /dev/null
+++ 
b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/default-load-balancer
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+class=org.apache.camel.impl.cloud.DefaultLoadBalancerFactory
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulDefaultServiceCallRouteTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulDefaultServiceCallRouteTest.java
 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulDefaultServiceCallRouteTest.java
index 749459d..fd790e1 100644
--- 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulDefaultServiceCallRouteTest.java
+++ 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulDefaultServiceCallRouteTest.java
@@ -67,7 +67,6 @@ public class ConsulDefaultServiceCallRouteTest extends 
ConsulTestSupport {
     public void tearDown() throws Exception {
         super.tearDown();
 
-
         registrations.forEach(r -> client.deregister(r.getId()));
     }
 
@@ -97,9 +96,9 @@ public class ConsulDefaultServiceCallRouteTest extends 
ConsulTestSupport {
                 from("direct:start")
                     .serviceCall()
                         .name(SERVICE_NAME)
-                        .consulServiceDiscovery()
-                        .endParent()
-                    
.to("log:org.apache.camel.component.consul.processor.service?level=INFO&showAll=true&multiline=true")
+                        .defaultLoadBalancer()
+                        .end()
+                    
.to("log:org.apache.camel.component.consul.cloud?level=INFO&showAll=true&multiline=true")
                     .to("mock:result");
 
                 registrations.forEach(r ->

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulRibbonServiceCallRouteTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulRibbonServiceCallRouteTest.java
 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulRibbonServiceCallRouteTest.java
index a8d1446..9009b20 100644
--- 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulRibbonServiceCallRouteTest.java
+++ 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulRibbonServiceCallRouteTest.java
@@ -97,9 +97,7 @@ public class ConsulRibbonServiceCallRouteTest extends 
ConsulTestSupport {
                 from("direct:start")
                     .serviceCall()
                         .name(SERVICE_NAME)
-                        .ribbonLoadBalancer()
-                        .consulServiceDiscovery()
-                        .endParent()
+                        .end()
                     
.to("log:org.apache.camel.component.consul.processor.service?level=INFO&showAll=true&multiline=true")
                     .to("mock:result");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java
index b1adfee..be76730 100644
--- 
a/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.spring.cloud;
 import 
org.apache.camel.model.cloud.BlacklistServiceCallServiceFilterConfiguration;
 import 
org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration;
 import 
org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration;
+import 
org.apache.camel.model.cloud.DefaultServiceCallLoadBalancerConfiguration;
 import 
org.apache.camel.model.cloud.HealthyServiceCallServiceFilterConfiguration;
 import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
 import 
org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration;
@@ -28,6 +29,7 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 public class ServiceCallConfigurationTest {
@@ -38,6 +40,8 @@ public class ServiceCallConfigurationTest {
         ServiceCallConfigurationDefinition conf1 = 
context.getServiceCallConfiguration("conf1");
         assertNotNull("No ServiceCallConfiguration (1)", conf1);
         assertNotNull("No ServiceDiscoveryConfiguration (1)", 
conf1.getServiceDiscoveryConfiguration());
+        assertNotNull("No ServiceCallLoadBalancerConfiguration (1)", 
conf1.getLoadBalancerConfiguration());
+        assertTrue(conf1.getLoadBalancerConfiguration() instanceof 
DefaultServiceCallLoadBalancerConfiguration);
 
         StaticServiceCallServiceDiscoveryConfiguration discovery1 = 
(StaticServiceCallServiceDiscoveryConfiguration)conf1.getServiceDiscoveryConfiguration();
         assertEquals(1, discovery1.getServers().size());
@@ -46,6 +50,7 @@ public class ServiceCallConfigurationTest {
         ServiceCallConfigurationDefinition conf2 = 
context.getServiceCallConfiguration("conf2");
         assertNotNull("No ServiceCallConfiguration (2)", conf2);
         assertNotNull("No ServiceDiscoveryConfiguration (2)", 
conf2.getServiceDiscoveryConfiguration());
+        assertNull(conf2.getLoadBalancerConfiguration());
 
         ChainedServiceCallServiceDiscoveryConfiguration discovery2 = 
(ChainedServiceCallServiceDiscoveryConfiguration)conf2.getServiceDiscoveryConfiguration();
         assertEquals(2, discovery2.getServiceDiscoveryConfigurations().size());

http://git-wip-us.apache.org/repos/asf/camel/blob/7dd45d91/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml
index 2ad4e54..70ed090 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallConfigurationTest.xml
@@ -29,6 +29,7 @@
       <staticServiceDiscovery>
         <servers>localhost:9091</servers>
       </staticServiceDiscovery>
+      <defaultLoadBalancer/>
     </serviceCallConfiguration>
 
     <serviceCallConfiguration id="conf2">

Reply via email to