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/06/25 11:59:37 UTC

[camel] branch master updated: CAMEL-12461: camel-consul: support service metadata

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 45596f3  CAMEL-12461: camel-consul: support service metadata
45596f3 is described below

commit 45596f3aeae6a3b9cb46f01217caa436a3502737
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Jun 25 13:59:15 2018 +0200

    CAMEL-12461: camel-consul: support service metadata
---
 components/camel-consul/pom.xml                         |  6 ++++++
 .../component/consul/cloud/ConsulServiceDiscovery.java  | 14 +++++++++++---
 .../camel/component/consul/ConsulTestSupport.java       |  2 +-
 .../consul/cloud/ConsulServiceDiscoveryTest.java        | 17 ++++++++++-------
 .../consul/CamelCloudConsulServiceRegistryTest.java     |  2 +-
 .../spring/ContainerAwareSpringTestSupportIT.java       |  2 +-
 .../testcontainers/ContainerAwareTestSupportIT.java     |  2 +-
 .../README.adoc                                         |  2 +-
 .../springboot/cloud/ConsulServiceRegistryIT.java       |  2 +-
 9 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/components/camel-consul/pom.xml b/components/camel-consul/pom.xml
index 94a578d..27c007f 100644
--- a/components/camel-consul/pom.xml
+++ b/components/camel-consul/pom.xml
@@ -80,6 +80,12 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <version>${assertj-version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-ribbon</artifactId>
       <scope>test</scope>
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 4cb1114..664ad65 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
@@ -78,10 +78,12 @@ public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
 
     private ServiceDefinition newService(String serviceName, CatalogService service, List<ServiceHealth> serviceHealthList) {
         Map<String, String> meta = new HashMap<>();
-        ObjectHelper.ifNotEmpty(service.getServiceId(), val -> meta.put("service_id", val));
-        ObjectHelper.ifNotEmpty(service.getNode(), val -> meta.put("node", val));
-        ObjectHelper.ifNotEmpty(service.getServiceName(), val -> meta.put("service_name", val));
+        ObjectHelper.ifNotEmpty(service.getServiceId(), val -> meta.put(ServiceDefinition.SERVICE_META_ID, val));
+        ObjectHelper.ifNotEmpty(service.getServiceName(), val -> meta.put(ServiceDefinition.SERVICE_META_NAME, val));
+        ObjectHelper.ifNotEmpty(service.getNode(), val -> meta.put("service.node", val));
 
+        // Consul < 1.0.7 does not have a concept of meta-data so meta is
+        // retrieved using tags
         List<String> tags = service.getServiceTags();
         if (tags != null) {
             for (String tag : service.getServiceTags()) {
@@ -94,6 +96,12 @@ public final class ConsulServiceDiscovery extends DefaultServiceDiscovery {
             }
         }
 
+        // From Consul => 1.0.7, a new meta data attribute has been introduced
+        // and it is now taken ito account
+        service.getServiceMeta().ifPresent(
+            serviceMeta -> serviceMeta.forEach(meta::put)
+        );
+
         return new DefaultServiceDefinition(
             serviceName,
             service.getServiceAddress(),
diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
index 9675ed9..9ede080 100644
--- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
+++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
@@ -30,7 +30,7 @@ import org.junit.rules.TestName;
 import org.testcontainers.containers.GenericContainer;
 
 public class ConsulTestSupport extends ContainerAwareTestSupport {
-    public static final String CONTAINER_IMAGE = "consul:1.0.0";
+    public static final String CONTAINER_IMAGE = "consul:1.0.7";
     public static final String CONTAINER_NAME = "consul";
     public static final String KV_PREFIX = "/camel";
 
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 7e7f431..2d7e199 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
@@ -28,6 +28,7 @@ import org.apache.camel.cloud.ServiceDefinition;
 import org.apache.camel.cloud.ServiceDiscovery;
 import org.apache.camel.component.consul.ConsulConfiguration;
 import org.apache.camel.component.consul.ConsulTestSupport;
+import org.assertj.core.api.Assertions;
 import org.junit.Test;
 import org.springframework.util.SocketUtils;
 
@@ -64,6 +65,7 @@ public class ConsulServiceDiscoveryTest extends ConsulTestSupport {
                 .addTags("key1=value1")
                 .addTags("key2=value2")
                 .addTags("healthy=" + healty)
+                .putMeta("meta-key", "meta-val")
                 .port(port)
                 .check(c)
                 .build();
@@ -96,13 +98,14 @@ public class ConsulServiceDiscoveryTest extends ConsulTestSupport {
         assertEquals(6, services.size());
 
         for (ServiceDefinition service : services) {
-            assertFalse(service.getMetadata().isEmpty());
-            assertTrue(service.getMetadata().containsKey("service_name"));
-            assertTrue(service.getMetadata().containsKey("service_id"));
-            assertTrue(service.getMetadata().containsKey("a-tag"));
-            assertTrue(service.getMetadata().containsKey("key1"));
-            assertTrue(service.getMetadata().containsKey("key2"));
-            assertEquals("" + service.getHealth().isHealthy(), service.getMetadata().get("healthy"));
+            Assertions.assertThat(service.getMetadata()).isNotEmpty();
+            Assertions.assertThat(service.getMetadata()).containsEntry(ServiceDefinition.SERVICE_META_NAME, "my-service");
+            Assertions.assertThat(service.getMetadata()).containsKey(ServiceDefinition.SERVICE_META_ID);
+            Assertions.assertThat(service.getMetadata()).containsKey("a-tag");
+            Assertions.assertThat(service.getMetadata()).containsEntry("key1", "value1");
+            Assertions.assertThat(service.getMetadata()).containsEntry("key2", "value2");
+            Assertions.assertThat(service.getMetadata()).containsEntry("meta-key", "meta-val");
+            Assertions.assertThat("" + service.getHealth().isHealthy()).isEqualTo(service.getMetadata().get("healthy"));
         }
     }
 }
diff --git a/components/camel-spring-cloud-consul/src/test/java/org/apache/camel/spring/cloud/consul/CamelCloudConsulServiceRegistryTest.java b/components/camel-spring-cloud-consul/src/test/java/org/apache/camel/spring/cloud/consul/CamelCloudConsulServiceRegistryTest.java
index d5cb60e..12528b7 100644
--- a/components/camel-spring-cloud-consul/src/test/java/org/apache/camel/spring/cloud/consul/CamelCloudConsulServiceRegistryTest.java
+++ b/components/camel-spring-cloud-consul/src/test/java/org/apache/camel/spring/cloud/consul/CamelCloudConsulServiceRegistryTest.java
@@ -48,7 +48,7 @@ public class CamelCloudConsulServiceRegistryTest {
     private static final int SERVICE_PORT = SocketUtils.findAvailableTcpPort();
 
     @Rule
-    public GenericContainer container =  new GenericContainer("consul:1.0.0")
+    public GenericContainer container =  new GenericContainer("consul:1.0.7")
         .withExposedPorts(8500)
         .waitingFor(Wait.forLogMessageContaining("Synced node info", 1))
         .withLogConsumer(new Slf4jLogConsumer(LOGGER).withPrefix("consul"))
diff --git a/components/camel-testcontainers-spring/src/test/java/org/apache/camel/test/testcontainers/spring/ContainerAwareSpringTestSupportIT.java b/components/camel-testcontainers-spring/src/test/java/org/apache/camel/test/testcontainers/spring/ContainerAwareSpringTestSupportIT.java
index 6dfc62e..d277ea0 100644
--- a/components/camel-testcontainers-spring/src/test/java/org/apache/camel/test/testcontainers/spring/ContainerAwareSpringTestSupportIT.java
+++ b/components/camel-testcontainers-spring/src/test/java/org/apache/camel/test/testcontainers/spring/ContainerAwareSpringTestSupportIT.java
@@ -42,7 +42,7 @@ public class ContainerAwareSpringTestSupportIT extends ContainerAwareSpringTestS
 
     @Override
     protected GenericContainer<?> createContainer() {
-        return new GenericContainer("consul:1.0.0")
+        return new GenericContainer("consul:1.0.7")
             .withNetworkAliases("myconsul")
             .withExposedPorts(8500)
             .waitingFor(Wait.forLogMessageContaining("Synced node info", 1))
diff --git a/components/camel-testcontainers/src/test/java/org/apache/camel/test/testcontainers/ContainerAwareTestSupportIT.java b/components/camel-testcontainers/src/test/java/org/apache/camel/test/testcontainers/ContainerAwareTestSupportIT.java
index 38e8659..ffaf6f0 100644
--- a/components/camel-testcontainers/src/test/java/org/apache/camel/test/testcontainers/ContainerAwareTestSupportIT.java
+++ b/components/camel-testcontainers/src/test/java/org/apache/camel/test/testcontainers/ContainerAwareTestSupportIT.java
@@ -34,7 +34,7 @@ public class ContainerAwareTestSupportIT extends ContainerAwareTestSupport {
 
     @Override
     protected GenericContainer<?> createContainer() {
-        return new GenericContainer("consul:1.0.0")
+        return new GenericContainer("consul:1.0.7")
             .withNetworkAliases("myconsul")
             .withExposedPorts(8500)
             .waitingFor(Wait.forLogMessageContaining("Synced node info", 1))
diff --git a/examples/camel-example-spring-cloud-serviceregistry/README.adoc b/examples/camel-example-spring-cloud-serviceregistry/README.adoc
index 28e37d2..ac9cb16 100644
--- a/examples/camel-example-spring-cloud-serviceregistry/README.adoc
+++ b/examples/camel-example-spring-cloud-serviceregistry/README.adoc
@@ -24,7 +24,7 @@ Using multiple shells:
  - start consul:
 
   docker run --rm -ti --publish 8500:8500 \
-    consul:1.0.0 \
+    consul:1.0.7 \
         agent \
             -dev \
             -server \
diff --git a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceRegistryIT.java b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceRegistryIT.java
index 3b8892b..0fcde26 100644
--- a/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceRegistryIT.java
+++ b/platforms/spring-boot/components-starter/camel-consul-starter/src/test/java/org/apache/camel/component/consul/springboot/cloud/ConsulServiceRegistryIT.java
@@ -46,7 +46,7 @@ public class ConsulServiceRegistryIT {
     private static final int SERVICE_PORT = SocketUtils.findAvailableTcpPort();
 
     @Rule
-    public GenericContainer container = new GenericContainer("consul:1.0.0")
+    public GenericContainer container = new GenericContainer("consul:1.0.7")
         .withExposedPorts(Consul.DEFAULT_HTTP_PORT)
         .waitingFor(Wait.forLogMessageContaining("Synced node info", 1))
         .withLogConsumer(new Slf4jLogConsumer(LOGGER).withPrefix("consul"))