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/01/30 18:37:20 UTC
[1/2] camel git commit: CAMEL-10761: ServiceCall EIP : support for
chaining service filters/discovery
Repository: camel
Updated Branches:
refs/heads/master 9c6263d8a -> 0aae1257b
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/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 ef9e3a4..aec0291 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
@@ -68,16 +68,25 @@ public class ServiceCallConfigurationDefinition extends IdentifiedType {
private Expression expression;
@XmlElements({
@XmlElement(name = "cachingServiceDiscovery", type = CachingServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "chainedServiceDiscovery", type = ChainedServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "consulServiceDiscovery", type = ConsulServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "dnsServiceDiscovery", type = DnsServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "etcdServiceDiscovery", type = EtcdServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "kubernetesServiceDiscovery", type = KubernetesServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "multiServiceDiscovery", type = MultiServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "staticServiceDiscovery", type = StaticServiceCallServiceDiscoveryConfiguration.class)}
)
private ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration;
@XmlElements({
+ @XmlElement(name = "blacklistServiceFilter", type = BlacklistServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "chainedServiceFilter", type = ChainedServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "customServiceFilter", type = CustomServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "healthyServiceFilter", type = HealthyServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "passThroughServiceFilter", type = PassThroughServiceCallServiceFilterConfiguration.class)}
+ )
+ private ServiceCallServiceFilterConfiguration serviceFilterConfiguration;
+
+ @XmlElements({
@XmlElement(name = "ribbonLoadBalancer", type = RibbonServiceCallLoadBalancerConfiguration.class)}
)
private ServiceCallLoadBalancerConfiguration loadBalancerConfiguration;
@@ -246,6 +255,17 @@ public class ServiceCallConfigurationDefinition extends IdentifiedType {
this.serviceDiscoveryConfiguration = serviceDiscoveryConfiguration;
}
+ public ServiceCallServiceFilterConfiguration getServiceFilterConfiguration() {
+ return serviceFilterConfiguration;
+ }
+
+ /**
+ * Configures the ServiceFilter using the given configuration.
+ */
+ public void setServiceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ this.serviceFilterConfiguration = serviceFilterConfiguration;
+ }
+
public ServiceCallLoadBalancerConfiguration getLoadBalancerConfiguration() {
return loadBalancerConfiguration;
}
@@ -392,6 +412,14 @@ public class ServiceCallConfigurationDefinition extends IdentifiedType {
}
/**
+ * Configures the ServiceFilter using the given configuration.
+ */
+ public ServiceCallConfigurationDefinition serviceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ setServiceFilterConfiguration(serviceFilterConfiguration);
+ return this;
+ }
+
+ /**
* Configures the LoadBalancer using the given configuration.
*/
public ServiceCallConfigurationDefinition loadBalancerConfiguration(ServiceCallLoadBalancerConfiguration loadBalancerConfiguration) {
@@ -494,8 +522,8 @@ public class ServiceCallConfigurationDefinition extends IdentifiedType {
return this;
}
- public MultiServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
- MultiServiceCallServiceDiscoveryConfiguration conf = new MultiServiceCallServiceDiscoveryConfiguration();
+ public ChainedServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
+ ChainedServiceCallServiceDiscoveryConfiguration conf = new ChainedServiceCallServiceDiscoveryConfiguration();
setServiceDiscoveryConfiguration(conf);
return conf;
@@ -509,6 +537,49 @@ public class ServiceCallConfigurationDefinition extends IdentifiedType {
}
// *****************************
+ // Shortcuts - ServiceFilter
+ // *****************************
+
+ public ServiceCallConfigurationDefinition healthyFilter() {
+ HealthyServiceCallServiceFilterConfiguration conf = new HealthyServiceCallServiceFilterConfiguration();
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ServiceCallConfigurationDefinition passThroughFilter() {
+ PassThroughServiceCallServiceFilterConfiguration conf = new PassThroughServiceCallServiceFilterConfiguration();
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration multiFilter() {
+ ChainedServiceCallServiceFilterConfiguration conf = new ChainedServiceCallServiceFilterConfiguration();
+ setServiceFilterConfiguration(conf);
+
+ return conf;
+ }
+
+ public ServiceCallConfigurationDefinition customFilter(String serviceFilter) {
+ CustomServiceCallServiceFilterConfiguration conf = new CustomServiceCallServiceFilterConfiguration();
+ conf.setServiceFilterRef(serviceFilter);
+
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ServiceCallConfigurationDefinition customFilter(ServiceFilter serviceFilter) {
+ CustomServiceCallServiceFilterConfiguration conf = new CustomServiceCallServiceFilterConfiguration();
+ conf.setServiceFilter(serviceFilter);
+
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ // *****************************
// Shortcuts - LoadBalancer
// *****************************
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/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 33f7011..1c535f2 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
@@ -22,11 +22,19 @@ 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(),
- new KubernetesServiceCallServiceDiscoveryConfiguration(),
- new MultiServiceCallServiceDiscoveryConfiguration()
+ new KubernetesServiceCallServiceDiscoveryConfiguration()
+ );
+
+ 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(
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/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 6c5cdc8..f51bbc4 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
@@ -39,11 +39,11 @@ import org.apache.camel.cloud.ServiceDiscovery;
import org.apache.camel.cloud.ServiceDiscoveryAware;
import org.apache.camel.cloud.ServiceFilter;
import org.apache.camel.cloud.ServiceFilterAware;
-import org.apache.camel.impl.cloud.AllServiceFilter;
import org.apache.camel.impl.cloud.DefaultLoadBalancer;
import org.apache.camel.impl.cloud.DefaultServiceCallExpression;
import org.apache.camel.impl.cloud.DefaultServiceCallProcessor;
import org.apache.camel.impl.cloud.HealthyServiceFilter;
+import org.apache.camel.impl.cloud.PassThroughServiceFilter;
import org.apache.camel.impl.cloud.RandomServiceChooser;
import org.apache.camel.impl.cloud.RoundRobinServiceChooser;
import org.apache.camel.model.NoOutputDefinition;
@@ -92,22 +92,31 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
@XmlElements({
@XmlElement(name = "cachingServiceDiscovery", type = CachingServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "chainedServiceDiscovery", type = ChainedServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "consulServiceDiscovery", type = ConsulServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "dnsServiceDiscovery", type = DnsServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "etcdServiceDiscovery", type = EtcdServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "kubernetesServiceDiscovery", type = KubernetesServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "multiServiceDiscovery", type = MultiServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "staticServiceDiscovery", type = StaticServiceCallServiceDiscoveryConfiguration.class)}
)
private ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration;
@XmlElements({
+ @XmlElement(name = "blacklistServiceFilter", type = BlacklistServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "chainedServiceFilter", type = ChainedServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "customServiceFilter", type = CustomServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "healthyServiceFilter", type = HealthyServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "passThroughServiceFilter", type = PassThroughServiceCallServiceFilterConfiguration.class)}
+ )
+ private ServiceCallServiceFilterConfiguration serviceFilterConfiguration;
+
+ @XmlElements({
@XmlElement(name = "ribbonLoadBalancer", type = RibbonServiceCallLoadBalancerConfiguration.class)}
)
private ServiceCallLoadBalancerConfiguration loadBalancerConfiguration;
@XmlElements({
- @XmlElement(name = "expressionCOnfiguration", type = ServiceCallExpressionConfiguration.class)}
+ @XmlElement(name = "expressionConfiguration", type = ServiceCallExpressionConfiguration.class)}
)
private ServiceCallExpressionConfiguration expressionConfiguration;
@@ -305,6 +314,17 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
this.serviceDiscoveryConfiguration = serviceDiscoveryConfiguration;
}
+ public ServiceCallServiceFilterConfiguration getServiceFilterConfiguration() {
+ return serviceFilterConfiguration;
+ }
+
+ /**
+ * Configures the ServiceFilter using the given configuration.
+ */
+ public void setServiceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ this.serviceFilterConfiguration = serviceFilterConfiguration;
+ }
+
public ServiceCallLoadBalancerConfiguration getLoadBalancerConfiguration() {
return loadBalancerConfiguration;
}
@@ -460,6 +480,14 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
}
/**
+ * Configures the ServiceFilter using the given configuration.
+ */
+ public ServiceCallDefinition serviceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ setServiceFilterConfiguration(serviceFilterConfiguration);
+ return this;
+ }
+
+ /**
* Configures the LoadBalancer using the given configuration.
*/
public ServiceCallDefinition loadBalancerConfiguration(ServiceCallLoadBalancerConfiguration loadBalancerConfiguration) {
@@ -562,8 +590,8 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
return this;
}
- public MultiServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
- MultiServiceCallServiceDiscoveryConfiguration conf = new MultiServiceCallServiceDiscoveryConfiguration(this);
+ public ChainedServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
+ ChainedServiceCallServiceDiscoveryConfiguration conf = new ChainedServiceCallServiceDiscoveryConfiguration(this);
setServiceDiscoveryConfiguration(conf);
return conf;
@@ -577,6 +605,49 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
}
// *****************************
+ // Shortcuts - ServiceFilter
+ // *****************************
+
+ public ServiceCallDefinition healthyFilter() {
+ HealthyServiceCallServiceFilterConfiguration conf = new HealthyServiceCallServiceFilterConfiguration(this);
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ServiceCallDefinition passThroughFilter() {
+ PassThroughServiceCallServiceFilterConfiguration conf = new PassThroughServiceCallServiceFilterConfiguration(this);
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration multiFilter() {
+ ChainedServiceCallServiceFilterConfiguration conf = new ChainedServiceCallServiceFilterConfiguration(this);
+ setServiceFilterConfiguration(conf);
+
+ return conf;
+ }
+
+ public ServiceCallDefinition customFilter(String serviceFilter) {
+ CustomServiceCallServiceFilterConfiguration conf = new CustomServiceCallServiceFilterConfiguration();
+ conf.setServiceFilterRef(serviceFilter);
+
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ public ServiceCallDefinition customFilter(ServiceFilter serviceFilter) {
+ CustomServiceCallServiceFilterConfiguration conf = new CustomServiceCallServiceFilterConfiguration();
+ conf.setServiceFilter(serviceFilter);
+
+ setServiceFilterConfiguration(conf);
+
+ return this;
+ }
+
+ // *****************************
// Shortcuts - LoadBalancer
// *****************************
@@ -697,22 +768,33 @@ public class ServiceCallDefinition extends NoOutputDefinition<ServiceCallDefinit
return answer;
}
- private ServiceFilter retrieveServiceFilter(CamelContext camelContext, ServiceCallConfigurationDefinition config) {
- ServiceFilter answer = retrieve(ServiceFilter.class, camelContext, this::getServiceFilter, this::getServiceFilterRef);
- if (answer == null && config != null) {
- answer = retrieve(ServiceFilter.class, camelContext, config::getServiceFilter, config::getServiceFilterRef);
+ private ServiceFilter retrieveServiceFilter(CamelContext camelContext, ServiceCallConfigurationDefinition config) throws Exception {
+ ServiceFilter answer;
- // If the ServiceFilter is not found but a ref is set, try to determine
- // the implementation according to the ref name.
- if (answer == null) {
- String ref = config.getServiceFilterRef();
- if (ObjectHelper.equal("healthy", ref, true)) {
- answer = new HealthyServiceFilter();
- } else if (ObjectHelper.equal("all", ref, true)) {
- answer = new AllServiceFilter();
+ if (serviceFilterConfiguration != null) {
+ answer = serviceFilterConfiguration.newInstance(camelContext);
+ } else if (config != null && config.getLoadBalancerConfiguration() != null) {
+ answer = config.getServiceFilterConfiguration().newInstance(camelContext);
+ } else {
+ answer = retrieve(ServiceFilter.class, camelContext, this::getServiceFilter, this::getServiceFilterRef);
+ if (answer == null && config != null) {
+ answer = retrieve(ServiceFilter.class, camelContext, config::getServiceFilter, config::getServiceFilterRef);
+
+ // If the ServiceFilter is not found but a ref is set, try to determine
+ // the implementation according to the ref name.
+ if (answer == null) {
+ String ref = config.getServiceFilterRef();
+ if (ObjectHelper.equal("healthy", ref, true)) {
+ answer = new HealthyServiceFilter();
+ } else if (ObjectHelper.equal("pass-through", ref, true)) {
+ answer = new PassThroughServiceFilter();
+ } else if (ObjectHelper.equal("passthrough", ref, true)) {
+ answer = new PassThroughServiceFilter();
+ }
}
}
}
+
if (answer == null) {
answer = findByType(camelContext, ServiceFilter.class);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/blacklist-service-filter
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/blacklist-service-filter b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/blacklist-service-filter
new file mode 100644
index 0000000..29ee4e6
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/blacklist-service-filter
@@ -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.BlacklistServiceFilterFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-discovery
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-discovery b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-discovery
new file mode 100644
index 0000000..e183367
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-discovery
@@ -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.ChainedServiceDiscoveryFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-filter
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-filter b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-filter
new file mode 100644
index 0000000..6eb18b5
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/chained-service-filter
@@ -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.ChainedServiceFilterFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/healthy-service-filter
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/healthy-service-filter b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/healthy-service-filter
new file mode 100644
index 0000000..b1cdd65
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/healthy-service-filter
@@ -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.HealthyServiceFilterFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/multi-service-discovery
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/multi-service-discovery b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/multi-service-discovery
deleted file mode 100644
index eacee81..0000000
--- a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/multi-service-discovery
+++ /dev/null
@@ -1,17 +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.
-#
-class=org.apache.camel.impl.cloud.MultiServiceDiscoveryFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/pass-through-service-filter
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/pass-through-service-filter b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/pass-through-service-filter
new file mode 100644
index 0000000..e1e1912
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/cloud/pass-through-service-filter
@@ -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.PassThroughServiceFilterFactory
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/resources/org/apache/camel/model/cloud/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/cloud/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/cloud/jaxb.index
index c275033..7d5156b 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/cloud/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/cloud/jaxb.index
@@ -20,11 +20,15 @@ ServiceCallServiceDiscoveryConfiguration
ServiceCallServiceFilterConfiguration
ServiceCallServiceChooserConfiguration
ServiceCallLoadBalancerConfiguration
+BlacklistServiceCallServiceFilterConfiguration
+ChainedServiceCallServiceFilterConfiguration
+PassThroughServiceCallServiceFilterConfiguration
CachingServiceCallServiceDiscoveryConfiguration
ConsulServiceCallServiceDiscoveryConfiguration
DnsServiceCallServiceDiscoveryConfiguration
EtcdServiceCallServiceDiscoveryConfiguration
+HealthyServiceCallServiceFilterConfiguration
KubernetesServiceCallServiceDiscoveryConfiguration
-MultiServiceCallServiceDiscoveryConfiguration
+ChainedServiceCallServiceDiscoveryConfiguration
StaticServiceCallServiceDiscoveryConfiguration
RibbonServiceCallLoadBalancerConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryTest.java b/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryTest.java
new file mode 100644
index 0000000..91377aa
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.Arrays;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.model.cloud.ChainedServiceCallServiceDiscoveryConfiguration;
+import org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ChainedServiceDiscoveryTest extends ContextTestSupport {
+ @Test
+ public void testMultiServiceDiscovery() throws Exception {
+ StaticServiceDiscovery discovery1 = new StaticServiceDiscovery();
+ discovery1.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1111));
+ discovery1.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1112));
+
+ StaticServiceDiscovery discovery2 = new StaticServiceDiscovery();
+ discovery2.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1113));
+ discovery2.addServer(new DefaultServiceDefinition("discovery2", "localhost", 1114));
+
+ ChainedServiceDiscovery discovery = ChainedServiceDiscovery.wrap(discovery1, discovery2);
+ Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
+ Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
+ }
+
+ @Test
+ public void testMultiServiceDiscoveryConfiguration() throws Exception {
+ StaticServiceCallServiceDiscoveryConfiguration staticConf1 = new StaticServiceCallServiceDiscoveryConfiguration();
+ staticConf1.setServers(Arrays.asList("discovery1@localhost:1111", "discovery1@localhost:1112"));
+
+ StaticServiceCallServiceDiscoveryConfiguration staticConf2 = new StaticServiceCallServiceDiscoveryConfiguration();
+ staticConf2.setServers(Arrays.asList("discovery1@localhost:1113", "discovery2@localhost:1114"));
+
+ ChainedServiceCallServiceDiscoveryConfiguration multiConf = new ChainedServiceCallServiceDiscoveryConfiguration();
+ multiConf.setServiceDiscoveryConfigurations(Arrays.asList(staticConf1, staticConf2));
+
+ ChainedServiceDiscovery discovery = (ChainedServiceDiscovery)multiConf.newInstance(context);
+ Assert.assertEquals(2, discovery.getDelegates().size());
+ Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
+ Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
+ }
+
+ @Test
+ public void testMultiServiceDiscoveryConfigurationDsl() throws Exception {
+ ChainedServiceCallServiceDiscoveryConfiguration multiConf = new ChainedServiceCallServiceDiscoveryConfiguration();
+ multiConf.staticServiceDiscovery().setServers(Arrays.asList("discovery1@localhost:1111", "discovery1@localhost:1112"));
+ multiConf.staticServiceDiscovery().setServers(Arrays.asList("discovery1@localhost:1113", "discovery2@localhost:1114"));
+
+ ChainedServiceDiscovery discovery = (ChainedServiceDiscovery)multiConf.newInstance(context);
+ Assert.assertEquals(2, discovery.getDelegates().size());
+ Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
+ Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceFilterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceFilterTest.java b/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceFilterTest.java
new file mode 100644
index 0000000..dc99d11
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/cloud/ChainedServiceFilterTest.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.impl.cloud;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.model.cloud.ChainedServiceCallServiceFilterConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ChainedServiceFilterTest extends ContextTestSupport {
+ @Test
+ public void testMultiServiceFilterConfiguration() throws Exception {
+ ChainedServiceCallServiceFilterConfiguration conf =
+ new ChainedServiceCallServiceFilterConfiguration()
+ .healthy()
+ .passThrough();
+
+ ChainedServiceFilter filter = (ChainedServiceFilter)conf.newInstance(context);
+ Assert.assertEquals(2, filter.getDelegates().size());
+ Assert.assertTrue(filter.getDelegates().get(0) instanceof HealthyServiceFilter);
+ Assert.assertTrue(filter.getDelegates().get(1) instanceof PassThroughServiceFilter);
+ }
+
+
+ @Test
+ public void testMultiServiceFilter() throws Exception {
+ ChainedServiceCallServiceFilterConfiguration conf =
+ new ChainedServiceCallServiceFilterConfiguration()
+ .healthy()
+ .custom(services -> services.stream().filter(s -> s.getPort() < 2000).collect(Collectors.toList())
+ );
+
+ List<ServiceDefinition> services = conf.newInstance(context).apply(Arrays.asList(
+ new DefaultServiceDefinition("no-name", "127.0.0.1", 1000),
+ new DefaultServiceDefinition("no-name", "127.0.0.1", 1001, new DefaultServiceHealth(false)),
+ new DefaultServiceDefinition("no-name", "127.0.0.1", 1002, new DefaultServiceHealth(true)),
+ new DefaultServiceDefinition("no-name", "127.0.0.1", 2001, new DefaultServiceHealth(true)),
+ new DefaultServiceDefinition("no-name", "127.0.0.1", 2001, new DefaultServiceHealth(false))
+ ));
+
+ Assert.assertEquals(2, services.size());
+ Assert.assertFalse(services.stream().anyMatch(s -> s.getHealth().isHealthy() == false));
+ Assert.assertFalse(services.stream().anyMatch(s -> s.getPort() > 2000));
+ Assert.assertTrue(services.stream().anyMatch(s -> s.getPort() == 1000));
+ Assert.assertTrue(services.stream().anyMatch(s -> s.getPort() == 1002));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/test/java/org/apache/camel/impl/cloud/LoadBalancerTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/cloud/LoadBalancerTest.java b/camel-core/src/test/java/org/apache/camel/impl/cloud/LoadBalancerTest.java
new file mode 100644
index 0000000..56cf63f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/cloud/LoadBalancerTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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 java.util.stream.Collectors;
+
+import org.apache.camel.ContextTestSupport;
+import org.junit.Test;
+
+public class LoadBalancerTest extends ContextTestSupport {
+ @Test
+ public void testLoadBalancer() throws Exception {
+ StaticServiceDiscovery serviceDiscovery = new StaticServiceDiscovery();
+ serviceDiscovery.addServer("no-name", "127.0.0.1", 2001);
+ serviceDiscovery.addServer("no-name", "127.0.0.1", 2002);
+ serviceDiscovery.addServer("no-name", "127.0.0.1", 1001);
+ serviceDiscovery.addServer("no-name", "127.0.0.1", 1002);
+
+ DefaultLoadBalancer loadBalancer = new DefaultLoadBalancer();
+ loadBalancer.setCamelContext(context);
+ loadBalancer.setServiceDiscovery(serviceDiscovery);
+ loadBalancer.setServiceFilter(services -> services.stream().filter(s -> s.getPort() < 2000).collect(Collectors.toList()));
+ loadBalancer.setServiceChooser(new RoundRobinServiceChooser());
+ loadBalancer.process("no-name", service -> { assertEquals(1001, service.getPort()); return false; });
+ loadBalancer.process("no-name", service -> { assertEquals(1002, service.getPort()); return false; });
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/test/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryTest.java b/camel-core/src/test/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryTest.java
deleted file mode 100644
index 108c5cd..0000000
--- a/camel-core/src/test/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryTest.java
+++ /dev/null
@@ -1,71 +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.impl.cloud;
-
-import java.util.Arrays;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.model.cloud.MultiServiceCallServiceDiscoveryConfiguration;
-import org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class MultiServiceDiscoveryTest extends ContextTestSupport {
- @Test
- public void testCachingServiceDiscovery() throws Exception {
- StaticServiceDiscovery discovery1 = new StaticServiceDiscovery();
- discovery1.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1111));
- discovery1.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1112));
-
- StaticServiceDiscovery discovery2 = new StaticServiceDiscovery();
- discovery2.addServer(new DefaultServiceDefinition("discovery1", "localhost", 1113));
- discovery2.addServer(new DefaultServiceDefinition("discovery2", "localhost", 1114));
-
- MultiServiceDiscovery discovery = MultiServiceDiscovery.wrap(discovery1, discovery2);
- Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
- Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
- }
-
- @Test
- public void testCachingServiceDiscoveryConfiguration() throws Exception {
- StaticServiceCallServiceDiscoveryConfiguration staticConf1 = new StaticServiceCallServiceDiscoveryConfiguration();
- staticConf1.setServers(Arrays.asList("discovery1@localhost:1111", "discovery1@localhost:1112"));
-
- StaticServiceCallServiceDiscoveryConfiguration staticConf2 = new StaticServiceCallServiceDiscoveryConfiguration();
- staticConf2.setServers(Arrays.asList("discovery1@localhost:1113", "discovery2@localhost:1114"));
-
- MultiServiceCallServiceDiscoveryConfiguration multiConf = new MultiServiceCallServiceDiscoveryConfiguration();
- multiConf.setServiceDiscoveryConfigurations(Arrays.asList(staticConf1, staticConf2));
-
- MultiServiceDiscovery discovery = (MultiServiceDiscovery)multiConf.newInstance(context);
- Assert.assertEquals(2, discovery.getDelegates().size());
- Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
- Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
- }
-
- @Test
- public void testCachingServiceDiscoveryConfigurationDsl() throws Exception {
- MultiServiceCallServiceDiscoveryConfiguration multiConf = new MultiServiceCallServiceDiscoveryConfiguration();
- multiConf.staticServiceDiscovery().setServers(Arrays.asList("discovery1@localhost:1111", "discovery1@localhost:1112"));
- multiConf.staticServiceDiscovery().setServers(Arrays.asList("discovery1@localhost:1113", "discovery2@localhost:1114"));
-
- MultiServiceDiscovery discovery = (MultiServiceDiscovery)multiConf.newInstance(context);
- Assert.assertEquals(2, discovery.getDelegates().size());
- Assert.assertEquals(3, discovery.getUpdatedListOfServices("discovery1").size());
- Assert.assertEquals(1, discovery.getUpdatedListOfServices("discovery2").size());
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancer.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancer.java b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancer.java
index eb23c1b..b08901d 100644
--- a/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancer.java
+++ b/components/camel-ribbon/src/main/java/org/apache/camel/component/ribbon/cloud/RibbonLoadBalancer.java
@@ -31,7 +31,6 @@ import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.PollingServerListUpdater;
import com.netflix.loadbalancer.RoundRobinRule;
import com.netflix.loadbalancer.ServerList;
-import com.netflix.loadbalancer.ServerListFilter;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
@@ -162,32 +161,40 @@ public class RibbonLoadBalancer
config,
configuration.getRuleOrDefault(RoundRobinRule::new),
configuration.getPingOrDefault(DummyPing::new),
- new RibbonServerList(serviceName, serviceDiscovery),
- new RibbonServerFilter(serviceFilter),
+ new RibbonServerList(serviceName, serviceDiscovery, serviceFilter),
+ null,
new PollingServerListUpdater(config));
}
static final class RibbonServerList implements ServerList<RibbonServiceDefinition> {
private final String serviceName;
private final ServiceDiscovery serviceDiscovery;
+ private final ServiceFilter serviceFilter;
- RibbonServerList(String serviceName, ServiceDiscovery serviceDiscovery) {
+ RibbonServerList(String serviceName, ServiceDiscovery serviceDiscovery, ServiceFilter serviceFilter) {
this.serviceName = serviceName;
this.serviceDiscovery = serviceDiscovery;
+ this.serviceFilter = serviceFilter;
}
@Override
public List<RibbonServiceDefinition> getInitialListOfServers() {
- return asRibbonServerList(
- serviceDiscovery.getInitialListOfServices(serviceName)
- );
+ List<ServiceDefinition> services = serviceDiscovery.getInitialListOfServices(serviceName);
+ if (serviceFilter != null) {
+ services = serviceFilter.apply(services);
+ }
+
+ return asRibbonServerList(services);
}
@Override
public List<RibbonServiceDefinition> getUpdatedListOfServers() {
- return asRibbonServerList(
- serviceDiscovery.getUpdatedListOfServices(serviceName)
- );
+ List<ServiceDefinition> services = serviceDiscovery.getUpdatedListOfServices(serviceName);
+ if (serviceFilter != null) {
+ services = serviceFilter.apply(services);
+ }
+
+ return asRibbonServerList(services);
}
private List<RibbonServiceDefinition> asRibbonServerList(List<ServiceDefinition> services) {
@@ -216,16 +223,4 @@ public class RibbonLoadBalancer
return ribbonServers;
}
}
-
- static final class RibbonServerFilter implements ServerListFilter<RibbonServiceDefinition> {
- private final ServiceFilter serviceFilter;
-
- RibbonServerFilter(ServiceFilter serviceFilter) {
- this.serviceFilter = serviceFilter;
- }
-
- public List<RibbonServiceDefinition> getFilteredListOfServers(List<RibbonServiceDefinition> servers) {
- return serviceFilter.apply(servers);
- }
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServerListTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServerListTest.java b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServerListTest.java
index fcc4f6b..f0d5dc3 100644
--- a/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServerListTest.java
+++ b/components/camel-ribbon/src/test/java/org/apache/camel/component/ribbon/cloud/RibbonServerListTest.java
@@ -17,15 +17,11 @@
package org.apache.camel.component.ribbon.cloud;
-import java.util.ArrayList;
-import java.util.List;
-
import com.netflix.loadbalancer.LoadBalancerBuilder;
import com.netflix.loadbalancer.RoundRobinRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
-import org.apache.camel.cloud.ServiceDefinition;
-import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.impl.cloud.PassThroughServiceFilter;
import org.apache.camel.impl.cloud.StaticServiceDiscovery;
import org.junit.Test;
@@ -34,14 +30,14 @@ import static org.junit.Assert.assertEquals;
public class RibbonServerListTest {
@Test
public void testFixedServerList() throws Exception {
- List<ServiceDefinition> servers = new ArrayList<>();
- servers.add(new RibbonServiceDefinition("unknown", "localhost", 9090));
- servers.add(new RibbonServiceDefinition("unknown", "localhost", 9091));
-
- ServiceDiscovery list = new StaticServiceDiscovery(servers);
-
ZoneAwareLoadBalancer<RibbonServiceDefinition> lb = LoadBalancerBuilder.<RibbonServiceDefinition>newBuilder()
- .withDynamicServerList(new RibbonLoadBalancer.RibbonServerList("unknown", list))
+ .withDynamicServerList(new RibbonLoadBalancer.RibbonServerList(
+ "unknown",
+ StaticServiceDiscovery.forServices(
+ new RibbonServiceDefinition("unknown", "localhost", 9090),
+ new RibbonServiceDefinition("unknown", "localhost", 9091)
+ ),
+ PassThroughServiceFilter.INSTANCE))
.withRule(new RoundRobinRule())
.buildDynamicServerListLoadBalancer();
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
index dd1124e..feeeb0d 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallConfigurationProperties.java
@@ -89,6 +89,7 @@ public class ServiceCallConfigurationProperties {
public static class ServiceFilter {
private boolean enabled = true;
+ private Map<String, String> blacklist = new HashMap<>();
public boolean isEnabled() {
return enabled;
@@ -97,6 +98,10 @@ public class ServiceCallConfigurationProperties {
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
+
+ public Map<String, String> getBlacklist() {
+ return blacklist;
+ }
}
public static class ServiceChooser {
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
index d97c7d1..cdcffc6 100644
--- a/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
+++ b/components/camel-spring-cloud/src/main/java/org/apache/camel/spring/cloud/ServiceCallServiceFilterAutoConfiguration.java
@@ -17,10 +17,14 @@
package org.apache.camel.spring.cloud;
+import java.util.Map;
+
import org.apache.camel.cloud.ServiceFilter;
-import org.apache.camel.impl.cloud.AllServiceFilter;
+import org.apache.camel.impl.cloud.BlacklistServiceFilter;
+import org.apache.camel.impl.cloud.ChainedServiceFilter;
import org.apache.camel.impl.cloud.HealthyServiceFilter;
import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.util.StringHelper;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
@@ -33,18 +37,24 @@ import org.springframework.context.annotation.Scope;
public class ServiceCallServiceFilterAutoConfiguration {
@Lazy
@Scope("prototype")
- @Bean(name = "service-filter-healthy")
+ @Bean(name = "service-filter-chained")
@Conditional(ServiceCallServiceFilterAutoConfiguration.ServiceFilterCondition.class)
- public ServiceFilter healthyServiceFilter() {
- return new HealthyServiceFilter();
- }
+ public ServiceFilter chainedServiceFilter(ServiceCallConfigurationProperties properties) {
+ BlacklistServiceFilter blacklist = new BlacklistServiceFilter();
- @Lazy
- @Scope("prototype")
- @Bean(name = "service-filter-all")
- @Conditional(ServiceCallServiceFilterAutoConfiguration.ServiceFilterCondition.class)
- public ServiceFilter allServiceFilter() {
- return new AllServiceFilter();
+ Map<String, String> services = properties.getServiceFilter().getBlacklist();
+ for (Map.Entry<String, String> entry : services.entrySet()) {
+
+ String[] parts = entry.getValue().split(",");
+ for (String part : parts) {
+ String host = StringHelper.before(part, ":");
+ String port = StringHelper.after(part, ":");
+
+ blacklist.addServer(entry.getKey(), host, Integer.parseInt(port));
+ }
+ }
+
+ return ChainedServiceFilter.wrap(new HealthyServiceFilter(), blacklist);
}
public static class ServiceFilterCondition extends GroupCondition {
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
index 5e26e74..c22b029 100644
--- a/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
+++ b/components/camel-spring-cloud/src/test/java/org/apache/camel/spring/cloud/CamelCloudServiceCallTest.java
@@ -42,7 +42,8 @@ import org.springframework.test.context.junit4.SpringRunner;
},
properties = {
"camel.cloud.servicecall.load-balancer.enabled=false",
- "camel.cloud.servicecall.service-discovery.services[custom-svc-list]=localhost:9090,localhost:9091",
+ "camel.cloud.servicecall.service-discovery.services[custom-svc-list]=localhost:9090,localhost:9091,localhost:9092",
+ "camel.cloud.servicecall.service-filter.blacklist[custom-svc-list]=localhost:9091",
"ribbon.enabled=false",
"debug=false"
}
@@ -54,7 +55,7 @@ public class CamelCloudServiceCallTest {
@Test
public void testServiceCall() throws Exception {
Assert.assertEquals("9090", template.requestBody("direct:start", null, String.class));
- Assert.assertEquals("9091", template.requestBody("direct:start", null, String.class));
+ Assert.assertEquals("9092", template.requestBody("direct:start", null, String.class));
}
// **************************
@@ -71,12 +72,16 @@ public class CamelCloudServiceCallTest {
from("direct:start")
.serviceCall()
.name("custom-svc-list/hello");
+
from("jetty:http://localhost:9090/hello")
.transform()
.constant("9090");
from("jetty:http://localhost:9091/hello")
.transform()
.constant("9091");
+ from("jetty:http://localhost:9092/hello")
+ .transform()
+ .constant("9092");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/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 97cac01..b1adfee 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
@@ -16,7 +16,10 @@
*/
package org.apache.camel.spring.cloud;
-import org.apache.camel.model.cloud.MultiServiceCallServiceDiscoveryConfiguration;
+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.HealthyServiceCallServiceFilterConfiguration;
import org.apache.camel.model.cloud.ServiceCallConfigurationDefinition;
import org.apache.camel.model.cloud.StaticServiceCallServiceDiscoveryConfiguration;
import org.apache.camel.spring.SpringCamelContext;
@@ -44,7 +47,7 @@ public class ServiceCallConfigurationTest {
assertNotNull("No ServiceCallConfiguration (2)", conf2);
assertNotNull("No ServiceDiscoveryConfiguration (2)", conf2.getServiceDiscoveryConfiguration());
- MultiServiceCallServiceDiscoveryConfiguration discovery2 = (MultiServiceCallServiceDiscoveryConfiguration)conf2.getServiceDiscoveryConfiguration();
+ ChainedServiceCallServiceDiscoveryConfiguration discovery2 = (ChainedServiceCallServiceDiscoveryConfiguration)conf2.getServiceDiscoveryConfiguration();
assertEquals(2, discovery2.getServiceDiscoveryConfigurations().size());
assertTrue(discovery2.getServiceDiscoveryConfigurations().get(0) instanceof StaticServiceCallServiceDiscoveryConfiguration);
assertTrue(discovery2.getServiceDiscoveryConfigurations().get(1) instanceof StaticServiceCallServiceDiscoveryConfiguration);
@@ -55,7 +58,12 @@ public class ServiceCallConfigurationTest {
StaticServiceCallServiceDiscoveryConfiguration sconf2 = (StaticServiceCallServiceDiscoveryConfiguration)discovery2.getServiceDiscoveryConfigurations().get(1);
assertEquals(1, sconf2.getServers().size());
- assertEquals("localhost:9093,localhost:9094", sconf2.getServers().get(0));
+ assertEquals("localhost:9093,localhost:9094,localhost:9095,localhost:9096", sconf2.getServers().get(0));
+
+ ChainedServiceCallServiceFilterConfiguration filter = (ChainedServiceCallServiceFilterConfiguration)conf2.getServiceFilterConfiguration();
+ assertEquals(2, filter.getServiceFilterConfigurations().size());
+ assertTrue(filter.getServiceFilterConfigurations().get(0) instanceof HealthyServiceCallServiceFilterConfiguration);
+ assertTrue(filter.getServiceFilterConfigurations().get(1) instanceof BlacklistServiceCallServiceFilterConfiguration);
}
protected SpringCamelContext createContext(String classpathConfigFile) {
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallFilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallFilterTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallFilterTest.java
new file mode 100644
index 0000000..442868b
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/cloud/ServiceCallFilterTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.spring.cloud;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.cloud.ServiceCallConstants;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
+
+@DirtiesContext
+public class ServiceCallFilterTest extends SpringTestSupport {
+ @Test
+ public void testServiceFilter() throws Exception {
+ Exchange result;
+
+ result = template.request("direct:start", emptyProcessor());
+ assertHeader(result, ServiceCallConstants.SERVICE_HOST, "host1");
+ assertHeader(result, ServiceCallConstants.SERVICE_PORT, 9093);
+
+ result = template.request("direct:start", emptyProcessor());
+ assertHeader(result, ServiceCallConstants.SERVICE_HOST, "host4");
+ assertHeader(result, ServiceCallConstants.SERVICE_PORT, 9094);
+ }
+
+ // *********************
+ // Helpers
+ // *********************
+
+ private void assertHeader(Exchange exchange, String header, Object expectedValue) {
+ Assert.assertNotNull(exchange);
+ Assert.assertTrue(exchange.getIn().getHeaders().containsKey(header));
+ Assert.assertEquals(expectedValue, exchange.getIn().getHeader(header));
+ }
+
+ private Processor emptyProcessor() {
+ return e -> {
+ return;
+ };
+ }
+
+ // *********************
+ // Application Context
+ // *********************
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/cloud/ServiceCallFilterTest.xml");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/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 d54348c..2ad4e54 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
@@ -32,14 +32,20 @@
</serviceCallConfiguration>
<serviceCallConfiguration id="conf2">
- <multiServiceDiscovery>
+ <chainedServiceDiscovery>
<staticServiceDiscovery>
<servers>localhost:9092</servers>
</staticServiceDiscovery>
<staticServiceDiscovery>
- <servers>localhost:9093,localhost:9094</servers>
+ <servers>localhost:9093,localhost:9094,localhost:9095,localhost:9096</servers>
</staticServiceDiscovery>
- </multiServiceDiscovery>
+ </chainedServiceDiscovery>
+ <chainedServiceFilter>
+ <healthyServiceFilter/>
+ <blacklistServiceFilter>
+ <servers>localhost:9095,localhost:9096</servers>
+ </blacklistServiceFilter>
+ </chainedServiceFilter>
</serviceCallConfiguration>
<route id="test1">
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallFilterTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallFilterTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallFilterTest.xml
new file mode 100644
index 0000000..1e4fe80
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/cloud/ServiceCallFilterTest.xml
@@ -0,0 +1,53 @@
+<?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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring
+ http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <interceptSendToEndpoint uri="file:*" skipSendToOriginalEndpoint="true">
+ <to uri="mock:result"/>
+ </interceptSendToEndpoint>
+
+ <route id="test">
+ <from uri="direct:start"/>
+ <serviceCall name="test" component="file">
+
+ <staticServiceDiscovery>
+ <servers>test@host1:9093</servers>
+ <servers>test@host2:9093</servers>
+ <servers>unknown@host1:9094</servers>
+ <servers>test@host3:9093</servers>
+ <servers>test@host4:9094</servers>
+ </staticServiceDiscovery>
+
+ <blacklistServiceFilter>
+ <servers>test@host2:9093</servers>
+ <servers>test@host3:9093</servers>
+ </blacklistServiceFilter>
+ </serviceCall>
+
+ </route>
+ </camelContext>
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.java
new file mode 100644
index 0000000..5c2a505
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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.test.blueprint.cloud;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.cloud.ServiceCallConstants;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ServiceCallFilterTest extends CamelBlueprintTestSupport {
+ @Test
+ public void testServiceFilter() throws Exception {
+ Exchange result;
+
+ result = template.request("direct:start", e -> { return; } );
+ assertHeader(result, ServiceCallConstants.SERVICE_HOST, "host1");
+ assertHeader(result, ServiceCallConstants.SERVICE_PORT, 9093);
+
+ result = template.request("direct:start", e -> { return; } );
+ assertHeader(result, ServiceCallConstants.SERVICE_HOST, "host4");
+ assertHeader(result, ServiceCallConstants.SERVICE_PORT, 9094);
+ }
+
+ // *********************
+ // Helpers
+ // *********************
+
+ private void assertHeader(Exchange exchange, String header, Object expectedValue) {
+ Assert.assertNotNull(exchange);
+ Assert.assertTrue(exchange.getIn().getHeaders().containsKey(header));
+ Assert.assertEquals(expectedValue, exchange.getIn().getHeader(header));
+ }
+
+ // *********************
+ // Blueprint
+ // *********************
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.xml";
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.xml
new file mode 100644
index 0000000..d3eb9b5
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/cloud/ServiceCallFilterTest.xml
@@ -0,0 +1,52 @@
+<?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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0
+ https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <interceptSendToEndpoint uri="file:*" skipSendToOriginalEndpoint="true">
+ <to uri="mock:result"/>
+ </interceptSendToEndpoint>
+
+ <route id="test">
+ <from uri="direct:start"/>
+ <serviceCall name="test" component="file">
+
+ <staticServiceDiscovery>
+ <servers>test@host1:9093</servers>
+ <servers>test@host2:9093</servers>
+ <servers>unknown@host1:9094</servers>
+ <servers>test@host3:9093</servers>
+ <servers>test@host4:9094</servers>
+ </staticServiceDiscovery>
+
+ <blacklistServiceFilter>
+ <servers>test@host2:9093</servers>
+ <servers>test@host3:9093</servers>
+ </blacklistServiceFilter>
+ </serviceCall>
+
+ </route>
+
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
[2/2] camel git commit: CAMEL-10761: ServiceCall EIP : support for
chaining service filters/discovery
Posted by lb...@apache.org.
CAMEL-10761: ServiceCall EIP : support for chaining service filters/discovery
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0aae1257
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0aae1257
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0aae1257
Branch: refs/heads/master
Commit: 0aae1257b4317504a717ff490ce827a686ac8edb
Parents: 9c6263d
Author: lburgazzoli <lb...@gmail.com>
Authored: Fri Jan 27 11:16:29 2017 +0100
Committer: lburgazzoli <lb...@gmail.com>
Committed: Mon Jan 30 19:34:31 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/cloud/ServiceFilter.java | 2 +-
.../camel/impl/cloud/AllServiceFilter.java | 32 ----
.../impl/cloud/BlacklistServiceFilter.java | 133 +++++++++++++++
.../cloud/BlacklistServiceFilterFactory.java | 57 +++++++
.../impl/cloud/CachingServiceDiscovery.java | 39 ++---
.../impl/cloud/ChainedServiceDiscovery.java | 59 +++++++
.../cloud/ChainedServiceDiscoveryFactory.java | 54 ++++++
.../camel/impl/cloud/ChainedServiceFilter.java | 57 +++++++
.../impl/cloud/ChainedServiceFilterFactory.java | 54 ++++++
.../impl/cloud/DefaultServiceDefinition.java | 26 +++
.../camel/impl/cloud/DefaultServiceFilter.java | 2 +-
.../camel/impl/cloud/HealthyServiceFilter.java | 2 +-
.../impl/cloud/HealthyServiceFilterFactory.java | 35 ++++
.../camel/impl/cloud/MultiServiceDiscovery.java | 59 -------
.../cloud/MultiServiceDiscoveryFactory.java | 54 ------
.../impl/cloud/PassThroughServiceFilter.java | 32 ++++
.../cloud/PassThroughServiceFilterFactory.java | 35 ++++
.../impl/cloud/StaticServiceDiscovery.java | 44 +++--
...stServiceCallServiceFilterConfiguration.java | 87 ++++++++++
...erviceCallServiceDiscoveryConfiguration.java | 6 +-
...erviceCallServiceDiscoveryConfiguration.java | 169 +++++++++++++++++++
...edServiceCallServiceFilterConfiguration.java | 138 +++++++++++++++
...omServiceCallServiceFilterConfiguration.java | 106 ++++++++++++
...hyServiceCallServiceFilterConfiguration.java | 36 ++++
...erviceCallServiceDiscoveryConfiguration.java | 169 -------------------
...ghServiceCallServiceFilterConfiguration.java | 36 ++++
.../ServiceCallConfigurationDefinition.java | 77 ++++++++-
.../camel/model/cloud/ServiceCallConstants.java | 12 +-
.../model/cloud/ServiceCallDefinition.java | 116 +++++++++++--
.../apache/camel/cloud/blacklist-service-filter | 17 ++
.../camel/cloud/chained-service-discovery | 17 ++
.../apache/camel/cloud/chained-service-filter | 17 ++
.../apache/camel/cloud/healthy-service-filter | 17 ++
.../apache/camel/cloud/multi-service-discovery | 17 --
.../camel/cloud/pass-through-service-filter | 17 ++
.../org/apache/camel/model/cloud/jaxb.index | 6 +-
.../impl/cloud/ChainedServiceDiscoveryTest.java | 71 ++++++++
.../impl/cloud/ChainedServiceFilterTest.java | 66 ++++++++
.../camel/impl/cloud/LoadBalancerTest.java | 42 +++++
.../impl/cloud/MultiServiceDiscoveryTest.java | 71 --------
.../ribbon/cloud/RibbonLoadBalancer.java | 39 ++---
.../ribbon/cloud/RibbonServerListTest.java | 20 +--
.../ServiceCallConfigurationProperties.java | 5 +
...rviceCallServiceFilterAutoConfiguration.java | 32 ++--
.../spring/cloud/CamelCloudServiceCallTest.java | 9 +-
.../cloud/ServiceCallConfigurationTest.java | 14 +-
.../spring/cloud/ServiceCallFilterTest.java | 69 ++++++++
.../cloud/ServiceCallConfigurationTest.xml | 12 +-
.../spring/cloud/ServiceCallFilterTest.xml | 53 ++++++
.../blueprint/cloud/ServiceCallFilterTest.java | 58 +++++++
.../blueprint/cloud/ServiceCallFilterTest.xml | 52 ++++++
51 files changed, 1929 insertions(+), 520 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/cloud/ServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/cloud/ServiceFilter.java b/camel-core/src/main/java/org/apache/camel/cloud/ServiceFilter.java
index a8d61b3..99c697a 100644
--- a/camel-core/src/main/java/org/apache/camel/cloud/ServiceFilter.java
+++ b/camel-core/src/main/java/org/apache/camel/cloud/ServiceFilter.java
@@ -31,5 +31,5 @@ public interface ServiceFilter {
* @param services list of services
* @return the chosen service to use.
*/
- <T extends ServiceDefinition> List<T> apply(List<T> services);
+ List<ServiceDefinition> apply(List<ServiceDefinition> services);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/AllServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/AllServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/AllServiceFilter.java
deleted file mode 100644
index 0635b33..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/AllServiceFilter.java
+++ /dev/null
@@ -1,32 +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.impl.cloud;
-
-import java.util.List;
-
-import org.apache.camel.cloud.ServiceDefinition;
-import org.apache.camel.cloud.ServiceFilter;
-
-public class AllServiceFilter implements ServiceFilter {
- public static final ServiceFilter INSTANCE = new AllServiceFilter();
-
- @Override
- public <T extends ServiceDefinition> List<T> apply(List<T> services) {
- return services;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilter.java
new file mode 100644
index 0000000..44edb3d
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilter.java
@@ -0,0 +1,133 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.util.StringHelper;
+
+public class BlacklistServiceFilter implements ServiceFilter {
+ private List<ServiceDefinition> services;
+
+ public BlacklistServiceFilter() {
+ this.services = new ArrayList<>();
+ }
+
+ public BlacklistServiceFilter(List<ServiceDefinition> blacklist) {
+ this.services = new ArrayList<>(blacklist);
+ }
+
+ /**
+ * Set the servers.
+ *
+ * @param servers server in the format: [service@]host:port.
+ */
+ public void setServers(List<String> servers) {
+ this.services.clear();
+ servers.forEach(this::addServer);
+ }
+
+ /**
+ * Set the servers.
+ *
+ * @param servers servers separated by comma in the format: [service@]host:port,[service@]host2:port,[service@]host3:port and so on.
+ */
+ public void setServers(String servers) {
+ this.services.clear();
+ addServer(servers);
+ }
+
+ /**
+ * Add a server to the known list of servers.
+ */
+ public void addServer(ServiceDefinition server) {
+ services.add(server);
+ }
+
+ /**
+ * Add a server to the known list of servers.
+ * @param serverString servers separated by comma in the format: [service@]host:port,[service@]host2:port,[service@]host3:port and so on.
+ */
+ public void addServer(String serverString) {
+ String[] parts = serverString.split(",");
+ for (String part : parts) {
+ String service = StringHelper.before(part, "@");
+ if (service != null) {
+ part = StringHelper.after(part, "@");
+ }
+ String host = StringHelper.before(part, ":");
+ String port = StringHelper.after(part, ":");
+
+ addServer(service, host, Integer.valueOf(port));
+ }
+ }
+
+ /**
+ * Add a server to the known list of servers.
+ */
+ public void addServer(String host, int port) {
+ addServer(null, host, port, null);
+ }
+
+ /**
+ * Add a server to the known list of servers.
+ */
+ public void addServer(String name, String host, int port) {
+ addServer(name, host, port, null);
+ }
+
+ /**
+ * Add a server to the known list of servers.
+ */
+ public void addServer(String name, String host, int port, Map<String, String> meta) {
+ services.add(new DefaultServiceDefinition(name, host, port, meta));
+ }
+
+ @Override
+ public List<ServiceDefinition> apply(List<ServiceDefinition> services) {
+ return services.stream().filter(s -> !this.services.contains(s)).collect(Collectors.toList());
+ }
+
+ // *************************************************************************
+ // Helpers
+ // *************************************************************************
+
+ public static BlacklistServiceFilter forServices(Collection<ServiceDefinition> definitions) {
+ BlacklistServiceFilter filter = new BlacklistServiceFilter();
+ for (ServiceDefinition definition: definitions) {
+ filter.addServer(definition);
+ }
+
+ return filter;
+ }
+
+ public static BlacklistServiceFilter forServices(ServiceDefinition... definitions) {
+ BlacklistServiceFilter filter = new BlacklistServiceFilter();
+ for (ServiceDefinition definition: definitions) {
+ filter.addServer(definition);
+ }
+
+ return filter;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilterFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilterFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilterFactory.java
new file mode 100644
index 0000000..5563fa3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/BlacklistServiceFilterFactory.java
@@ -0,0 +1,57 @@
+/**
+ * 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 java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.cloud.ServiceFilterFactory;
+
+public class BlacklistServiceFilterFactory implements ServiceFilterFactory {
+ private List<String> servers;
+
+ public BlacklistServiceFilterFactory() {
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<String> getServers() {
+ return servers;
+ }
+
+ public void setServers(List<String> servers) {
+ this.servers = servers;
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
+ BlacklistServiceFilter serviceFilter = new BlacklistServiceFilter();
+ if (servers != null) {
+ serviceFilter.setServers(servers);
+ }
+
+ return serviceFilter;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/CachingServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/CachingServiceDiscovery.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/CachingServiceDiscovery.java
index 56ee5fb..99923e9 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/CachingServiceDiscovery.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/CachingServiceDiscovery.java
@@ -17,30 +17,31 @@
package org.apache.camel.impl.cloud;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
import org.apache.camel.cloud.ServiceDefinition;
import org.apache.camel.cloud.ServiceDiscovery;
import org.apache.camel.util.ObjectHelper;
-public class CachingServiceDiscovery implements ServiceDiscovery {
+public final class CachingServiceDiscovery implements ServiceDiscovery {
private final ServiceDiscovery delegate;
- private List<ServiceDefinition> services;
- private long lastUpdate;
+ private LoadingCache<String, List<ServiceDefinition>> cache;
private long timeout;
public CachingServiceDiscovery(ServiceDiscovery delegate) {
this(delegate, 60 * 1000);
}
+ public CachingServiceDiscovery(ServiceDiscovery delegate, long timeout, TimeUnit unit) {
+ this(delegate, unit.toMillis(timeout));
+ }
+
public CachingServiceDiscovery(ServiceDiscovery delegate, long timeout) {
this.delegate = ObjectHelper.notNull(delegate, "delegate");
- this.lastUpdate = 0;
- this.services = Collections.emptyList();
- this.timeout = timeout;
+ setTimeout(timeout);
}
public ServiceDiscovery getDelegate() {
@@ -49,10 +50,13 @@ public class CachingServiceDiscovery implements ServiceDiscovery {
public void setTimeout(long timeout) {
this.timeout = timeout;
+ this.cache = Caffeine.newBuilder()
+ .expireAfterAccess(timeout, TimeUnit.MILLISECONDS)
+ .build(delegate::getUpdatedListOfServices);
}
public void setTimeout(long timeout, TimeUnit unit) {
- this.timeout = unit.toMillis(timeout);
+ setTimeout(unit.toMillis(timeout));
}
public long getTimeout() {
@@ -76,22 +80,7 @@ public class CachingServiceDiscovery implements ServiceDiscovery {
@Override
public List<ServiceDefinition> getUpdatedListOfServices(String name) {
- long now = System.currentTimeMillis();
-
- if (lastUpdate == 0 || now > lastUpdate + timeout) {
- List<ServiceDefinition> updatedList = delegate.getUpdatedListOfServices(name);
- if (updatedList.isEmpty()) {
- services = Collections.emptyList();
- } else {
- // List is copied as the delegated ServiceCallServiceDiscovery
- // may update the list
- services = Collections.unmodifiableList(new ArrayList<>(updatedList));
- }
-
- lastUpdate = now;
- }
-
- return services;
+ return cache.get(name);
}
// **********************
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscovery.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscovery.java
new file mode 100644
index 0000000..a00fe5b
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscovery.java
@@ -0,0 +1,59 @@
+/**
+ * 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 java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.cloud.ServiceDiscovery;
+
+public class ChainedServiceDiscovery implements ServiceDiscovery {
+ private final List<ServiceDiscovery> delegates;
+
+ public ChainedServiceDiscovery(List<ServiceDiscovery> delegates) {
+ this.delegates = Collections.unmodifiableList(delegates);
+ }
+
+ public List<ServiceDiscovery> getDelegates() {
+ return this.delegates;
+ }
+
+ @Override
+ public List<ServiceDefinition> getInitialListOfServices(String name) {
+ return delegates.stream()
+ .flatMap(d -> d.getInitialListOfServices(name).stream())
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<ServiceDefinition> getUpdatedListOfServices(String name) {
+ return delegates.stream()
+ .flatMap(d -> d.getInitialListOfServices(name).stream())
+ .collect(Collectors.toList());
+ }
+
+ // **********************
+ // Helpers
+ // **********************
+
+ public static ChainedServiceDiscovery wrap(ServiceDiscovery... delegates) {
+ return new ChainedServiceDiscovery(Arrays.asList(delegates));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryFactory.java
new file mode 100644
index 0000000..6c8acc8
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceDiscoveryFactory.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.impl.cloud;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.cloud.ServiceDiscoveryFactory;
+import org.apache.camel.util.ObjectHelper;
+
+public class ChainedServiceDiscoveryFactory implements ServiceDiscoveryFactory {
+ private List<ServiceDiscovery> serviceDiscoveryList;
+
+ public ChainedServiceDiscoveryFactory() {
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<ServiceDiscovery> getServiceDiscoveryList() {
+ return serviceDiscoveryList;
+ }
+
+ public void setServiceDiscoveryList(List<ServiceDiscovery> serviceDiscoveryList) {
+ this.serviceDiscoveryList = serviceDiscoveryList;
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceDiscovery newInstance(CamelContext camelContext) throws Exception {
+ ObjectHelper.notNull(serviceDiscoveryList, "ServiceDiscovery list");
+
+ return new ChainedServiceDiscovery(serviceDiscoveryList);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilter.java
new file mode 100644
index 0000000..caeebbc
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilter.java
@@ -0,0 +1,57 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.cloud.ServiceFilter;
+
+public class ChainedServiceFilter implements ServiceFilter {
+ private final List<ServiceFilter> delegates;
+ private final int delegatesSize;
+
+ public ChainedServiceFilter(List<ServiceFilter> delegates) {
+ this.delegates = Collections.unmodifiableList(new ArrayList<>(delegates));
+ this.delegatesSize = this.delegates.size();
+ }
+
+ public List<ServiceFilter> getDelegates() {
+ return this.delegates;
+ }
+
+
+ @Override
+ public List<ServiceDefinition> apply(List<ServiceDefinition> services) {
+ for (int i = 0; i < delegatesSize; i++) {
+ services = delegates.get(i).apply(services);
+ }
+
+ return services;
+ }
+
+ // **********************
+ // Helpers
+ // **********************
+
+ public static ChainedServiceFilter wrap(ServiceFilter... delegates) {
+ return new ChainedServiceFilter(Arrays.asList(delegates));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilterFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilterFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilterFactory.java
new file mode 100644
index 0000000..15c9af7
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/ChainedServiceFilterFactory.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.impl.cloud;
+
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.cloud.ServiceFilterFactory;
+import org.apache.camel.util.ObjectHelper;
+
+public class ChainedServiceFilterFactory implements ServiceFilterFactory {
+ private List<ServiceFilter> serviceFilterList;
+
+ public ChainedServiceFilterFactory() {
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<ServiceFilter> getServiceFilterList() {
+ return serviceFilterList;
+ }
+
+ public void setServiceFilterList(List<ServiceFilter> serviceFilterList) {
+ this.serviceFilterList = serviceFilterList;
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
+ ObjectHelper.notNull(serviceFilterList, "ServiceFilter list");
+
+ return new ChainedServiceFilter(serviceFilterList);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceDefinition.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceDefinition.java
index d510847..5e72a7b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceDefinition.java
@@ -94,5 +94,31 @@ public class DefaultServiceDefinition implements ServiceDefinition {
return "DefaultServiceCallService[" + name + "@" + host + ":" + port + "]";
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ DefaultServiceDefinition that = (DefaultServiceDefinition) o;
+
+ if (port != that.port) {
+ return false;
+ }
+ if (name != null ? !name.equals(that.name) : that.name != null) {
+ return false;
+ }
+ return host != null ? host.equals(that.host) : that.host == null;
+ }
+ @Override
+ public int hashCode() {
+ int result = name != null ? name.hashCode() : 0;
+ result = 31 * result + (host != null ? host.hashCode() : 0);
+ result = 31 * result + port;
+ return result;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceFilter.java
index 2b58032..1fd6ee6 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceFilter.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/DefaultServiceFilter.java
@@ -24,7 +24,7 @@ import org.apache.camel.cloud.ServiceFilter;
public class DefaultServiceFilter implements ServiceFilter {
@Override
- public <T extends ServiceDefinition> List<T> apply(List<T> services) {
+ public List<ServiceDefinition> apply(List<ServiceDefinition> services) {
return services;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilter.java
index deb55ae..26c5795 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilter.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilter.java
@@ -27,7 +27,7 @@ public class HealthyServiceFilter implements ServiceFilter {
public static final ServiceFilter INSTANCE = new HealthyServiceFilter();
@Override
- public <T extends ServiceDefinition> List<T> apply(List<T> services) {
+ public List<ServiceDefinition> apply(List<ServiceDefinition> services) {
return services.stream().filter(s -> s.getHealth().isHealthy()).collect(Collectors.toList());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilterFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilterFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilterFactory.java
new file mode 100644
index 0000000..2bde718
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/HealthyServiceFilterFactory.java
@@ -0,0 +1,35 @@
+/**
+ * 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.ServiceFilter;
+import org.apache.camel.cloud.ServiceFilterFactory;
+
+public class HealthyServiceFilterFactory implements ServiceFilterFactory {
+ public HealthyServiceFilterFactory() {
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
+ return new HealthyServiceFilter();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscovery.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscovery.java
deleted file mode 100644
index 44ea721..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscovery.java
+++ /dev/null
@@ -1,59 +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.impl.cloud;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.apache.camel.cloud.ServiceDefinition;
-import org.apache.camel.cloud.ServiceDiscovery;
-
-public class MultiServiceDiscovery implements ServiceDiscovery {
- private final List<ServiceDiscovery> delegates;
-
- public MultiServiceDiscovery(List<ServiceDiscovery> delegates) {
- this.delegates = Collections.unmodifiableList(delegates);
- }
-
- public List<ServiceDiscovery> getDelegates() {
- return this.delegates;
- }
-
- @Override
- public List<ServiceDefinition> getInitialListOfServices(String name) {
- return delegates.stream()
- .flatMap(d -> d.getInitialListOfServices(name).stream())
- .collect(Collectors.toList());
- }
-
- @Override
- public List<ServiceDefinition> getUpdatedListOfServices(String name) {
- return delegates.stream()
- .flatMap(d -> d.getInitialListOfServices(name).stream())
- .collect(Collectors.toList());
- }
-
- // **********************
- // Helpers
- // **********************
-
- public static MultiServiceDiscovery wrap(ServiceDiscovery... delegates) {
- return new MultiServiceDiscovery(Arrays.asList(delegates));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryFactory.java
deleted file mode 100644
index 61dcd76..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/MultiServiceDiscoveryFactory.java
+++ /dev/null
@@ -1,54 +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.impl.cloud;
-
-import java.util.List;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.cloud.ServiceDiscoveryFactory;
-import org.apache.camel.util.ObjectHelper;
-
-public class MultiServiceDiscoveryFactory implements ServiceDiscoveryFactory {
- private List<ServiceDiscovery> serviceDiscoveryList;
-
- public MultiServiceDiscoveryFactory() {
- }
-
- // *************************************************************************
- // Properties
- // *************************************************************************
-
- public List<ServiceDiscovery> getServiceDiscoveryList() {
- return serviceDiscoveryList;
- }
-
- public void setServiceDiscoveryList(List<ServiceDiscovery> serviceDiscoveryList) {
- this.serviceDiscoveryList = serviceDiscoveryList;
- }
-
- // *************************************************************************
- // Factory
- // *************************************************************************
-
- @Override
- public ServiceDiscovery newInstance(CamelContext camelContext) throws Exception {
- ObjectHelper.notNull(serviceDiscoveryList, "ServiceDiscovery list");
-
- return new MultiServiceDiscovery(serviceDiscoveryList);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilter.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilter.java
new file mode 100644
index 0000000..2b80a7c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilter.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 java.util.List;
+
+import org.apache.camel.cloud.ServiceDefinition;
+import org.apache.camel.cloud.ServiceFilter;
+
+public class PassThroughServiceFilter implements ServiceFilter {
+ public static final ServiceFilter INSTANCE = new PassThroughServiceFilter();
+
+ @Override
+ public List<ServiceDefinition> apply(List<ServiceDefinition> services) {
+ return services;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilterFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilterFactory.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilterFactory.java
new file mode 100644
index 0000000..86468c6
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/PassThroughServiceFilterFactory.java
@@ -0,0 +1,35 @@
+/**
+ * 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.ServiceFilter;
+import org.apache.camel.cloud.ServiceFilterFactory;
+
+public class PassThroughServiceFilterFactory implements ServiceFilterFactory {
+ public PassThroughServiceFilterFactory() {
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
+ return new PassThroughServiceFilter();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java b/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
index 49d3094..1507b24 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/cloud/StaticServiceDiscovery.java
@@ -18,6 +18,7 @@
package org.apache.camel.impl.cloud;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -31,15 +32,14 @@ import org.apache.camel.util.StringHelper;
* A static list of known servers Camel Service Call EIP.
*/
public class StaticServiceDiscovery extends DefaultServiceDiscovery {
-
- private final List<ServiceDefinition> servers;
+ private final List<ServiceDefinition> services;
public StaticServiceDiscovery() {
- this.servers = new ArrayList<>();
+ this.services = new ArrayList<>();
}
public StaticServiceDiscovery(List<ServiceDefinition> servers) {
- this.servers = new ArrayList<>(servers);
+ this.services = new ArrayList<>(servers);
}
/**
@@ -48,7 +48,7 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
* @param servers server in the format: [service@]host:port.
*/
public void setServers(List<String> servers) {
- this.servers.clear();
+ this.services.clear();
servers.forEach(this::addServer);
}
@@ -58,7 +58,7 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
* @param servers servers separated by comma in the format: [service@]host:port,[service@]host2:port,[service@]host3:port and so on.
*/
public void setServers(String servers) {
- this.servers.clear();
+ this.services.clear();
addServer(servers);
}
@@ -66,7 +66,7 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
* Add a server to the known list of servers.
*/
public void addServer(ServiceDefinition server) {
- servers.add(server);
+ services.add(server);
}
/**
@@ -105,14 +105,14 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
* Add a server to the known list of servers.
*/
public void addServer(String name, String host, int port, Map<String, String> meta) {
- servers.add(new DefaultServiceDefinition(name, host, port, meta));
+ services.add(new DefaultServiceDefinition(name, host, port, meta));
}
/**
* Remove an existing server from the list of known servers.
*/
public void removeServer(String host, int port) {
- servers.removeIf(
+ services.removeIf(
s -> Objects.equals(host, s.getHost()) && port == s.getPort()
);
}
@@ -121,7 +121,7 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
* Remove an existing server from the list of known servers.
*/
public void removeServer(String name, String host, int port) {
- servers.removeIf(
+ services.removeIf(
s -> Objects.equals(name, s.getName()) && Objects.equals(host, s.getHost()) && port == s.getPort()
);
}
@@ -129,9 +129,31 @@ public class StaticServiceDiscovery extends DefaultServiceDiscovery {
@Override
public List<ServiceDefinition> getUpdatedListOfServices(String name) {
return Collections.unmodifiableList(
- servers.stream()
+ services.stream()
.filter(s -> Objects.isNull(s.getName()) || Objects.equals(name, s.getName()))
.collect(Collectors.toList())
);
}
+
+ // *************************************************************************
+ // Helpers
+ // *************************************************************************
+
+ public static StaticServiceDiscovery forServices(Collection<ServiceDefinition> definitions) {
+ StaticServiceDiscovery discovery = new StaticServiceDiscovery();
+ for (ServiceDefinition definition: definitions) {
+ discovery.addServer(definition);
+ }
+
+ return discovery;
+ }
+
+ public static StaticServiceDiscovery forServices(ServiceDefinition... definitions) {
+ StaticServiceDiscovery discovery = new StaticServiceDiscovery();
+ for (ServiceDefinition definition: definitions) {
+ discovery.addServer(definition);
+ }
+
+ return discovery;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/BlacklistServiceCallServiceFilterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/BlacklistServiceCallServiceFilterConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/BlacklistServiceCallServiceFilterConfiguration.java
new file mode 100644
index 0000000..ea67c25
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/BlacklistServiceCallServiceFilterConfiguration.java
@@ -0,0 +1,87 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "routing,cloud,service-filter")
+@XmlRootElement(name = "blacklistServiceFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class BlacklistServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
+ @XmlElement
+ private List<String> servers;
+
+ public BlacklistServiceCallServiceFilterConfiguration() {
+ this(null);
+ }
+
+ public BlacklistServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
+ super(parent, "blacklist-service-filter");
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<String> getServers() {
+ return servers;
+ }
+
+ /**
+ * Sets the server list;
+ */
+ public void setServers(List<String> servers) {
+ this.servers = servers;
+ }
+
+ /**
+ * Sets the server list;
+ */
+ public void addServer(String server) {
+ if (this.servers == null) {
+ this.servers = new ArrayList<>();
+ }
+
+ this.servers.add(server);
+ }
+
+ // *************************************************************************
+ // Fluent API
+ // *************************************************************************
+
+ /**
+ * Sets the server list;
+ */
+ public BlacklistServiceCallServiceFilterConfiguration servers(List<String> servers) {
+ setServers(servers);
+ return this;
+ }
+ /**
+ * Add a server to the list of servers
+ */
+ public BlacklistServiceCallServiceFilterConfiguration server(String server) {
+ addServer(server);
+ return this;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/CachingServiceCallServiceDiscoveryConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/CachingServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/CachingServiceCallServiceDiscoveryConfiguration.java
index 5c1682b..9b7ee98 100644
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/CachingServiceCallServiceDiscoveryConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/CachingServiceCallServiceDiscoveryConfiguration.java
@@ -45,7 +45,7 @@ public class CachingServiceCallServiceDiscoveryConfiguration extends ServiceCall
@XmlElement(name = "dnsServiceDiscovery", type = DnsServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "etcdServiceDiscovery", type = EtcdServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "kubernetesServiceDiscovery", type = KubernetesServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "multiServiceDiscovery", type = MultiServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "multiServiceDiscovery", type = ChainedServiceCallServiceDiscoveryConfiguration.class),
@XmlElement(name = "staticServiceDiscovery", type = StaticServiceCallServiceDiscoveryConfiguration.class)}
)
private ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration;
@@ -163,8 +163,8 @@ public class CachingServiceCallServiceDiscoveryConfiguration extends ServiceCall
return conf;
}
- public MultiServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
- MultiServiceCallServiceDiscoveryConfiguration conf = new MultiServiceCallServiceDiscoveryConfiguration();
+ public ChainedServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
+ ChainedServiceCallServiceDiscoveryConfiguration conf = new ChainedServiceCallServiceDiscoveryConfiguration();
setServiceDiscoveryConfiguration(conf);
return conf;
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceDiscoveryConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceDiscoveryConfiguration.java
new file mode 100644
index 0000000..5197d0e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceDiscoveryConfiguration.java
@@ -0,0 +1,169 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceDiscovery;
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "routing,cloud,service-discovery")
+@XmlRootElement(name = "multiServiceDiscovery")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ChainedServiceCallServiceDiscoveryConfiguration extends ServiceCallServiceDiscoveryConfiguration {
+ @XmlElements({
+ @XmlElement(name = "consulServiceDiscovery", type = ConsulServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "dnsServiceDiscovery", type = DnsServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "etcdServiceDiscovery", type = EtcdServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "kubernetesServiceDiscovery", type = KubernetesServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "staticServiceDiscovery", type = StaticServiceCallServiceDiscoveryConfiguration.class),
+ @XmlElement(name = "cachingServiceDiscovery", type = CachingServiceCallServiceDiscoveryConfiguration.class)}
+ )
+ private List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations;
+
+ public ChainedServiceCallServiceDiscoveryConfiguration() {
+ this(null);
+ }
+
+ public ChainedServiceCallServiceDiscoveryConfiguration(ServiceCallDefinition parent) {
+ super(parent, "chained-service-discovery");
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<ServiceCallServiceDiscoveryConfiguration> getServiceDiscoveryConfigurations() {
+ return serviceDiscoveryConfigurations;
+ }
+
+ /**
+ * List of ServiceDiscovery configuration to use
+ * @param serviceDiscoveryConfigurations
+ */
+ public void setServiceDiscoveryConfigurations(List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations) {
+ this.serviceDiscoveryConfigurations = serviceDiscoveryConfigurations;
+ }
+
+ /**
+ * Add a ServiceDiscovery configuration
+ */
+ public void addServiceDiscoveryConfigurations(ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration) {
+ if (serviceDiscoveryConfigurations == null) {
+ serviceDiscoveryConfigurations = new ArrayList<>();
+ }
+
+ serviceDiscoveryConfigurations.add(serviceDiscoveryConfiguration);
+ }
+
+ // *************************************************************************
+ // Fluent API
+ // *************************************************************************
+
+ /**
+ * List of ServiceDiscovery configuration to use
+ */
+ public ChainedServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfigurations(List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations) {
+ setServiceDiscoveryConfigurations(serviceDiscoveryConfigurations);
+ return this;
+ }
+
+ /**
+ * Add a ServiceDiscovery configuration
+ */
+ public ChainedServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration(ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration) {
+ addServiceDiscoveryConfigurations(serviceDiscoveryConfiguration);
+ return this;
+ }
+
+ // *****************************
+ // Shortcuts - ServiceDiscovery
+ // *****************************
+
+ public CachingServiceCallServiceDiscoveryConfiguration cachingServiceDiscovery() {
+ CachingServiceCallServiceDiscoveryConfiguration conf = new CachingServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public ConsulServiceCallServiceDiscoveryConfiguration consulServiceDiscovery() {
+ ConsulServiceCallServiceDiscoveryConfiguration conf = new ConsulServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public DnsServiceCallServiceDiscoveryConfiguration dnsServiceDiscovery() {
+ DnsServiceCallServiceDiscoveryConfiguration conf = new DnsServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public EtcdServiceCallServiceDiscoveryConfiguration etcdServiceDiscovery() {
+ EtcdServiceCallServiceDiscoveryConfiguration conf = new EtcdServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public KubernetesServiceCallServiceDiscoveryConfiguration kubernetesServiceDiscovery() {
+ KubernetesServiceCallServiceDiscoveryConfiguration conf = new KubernetesServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public ChainedServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
+ ChainedServiceCallServiceDiscoveryConfiguration conf = new ChainedServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ public StaticServiceCallServiceDiscoveryConfiguration staticServiceDiscovery() {
+ StaticServiceCallServiceDiscoveryConfiguration conf = new StaticServiceCallServiceDiscoveryConfiguration();
+ addServiceDiscoveryConfigurations(conf);
+
+ return conf;
+ }
+
+ // *************************************************************************
+ // Utilities
+ // *************************************************************************
+
+ @Override
+ protected void postProcessFactoryParameters(final CamelContext camelContext, final Map<String, Object> parameters) throws Exception {
+ if (serviceDiscoveryConfigurations != null && !serviceDiscoveryConfigurations.isEmpty()) {
+ List<ServiceDiscovery> discoveries = new ArrayList<>(serviceDiscoveryConfigurations.size());
+ for (ServiceCallServiceDiscoveryConfiguration conf : serviceDiscoveryConfigurations) {
+ discoveries.add(conf.newInstance(camelContext));
+ }
+
+ parameters.put("serviceDiscoveryList", discoveries);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceFilterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceFilterConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceFilterConfiguration.java
new file mode 100644
index 0000000..e6e2ff3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/ChainedServiceCallServiceFilterConfiguration.java
@@ -0,0 +1,138 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "routing,cloud,service-filter")
+@XmlRootElement(name = "multiServiceFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ChainedServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
+ @XmlElements({
+ @XmlElement(name = "blacklistServiceFilter", type = BlacklistServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "customServiceFilter", type = CustomServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "healthyServiceFilter", type = HealthyServiceCallServiceFilterConfiguration.class),
+ @XmlElement(name = "passThroughServiceFilter", type = PassThroughServiceCallServiceFilterConfiguration.class) }
+ )
+ private List<ServiceCallServiceFilterConfiguration> serviceFilterConfigurations;
+
+ public ChainedServiceCallServiceFilterConfiguration() {
+ this(null);
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
+ super(parent, "chained-service-filter");
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public List<ServiceCallServiceFilterConfiguration> getServiceFilterConfigurations() {
+ return serviceFilterConfigurations;
+ }
+
+ /**
+ * List of ServiceFilter configuration to use
+ * @param serviceFilterConfigurations
+ */
+ public void setServiceFilterConfigurations(List<ServiceCallServiceFilterConfiguration> serviceFilterConfigurations) {
+ this.serviceFilterConfigurations = serviceFilterConfigurations;
+ }
+
+ /**
+ * Add a ServiceFilter configuration
+ */
+ public void addServiceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ if (serviceFilterConfigurations == null) {
+ serviceFilterConfigurations = new ArrayList<>();
+ }
+
+ serviceFilterConfigurations.add(serviceFilterConfiguration);
+ }
+
+ // *************************************************************************
+ // Fluent API
+ // *************************************************************************
+
+ /**
+ * List of ServiceFilter configuration to use
+ */
+ public ChainedServiceCallServiceFilterConfiguration serviceFilterConfigurations(List<ServiceCallServiceFilterConfiguration> serviceFilterConfigurations) {
+ setServiceFilterConfigurations(serviceFilterConfigurations);
+ return this;
+ }
+
+ /**
+ * Add a ServiceFilter configuration
+ */
+ public ChainedServiceCallServiceFilterConfiguration serviceFilterConfiguration(ServiceCallServiceFilterConfiguration serviceFilterConfiguration) {
+ addServiceFilterConfiguration(serviceFilterConfiguration);
+ return this;
+ }
+
+ // *****************************
+ // Shortcuts - ServiceFilter
+ // *****************************
+
+ public ChainedServiceCallServiceFilterConfiguration healthy() {
+ addServiceFilterConfiguration(new HealthyServiceCallServiceFilterConfiguration());
+ return this;
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration passThrough() {
+ addServiceFilterConfiguration(new PassThroughServiceCallServiceFilterConfiguration());
+ return this;
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration custom(String serviceFilter) {
+ addServiceFilterConfiguration(new CustomServiceCallServiceFilterConfiguration().serviceFilter(serviceFilter));
+ return this;
+ }
+
+ public ChainedServiceCallServiceFilterConfiguration custom(ServiceFilter serviceFilter) {
+ addServiceFilterConfiguration(new CustomServiceCallServiceFilterConfiguration().serviceFilter(serviceFilter));
+ return this;
+ }
+
+ // *************************************************************************
+ // Utilities
+ // *************************************************************************
+
+ @Override
+ protected void postProcessFactoryParameters(final CamelContext camelContext, final Map<String, Object> parameters) throws Exception {
+ if (serviceFilterConfigurations != null && !serviceFilterConfigurations.isEmpty()) {
+ List<ServiceFilter> discoveries = new ArrayList<>(serviceFilterConfigurations.size());
+ for (ServiceCallServiceFilterConfiguration conf : serviceFilterConfigurations) {
+ discoveries.add(conf.newInstance(camelContext));
+ }
+
+ parameters.put("serviceFilterList", discoveries);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/CustomServiceCallServiceFilterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/CustomServiceCallServiceFilterConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/CustomServiceCallServiceFilterConfiguration.java
new file mode 100644
index 0000000..64f9548
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/CustomServiceCallServiceFilterConfiguration.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.model.cloud;
+
+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 javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cloud.ServiceFilter;
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "routing,cloud,service-filter")
+@XmlRootElement(name = "customServiceFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CustomServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
+ @XmlAttribute(name = "ref")
+ private String serviceFilterRef;
+ @XmlTransient
+ private ServiceFilter serviceFilter;
+
+ public CustomServiceCallServiceFilterConfiguration() {
+ this(null);
+ }
+
+ public CustomServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
+ super(parent, "custom-service-filter");
+ }
+
+ // *************************************************************************
+ // Properties
+ // *************************************************************************
+
+ public String getServiceFilterRef() {
+ return serviceFilterRef;
+ }
+
+ /**
+ * Reference of a ServiceFilter
+ */
+ public void setServiceFilterRef(String serviceFilterRef) {
+ this.serviceFilterRef = serviceFilterRef;
+ }
+
+ public ServiceFilter getServiceFilter() {
+ return serviceFilter;
+ }
+
+ /**
+ * Set the ServiceFilter
+ */
+ public void setServiceFilter(ServiceFilter serviceFilter) {
+ this.serviceFilter = serviceFilter;
+ }
+
+
+ // *************************************************************************
+ // Fluent API
+ // *************************************************************************
+
+ /**
+ * Reference of a ServiceFilter
+ */
+ public CustomServiceCallServiceFilterConfiguration serviceFilter(String serviceFilter) {
+ setServiceFilterRef(serviceFilter);
+ return this;
+ }
+
+ /**
+ * Set the ServiceFilter
+ */
+ public CustomServiceCallServiceFilterConfiguration serviceFilter(ServiceFilter serviceFilter) {
+ setServiceFilter(serviceFilter);
+ return this;
+ }
+
+ // *************************************************************************
+ // Factory
+ // *************************************************************************
+
+ @Override
+ public ServiceFilter newInstance(CamelContext camelContext) throws Exception {
+ ServiceFilter answer = serviceFilter;
+ if (serviceFilterRef != null) {
+ answer = camelContext.getRegistry().lookupByNameAndType(serviceFilterRef, ServiceFilter.class);
+ }
+
+ return answer;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/HealthyServiceCallServiceFilterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/HealthyServiceCallServiceFilterConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/HealthyServiceCallServiceFilterConfiguration.java
new file mode 100644
index 0000000..898715d
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/HealthyServiceCallServiceFilterConfiguration.java
@@ -0,0 +1,36 @@
+/**
+ * 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,service-filter")
+@XmlRootElement(name = "healthyServiceFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HealthyServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
+ public HealthyServiceCallServiceFilterConfiguration() {
+ this(null);
+ }
+
+ public HealthyServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
+ super(parent, "healthy-service-filter");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/MultiServiceCallServiceDiscoveryConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/MultiServiceCallServiceDiscoveryConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/MultiServiceCallServiceDiscoveryConfiguration.java
deleted file mode 100644
index b45ac99..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/cloud/MultiServiceCallServiceDiscoveryConfiguration.java
+++ /dev/null
@@ -1,169 +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.model.cloud;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElements;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.cloud.ServiceDiscovery;
-import org.apache.camel.spi.Metadata;
-
-@Metadata(label = "routing,cloud,service-discovery")
-@XmlRootElement(name = "multiServiceDiscovery")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class MultiServiceCallServiceDiscoveryConfiguration extends ServiceCallServiceDiscoveryConfiguration {
- @XmlElements({
- @XmlElement(name = "consulServiceDiscovery", type = ConsulServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "dnsServiceDiscovery", type = DnsServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "etcdServiceDiscovery", type = EtcdServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "kubernetesServiceDiscovery", type = KubernetesServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "staticServiceDiscovery", type = StaticServiceCallServiceDiscoveryConfiguration.class),
- @XmlElement(name = "cachingServiceDiscovery", type = CachingServiceCallServiceDiscoveryConfiguration.class)}
- )
- private List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations;
-
- public MultiServiceCallServiceDiscoveryConfiguration() {
- this(null);
- }
-
- public MultiServiceCallServiceDiscoveryConfiguration(ServiceCallDefinition parent) {
- super(parent, "multi-service-discovery");
- }
-
- // *************************************************************************
- // Properties
- // *************************************************************************
-
- public List<ServiceCallServiceDiscoveryConfiguration> getServiceDiscoveryConfigurations() {
- return serviceDiscoveryConfigurations;
- }
-
- /**
- * List of ServiceDiscovery configuration to use
- * @param serviceDiscoveryConfigurations
- */
- public void setServiceDiscoveryConfigurations(List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations) {
- this.serviceDiscoveryConfigurations = serviceDiscoveryConfigurations;
- }
-
- /**
- * Add a ServiceDiscovery configuration
- */
- public void addServiceDiscoveryConfigurations(ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration) {
- if (serviceDiscoveryConfigurations == null) {
- serviceDiscoveryConfigurations = new ArrayList<>();
- }
-
- serviceDiscoveryConfigurations.add(serviceDiscoveryConfiguration);
- }
-
- // *************************************************************************
- // Fluent API
- // *************************************************************************
-
- /**
- * List of ServiceDiscovery configuration to use
- */
- public MultiServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfigurations(List<ServiceCallServiceDiscoveryConfiguration> serviceDiscoveryConfigurations) {
- setServiceDiscoveryConfigurations(serviceDiscoveryConfigurations);
- return this;
- }
-
- /**
- * Add a ServiceDiscovery configuration
- */
- public MultiServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration(ServiceCallServiceDiscoveryConfiguration serviceDiscoveryConfiguration) {
- addServiceDiscoveryConfigurations(serviceDiscoveryConfiguration);
- return this;
- }
-
- // *****************************
- // Shortcuts - ServiceDiscovery
- // *****************************
-
- public CachingServiceCallServiceDiscoveryConfiguration cachingServiceDiscovery() {
- CachingServiceCallServiceDiscoveryConfiguration conf = new CachingServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public ConsulServiceCallServiceDiscoveryConfiguration consulServiceDiscovery() {
- ConsulServiceCallServiceDiscoveryConfiguration conf = new ConsulServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public DnsServiceCallServiceDiscoveryConfiguration dnsServiceDiscovery() {
- DnsServiceCallServiceDiscoveryConfiguration conf = new DnsServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public EtcdServiceCallServiceDiscoveryConfiguration etcdServiceDiscovery() {
- EtcdServiceCallServiceDiscoveryConfiguration conf = new EtcdServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public KubernetesServiceCallServiceDiscoveryConfiguration kubernetesServiceDiscovery() {
- KubernetesServiceCallServiceDiscoveryConfiguration conf = new KubernetesServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public MultiServiceCallServiceDiscoveryConfiguration multiServiceDiscovery() {
- MultiServiceCallServiceDiscoveryConfiguration conf = new MultiServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- public StaticServiceCallServiceDiscoveryConfiguration staticServiceDiscovery() {
- StaticServiceCallServiceDiscoveryConfiguration conf = new StaticServiceCallServiceDiscoveryConfiguration();
- addServiceDiscoveryConfigurations(conf);
-
- return conf;
- }
-
- // *************************************************************************
- // Utilities
- // *************************************************************************
-
- @Override
- protected void postProcessFactoryParameters(final CamelContext camelContext, final Map<String, Object> parameters) throws Exception {
- if (serviceDiscoveryConfigurations != null && !serviceDiscoveryConfigurations.isEmpty()) {
- List<ServiceDiscovery> discoveries = new ArrayList<>(serviceDiscoveryConfigurations.size());
- for (ServiceCallServiceDiscoveryConfiguration conf : serviceDiscoveryConfigurations) {
- discoveries.add(conf.newInstance(camelContext));
- }
-
- parameters.put("serviceDiscoveryList", discoveries);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0aae1257/camel-core/src/main/java/org/apache/camel/model/cloud/PassThroughServiceCallServiceFilterConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/cloud/PassThroughServiceCallServiceFilterConfiguration.java b/camel-core/src/main/java/org/apache/camel/model/cloud/PassThroughServiceCallServiceFilterConfiguration.java
new file mode 100644
index 0000000..a61c305
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/cloud/PassThroughServiceCallServiceFilterConfiguration.java
@@ -0,0 +1,36 @@
+/**
+ * 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,service-filter")
+@XmlRootElement(name = "passThroughServiceFilter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PassThroughServiceCallServiceFilterConfiguration extends ServiceCallServiceFilterConfiguration {
+ public PassThroughServiceCallServiceFilterConfiguration() {
+ this(null);
+ }
+
+ public PassThroughServiceCallServiceFilterConfiguration(ServiceCallDefinition parent) {
+ super(parent, "pass-through-service-filter");
+ }
+}
\ No newline at end of file