Search in sources :

Example 31 with Server

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));
}
Also used : Server(com.netflix.loadbalancer.Server) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 32 with Server

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());
    }
}
Also used : RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) Server(com.netflix.loadbalancer.Server) RibbonServer(org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer) ServerStats(com.netflix.loadbalancer.ServerStats) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 33 with Server

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;
}
Also used : Server(com.netflix.loadbalancer.Server) IOException(java.io.IOException) IOException(java.io.IOException)

Example 34 with Server

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);
}
Also used : Server(com.netflix.loadbalancer.Server) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer)

Example 35 with Server

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;
}
Also used : Server(com.netflix.loadbalancer.Server) ArrayList(java.util.ArrayList)

Aggregations

Server (com.netflix.loadbalancer.Server)133 Test (org.junit.Test)98 ArrayList (java.util.ArrayList)40 ByteBuf (io.netty.buffer.ByteBuf)26 MockWebServer (com.google.mockwebserver.MockWebServer)25 BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)25 IClientConfig (com.netflix.client.config.IClientConfig)23 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)20 DummyPing (com.netflix.loadbalancer.DummyPing)18 HttpServer (com.sun.net.httpserver.HttpServer)18 URI (java.net.URI)15 Invocation (org.apache.servicecomb.core.Invocation)14 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)12 ServerStats (com.netflix.loadbalancer.ServerStats)12 Person (com.netflix.ribbon.test.resources.EmbeddedResources.Person)12 MockUp (mockit.MockUp)12 ClientException (com.netflix.client.ClientException)11 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)10 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)9 HttpClientResponse (io.reactivex.netty.protocol.http.client.HttpClientResponse)9