diff --git a/docs/pom.xml b/docs/pom.xml index b56304c9..c2bacb63 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT spring-cloud-consul-docs pom diff --git a/pom.xml b/pom.xml index 985e1c80..aed34f26 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT pom Spring Cloud Consul Spring Cloud Consul @@ -14,18 +14,18 @@ org.springframework.cloud spring-cloud-build - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT - 2.2.1.BUILD-SNAPSHOT - 2.2.2.BUILD-SNAPSHOT - 2.2.2.BUILD-SNAPSHOT - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT 1.0.3.RELEASE - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT Horsham.SR1 diff --git a/spring-cloud-consul-binder/pom.xml b/spring-cloud-consul-binder/pom.xml index be099f32..c54f9bf7 100644 --- a/spring-cloud-consul-binder/pom.xml +++ b/spring-cloud-consul-binder/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-consul-config/pom.xml b/spring-cloud-consul-config/pom.xml index 1f180ea1..b650811d 100644 --- a/spring-cloud-consul-config/pom.xml +++ b/spring-cloud-consul-config/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java index 32262f44..b7a3fb40 100644 --- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java +++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java @@ -32,10 +32,10 @@ import org.springframework.cloud.endpoint.event.RefreshEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.util.StringUtils; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; diff --git a/spring-cloud-consul-core/pom.xml b/spring-cloud-consul-core/pom.xml index 023803d5..11cad174 100644 --- a/spring-cloud-consul-core/pom.xml +++ b/spring-cloud-consul-core/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. @@ -22,6 +22,10 @@ spring-boot-configuration-processor true + + org.springframework.boot + spring-boot-starter-validation + org.springframework.boot spring-boot-starter-web diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java index da6d2d86..ed388c70 100644 --- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java +++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java @@ -20,7 +20,7 @@ import com.ecwid.consul.transport.TLSConfig; import com.ecwid.consul.v1.ConsulClient; import org.aspectj.lang.annotation.Aspect; -import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration; @@ -74,7 +74,7 @@ public class ConsulAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnEnabledEndpoint + @ConditionalOnAvailableEndpoint public ConsulEndpoint consulEndpoint(ConsulClient consulClient) { return new ConsulEndpoint(consulClient); } diff --git a/spring-cloud-consul-dependencies/pom.xml b/spring-cloud-consul-dependencies/pom.xml index dc5f9eea..76f977a2 100644 --- a/spring-cloud-consul-dependencies/pom.xml +++ b/spring-cloud-consul-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.2.1.RELEASE + 3.0.0.BUILD-SNAPSHOT spring-cloud-consul-dependencies - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT pom spring-cloud-consul-dependencies Spring Cloud Consul Dependencies diff --git a/spring-cloud-consul-discovery/pom.xml b/spring-cloud-consul-discovery/pom.xml index 233ef214..e5911b2b 100644 --- a/spring-cloud-consul-discovery/pom.xml +++ b/spring-cloud-consul-discovery/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. @@ -67,36 +67,6 @@ httpcore true - - org.springframework.cloud - spring-cloud-netflix-hystrix - true - - - org.springframework.cloud - spring-cloud-starter-netflix-archaius - true - - - com.netflix.ribbon - ribbon - true - - - com.netflix.ribbon - ribbon-core - true - - - com.netflix.ribbon - ribbon-httpclient - true - - - com.netflix.ribbon - ribbon-loadbalancer - true - org.springframework.retry spring-retry @@ -123,11 +93,6 @@ spring-boot-starter-test test - - joda-time - joda-time - true - org.springframework.boot spring-boot-starter-web diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulPing.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulPing.java deleted file mode 100644 index 7aad80e7..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulPing.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 com.netflix.loadbalancer.IPing; -import com.netflix.loadbalancer.Server; - -/** - * "Ping" Consul i.e. we dont do a real "ping". We just assume that the server is up if - * Consul says so - * - * @author Spencer Gibb - */ -public class ConsulPing implements IPing { - - @Override - public boolean isAlive(Server server) { - boolean isAlive = true; - - if (server != null && server instanceof ConsulServer) { - ConsulServer consulServer = (ConsulServer) server; - return consulServer.isPassingChecks(); - } - - return isAlive; - } - -} 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 deleted file mode 100644 index cb6d07c5..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulRibbonClientConfiguration.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 javax.annotation.PostConstruct; - -import com.ecwid.consul.v1.ConsulClient; -import com.netflix.client.config.IClientConfig; -import com.netflix.config.ConfigurationManager; -import com.netflix.config.DynamicPropertyFactory; -import com.netflix.config.DynamicStringProperty; -import com.netflix.loadbalancer.IPing; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerList; -import com.netflix.loadbalancer.ServerListFilter; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses; -import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity; - -/** - * Preprocessor that configures defaults for Consul-discovered ribbon clients. Such as: - * @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses, - * NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more - * - * @author Spencer Gibb - * @author Dave Syer - */ -@Configuration(proxyBeanMethods = false) -public class ConsulRibbonClientConfiguration { - - protected static final String VALUE_NOT_SET = "__not__set__"; - - protected static final String DEFAULT_NAMESPACE = "ribbon"; - - @Autowired - private ConsulClient client; - - @Value("${ribbon.client.name}") - private String serviceId = "client"; - - public ConsulRibbonClientConfiguration() { - } - - public ConsulRibbonClientConfiguration(String serviceId) { - this.serviceId = serviceId; - } - - @Bean - @ConditionalOnMissingBean - public ServerList ribbonServerList(IClientConfig config, - ConsulDiscoveryProperties properties) { - ConsulServerList serverList = new ConsulServerList(this.client, properties); - serverList.initWithNiwsConfig(config); - return serverList; - } - - @Bean - @ConditionalOnMissingBean - public ServerListFilter ribbonServerListFilter() { - return new HealthServiceServerListFilter(); - } - - @Bean - @ConditionalOnMissingBean - public IPing ribbonPing() { - return new ConsulPing(); - } - - @Bean - @ConditionalOnMissingBean - public ConsulServerIntrospector serverIntrospector() { - return new ConsulServerIntrospector(); - } - - @PostConstruct - public void preprocess() { - setProp(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId); - setProp(this.serviceId, EnableZoneAffinity.key(), "true"); - } - - 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/ConsulServer.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServer.java deleted file mode 100644 index 5f0fdae4..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.Map; - -import com.ecwid.consul.v1.health.model.Check; -import com.ecwid.consul.v1.health.model.HealthService; -import com.netflix.loadbalancer.Server; - -import static org.springframework.cloud.consul.discovery.ConsulServerUtils.findHost; - -/** - * @author Spencer Gibb - */ -public class ConsulServer extends Server { - - private final MetaInfo metaInfo; - - private final HealthService service; - - private final Map metadata; - - public ConsulServer(final HealthService healthService) { - super(findHost(healthService), healthService.getService().getPort()); - this.service = healthService; - this.metadata = ConsulServerUtils.getMetadata(this.service); - this.metaInfo = new MetaInfo() { - @Override - public String getAppName() { - return ConsulServer.this.service.getService().getService(); - } - - @Override - public String getServerGroup() { - return getMetadata().get("group"); - } - - @Override - public String getServiceIdForDiscovery() { - return null; - } - - @Override - public String getInstanceId() { - return ConsulServer.this.service.getService().getId(); - } - }; - - setAlive(isPassingChecks()); - } - - @Override - public MetaInfo getMetaInfo() { - return this.metaInfo; - } - - public HealthService getHealthService() { - return this.service; - } - - public Map getMetadata() { - return this.metadata; - } - - public boolean isPassingChecks() { - for (Check check : this.service.getChecks()) { - if (check.getStatus() != Check.CheckStatus.PASSING) { - return false; - } - } - return true; - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerIntrospector.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerIntrospector.java deleted file mode 100644 index 8c95c187..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerIntrospector.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.Map; - -import com.netflix.loadbalancer.Server; - -import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; - -/** - * @author Spencer Gibb - */ -public class ConsulServerIntrospector extends DefaultServerIntrospector { - - @Override - public boolean isSecure(Server server) { - Map metadata = getMetadata(server); - if (metadata != null && metadata.containsKey("secure")) { - return metadata.getOrDefault("secure", "false").equalsIgnoreCase("true"); - } - return super.isSecure(server); - } - - @Override - public Map getMetadata(Server server) { - if (server instanceof ConsulServer) { - ConsulServer consulServer = (ConsulServer) server; - return consulServer.getMetadata(); - } - return super.getMetadata(server); - } - -} 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 deleted file mode 100644 index a34d06fb..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.QueryParams; -import com.ecwid.consul.v1.Response; -import com.ecwid.consul.v1.health.model.HealthService; -import com.netflix.client.config.IClientConfig; -import com.netflix.loadbalancer.AbstractServerList; - -/** - * @author Spencer Gibb - * @author Richard Kettelerij - * @author Varnson Fan - */ -public class ConsulServerList extends AbstractServerList { - - private final ConsulClient client; - - private final ConsulDiscoveryProperties properties; - - private String serviceId; - - public ConsulServerList(ConsulClient client, ConsulDiscoveryProperties properties) { - this.client = client; - this.properties = properties; - } - - protected ConsulClient getClient() { - return this.client; - } - - protected ConsulDiscoveryProperties getProperties() { - return this.properties; - } - - protected String getServiceId() { - return this.serviceId; - } - - @Override - public void initWithNiwsConfig(IClientConfig clientConfig) { - this.serviceId = clientConfig.getClientName(); - } - - @Override - public List getInitialListOfServers() { - return getServers(); - } - - @Override - public List getUpdatedListOfServers() { - return getServers(); - } - - private List getServers() { - if (this.client == null) { - return Collections.emptyList(); - } - String tag = getTag(); // null is ok - Response> response = this.client.getHealthServices( - this.serviceId, tag, this.properties.isQueryPassing(), - createQueryParamsForClientRequest(), this.properties.getAclToken()); - if (response.getValue() == null || response.getValue().isEmpty()) { - return Collections.emptyList(); - } - return transformResponse(response.getValue()); - } - - /** - * Transforms the response from Consul in to a list of usable {@link ConsulServer}s. - * @param healthServices the initial list of servers from Consul. Guaranteed to be - * non-empty list - * @return ConsulServer instances - * @see ConsulServer#ConsulServer(HealthService) - */ - protected List transformResponse(List healthServices) { - List servers = new ArrayList<>(); - for (HealthService service : healthServices) { - ConsulServer server = new ConsulServer(service); - if (server.getMetadata() - .containsKey(this.properties.getDefaultZoneMetadataName())) { - server.setZone(server.getMetadata() - .get(this.properties.getDefaultZoneMetadataName())); - } - servers.add(server); - } - return servers; - } - - /** - * This method will create the {@link QueryParams} to use when retrieving the services - * from Consul. By default {@link QueryParams#DEFAULT} is used. In case a datacenter - * is specified for the current serviceId {@link QueryParams#datacenter} is set. - * @return an instance of {@link QueryParams} - */ - protected QueryParams createQueryParamsForClientRequest() { - String datacenter = getDatacenter(); - if (datacenter != null) { - return new QueryParams(datacenter, this.properties.getConsistencyMode()); - } - return new QueryParams(this.properties.getConsistencyMode()); - } - - protected String getTag() { - return this.properties.getQueryTagForService(this.serviceId); - } - - protected String getDatacenter() { - return this.properties.getDatacenters().get(this.serviceId); - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("ConsulServerList{"); - sb.append("serviceId='").append(this.serviceId).append('\''); - sb.append(", tag=").append(getTag()); - sb.append('}'); - return sb.toString(); - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilter.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilter.java deleted file mode 100644 index c1fcd84b..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilter.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.ArrayList; -import java.util.List; - -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerListFilter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * ServerList implementation that filters ConsulServers based on if all their Health - * Checks are PASSING. - * - * @author Spencer Gibb - */ -public class HealthServiceServerListFilter implements ServerListFilter { - - private static final Log log = LogFactory.getLog(HealthServiceServerListFilter.class); - - @Override - public List getFilteredListOfServers(List servers) { - List filtered = new ArrayList<>(); - - for (Server server : servers) { - if (server instanceof ConsulServer) { - ConsulServer consulServer = (ConsulServer) server; - - if (consulServer.isPassingChecks()) { - filtered.add(server); - } - - } - else { - if (log.isDebugEnabled()) { - log.debug("Unable to determine aliveness of server type " - + server.getClass() + ", " + server); - } - filtered.add(server); - } - } - - return filtered; - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java index 1738d424..3a932634 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/HeartbeatProperties.java @@ -94,8 +94,8 @@ public class HeartbeatProperties { @Override public String toString() { return new ToStringCreator(this).append("enabled", this.enabled) - .append("ttl", this.ttl) - .append("intervalRatio", this.intervalRatio).toString(); + .append("ttl", this.ttl).append("intervalRatio", this.intervalRatio) + .toString(); } } 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 deleted file mode 100644 index fa25ffab..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/RibbonConsulAutoConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.consul.ConditionalOnConsulEnabled; -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(proxyBeanMethods = false) -@EnableConfigurationProperties -@ConditionalOnConsulEnabled -@ConditionalOnBean(SpringClientFactory.class) -@ConditionalOnProperty(value = "spring.cloud.consul.ribbon.enabled", - matchIfMissing = true) -@AutoConfigureAfter(RibbonAutoConfiguration.class) -@RibbonClients(defaultConfiguration = ConsulRibbonClientConfiguration.class) -public class RibbonConsulAutoConfiguration { - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java index dd3bc39f..2b25c25b 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/TtlScheduler.java @@ -63,8 +63,8 @@ public class TtlScheduler { */ public void add(String instanceId) { ScheduledFuture task = this.scheduler.scheduleAtFixedRate( - new ConsulHeartbeatTask(instanceId), this.configuration - .computeHearbeatInterval().toMillis()); + new ConsulHeartbeatTask(instanceId), + this.configuration.computeHearbeatInterval().toMillis()); ScheduledFuture previousTask = this.serviceHeartbeats.put(instanceId, task); if (previousTask != null) { previousTask.cancel(true); diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/AliveServerListFilter.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/AliveServerListFilter.java deleted file mode 100644 index 16a2494c..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/AliveServerListFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.filters; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerListFilter; - -import org.springframework.cloud.consul.discovery.ConsulServer; - -/** - * Server filter: returns only alive servers. Each consul agent runs a serf agent which is - * a member of the serf gossip pool. The serf status (alive/failed/etc) is reflected in 2 - * consul APIs: in the agent API and in the catalog API. We prefer the agent API because - * it is most up to date (or perhaps we should intersect them and pick members that are - * live in both). - * - * @author nicu marasoiu on 10.03.2015. - */ -@Deprecated -public class AliveServerListFilter implements ServerListFilter { - - private FilteringAgentClient filteringAgentClient; - - public AliveServerListFilter(FilteringAgentClient filteringAgentClient) { - this.filteringAgentClient = filteringAgentClient; - } - - @Override - public List getFilteredListOfServers(List servers) { - Set liveNodes = this.filteringAgentClient.getAliveAgentsAddresses(); - List filteredServers = new ArrayList<>(); - for (Server server : servers) { - ConsulServer consulServer = ConsulServer.class.cast(server); - if (liveNodes.contains( - consulServer.getHealthService().getService().getAddress())) { - filteredServers.add(server); - } - } - return filteredServers; - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/FilteringAgentClient.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/FilteringAgentClient.java deleted file mode 100644 index 310f3b3b..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/FilteringAgentClient.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.filters; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.agent.model.Member; - -import org.springframework.cloud.consul.model.SerfStatusEnum; - -/** - * @author Nicu Marasoiu - */ -@Deprecated -public class FilteringAgentClient { - - private static final int ALIVE_STATUS = SerfStatusEnum.StatusAlive.getCode(); - - private final ConsulClient client; - - public FilteringAgentClient(ConsulClient client) { - this.client = client; - } - - public List getAliveAgents() { - List members = this.client.getAgentMembers().getValue(); - List liveMembers = new ArrayList<>(members.size()); - for (Member peer : members) { - if (peer.getStatus() == ALIVE_STATUS) { - liveMembers.add(peer); - } - } - return liveMembers; - } - - public Set getAliveAgentsAddresses() { - Set addresses = new HashSet<>(); - for (Member server : getAliveAgents()) { - addresses.add(server.getAddress()); - } - return addresses; - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/ServiceCheckServerListFilter.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/ServiceCheckServerListFilter.java deleted file mode 100644 index a59af712..00000000 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/filters/ServiceCheckServerListFilter.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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.filters; - -import java.util.ArrayList; -import java.util.List; - -import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.QueryParams; -import com.ecwid.consul.v1.health.model.Check; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerListFilter; - -/** - * Created by nicu on 12.03.2015. - * - * @author Nicu Marasoiu - */ -@Deprecated -public class ServiceCheckServerListFilter implements ServerListFilter { - - private ConsulClient client; - - public ServiceCheckServerListFilter(ConsulClient client) { - this.client = client; - } - - @Override - public List getFilteredListOfServers(List servers) { - List okServers = new ArrayList<>(servers.size()); - - for (Server server : servers) { - String appName = server.getMetaInfo().getAppName(); - String instanceId = server.getMetaInfo().getInstanceId(); - // TODO: cache getHealthChecks? this is hit often - List serviceChecks = this.client - .getHealthChecksForService(appName, QueryParams.DEFAULT).getValue(); - boolean serviceOk = true; - for (Check check : serviceChecks) { - if (check.getServiceId().equals(instanceId) - && check.getStatus() != Check.CheckStatus.PASSING) { - serviceOk = false; - break; // just need one to fail - } - } - if (serviceOk) { - okServers.add(server); - } - } - - return okServers; - } - -} diff --git a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java index 0f02b94a..04c4d9f2 100644 --- a/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java +++ b/spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoRegistration.java @@ -228,7 +228,9 @@ public class ConsulAutoRegistration extends ConsulRegistration { properties.getHealthCheckCriticalTimeout()); } if (ttlConfig.isEnabled()) { - check.setTtl(ttlConfig.getTtl()); + // FIXME 3.0.0 + // https://github.com/spring-cloud/spring-cloud-consul/issues/614 + check.setTtl(ttlConfig.getTtl().getSeconds() + "s"); return check; } 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 49efda74..935e9e7d 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,5 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.springframework.cloud.consul.discovery.RibbonConsulAutoConfiguration,\ org.springframework.cloud.consul.discovery.configclient.ConsulConfigServerAutoConfiguration,\ org.springframework.cloud.consul.serviceregistry.ConsulAutoServiceRegistrationAutoConfiguration,\ org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration,\ diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulLoadbalancerClientTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulLoadbalancerClientTests.java index 0e04eeee..7516b7ea 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulLoadbalancerClientTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulLoadbalancerClientTests.java @@ -16,8 +16,7 @@ package org.springframework.cloud.consul.discovery; -import com.netflix.loadbalancer.Server; -import com.netflix.loadbalancer.ServerListFilter; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,8 +27,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; -import org.springframework.cloud.netflix.ribbon.RibbonClient; -import org.springframework.context.annotation.Bean; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -50,6 +47,7 @@ public class ConsulLoadbalancerClientTests { private LoadBalancerClient client; @Test + @Ignore // FIXME: 3.0.0 public void chooseWorks() { ServiceInstance instance = this.client.choose("testConsulLoadBalancer"); assertThat(instance).isNotNull(); @@ -67,7 +65,8 @@ public class ConsulLoadbalancerClientTests { @SpringBootConfiguration @EnableAutoConfiguration @EnableDiscoveryClient - @RibbonClient(name = "testConsulLoadBalancer", configuration = MyRibbonConfig.class) + // @RibbonClient(name = "testConsulLoadBalancer", configuration = + // MyRibbonConfig.class) public static class MyTestConfig { } @@ -78,10 +77,10 @@ public class ConsulLoadbalancerClientTests { System.err.println("here"); } - @Bean - public ServerListFilter ribbonServerListFilter() { - return servers -> servers; - } + // @Bean + // public ServerListFilter ribbonServerListFilter() { + // return servers -> servers; + // } } diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListAclTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListAclTests.java deleted file mode 100644 index 9716c127..00000000 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListAclTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.List; - -import com.ecwid.consul.v1.ConsulClient; -import com.netflix.client.config.DefaultClientConfigImpl; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author b omee - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ConsulServerListAclTests.TestConfig.class, - properties = { "spring.application.name=testConsulServerListAcl", - "spring.cloud.consul.discovery.preferIpAddress=true", - "consul.token=2d2e6b3b-1c82-40ab-8171-54609d8ad304" }, - webEnvironment = RANDOM_PORT) -public class ConsulServerListAclTests { - - @Autowired - private ConsulClient consulClient; - - @Autowired - private ConsulDiscoveryProperties properties; - - @Test - public void serverListWorksWithAcl() { - ConsulServerList consulServerList = new ConsulServerList(this.consulClient, - this.properties); - DefaultClientConfigImpl config = new DefaultClientConfigImpl(); - config.setClientName("testConsulServerListAcl"); - consulServerList.initWithNiwsConfig(config); - List servers = consulServerList.getUpdatedListOfServers(); - assertThat(servers).as("servers was null").isNotNull(); - assertThat(servers.isEmpty()).as("servers was empty").isFalse(); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @EnableDiscoveryClient - public static class TestConfig { - - } - -} diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeDefaultTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeDefaultTests.java deleted file mode 100644 index 388373ba..00000000 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeDefaultTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 com.ecwid.consul.v1.ConsistencyMode; -import com.ecwid.consul.v1.ConsulClient; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Varnson Fan - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ConsulServerListConsistencyModeDefaultTests.TestConfig.class, - properties = { "spring.application.name=testConsulServerListConsistencyMode", - "spring.cloud.consul.discovery.preferIpAddress=true" }, - webEnvironment = RANDOM_PORT) -public class ConsulServerListConsistencyModeDefaultTests { - - @Autowired - private ConsulClient consulClient; - - @Autowired - private ConsulDiscoveryProperties properties; - - @Test - public void serverListWorksWithConsistencyMode() { - ConsulServerList consulServerList = new ConsulServerList(this.consulClient, - this.properties); - - assertThat(consulServerList.getProperties().getConsistencyMode() - .equals(ConsistencyMode.DEFAULT)).as("ConsistencyMode is default") - .isTrue(); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @EnableDiscoveryClient - public static class TestConfig { - - } - -} diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeStaleTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeStaleTests.java deleted file mode 100644 index 53f75c68..00000000 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListConsistencyModeStaleTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 com.ecwid.consul.v1.ConsistencyMode; -import com.ecwid.consul.v1.ConsulClient; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -/** - * @author Varnson Fan - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ConsulServerListConsistencyModeStaleTests.TestConfig.class, - properties = { "spring.application.name=testConsulServerListConsistencyMode", - "spring.cloud.consul.discovery.preferIpAddress=true", - "spring.cloud.consul.discovery.consistencyMode=STALE" }, - webEnvironment = RANDOM_PORT) -public class ConsulServerListConsistencyModeStaleTests { - - @Autowired - private ConsulClient consulClient; - - @Autowired - private ConsulDiscoveryProperties properties; - - @Test - public void serverListWorksWithConsistencyMode() { - ConsulServerList consulServerList = new ConsulServerList(this.consulClient, - this.properties); - - assertThat(consulServerList.getProperties().getConsistencyMode() - .equals(ConsistencyMode.STALE)).as("ConsistencyMode is stale").isTrue(); - } - - @Configuration(proxyBeanMethods = false) - @EnableAutoConfiguration - @EnableDiscoveryClient - public static class TestConfig { - - } - -} diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListTests.java deleted file mode 100644 index 7da9dcc4..00000000 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/ConsulServerListTests.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import com.ecwid.consul.v1.ConsulClient; -import com.ecwid.consul.v1.agent.model.NewService; -import com.netflix.client.config.DefaultClientConfigImpl; -import org.junit.Test; - -import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.cloud.commons.util.InetUtilsProperties; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Spencer Gibb - */ -public class ConsulServerListTests { - - private final String name = "consulServerListTestsService"; - - @Test - public void tagsWork() { - ConsulClient consul = new ConsulClient(); - - NewService nonTagged = createService("NonTagged", 8080, null); - - String tag = "mytag"; - NewService tagged = createService("Tagged", 9080, Arrays.asList(tag)); - - String zone = "myzone"; - NewService withZone = createService("WithZone", 10080, - Arrays.asList("zone=" + zone)); - - String group = "test"; - NewService withGroup = createService("WithGroup", 11080, - Arrays.asList("group=" + group)); - - try { - consul.agentServiceRegister(nonTagged); - consul.agentServiceRegister(tagged); - consul.agentServiceRegister(withZone); - consul.agentServiceRegister(withGroup); - - InetUtils inetUtils = new InetUtils(new InetUtilsProperties()); - DefaultClientConfigImpl config = new DefaultClientConfigImpl(); - config.setClientName(this.name); - - ConsulServerList serverList = new ConsulServerList(consul, - new ConsulDiscoveryProperties(inetUtils)); - serverList.initWithNiwsConfig(config); - - List servers = serverList.getInitialListOfServers(); - assertThat(servers).as("servers was wrong size").hasSize(4); - - int serverWithZoneCount = 0; - for (ConsulServer server : servers) { - if (server.getMetadata().containsKey("zone")) { - serverWithZoneCount++; - assertThat(server.getZone()).as("server was wrong zone") - .isEqualTo(zone); - } - else { - assertThat(server.getZone()).as("server was wrong zone") - .isEqualTo(ConsulServer.UNKNOWN_ZONE); - } - } - assertThat(serverWithZoneCount).as("server was wrong zone").isEqualTo(1); - - serverList = new ConsulServerList(consul, - getProperties(this.name, tag, inetUtils)); - serverList.initWithNiwsConfig(config); - - servers = serverList.getInitialListOfServers(); - assertThat(servers).as("servers was wrong size").hasSize(1); - ConsulServer server = servers.get(0); - assertThat(server.getPort()).as("server was wrong").isEqualTo(9080); - - // test server group - serverList = new ConsulServerList(consul, - getProperties(this.name, "group=" + group, inetUtils)); - serverList.initWithNiwsConfig(config); - - servers = serverList.getInitialListOfServers(); - assertThat(servers).as("servers was wrong size").hasSize(1); - server = servers.get(0); - assertThat(server.getPort()).as("server was wrong").isEqualTo(11080); - assertThat(server.getMetaInfo().getServerGroup()).as("server group was wrong") - .isEqualTo(group); - } - finally { - consul.agentServiceDeregister(nonTagged.getId()); - consul.agentServiceDeregister(tagged.getId()); - consul.agentServiceDeregister(withZone.getId()); - consul.agentServiceDeregister(withGroup.getId()); - } - } - - private ConsulDiscoveryProperties getProperties(String name, String tag, - InetUtils inetUtils) { - ConsulDiscoveryProperties properties = new ConsulDiscoveryProperties(inetUtils); - HashMap map = new HashMap<>(); - map.put(name, tag); - properties.setServerListQueryTags(map); - return properties; - } - - private NewService createService(String id, int port, List tags) { - NewService service = new NewService(); - service.setName(this.name); - service.setId(this.name + id); - service.setAddress("localhost"); - service.setPort(port); - if (tags != null) { - service.setTags(tags); - } - return service; - } - -} diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilterTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilterTests.java deleted file mode 100644 index 25e162f3..00000000 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/HealthServiceServerListFilterTests.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2013-2019 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 - * - * https://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 java.util.ArrayList; -import java.util.List; - -import com.ecwid.consul.v1.health.model.Check; -import com.ecwid.consul.v1.health.model.HealthService; -import com.netflix.loadbalancer.Server; -import org.junit.Test; - -import static com.ecwid.consul.v1.health.model.Check.CheckStatus.CRITICAL; -import static com.ecwid.consul.v1.health.model.Check.CheckStatus.PASSING; -import static com.ecwid.consul.v1.health.model.Check.CheckStatus.WARNING; -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Spencer Gibb - */ -public class HealthServiceServerListFilterTests { - - @Test - public void testGetFilteredListOfServers() { - HealthServiceServerListFilter filter = new HealthServiceServerListFilter(); - - ArrayList servers = new ArrayList<>(); - servers.add(newServer(PASSING)); - servers.add(newServer(PASSING)); - servers.add(newServer(CRITICAL)); - servers.add(newServer(WARNING)); - - List filtered = filter.getFilteredListOfServers(servers); - assertThat(filtered).as("wrong # of filtered servers").hasSize(2); - } - - private ConsulServer newServer(Check.CheckStatus checkStatus) { - HealthService healthService = new HealthService(); - HealthService.Node node = new HealthService.Node(); - node.setAddress("nodeaddr" + checkStatus.name()); - node.setNode("nodenode" + checkStatus.name()); - healthService.setNode(node); - HealthService.Service service = new HealthService.Service(); - service.setAddress("serviceaddr" + checkStatus.name()); - service.setId("serviceid" + checkStatus.name()); - service.setPort(8080); - service.setService("serviceservice" + checkStatus.name()); - healthService.setService(service); - ArrayList checks = new ArrayList<>(); - Check check = new Check(); - check.setStatus(checkStatus); - checks.add(check); - healthService.setChecks(checks); - return new ConsulServer(healthService); - } - -} diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/configclient/TestConsulDiscoveryClientBootstrapConfiguration.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/configclient/TestConsulDiscoveryClientBootstrapConfiguration.java index e106a981..80a89eaa 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/configclient/TestConsulDiscoveryClientBootstrapConfiguration.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/discovery/configclient/TestConsulDiscoveryClientBootstrapConfiguration.java @@ -38,8 +38,8 @@ public class TestConsulDiscoveryClientBootstrapConfiguration { public ConsulDiscoveryClient consulDiscoveryClient( ConsulDiscoveryProperties properties) { ConsulDiscoveryClient client = mock(ConsulDiscoveryClient.class); - ServiceInstance instance = new DefaultServiceInstance("configserver", - properties.getHostname(), properties.getPort(), false); + ServiceInstance instance = new DefaultServiceInstance("configserver1", + "configserver", properties.getHostname(), properties.getPort(), false); given(client.getInstances("configserver")).willReturn(Arrays.asList(instance)); return client; } diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedInstanceGroupTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedInstanceGroupTests.java index 3ac0d72a..b23c743f 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedInstanceGroupTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationCustomizedInstanceGroupTests.java @@ -16,13 +16,12 @@ package org.springframework.cloud.consul.serviceregistry; -import java.util.List; import java.util.Map; import com.ecwid.consul.v1.ConsulClient; import com.ecwid.consul.v1.Response; import com.ecwid.consul.v1.agent.model.Service; -import com.netflix.client.config.DefaultClientConfigImpl; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,8 +32,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; import org.springframework.cloud.consul.ConsulAutoConfiguration; import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties; -import org.springframework.cloud.consul.discovery.ConsulServer; -import org.springframework.cloud.consul.discovery.ConsulServerList; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.junit4.SpringRunner; @@ -60,6 +57,7 @@ public class ConsulAutoServiceRegistrationCustomizedInstanceGroupTests { private ConsulDiscoveryProperties properties; @Test + @Ignore // FIXME: 3.0.0 public void contextLoads() { Response> response = this.consul.getAgentServices(); Map services = response.getValue(); @@ -71,15 +69,16 @@ public class ConsulAutoServiceRegistrationCustomizedInstanceGroupTests { assertThat(service.getTags().contains("group=test")).as("service group was wrong") .isTrue(); - ConsulServerList serverList = new ConsulServerList(this.consul, this.properties); - DefaultClientConfigImpl config = new DefaultClientConfigImpl(); - config.setClientName("myTestService-WithGroup"); - serverList.initWithNiwsConfig(config); - - List servers = serverList.getInitialListOfServers(); - assertThat(servers.size()).as("servers was wrong size").isEqualTo(1); - assertThat(servers.get(0).getMetaInfo().getServerGroup()) - .as("service group was wrong").isEqualTo("test"); + // ConsulServerList serverList = new ConsulServerList(this.consul, + // this.properties); + // DefaultClientConfigImpl config = new DefaultClientConfigImpl(); + // config.setClientName("myTestService-WithGroup"); + // serverList.initWithNiwsConfig(config); + // + // List servers = serverList.getInitialListOfServers(); + // assertThat(servers.size()).as("servers was wrong size").isEqualTo(1); + // assertThat(servers.get(0).getMetaInfo().getServerGroup()) + // .as("service group was wrong").isEqualTo("test"); } @Configuration(proxyBeanMethods = false) diff --git a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationRetryTests.java b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationRetryTests.java index d1b4c3a5..66bcdc85 100644 --- a/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationRetryTests.java +++ b/spring-cloud-consul-discovery/src/test/java/org/springframework/cloud/consul/serviceregistry/ConsulAutoServiceRegistrationRetryTests.java @@ -27,7 +27,7 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.system.OutputCaptureRule; import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationConfiguration; import org.springframework.cloud.consul.ConsulAutoConfiguration; import org.springframework.context.ConfigurableApplicationContext; @@ -45,7 +45,7 @@ public class ConsulAutoServiceRegistrationRetryTests { public ExpectedException exception = ExpectedException.none(); @Rule - public OutputCapture output = new OutputCapture(); + public OutputCaptureRule output = new OutputCaptureRule(); @Test public void testRetry() { diff --git a/spring-cloud-consul-sample/pom.xml b/spring-cloud-consul-sample/pom.xml index be464abb..a0155f7a 100644 --- a/spring-cloud-consul-sample/pom.xml +++ b/spring-cloud-consul-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-consul-all/pom.xml b/spring-cloud-starter-consul-all/pom.xml index 889da389..bcb1094b 100644 --- a/spring-cloud-starter-consul-all/pom.xml +++ b/spring-cloud-starter-consul-all/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. spring-cloud-starter-consul-all diff --git a/spring-cloud-starter-consul-bus/pom.xml b/spring-cloud-starter-consul-bus/pom.xml index 2d505571..e17c5b6d 100644 --- a/spring-cloud-starter-consul-bus/pom.xml +++ b/spring-cloud-starter-consul-bus/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. spring-cloud-starter-consul-bus diff --git a/spring-cloud-starter-consul-config/pom.xml b/spring-cloud-starter-consul-config/pom.xml index 4eb5e29c..d19358e6 100644 --- a/spring-cloud-starter-consul-config/pom.xml +++ b/spring-cloud-starter-consul-config/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. spring-cloud-starter-consul-config diff --git a/spring-cloud-starter-consul-discovery/pom.xml b/spring-cloud-starter-consul-discovery/pom.xml index 5ee99966..c3ec7089 100644 --- a/spring-cloud-starter-consul-discovery/pom.xml +++ b/spring-cloud-starter-consul-discovery/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. spring-cloud-starter-consul-discovery @@ -29,21 +29,9 @@ org.springframework.cloud spring-cloud-consul-discovery - - org.springframework.cloud - spring-cloud-netflix-hystrix - - - org.springframework.cloud - spring-cloud-starter-netflix-ribbon - org.springframework.cloud spring-cloud-starter-loadbalancer - - joda-time - joda-time - diff --git a/spring-cloud-starter-consul/pom.xml b/spring-cloud-starter-consul/pom.xml index 7dc40efb..38a8357d 100644 --- a/spring-cloud-starter-consul/pom.xml +++ b/spring-cloud-starter-consul/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-consul - 2.2.2.BUILD-SNAPSHOT + 3.0.0.BUILD-SNAPSHOT .. spring-cloud-starter-consul