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