Commit 50b1c482 by Spencer Gibb

renamed ServerListInitializer to RibbonClientPreprocessor as it is a bit more descriptive

parent 6654d320
......@@ -7,7 +7,7 @@ import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.ribbon.LoadBalancingTarget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.ServerListInitializer;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.cloud.netflix.archaius.ConfigurableEnvironmentConfiguration;
......@@ -22,7 +22,7 @@ public class FeignConfigurer {
ConfigurableEnvironmentConfiguration envConfig; //FIXME: howto enforce this?
@Autowired
ServerListInitializer serverListInitializer;
RibbonClientPreprocessor ribbonClientPreprocessor;
@Autowired
Decoder decoder;
......@@ -52,7 +52,7 @@ public class FeignConfigurer {
protected <T> T loadBalance(Feign.Builder builder, Class<T> type, String schemeName) {
String name = URI.create(schemeName).getHost();
serverListInitializer.initialize(name);
ribbonClientPreprocessor.preprocess(name);
return builder.target(LoadBalancingTarget.create(type, schemeName));
}
......
......@@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonInitializer;
import org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientPreprocessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestInterceptor;
......@@ -28,7 +28,7 @@ public class RibbonAutoConfiguration {
private List<BaseLoadBalancer> balancers = Collections.emptyList();
@Autowired(required=false)
private EurekaRibbonInitializer initializer;
private EurekaRibbonClientPreprocessor clientPreprocessor;
@Bean
@ConditionalOnMissingBean(RestTemplate.class)
......@@ -52,10 +52,10 @@ public class RibbonAutoConfiguration {
}
@Bean
public ServerListInitializer serverListInitializer() {
return new ServerListInitializer() {
public RibbonClientPreprocessor ribbonClientPreprocessor() {
return new RibbonClientPreprocessor() {
@Override
public void initialize(String serviceId) {
public void preprocess(String serviceId) {
//no-op
}
};
......
package org.springframework.cloud.netflix.ribbon;
/**
* Allows different service discovery implementations to configure ribbon prior to usage.
* TODO: this could potentially be done via AOP
* @author Spencer Gibb
*/
public interface ServerListInitializer {
public void initialize(String serviceId);
public interface RibbonClientPreprocessor {
public void preprocess(String serviceId);
}
......@@ -19,7 +19,7 @@ import com.netflix.loadbalancer.Server;
public class RibbonLoadBalancerClient implements LoadBalancerClient {
@Autowired
private ServerListInitializer serverListInitializer;
private RibbonClientPreprocessor ribbonClientPreprocessor;
@Autowired
private SpringClientFactory clientFactory;
......@@ -34,7 +34,7 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
@Override
public ServiceInstance choose(String serviceId) {
serverListInitializer.initialize(serviceId);
ribbonClientPreprocessor.preprocess(serviceId);
ILoadBalancer loadBalancer = this.balancers.get(serviceId);
if (loadBalancer == null) {
loadBalancer = clientFactory.getNamedLoadBalancer(serviceId);
......
......@@ -7,7 +7,7 @@ import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListClas
import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListFilterClassName;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.ServerListInitializer;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext.ContextKey;
......@@ -20,24 +20,25 @@ import com.netflix.loadbalancer.ZoneAvoidanceRule;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
/**
* Convenience class that sets up some configuration defaults for eureka-discovered ribbon
* clients.
* Preprocessor that configures defaults for eureka-discovered ribbon clients.
* Such as: @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses,
* NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more
*
* @author Spencer Gibb
* @author Dave Syer
*/
public class EurekaRibbonInitializer implements ServerListInitializer {
public class EurekaRibbonClientPreprocessor implements RibbonClientPreprocessor {
private EurekaClientConfig clientConfig;
private SpringClientFactory clientFactory;
public EurekaRibbonInitializer(EurekaClientConfig clientConfig, SpringClientFactory clientFactory) {
public EurekaRibbonClientPreprocessor(EurekaClientConfig clientConfig, SpringClientFactory clientFactory) {
this.clientConfig = clientConfig;
this.clientFactory = clientFactory;
}
@Override
public void initialize(String serviceId) {
public void preprocess(String serviceId) {
if (clientConfig != null
&& ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone) == null) {
String[] zones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
......
......@@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.ServerListInitializer;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -44,7 +44,7 @@ public class RibbonEurekaAutoConfiguration {
private EurekaClientConfig clientConfig;
@Bean
public ServerListInitializer serverListInitializer(SpringClientFactory clientFactory) {
return new EurekaRibbonInitializer(clientConfig, clientFactory);
public RibbonClientPreprocessor ribbonClientPreprocessor(SpringClientFactory clientFactory) {
return new EurekaRibbonClientPreprocessor(clientConfig, clientFactory);
}
}
......@@ -17,7 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.netflix.ribbon.ServerListInitializer;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor;
import org.springframework.cloud.netflix.zuul.RibbonCommand;
import org.springframework.cloud.netflix.zuul.SpringFilter;
import org.springframework.util.StringUtils;
......@@ -71,7 +71,7 @@ public class RibbonRoutingFilter extends SpringFilter {
String serviceId = (String) context.get("serviceId");
getBean(ServerListInitializer.class).initialize(serviceId);
getBean(RibbonClientPreprocessor.class).preprocess(serviceId);
RestClient restClient = getBean(SpringClientFactory.class).namedClient(serviceId, RestClient.class);
......
......@@ -34,7 +34,7 @@ import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
* @author Dave Syer
*
*/
public class EurekaRibbonInitializerTests {
public class EurekaRibbonClientPreprocessorTests {
@After
public void close() {
......@@ -46,9 +46,9 @@ public class EurekaRibbonInitializerTests {
EurekaClientConfigBean client = new EurekaClientConfigBean();
client.getAvailabilityZones().put(client.getRegion(), "foo");
SpringClientFactory clientFactory = new SpringClientFactory();
EurekaRibbonInitializer initializer = new EurekaRibbonInitializer(
EurekaRibbonClientPreprocessor clientPreprocessor = new EurekaRibbonClientPreprocessor(
client, clientFactory);
initializer.initialize("service");
clientPreprocessor.preprocess("service");
ILoadBalancer balancer = clientFactory.getNamedLoadBalancer("service");
assertNotNull(balancer);
@SuppressWarnings("unchecked")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment