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 2018/04/16 13:18:08 UTC
[camel] branch master updated: CAMEL-12448 - camel-consul: filter
health checks by service id (#2296)
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 7097b32 CAMEL-12448 - camel-consul: filter health checks by service id (#2296)
7097b32 is described below
commit 7097b32f96d53e959ea6300eb2b6885a4c95fa89
Author: player13 <83...@users.noreply.github.com>
AuthorDate: Mon Apr 16 16:18:02 2018 +0300
CAMEL-12448 - camel-consul: filter health checks by service id (#2296)
CAMEL-12448 - camel-consul - service health state calculated from all services with same name
---
.../camel/component/consul/cloud/ConsulServiceDiscovery.java | 6 +++++-
.../component/consul/cloud/ConsulServiceDiscoveryTest.java | 12 ++++++++++--
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
index e7cfd5f..74b7c00 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscovery.java
@@ -99,7 +99,11 @@ public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
service.getServiceAddress(),
service.getServicePort(),
meta,
- new DefaultServiceHealth(serviceHealthList.stream().allMatch(this::isHealthy))
+ new DefaultServiceHealth(
+ serviceHealthList.stream()
+ .filter(h -> ObjectHelper.equal(h.getService().getId(), service.getServiceId()))
+ .allMatch(this::isHealthy)
+ )
);
}
}
diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java
index 2523ad7..119e85b 100644
--- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java
+++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/ConsulServiceDiscoveryTest.java
@@ -21,6 +21,7 @@ import java.util.List;
import com.orbitz.consul.AgentClient;
import com.orbitz.consul.Consul;
+import com.orbitz.consul.model.agent.ImmutableRegCheck;
import com.orbitz.consul.model.agent.ImmutableRegistration;
import com.orbitz.consul.model.agent.Registration;
import org.apache.camel.cloud.ServiceDefinition;
@@ -44,7 +45,12 @@ public class ConsulServiceDiscoveryTest {
client = Consul.builder().build().agentClient();
registrations = new ArrayList<>(3);
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < 6; i++) {
+ Registration.RegCheck c = ImmutableRegCheck.builder()
+ .ttl("1m")
+ .status(i < 3 ? "passing" : "critical")
+ .build();
+
Registration r = ImmutableRegistration.builder()
.id("service-" + i)
.name("my-service")
@@ -53,6 +59,7 @@ public class ConsulServiceDiscoveryTest {
.addTags("key1=value1")
.addTags("key2=value2")
.port(9000 + i)
+ .check(c)
.build();
client.register(r);
@@ -76,7 +83,7 @@ public class ConsulServiceDiscoveryTest {
List<ServiceDefinition> services = discovery.getServices("my-service");
assertNotNull(services);
- assertEquals(3, services.size());
+ assertEquals(6, services.size());
for (ServiceDefinition service : services) {
assertFalse(service.getMetadata().isEmpty());
@@ -85,6 +92,7 @@ public class ConsulServiceDiscoveryTest {
assertTrue(service.getMetadata().containsKey("a-tag"));
assertTrue(service.getMetadata().containsKey("key1"));
assertTrue(service.getMetadata().containsKey("key2"));
+ assertTrue(service.getPort() < 9003 ? service.getHealth().isHealthy() : !service.getHealth().isHealthy());
}
}
}
--
To stop receiving notification emails like this one, please contact
lburgazzoli@apache.org.