use of com.netflix.loadbalancer.Server in project spring-cloud-netflix by spring-cloud.
the class DefaultServerIntrospectorDefaultTests method testDefaultSslPorts.
@Test
public void testDefaultSslPorts() {
Server serverMock = mock(Server.class);
when(serverMock.getPort()).thenReturn(443);
Assert.assertTrue(serverIntrospector.isSecure(serverMock));
when(serverMock.getPort()).thenReturn(8443);
Assert.assertTrue(serverIntrospector.isSecure(serverMock));
when(serverMock.getPort()).thenReturn(16443);
Assert.assertFalse(serverIntrospector.isSecure(serverMock));
}
use of com.netflix.loadbalancer.Server in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancedRetryPolicy method updateServerInstanceStats.
private void updateServerInstanceStats(LoadBalancedRetryContext context) {
ServiceInstance serviceInstance = context.getServiceInstance();
if (serviceInstance instanceof RibbonServer) {
Server lbServer = ((RibbonServer) serviceInstance).getServer();
ServerStats serverStats = lbContext.getServerStats(lbServer);
serverStats.incrementSuccessiveConnectionFailureCount();
serverStats.addToFailureCount();
LOGGER.debug(lbServer.getHostPort() + " RetryCount: " + context.getRetryCount() + " Successive Failures: " + serverStats.getSuccessiveConnectionFailureCount() + " CircuitBreakerTripped:" + serverStats.isCircuitBreakerTripped());
}
}
use of com.netflix.loadbalancer.Server in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClient method execute.
@Override
public <T> T execute(String serviceId, ServiceInstance serviceInstance, LoadBalancerRequest<T> request) throws IOException {
Server server = null;
if (serviceInstance instanceof RibbonServer) {
server = ((RibbonServer) serviceInstance).getServer();
}
if (server == null) {
throw new IllegalStateException("No instances available for " + serviceId);
}
RibbonLoadBalancerContext context = this.clientFactory.getLoadBalancerContext(serviceId);
RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server);
try {
T returnVal = request.apply(serviceInstance);
statsRecorder.recordStats(returnVal);
return returnVal;
}// catch IOException and rethrow so RestTemplate behaves correctly
catch (IOException ex) {
statsRecorder.recordStats(ex);
throw ex;
} catch (Exception ex) {
statsRecorder.recordStats(ex);
ReflectionUtils.rethrowRuntimeException(ex);
}
return null;
}
use of com.netflix.loadbalancer.Server in project spring-cloud-netflix by spring-cloud.
the class RibbonLoadBalancerClient method execute.
@Override
public <T> T execute(String serviceId, LoadBalancerRequest<T> request) throws IOException {
ILoadBalancer loadBalancer = getLoadBalancer(serviceId);
Server server = getServer(loadBalancer);
if (server == null) {
throw new IllegalStateException("No instances available for " + serviceId);
}
RibbonServer ribbonServer = new RibbonServer(serviceId, server, isSecure(server, serviceId), serverIntrospector(serviceId).getMetadata(server));
return execute(serviceId, ribbonServer, request);
}
use of com.netflix.loadbalancer.Server in project spring-cloud-consul by spring-cloud.
the class HealthServiceServerListFilter method getFilteredListOfServers.
@Override
public List<Server> getFilteredListOfServers(List<Server> servers) {
List<Server> filtered = new ArrayList<>();
for (Server server : servers) {
if (server instanceof ConsulServer) {
ConsulServer consulServer = (ConsulServer) server;
if (consulServer.isPassingChecks()) {
filtered.add(server);
}
} else {
log.debug("Unable to determine aliveness of server type " + server.getClass() + ", " + server);
filtered.add(server);
}
}
return filtered;
}
Aggregations