Commit 790ac76a by Spencer Gibb

Change type of loadBalancerClient back LoadBalancerClient.

parent 1d1ad75a
...@@ -67,7 +67,7 @@ public class RibbonAutoConfiguration { ...@@ -67,7 +67,7 @@ public class RibbonAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(LoadBalancerClient.class) @ConditionalOnMissingBean(LoadBalancerClient.class)
public RibbonLoadBalancerClient loadBalancerClient() { public LoadBalancerClient loadBalancerClient() {
return new RibbonLoadBalancerClient(springClientFactory()); return new RibbonLoadBalancerClient(springClientFactory());
} }
...@@ -80,7 +80,7 @@ public class RibbonAutoConfiguration { ...@@ -80,7 +80,7 @@ public class RibbonAutoConfiguration {
private SpringClientFactory springClientFactory; private SpringClientFactory springClientFactory;
@Autowired @Autowired
private RibbonLoadBalancerClient loadBalancerClient; private LoadBalancerClient loadBalancerClient;
@Bean @Bean
public RestTemplateCustomizer restTemplateCustomizer() { public RestTemplateCustomizer restTemplateCustomizer() {
......
...@@ -19,6 +19,8 @@ package org.springframework.cloud.netflix.ribbon; ...@@ -19,6 +19,8 @@ package org.springframework.cloud.netflix.ribbon;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer; import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
...@@ -26,6 +28,7 @@ import org.springframework.http.client.ClientHttpRequestFactory; ...@@ -26,6 +28,7 @@ import org.springframework.http.client.ClientHttpRequestFactory;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.client.http.HttpRequest; import com.netflix.client.http.HttpRequest;
import com.netflix.loadbalancer.Server;
import com.netflix.niws.client.http.RestClient; import com.netflix.niws.client.http.RestClient;
/** /**
...@@ -35,9 +38,9 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory ...@@ -35,9 +38,9 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
private final SpringClientFactory clientFactory; private final SpringClientFactory clientFactory;
private RibbonLoadBalancerClient loadBalancer; private LoadBalancerClient loadBalancer;
public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, RibbonLoadBalancerClient loadBalancer) { public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory, LoadBalancerClient loadBalancer) {
this.clientFactory = clientFactory; this.clientFactory = clientFactory;
this.loadBalancer = loadBalancer; this.loadBalancer = loadBalancer;
} }
...@@ -50,7 +53,7 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory ...@@ -50,7 +53,7 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
if (serviceId == null) { if (serviceId == null) {
throw new IOException("Invalid hostname in the URI [" + originalUri.toASCIIString() + "]"); throw new IOException("Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
} }
RibbonServer instance = loadBalancer.chooseRibbonServer(serviceId); ServiceInstance instance = loadBalancer.choose(serviceId);
if (instance == null) { if (instance == null) {
throw new IllegalStateException("No instances available for "+serviceId); throw new IllegalStateException("No instances available for "+serviceId);
} }
...@@ -60,7 +63,13 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory ...@@ -60,7 +63,13 @@ public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory
RestClient client = this.clientFactory.getClient(instance.getServiceId(), RestClient.class); RestClient client = this.clientFactory.getClient(instance.getServiceId(), RestClient.class);
HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name()); HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name());
RibbonLoadBalancerContext context = this.clientFactory.getLoadBalancerContext(serviceId); RibbonLoadBalancerContext context = this.clientFactory.getLoadBalancerContext(serviceId);
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, instance.getServer());
Server server = null;
if (instance instanceof RibbonServer) {
server = ((RibbonServer)instance).getServer();
}
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server);
//@formatter:on //@formatter:on
return new RibbonHttpRequest(uri, verb, client, clientConfig, statsRecorder); return new RibbonHttpRequest(uri, verb, client, clientConfig, statsRecorder);
} }
......
...@@ -62,10 +62,6 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -62,10 +62,6 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
@Override @Override
public ServiceInstance choose(String serviceId) { public ServiceInstance choose(String serviceId) {
return this.chooseRibbonServer(serviceId);
}
RibbonServer chooseRibbonServer(String serviceId) {
Server server = getServer(serviceId); Server server = getServer(serviceId);
if (server == null) { if (server == null) {
return null; return null;
......
...@@ -12,15 +12,17 @@ import com.netflix.servo.monitor.Stopwatch; ...@@ -12,15 +12,17 @@ import com.netflix.servo.monitor.Stopwatch;
public class RibbonStatsRecorder { public class RibbonStatsRecorder {
private RibbonLoadBalancerContext context; private RibbonLoadBalancerContext context;
private final ServerStats serverStats; private ServerStats serverStats;
private final Stopwatch tracer; private Stopwatch tracer;
public RibbonStatsRecorder(RibbonLoadBalancerContext context, Server server) { public RibbonStatsRecorder(RibbonLoadBalancerContext context, Server server) {
this.context = context; this.context = context;
if (server != null) {
serverStats = context.getServerStats(server); serverStats = context.getServerStats(server);
context.noteOpenConnection(serverStats); context.noteOpenConnection(serverStats);
tracer = context.getExecuteTracer().start(); tracer = context.getExecuteTracer().start();
} }
}
public void recordStats(Object entity) { public void recordStats(Object entity) {
this.recordStats(entity, null); this.recordStats(entity, null);
...@@ -31,8 +33,10 @@ public class RibbonStatsRecorder { ...@@ -31,8 +33,10 @@ public class RibbonStatsRecorder {
} }
protected void recordStats(Object entity, Throwable exception) { protected void recordStats(Object entity, Throwable exception) {
if (this.tracer != null && this.serverStats != null) {
this.tracer.stop(); this.tracer.stop();
long duration = this.tracer.getDuration(TimeUnit.MILLISECONDS); long duration = this.tracer.getDuration(TimeUnit.MILLISECONDS);
this.context.noteRequestCompletion(serverStats, entity, exception, duration, null/* errorHandler */); this.context.noteRequestCompletion(serverStats, entity, exception, duration, null/* errorHandler */);
} }
}
} }
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