Removes ribbon and hystrix dependencies.

This commit is contained in:
Spencer Gibb
2020-01-22 12:39:59 -05:00
parent 4debd04bd7
commit a33ee7fd6b
27 changed files with 179 additions and 976 deletions

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-cloud-zookeeper-docs</artifactId>
<packaging>pom</packaging>

27
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Spring Cloud Zookeeper</name>
<description>Spring Cloud Zookeeper</description>
@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId>
<version>2.2.2.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
@@ -97,19 +97,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- archaius dependencies that are now runtime -->
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- end archaius deps -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
@@ -177,11 +164,11 @@
</dependencyManagement>
<properties>
<spring-cloud-build.version>2.2.2.BUILD-SNAPSHOT</spring-cloud-build.version>
<spring-cloud-commons.version>2.2.2.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>2.2.2.BUILD-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-netflix.version>2.2.2.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>2.2.2.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
<spring-cloud-build.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-build.version>
<spring-cloud-commons.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-commons.version>
<spring-cloud-config.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-config.version>
<spring-cloud-netflix.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
</properties>
<profiles>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-zookeeper-config</artifactId>

View File

@@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
@@ -33,18 +33,6 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-cloud-starter-zookeeper</artifactId>

View File

@@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

View File

@@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
@@ -41,6 +41,10 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>

View File

@@ -5,11 +5,11 @@
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>2.2.1.RELEASE</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath/>
</parent>
<artifactId>spring-cloud-zookeeper-dependencies</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<packaging>pom</packaging>
<name>spring-cloud-zookeeper-dependencies</name>
<description>Spring Cloud Zookeeper Dependencies</description>

View File

@@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
@@ -68,41 +68,11 @@
<artifactId>curator-x-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-archaius</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-loadbalancer</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-httpclient</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
@@ -138,10 +108,6 @@
<artifactId>spring-cloud-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
* Wrapper annotation to enable Ribbon for Zookeeper.
*
* @author Marcin Grzejszczak
* * @since 1.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@ConditionalOnProperty(value = "ribbon.zookeeper.enabled", matchIfMissing = true)
public @interface ConditionalOnRibbonZookeeper {
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
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.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.context.annotation.Configuration;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} that sets up Ribbon for Zookeeper.
*
* @author Dave Syer
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnZookeeperEnabled
@ConditionalOnBean(SpringClientFactory.class)
@ConditionalOnRibbonZookeeper
@AutoConfigureAfter(RibbonAutoConfiguration.class)
@RibbonClients(defaultConfiguration = ZookeeperRibbonClientConfiguration.class)
public class RibbonZookeeperAutoConfiguration {
}

View File

@@ -1,146 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import javax.annotation.PostConstruct;
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.ILoadBalancer;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.PingUrl;
import com.netflix.loadbalancer.ServerList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
import org.springframework.cloud.zookeeper.discovery.dependency.ConditionalOnDependenciesNotPassed;
import org.springframework.cloud.zookeeper.discovery.dependency.ConditionalOnDependenciesPassed;
import org.springframework.cloud.zookeeper.discovery.dependency.DependenciesBasedLoadBalancer;
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
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 zookeeper-discovered ribbon clients. Such as:
* <code>@zone</code>, NIWSServerListClassName, DeploymentContextBasedVipAddresses,
* NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more.
*
* @author Spencer Gibb
* @author Dave Syer
* @author Marcin Grzejszczak
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
public class ZookeeperRibbonClientConfiguration {
private static final Log log = LogFactory
.getLog(ZookeeperRibbonClientConfiguration.class);
protected static final String VALUE_NOT_SET = "__not__set__";
protected static final String DEFAULT_NAMESPACE = "ribbon";
@Value("${ribbon.client.name}")
private String serviceId = "client";
public ZookeeperRibbonClientConfiguration() {
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
public ServerList<?> ribbonServerListFromDependencies(IClientConfig config,
ZookeeperDependencies zookeeperDependencies,
ServiceDiscovery<ZookeeperInstance> serviceDiscovery) {
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
serverList.initFromDependencies(config, zookeeperDependencies);
log.debug(String.format(
"Server list for Ribbon's dependencies based load balancing is [%s]",
serverList));
return serverList;
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.ribbon.loadbalancer", matchIfMissing = true)
public ILoadBalancer dependenciesBasedLoadBalancer(
ZookeeperDependencies zookeeperDependencies, ServerList<?> serverList,
IClientConfig config, IPing iPing) {
return new DependenciesBasedLoadBalancer(zookeeperDependencies, serverList,
config, iPing);
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesPassed
public IPing healthCheckingRule(ZookeeperDependencies zookeeperDependencies) {
return new PingUrl(false, zookeeperDependencies.getDefaultHealthEndpoint());
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnDependenciesNotPassed
public ServerList<?> ribbonServerList(IClientConfig config,
ServiceDiscovery<ZookeeperInstance> serviceDiscovery) {
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
serverList.initWithNiwsConfig(config);
log.debug(String.format(
"Server list for Ribbon's non-dependency based load balancing is [%s]",
serverList));
return serverList;
}
@Bean
public ServerIntrospector serverIntrospector() {
return new ZookeeperServerIntrospector();
}
@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;
}
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import com.netflix.loadbalancer.Server;
import org.apache.curator.x.discovery.ServiceInstance;
/**
* A Zookeeper version of a {@link Server Ribbon Server}.
*
* @author Spencer Gibb
* @since 1.0.0
*/
public class ZookeeperServer extends Server {
private final MetaInfo metaInfo;
private ServiceInstance<ZookeeperInstance> instance;
public ZookeeperServer(final ServiceInstance<ZookeeperInstance> instance) {
// TODO: ssl support
super(instance.getAddress(), instance.getPort());
this.metaInfo = new MetaInfo() {
@Override
public String getAppName() {
return instance.getName();
}
@Override
public String getServerGroup() {
return null;
}
@Override
public String getServiceIdForDiscovery() {
return null;
}
@Override
public String getInstanceId() {
return instance.getId();
}
};
this.instance = instance;
}
@Override
public MetaInfo getMetaInfo() {
return this.metaInfo;
}
public ServiceInstance<ZookeeperInstance> getInstance() {
return this.instance;
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import java.util.Map;
import com.netflix.loadbalancer.Server;
import org.apache.curator.x.discovery.ServiceInstance;
import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector;
/**
* @author Spencer Gibb
*/
public class ZookeeperServerIntrospector extends DefaultServerIntrospector {
@Override
public boolean isSecure(Server server) {
if (server instanceof ZookeeperServer) {
ZookeeperServer zookeeperServer = (ZookeeperServer) server;
Integer sslPort = zookeeperServer.getInstance().getSslPort();
return sslPort != null && sslPort > 0;
}
return super.isSecure(server);
}
@Override
public Map<String, String> getMetadata(Server server) {
if (server instanceof ZookeeperServer) {
ZookeeperServer zookeeperServer = (ZookeeperServer) server;
ServiceInstance<ZookeeperInstance> instance = zookeeperServer.getInstance();
if (instance != null && instance.getPayload() != null) {
return instance.getPayload().getMetadata();
}
}
return super.getMetadata(server);
}
}

View File

@@ -1,116 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList;
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceInstance;
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependencies;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.zookeeper.support.StatusConstants.INSTANCE_STATUS_KEY;
import static org.springframework.cloud.zookeeper.support.StatusConstants.STATUS_UP;
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
/**
* Zookeeper version of {@link AbstractServerList} that returns the list of servers on
* which instances are ran. The implementation is capable of resolving the servers from
* {@link ZookeeperDependencies}.
*
* @author Spencer Gibb
* @author Marcin Grzejszczak
* @since 1.0.0
*/
public class ZookeeperServerList extends AbstractServerList<ZookeeperServer> {
private String serviceId;
private final ServiceDiscovery<ZookeeperInstance> serviceDiscovery;
public ZookeeperServerList(ServiceDiscovery<ZookeeperInstance> serviceDiscovery) {
this.serviceDiscovery = serviceDiscovery;
}
@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
this.serviceId = clientConfig.getClientName();
}
public void initFromDependencies(IClientConfig clientConfig,
ZookeeperDependencies zookeeperDependencies) {
this.serviceId = getServiceIdFromDepsOrClientName(clientConfig,
zookeeperDependencies);
}
private String getServiceIdFromDepsOrClientName(IClientConfig clientConfig,
ZookeeperDependencies zookeeperDependencies) {
String serviceIdFromDeps = zookeeperDependencies
.getPathForAlias(clientConfig.getClientName());
return StringUtils.hasText(serviceIdFromDeps) ? serviceIdFromDeps
: clientConfig.getClientName();
}
@Override
public List<ZookeeperServer> getInitialListOfServers() {
return getServers();
}
@Override
public List<ZookeeperServer> getUpdatedListOfServers() {
return getServers();
}
@SuppressWarnings("unchecked")
protected List<ZookeeperServer> getServers() {
try {
if (this.serviceDiscovery == null) {
return Collections.EMPTY_LIST;
}
Collection<ServiceInstance<ZookeeperInstance>> instances = this.serviceDiscovery
.queryForInstances(this.serviceId);
if (instances == null || instances.isEmpty()) {
return Collections.EMPTY_LIST;
}
List<ZookeeperServer> servers = new ArrayList<>();
for (ServiceInstance<ZookeeperInstance> instance : instances) {
String instanceStatus = null;
if (instance.getPayload() != null
&& instance.getPayload().getMetadata() != null) {
instanceStatus = instance.getPayload().getMetadata()
.get(INSTANCE_STATUS_KEY);
}
if (!StringUtils.hasText(instanceStatus) // backwards compatibility
|| instanceStatus.equalsIgnoreCase(STATUS_UP)) {
servers.add(new ZookeeperServer(instance));
}
}
return servers;
}
catch (Exception e) {
rethrowRuntimeException(e);
}
return Collections.EMPTY_LIST;
}
}

View File

@@ -16,17 +16,6 @@
package org.springframework.cloud.zookeeper.discovery.dependency;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.DynamicServerListLoadBalancer;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,85 +26,86 @@ import org.apache.commons.logging.LogFactory;
* @author Marcin Grzejszczak
* @since 1.0.0
*/
public class DependenciesBasedLoadBalancer extends DynamicServerListLoadBalancer {
public class DependenciesBasedLoadBalancer /*extends DynamicServerListLoadBalancer*/ {
private static final Log log = LogFactory.getLog(DependenciesBasedLoadBalancer.class);
private final Map<String, IRule> ruleCache = new ConcurrentHashMap<>();
//private final Map<String, IRule> ruleCache = new ConcurrentHashMap<>();
private final ZookeeperDependencies zookeeperDependencies;
public DependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies,
ServerList<?> serverList, IClientConfig config, IPing iPing) {
super(config);
public DependenciesBasedLoadBalancer(ZookeeperDependencies zookeeperDependencies/*,
ServerList<?> serverList, IClientConfig config, IPing iPing*/) {
//super(config);
this.zookeeperDependencies = zookeeperDependencies;
setServersList(serverList.getInitialListOfServers());
setPing(iPing);
setServerListImpl(serverList);
//setServersList(serverList.getInitialListOfServers());
//setPing(iPing);
//setServerListImpl(serverList);
}
@Override
public Server chooseServer(Object key) {
String keyAsString;
if ("default".equals(key)) { // this is the default hint, use name instead
keyAsString = getName();
}
else {
keyAsString = (String) key;
}
ZookeeperDependency dependency = this.zookeeperDependencies
.getDependencyForAlias(keyAsString);
log.debug(String.format("Current dependencies are [%s]",
this.zookeeperDependencies));
if (dependency == null) {
log.debug(String.format(
"No dependency found for alias [%s] - will use the default rule which is [%s]",
keyAsString, this.rule));
return this.rule.choose(key);
}
cacheEntryIfMissing(keyAsString, dependency);
log.debug(String.format(
"Will try to retrieve dependency for key [%s]. Current cache contents [%s]",
keyAsString, this.ruleCache));
updateListOfServers();
return this.ruleCache.get(keyAsString).choose(key);
}
private void cacheEntryIfMissing(String keyAsString, ZookeeperDependency dependency) {
if (!this.ruleCache.containsKey(keyAsString)) {
log.debug(String.format("Cache doesn't contain entry for [%s]", keyAsString));
this.ruleCache.put(keyAsString,
chooseRuleForLoadBalancerType(dependency.getLoadBalancerType()));
}
}
private IRule chooseRuleForLoadBalancerType(LoadBalancerType type) {
switch (type) {
case ROUND_ROBIN:
return getRoundRobinRule();
case RANDOM:
return getRandomRule();
case STICKY:
return getStickyRule();
default:
throw new IllegalArgumentException("Unknown load balancer type " + type);
}
}
private RoundRobinRule getRoundRobinRule() {
return new RoundRobinRule(this);
}
private IRule getRandomRule() {
RandomRule randomRule = new RandomRule();
randomRule.setLoadBalancer(this);
return randomRule;
}
private IRule getStickyRule() {
StickyRule stickyRule = new StickyRule(getRoundRobinRule());
stickyRule.setLoadBalancer(this);
return stickyRule;
}
// FIXME: 3.0.0
//@Override
//public Server chooseServer(Object key) {
// String keyAsString;
// if ("default".equals(key)) { // this is the default hint, use name instead
// keyAsString = getName();
// }
// else {
// keyAsString = (String) key;
// }
// ZookeeperDependency dependency = this.zookeeperDependencies
// .getDependencyForAlias(keyAsString);
// log.debug(String.format("Current dependencies are [%s]",
// this.zookeeperDependencies));
// if (dependency == null) {
// log.debug(String.format(
// "No dependency found for alias [%s] - will use the default rule which is [%s]",
// keyAsString, this.rule));
// return this.rule.choose(key);
// }
// cacheEntryIfMissing(keyAsString, dependency);
// log.debug(String.format(
// "Will try to retrieve dependency for key [%s]. Current cache contents [%s]",
// keyAsString, this.ruleCache));
// updateListOfServers();
// return this.ruleCache.get(keyAsString).choose(key);
//}
//
//private void cacheEntryIfMissing(String keyAsString, ZookeeperDependency dependency) {
// if (!this.ruleCache.containsKey(keyAsString)) {
// log.debug(String.format("Cache doesn't contain entry for [%s]", keyAsString));
// this.ruleCache.put(keyAsString,
// chooseRuleForLoadBalancerType(dependency.getLoadBalancerType()));
// }
//}
//
//private IRule chooseRuleForLoadBalancerType(LoadBalancerType type) {
// switch (type) {
// case ROUND_ROBIN:
// return getRoundRobinRule();
// case RANDOM:
// return getRandomRule();
// case STICKY:
// return getStickyRule();
// default:
// throw new IllegalArgumentException("Unknown load balancer type " + type);
// }
//}
//
//private RoundRobinRule getRoundRobinRule() {
// return new RoundRobinRule(this);
//}
//
//private IRule getRandomRule() {
// RandomRule randomRule = new RandomRule();
// randomRule.setLoadBalancer(this);
// return randomRule;
//}
//
//private IRule getStickyRule() {
// StickyRule stickyRule = new StickyRule(getRoundRobinRule());
// stickyRule.setLoadBalancer(this);
// return stickyRule;
//}
}

View File

@@ -16,30 +16,12 @@
package org.springframework.cloud.zookeeper.discovery.dependency;
import java.io.IOException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import feign.Client;
import feign.Request;
import feign.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.FeignRibbonClientAutoConfiguration;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* Configuration for ensuring that headers are set for a given dependency when Feign is
@@ -52,61 +34,62 @@ import org.springframework.context.annotation.Primary;
@ConditionalOnDependenciesPassed
@ConditionalOnZookeeperEnabled
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.headers.enabled", matchIfMissing = true)
@ConditionalOnClass({ Client.class, LoadBalancerFeignClient.class })
@AutoConfigureAfter({ RibbonAutoConfiguration.class,
FeignRibbonClientAutoConfiguration.class })
@ConditionalOnClass({ Client.class/*, LoadBalancerFeignClient.class*/ })
/*@AutoConfigureAfter({ RibbonAutoConfiguration.class,
FeignRibbonClientAutoConfiguration.class })*/
public class DependencyFeignClientAutoConfiguration {
@Autowired(required = false)
private LoadBalancerFeignClient ribbonClient;
@Autowired
private ZookeeperDependencies zookeeperDependencies;
@Autowired
private CachingSpringLoadBalancerFactory loadBalancerFactory;
@Autowired
private SpringClientFactory springClientFactory;
@Bean
@Primary
Client dependencyBasedFeignClient() {
return new LoadBalancerFeignClient(new Client.Default(null, null),
this.loadBalancerFactory, this.springClientFactory) {
@Override
public Response execute(Request request, Request.Options options)
throws IOException {
URI asUri = URI.create(request.url());
String clientName = asUri.getHost();
ZookeeperDependency dependencyForAlias = DependencyFeignClientAutoConfiguration.this.zookeeperDependencies
.getDependencyForAlias(clientName);
Map<String, Collection<String>> headers = getUpdatedHeadersIfPossible(
request, dependencyForAlias);
if (DependencyFeignClientAutoConfiguration.this.ribbonClient != null) {
return DependencyFeignClientAutoConfiguration.this.ribbonClient
.execute(request(request, headers), options);
}
return super.execute(request(request, headers), options);
}
private Request request(Request request,
Map<String, Collection<String>> headers) {
return Request.create(request.method(), request.url(), headers,
request.body(), request.charset());
}
private Map<String, Collection<String>> getUpdatedHeadersIfPossible(
Request request, ZookeeperDependency dependencyForAlias) {
if (dependencyForAlias != null) {
return Collections.unmodifiableMap(new HashMap<>(
dependencyForAlias.getUpdatedHeaders(request.headers())));
}
return request.headers();
}
};
}
// FIXME: 3.0.0
//@Autowired(required = false)
//private LoadBalancerFeignClient ribbonClient;
//
//@Autowired
//private ZookeeperDependencies zookeeperDependencies;
//
//@Autowired
//private CachingSpringLoadBalancerFactory loadBalancerFactory;
//
//@Autowired
//private SpringClientFactory springClientFactory;
//
//@Bean
//@Primary
//Client dependencyBasedFeignClient() {
// return new LoadBalancerFeignClient(new Client.Default(null, null),
// this.loadBalancerFactory, this.springClientFactory) {
//
// @Override
// public Response execute(Request request, Request.Options options)
// throws IOException {
// URI asUri = URI.create(request.url());
// String clientName = asUri.getHost();
// ZookeeperDependency dependencyForAlias = DependencyFeignClientAutoConfiguration.this.zookeeperDependencies
// .getDependencyForAlias(clientName);
// Map<String, Collection<String>> headers = getUpdatedHeadersIfPossible(
// request, dependencyForAlias);
// if (DependencyFeignClientAutoConfiguration.this.ribbonClient != null) {
// return DependencyFeignClientAutoConfiguration.this.ribbonClient
// .execute(request(request, headers), options);
// }
// return super.execute(request(request, headers), options);
// }
//
// private Request request(Request request,
// Map<String, Collection<String>> headers) {
// return Request.create(request.method(), request.url(), headers,
// request.body(), request.charset());
// }
//
// private Map<String, Collection<String>> getUpdatedHeadersIfPossible(
// Request request, ZookeeperDependency dependencyForAlias) {
// if (dependencyForAlias != null) {
// return Collections.unmodifiableMap(new HashMap<>(
// dependencyForAlias.getUpdatedHeaders(request.headers())));
// }
// return request.headers();
// }
//
// };
//}
}

View File

@@ -26,11 +26,9 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.cloud.zookeeper.discovery.ConditionalOnRibbonZookeeper;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
@@ -47,10 +45,8 @@ import org.springframework.web.client.RestTemplate;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnZookeeperEnabled
@ConditionalOnRibbonZookeeper
@ConditionalOnDependenciesPassed
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.resttemplate.enabled", matchIfMissing = true)
@AutoConfigureAfter(DependencyRibbonAutoConfiguration.class)
public class DependencyRestTemplateAutoConfiguration {
@Autowired

View File

@@ -1,85 +0,0 @@
/*
* Copyright 2015-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.zookeeper.discovery.dependency;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
import org.springframework.cloud.zookeeper.discovery.ConditionalOnRibbonZookeeper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* Provides LoadBalancerClient that at runtime can pick proper load balancing strategy
* basing on the Zookeeper dependencies from properties.
*
* @author Marcin Grzejszczak
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnZookeeperEnabled
@ConditionalOnRibbonZookeeper
@ConditionalOnDependenciesPassed
@AutoConfigureBefore(RibbonAutoConfiguration.class)
public class DependencyRibbonAutoConfiguration {
private static final Log log = LogFactory
.getLog(DependencyRibbonAutoConfiguration.class);
@Autowired
ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "spring.cloud.zookeeper.dependency.ribbon.enabled", matchIfMissing = true)
public LoadBalancerClient loadBalancerClient(
SpringClientFactory springClientFactory) {
return new RibbonLoadBalancerClient(springClientFactory) {
@Override
protected Server getServer(String serviceId) {
ILoadBalancer loadBalancer = this.getLoadBalancer(serviceId);
return loadBalancer == null ? null
: chooseServerByServiceIdOrDefault(loadBalancer, serviceId);
}
private Server chooseServerByServiceIdOrDefault(ILoadBalancer loadBalancer,
String serviceId) {
log.debug(String.format(
"Dependencies are set - will try to load balance via provided load balancer [%s] for key [%s]",
loadBalancer, serviceId));
Server server = loadBalancer.chooseServer(serviceId);
log.debug(
String.format("Retrieved server [%s] via load balancer", server));
return server != null ? server : loadBalancer.chooseServer("default");
}
};
}
}

View File

@@ -16,14 +16,8 @@
package org.springframework.cloud.zookeeper.discovery.dependency;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -35,42 +29,43 @@ import org.apache.commons.logging.LogFactory;
* @author Marcin Grzejszczak
* @since 1.0.0
*/
public class StickyRule extends AbstractLoadBalancerRule {
public class StickyRule /*extends AbstractLoadBalancerRule*/ {
private static final Log log = LogFactory.getLog(StickyRule.class);
private final IRule masterStrategy;
//private final IRule masterStrategy;
private final AtomicReference<Server> ourInstance = new AtomicReference<>(null);
//private final AtomicReference<Server> ourInstance = new AtomicReference<>(null);
private final AtomicInteger instanceNumber = new AtomicInteger(-1);
public StickyRule(IRule masterStrategy) {
this.masterStrategy = masterStrategy;
}
@Override
public void initWithNiwsConfig(IClientConfig iClientConfig) {
}
@Override
public Server choose(Object key) {
final List<Server> instances = getLoadBalancer().getServerList(true);
log.debug(String.format("Instances taken from load balancer [%s]", instances));
Server localOurInstance = this.ourInstance.get();
log.debug(String.format("Current saved instance [%s]", localOurInstance));
if (!instances.contains(localOurInstance)) {
this.ourInstance.compareAndSet(localOurInstance, null);
}
if (this.ourInstance.get() == null) {
Server instance = this.masterStrategy.choose(key);
if (this.ourInstance.compareAndSet(null, instance)) {
this.instanceNumber.incrementAndGet();
}
}
return this.ourInstance.get();
}
// FIXME: 3.0.0
//public StickyRule(IRule masterStrategy) {
// this.masterStrategy = masterStrategy;
//}
//
//@Override
//public void initWithNiwsConfig(IClientConfig iClientConfig) {
//
//}
//
//@Override
//public Server choose(Object key) {
// final List<Server> instances = getLoadBalancer().getServerList(true);
// log.debug(String.format("Instances taken from load balancer [%s]", instances));
// Server localOurInstance = this.ourInstance.get();
// log.debug(String.format("Current saved instance [%s]", localOurInstance));
// if (!instances.contains(localOurInstance)) {
// this.ourInstance.compareAndSet(localOurInstance, null);
// }
// if (this.ourInstance.get() == null) {
// Server instance = this.masterStrategy.choose(key);
// if (this.ourInstance.compareAndSet(null, instance)) {
// this.instanceNumber.incrementAndGet();
// }
// }
// return this.ourInstance.get();
//}
/**
* Each time a new instance is picked, an internal counter is incremented. This way

View File

@@ -1,9 +1,7 @@
# Auto Configuration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.zookeeper.discovery.RibbonZookeeperAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.dependency.DependencyFeignClientAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.dependency.DependencyRestTemplateAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependenciesAutoConfiguration,\
org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherAutoConfiguration,\

View File

@@ -1,118 +0,0 @@
/*
* Copyright 2015-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.zookeeper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceInstance;
import org.assertj.core.data.MapEntry;
import org.junit.Test;
import org.springframework.cloud.zookeeper.discovery.ZookeeperInstance;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServer;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServerList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.cloud.zookeeper.support.StatusConstants.INSTANCE_STATUS_KEY;
import static org.springframework.cloud.zookeeper.support.StatusConstants.STATUS_OUT_OF_SERVICE;
import static org.springframework.cloud.zookeeper.support.StatusConstants.STATUS_UP;
/**
* @author Spencer Gibb
*/
public class ZookeeperServerListTests {
@Test
public void testNullServiceDiscoveryReturnsEmptyList() {
ZookeeperServerList serverList = new ZookeeperServerList(null);
List<ZookeeperServer> servers = serverList.getInitialListOfServers();
assertThat(servers).isEmpty();
}
@Test
@SuppressWarnings("unchecked")
public void testEmptyInstancesReturnsEmptyList() throws Exception {
ServiceDiscovery<ZookeeperInstance> serviceDiscovery = mock(
ServiceDiscovery.class);
when(serviceDiscovery.queryForInstances(anyString())).thenReturn(null);
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
List<ZookeeperServer> servers = serverList.getInitialListOfServers();
assertThat(servers).isEmpty();
}
@Test
@SuppressWarnings("unchecked")
public void testGetServers() throws Exception {
ArrayList<ServiceInstance<ZookeeperInstance>> instances = new ArrayList<>();
instances.add(serviceInstance(1, null));
ServiceDiscovery<ZookeeperInstance> serviceDiscovery = mock(
ServiceDiscovery.class);
when(serviceDiscovery.queryForInstances(nullable(String.class)))
.thenReturn(instances);
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
List<ZookeeperServer> servers = serverList.getInitialListOfServers();
assertThat(servers).hasSize(1);
}
private ServiceInstance<ZookeeperInstance> serviceInstance(int instanceNum,
String instanceStatus) {
String id = "instance" + instanceNum + "id";
String name = "instance" + instanceNum + "name";
ZookeeperInstance payload = null;
if (instanceStatus != null) {
payload = new ZookeeperInstance(id, name,
Collections.singletonMap(INSTANCE_STATUS_KEY, instanceStatus));
}
String address = "instance" + instanceNum + "addr";
int port = 8080 + instanceNum;
return new ServiceInstance<>(name, id, address, port, null, payload, 0, null,
null);
}
@Test
@SuppressWarnings("unchecked")
public void testGetServersWithInstanceStatus() throws Exception {
ArrayList<ServiceInstance<ZookeeperInstance>> instances = new ArrayList<>();
instances.add(serviceInstance(1, STATUS_UP));
instances.add(serviceInstance(2, STATUS_OUT_OF_SERVICE));
ServiceDiscovery<ZookeeperInstance> serviceDiscovery = mock(
ServiceDiscovery.class);
when(serviceDiscovery.queryForInstances(nullable(String.class)))
.thenReturn(instances);
ZookeeperServerList serverList = new ZookeeperServerList(serviceDiscovery);
List<ZookeeperServer> servers = serverList.getInitialListOfServers();
assertThat(servers).hasSize(1);
assertThat(servers.get(0).getInstance().getPayload().getMetadata())
.contains(MapEntry.entry(INSTANCE_STATUS_KEY, STATUS_UP));
}
}

View File

@@ -25,8 +25,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.zookeeper.discovery.test.CommonTestConfig;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration;
import org.springframework.context.annotation.Configuration;
@@ -57,23 +55,9 @@ public class ZookeeperDiscoverySecurePortTests {
@Autowired
private ZookeeperRegistration zookeeperRegistration;
@Autowired
private SpringClientFactory clientFactory;
@Value("${spring.application.name}")
private String springAppName;
@Test
public void zookeeperServerIntrospectorWorks() {
ServerIntrospector serverIntrospector = this.clientFactory
.getInstance(springAppName, ServerIntrospector.class);
then(serverIntrospector).isInstanceOf(ZookeeperServerIntrospector.class);
ZookeeperServer zookeeperServer = new ZookeeperServer(
this.zookeeperRegistration.getServiceInstance());
then(serverIntrospector.isSecure(zookeeperServer)).isTrue();
}
@Test
public void isSecureIsTrue() {
ServiceInstance instance = this.loadBalancerClient.choose(this.springAppName);

View File

@@ -21,8 +21,6 @@ import java.util.List;
import java.util.concurrent.Callable;
import com.jayway.awaitility.Awaitility;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.NoOpPing;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.TestingServer;
import org.junit.Test;
@@ -130,11 +128,6 @@ public class StickyRuleTests {
curatorFramework);
}
@Bean
IPing noOpPing() {
return new NoOpPing();
}
}
}

View File

@@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-zookeeper</artifactId>
<version>2.2.1.BUILD-SNAPSHOT</version>
<version>3.0.0.BUILD-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

View File

@@ -23,11 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.zookeeper.ZookeeperAutoConfiguration;
import org.springframework.cloud.zookeeper.config.ZookeeperConfigAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.RibbonZookeeperAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.dependency.DependencyFeignClientAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.dependency.DependencyRestTemplateAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.dependency.ZookeeperDependenciesAutoConfiguration;
import org.springframework.cloud.zookeeper.discovery.watcher.DependencyWatcherAutoConfiguration;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperAutoServiceRegistrationAutoConfiguration;
@@ -49,18 +47,12 @@ public class ZookeeperDisabledTests {
@Autowired(required = false)
private ZookeeperConfigAutoConfiguration zookeeperConfigAutoConfiguration;
@Autowired(required = false)
private RibbonZookeeperAutoConfiguration ribbonZookeeperAutoConfiguration;
@Autowired(required = false)
private ZookeeperDiscoveryAutoConfiguration zookeeperDiscoveryAutoConfiguration;
@Autowired(required = false)
private DependencyFeignClientAutoConfiguration dependencyFeignClientAutoConfiguration;
@Autowired(required = false)
private DependencyRibbonAutoConfiguration dependencyRibbonAutoConfiguration;
@Autowired(required = false)
private DependencyRestTemplateAutoConfiguration dependencyRestTemplateAutoConfiguration;
@@ -85,14 +77,10 @@ public class ZookeeperDisabledTests {
.as("ZookeeperAutoConfiguration was not disabled").isNull();
assertThat(this.zookeeperConfigAutoConfiguration)
.as("ZookeeperConfigAutoConfiguration was not disabled").isNull();
assertThat(this.ribbonZookeeperAutoConfiguration)
.as("RibbonZookeeperAutoConfiguration was not disabled").isNull();
assertThat(this.zookeeperDiscoveryAutoConfiguration)
.as("ZookeeperDiscoveryAutoConfiguration was not disabled").isNull();
assertThat(this.dependencyFeignClientAutoConfiguration)
.as("DependencyFeignClientAutoConfiguration was not disabled").isNull();
assertThat(this.dependencyRibbonAutoConfiguration)
.as("DependencyRibbonAutoConfiguration was not disabled").isNull();
assertThat(this.dependencyRestTemplateAutoConfiguration)
.as("DependencyRestTemplateAutoConfiguration was not disabled").isNull();
assertThat(this.zookeeperDependenciesAutoConfiguration)