diff --git a/README.md b/README.md index 360fd85c..a68555e7 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,3 @@ Preview of Spring Cloud Consul implementation 6. visit [http://localhost:8080](http://localhost:8080), verify that `{"serviceId":":8080","host":"","port":8080}` results 5. run `java -jar spring-cloud-consul-sample/target/spring-cloud-consul-sample-1.0.0.BUILD-SNAPSHOT.jar --server.port=8081` 6. visit [http://localhost:8080](http://localhost:8080) again, verify that `{"serviceId":":8081","host":"","port":8081}` eventually shows up in the results in a round robbin fashion (may take a minute or so). - -### TODO - -- [X] consul config -- [X] consul service discovery -- [X] consul ribbon load balancer -- [X] consul ui (on the sample agent) -- [X] consul property source -- [X] consul event bus - - [X] send messages - - [X] receive messages -- [ ] consul locks -- [ ] consul leader election diff --git a/pom.xml b/pom.xml index 094457af..ceb7fcb6 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,7 @@ spring-cloud-consul-config spring-cloud-consul-discovery spring-cloud-consul-bus + spring-cloud-consul-sidecar spring-cloud-consul-sample @@ -106,6 +107,26 @@ spring-cloud-config-client 1.0.0.BUILD-SNAPSHOT + + org.springframework.cloud + spring-cloud-netflix-sidecar + 1.0.0.BUILD-SNAPSHOT + + + com.netflix.eureka + eureka-client + + + com.netflix.ribbon + ribbon-eureka + + + + + org.springframework.cloud + spring-cloud-netflix-core + 1.0.0.BUILD-SNAPSHOT + com.netflix.feign feign-core @@ -116,6 +137,11 @@ feign-jackson ${feign.version} + + com.netflix.feign + feign-slf4j + ${feign.version} + com.netflix.ribbon ribbon @@ -126,6 +152,11 @@ ribbon-core ${ribbon.version} + + com.netflix.ribbon + ribbon-httpclient + ${ribbon.version} + org.projectlombok lombok @@ -141,8 +172,8 @@ - 6.1.2 - 2.0-RC9 + 7.1.0 + 2.0-RC13 diff --git a/spring-cloud-consul-core/pom.xml b/spring-cloud-consul-core/pom.xml index 85832945..d1bb308f 100644 --- a/spring-cloud-consul-core/pom.xml +++ b/spring-cloud-consul-core/pom.xml @@ -36,6 +36,10 @@ com.netflix.feign feign-jackson + + com.netflix.feign + feign-slf4j + org.projectlombok lombok diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/AgentClient.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/AgentClient.java index 090f800e..127c8b4f 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/AgentClient.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/AgentClient.java @@ -1,9 +1,9 @@ package org.springframework.cloud.consul.client; +import feign.Param; import feign.RequestLine; import org.springframework.cloud.consul.model.Service; -import javax.inject.Named; import java.util.Map; /** @@ -21,5 +21,5 @@ public interface AgentClient { void register(Service service); @RequestLine("PUT /v1/agent/service/deregister/{serviceId}") - void deregister(@Named("serviceId") String serviceId); + void deregister(@Param("serviceId") String serviceId); } diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/CatalogClient.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/CatalogClient.java index c4cc8594..cea7746a 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/CatalogClient.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/CatalogClient.java @@ -1,9 +1,9 @@ package org.springframework.cloud.consul.client; +import feign.Param; import feign.RequestLine; import org.springframework.cloud.consul.model.ServiceNode; -import javax.inject.Named; import java.util.List; import java.util.Map; @@ -15,5 +15,5 @@ public interface CatalogClient { Map> getServices(); @RequestLine("GET /v1/catalog/service/{serviceId}") - List getServiceNodes(@Named("serviceId") String serviceId); + List getServiceNodes(@Param("serviceId") String serviceId); } diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventClient.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventClient.java index 81c4ecd8..e2d16d8d 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventClient.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventClient.java @@ -1,10 +1,10 @@ package org.springframework.cloud.consul.client; +import feign.Param; import feign.RequestLine; import feign.Response; import org.springframework.cloud.consul.model.Event; -import javax.inject.Named; import java.util.List; /** @@ -13,7 +13,7 @@ import java.util.List; public interface EventClient { //?node=, ?service=, and ?tag= ?dc= @RequestLine("PUT /v1/event/fire/{name}") - Event fire(@Named("name") String name, String payload); + Event fire(@Param("name") String name, String payload); //?name= //?wait=&index= @@ -24,5 +24,5 @@ public interface EventClient { Response getEventsResponse(); @RequestLine("GET /v1/event/list?wait={wait}&index={index}") - Response watch(@Named("wait") String wait, @Named("index") String index); + Response watch(@Param("wait") String wait, @Param("index") String index); } diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventService.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventService.java index 78b10b61..c0aec0b1 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventService.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventService.java @@ -3,12 +3,12 @@ package org.springframework.cloud.consul.client; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; import com.google.common.base.Throwables; +import feign.Param; import feign.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.consul.model.Event; import javax.annotation.PostConstruct; -import javax.inject.Named; import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; @@ -46,7 +46,7 @@ public class EventService { return lastIndex.get(); } - public Event fire(@Named("name") String name, String payload) { + public Event fire(@Param("name") String name, String payload) { return client.fire(name, payload); } diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/KeyValueClient.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/KeyValueClient.java index 039b4988..98cb5c72 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/KeyValueClient.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/KeyValueClient.java @@ -1,9 +1,9 @@ package org.springframework.cloud.consul.client; +import feign.Param; import feign.RequestLine; import org.springframework.cloud.consul.model.KeyValue; -import javax.inject.Named; import java.util.List; /** @@ -11,23 +11,23 @@ import java.util.List; */ public interface KeyValueClient { @RequestLine("GET /v1/kv/{key}") - List getKeyValue(@Named("key") String key); + List getKeyValue(@Param("key") String key); @RequestLine("GET /v1/kv/?recurse=true") List getKeyValueRecurse(); @RequestLine("GET /v1/kv/{key}?recurse=true") - List getKeyValueRecurse(@Named("key") String key); + List getKeyValueRecurse(@Param("key") String key); @RequestLine("GET /v1/kv/?keys=true") List getKeys(); @RequestLine("GET /v1/kv/{key}?keys=true") - List getKeys(@Named("key") String key); + List getKeys(@Param("key") String key); @RequestLine("PUT /v1/kv/{key}") - boolean put(@Named("key") String key, Object value); + boolean put(@Param("key") String key, Object value); @RequestLine("DELETE /v1/kv/{key}") - void delete(@Named("key") String key); + void delete(@Param("key") String key); } diff --git a/spring-cloud-consul-discovery/pom.xml b/spring-cloud-consul-discovery/pom.xml index ca72093f..bf38c124 100644 --- a/spring-cloud-consul-discovery/pom.xml +++ b/spring-cloud-consul-discovery/pom.xml @@ -20,6 +20,10 @@ org.springframework.cloud spring-cloud-consul-core + + org.springframework.cloud + spring-cloud-netflix-core + com.netflix.ribbon ribbon @@ -28,6 +32,10 @@ com.netflix.ribbon ribbon-core + + com.netflix.ribbon + ribbon-httpclient + org.projectlombok lombok diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClientConfiguration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClientConfiguration.java index c9ea8615..561d93dd 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClientConfiguration.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClientConfiguration.java @@ -13,10 +13,10 @@ public class ConsulDiscoveryClientConfiguration { return new ConsulLifecycle(); } - @Bean + /*@Bean public ConsulLoadBalancerClient consulLoadBalancerClient() { return new ConsulLoadBalancerClient(); - } + }*/ @Bean public ConsulDiscoveryClient consulDiscoveryClient() { diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulRibbonClientConfiguration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulRibbonClientConfiguration.java new file mode 100644 index 00000000..feca80f1 --- /dev/null +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulRibbonClientConfiguration.java @@ -0,0 +1,122 @@ +/* + * Copyright 2013-2015 the original author or authors. + * + * Licensed 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.springframework.cloud.consul.discovery; + +import static com.netflix.client.config.CommonClientConfigKey.*; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.cloud.consul.client.CatalogClient; +import org.springframework.cloud.netflix.ribbon.ZonePreferenceServerListFilter; +import org.springframework.context.annotation.Configuration; + +import com.netflix.config.ConfigurationManager; +import com.netflix.config.DynamicPropertyFactory; +import com.netflix.config.DynamicStringProperty; +import com.netflix.loadbalancer.DynamicServerListLoadBalancer; +import com.netflix.loadbalancer.ServerList; +import com.netflix.loadbalancer.ZoneAvoidanceRule; + +/** + * Preprocessor that configures defaults for eureka-discovered ribbon clients. Such as: + * @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses, + * NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more + * + * @author Spencer Gibb + * @author Dave Syer + */ +@Configuration +public class ConsulRibbonClientConfiguration implements BeanPostProcessor { + @Autowired + CatalogClient client; + + @Value("${ribbon.client.name}") + private String serviceId = "client"; + + protected static final String VALUE_NOT_SET = "__not__set__"; + + protected static final String DEFAULT_NAMESPACE = "ribbon"; + + public ConsulRibbonClientConfiguration() { + System.out.println("here"); + } + + public ConsulRibbonClientConfiguration(String serviceId) { + this.serviceId = serviceId; + } + + @PostConstruct + public void preprocess() { + // TODO: should this look more like hibernate spring boot props? + setProp(this.serviceId, NIWSServerListClassName.key(), + ConsulServerList.class.getName()); + // FIXME: what should this be? + setProp(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId); + setProp(this.serviceId, NFLoadBalancerRuleClassName.key(), + ZoneAvoidanceRule.class.getName()); + setProp(this.serviceId, NIWSServerListFilterClassName.key(), + ZonePreferenceServerListFilter.class.getName()); + setProp(this.serviceId, EnableZoneAffinity.key(), "true"); + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) + throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) + throws BeansException { + if (bean instanceof DynamicServerListLoadBalancer) { + wrapServerList((DynamicServerListLoadBalancer) bean); + } + return bean; + } + + private void wrapServerList(DynamicServerListLoadBalancer balancer) { + @SuppressWarnings("unchecked") + DynamicServerListLoadBalancer dynamic = (DynamicServerListLoadBalancer) balancer; + ServerList list = dynamic.getServerListImpl(); + if (list instanceof ConsulServerList) { + ConsulServerList csl = (ConsulServerList) list; + csl.setClient(client); + } + } + + protected void setProp(String serviceId, String suffix, String value) { + // how to set the namespace properly? + String key = getKey(serviceId, suffix); + DynamicStringProperty property = getProperty(key); + if (property.get().equals(VALUE_NOT_SET)) { + ConfigurationManager.getConfigInstance().setProperty(key, value); + } + } + + protected DynamicStringProperty getProperty(String key) { + return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET); + } + + protected String getKey(String serviceId, String suffix) { + return serviceId + "." + DEFAULT_NAMESPACE + "." + suffix; + } + +} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java index 046558d8..52d8ec31 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java @@ -23,14 +23,21 @@ public class ConsulServerList extends AbstractServerList { private String serviceId; + public ConsulServerList() { + } public ConsulServerList(CatalogClient client, String serviceId) { this.client = client; this.serviceId = serviceId; } + public void setClient(CatalogClient client) { + this.client = client; + } + @Override public void initWithNiwsConfig(IClientConfig clientConfig) { + this.serviceId = clientConfig.getClientName(); } @Override @@ -44,6 +51,9 @@ public class ConsulServerList extends AbstractServerList { } private List getServers() { + if (client == null) { + return Collections.emptyList(); + } List nodes = client.getServiceNodes(serviceId); if (nodes == null || nodes.isEmpty()) { return Collections.EMPTY_LIST; diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/RibbonConsulAutoConfiguration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/RibbonConsulAutoConfiguration.java new file mode 100644 index 00000000..b3785720 --- /dev/null +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/RibbonConsulAutoConfiguration.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2014 the original author or authors. + * + * Licensed 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.springframework.cloud.consul.discovery; + +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; +import org.springframework.cloud.netflix.ribbon.RibbonClients; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.context.annotation.Configuration; + +/** + * @author Dave Syer + */ +@Configuration +@EnableConfigurationProperties +@ConditionalOnBean(SpringClientFactory.class) +@ConditionalOnProperty(value = "ribbon.consul.enabled", matchIfMissing = true) +@AutoConfigureAfter(RibbonAutoConfiguration.class) +@RibbonClients(defaultConfiguration = ConsulRibbonClientConfiguration.class) +public class RibbonConsulAutoConfiguration { + +} diff --git a/spring-cloud-consul-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-consul-discovery/src/main/resources/META-INF/spring.factories index 46c566d9..82297a41 100644 --- a/spring-cloud-consul-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-consul-discovery/src/main/resources/META-INF/spring.factories @@ -1,3 +1,6 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.springframework.cloud.consul.discovery.RibbonConsulAutoConfiguration + # Discovery Client Configuration org.springframework.cloud.client.discovery.EnableDiscoveryClient=\ org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration diff --git a/spring-cloud-consul-sample/src/main/java/org/springframework/cloud/consul/sample/SampleApplication.java b/spring-cloud-consul-sample/src/main/java/org/springframework/cloud/consul/sample/SampleApplication.java index 9fcd553a..d331d884 100644 --- a/spring-cloud-consul-sample/src/main/java/org/springframework/cloud/consul/sample/SampleApplication.java +++ b/spring-cloud-consul-sample/src/main/java/org/springframework/cloud/consul/sample/SampleApplication.java @@ -7,9 +7,10 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.cloud.bus.jackson.SubtypeModule; import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; import org.springframework.cloud.consul.bus.SimpleRemoteEvent; -import org.springframework.cloud.consul.discovery.ConsulLoadBalancerClient; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -31,7 +32,10 @@ public class SampleApplication implements ApplicationListener public static final String CLIENT_NAME = "testConsulApp"; @Autowired - ConsulLoadBalancerClient loadBalancer; + LoadBalancerClient loadBalancer; + + @Autowired + DiscoveryClient discoveryClient; @Autowired Environment env; @@ -39,6 +43,11 @@ public class SampleApplication implements ApplicationListener @Autowired(required = false) RelaxedPropertyResolver resolver; + @RequestMapping("/me") + public ServiceInstance me() { + return discoveryClient.getLocalServiceInstance(); + } + @RequestMapping("/") public ServiceInstance lb() { return loadBalancer.choose(CLIENT_NAME); diff --git a/spring-cloud-consul-sidecar/pom.xml b/spring-cloud-consul-sidecar/pom.xml new file mode 100644 index 00000000..4c076453 --- /dev/null +++ b/spring-cloud-consul-sidecar/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + spring-cloud-consul-sidecar + jar + Spring Cloud Consul Sidecar + Spring Cloud Consul Sidecar + + + org.springframework.cloud + spring-cloud-consul + 1.0.0.BUILD-SNAPSHOT + .. + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-consul-config + + + org.springframework.cloud + spring-cloud-consul-discovery + + + org.springframework.cloud + spring-cloud-netflix-sidecar + + + org.projectlombok + lombok + + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + com.google.guava + guava + + + + + diff --git a/spring-cloud-consul-sidecar/run-server.sh b/spring-cloud-consul-sidecar/run-server.sh new file mode 100755 index 00000000..8bacc042 --- /dev/null +++ b/spring-cloud-consul-sidecar/run-server.sh @@ -0,0 +1 @@ +python -m SimpleHTTPServer diff --git a/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/ConsulSidecarConfiguration.java b/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/ConsulSidecarConfiguration.java new file mode 100644 index 00000000..4107dad2 --- /dev/null +++ b/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/ConsulSidecarConfiguration.java @@ -0,0 +1,10 @@ +package org.springframework.cloud.consul.sidecar; + +import org.springframework.context.annotation.Configuration; + +/** + * @author Spencer Gibb + */ +@Configuration +public class ConsulSidecarConfiguration { +} diff --git a/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/EnableSidecar.java b/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/EnableSidecar.java new file mode 100644 index 00000000..3ec902df --- /dev/null +++ b/spring-cloud-consul-sidecar/src/main/java/org/springframework/cloud/consul/sidecar/EnableSidecar.java @@ -0,0 +1,23 @@ +package org.springframework.cloud.consul.sidecar; + +import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.sidecar.SidecarConfiguration; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +/** + * @author Spencer Gibb + */ +@EnableCircuitBreaker +@EnableDiscoveryClient +@EnableZuulProxy +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Import({SidecarConfiguration.class, ConsulSidecarConfiguration.class}) +public @interface EnableSidecar { + +} diff --git a/spring-cloud-consul-sidecar/src/test/java/org/springframework/cloud/consul/sidecar/SidecarApplicationTests.java b/spring-cloud-consul-sidecar/src/test/java/org/springframework/cloud/consul/sidecar/SidecarApplicationTests.java new file mode 100644 index 00000000..b586b01f --- /dev/null +++ b/spring-cloud-consul-sidecar/src/test/java/org/springframework/cloud/consul/sidecar/SidecarApplicationTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2013-2015 the original author or authors. + * + * Licensed 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.springframework.cloud.consul.sidecar; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.actuate.metrics.repository.InMemoryMetricRepository; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.netflix.sidecar.*; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.web.bind.annotation.RestController; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SidecarApplicationTests.SidecarApplication.class) +@IntegrationTest("server.port=0") +public class SidecarApplicationTests { + + @Test + public void contextLoads() { + } + + + @SpringBootApplication + @org.springframework.cloud.netflix.sidecar.EnableSidecar + @RestController + public static class SidecarApplication { + + @Bean + public InMemoryMetricRepository inMemoryMetricRepository() { + return new InMemoryMetricRepository(); + } + + public static void main(String[] args) { + SpringApplication.run(SidecarApplication.class, args); + } + + } +} diff --git a/spring-cloud-consul-sidecar/src/test/resources/application.yml b/spring-cloud-consul-sidecar/src/test/resources/application.yml new file mode 100644 index 00000000..ce295c8c --- /dev/null +++ b/spring-cloud-consul-sidecar/src/test/resources/application.yml @@ -0,0 +1,21 @@ +server: + port: 5678 +spring: + application: + name: sidecarTest + +sidecar: + port: 8000 + health-uri: http://localhost:8000/src/test/resources/health.json + +ribbon: + ServerListRefreshInterval: 5000 + +endpoints: + refresh: + enabled: true + shutdown: + enabled: true + health: + sensitive: false + diff --git a/spring-cloud-consul-sidecar/src/test/resources/bootstrap.yml b/spring-cloud-consul-sidecar/src/test/resources/bootstrap.yml new file mode 100644 index 00000000..bbd58928 --- /dev/null +++ b/spring-cloud-consul-sidecar/src/test/resources/bootstrap.yml @@ -0,0 +1,7 @@ +spring: + #application: + # name: sideCarTest + cloud: + config: + username: user + password: password diff --git a/spring-cloud-consul-sidecar/src/test/resources/health.json b/spring-cloud-consul-sidecar/src/test/resources/health.json new file mode 100644 index 00000000..41f3615e --- /dev/null +++ b/spring-cloud-consul-sidecar/src/test/resources/health.json @@ -0,0 +1 @@ +{"status":"UP"} \ No newline at end of file