Search in sources :

Example 6 with DiscoveryResult

use of com.netflix.zuul.discovery.DiscoveryResult in project zuul by Netflix.

the class DefaultClientChannelManagerTest method pickAddressInternal_discovery.

@Test
public void pickAddressInternal_discovery() {
    InstanceInfo instanceInfo = Builder.newBuilder().setAppName("app").setHostName("192.168.0.1").setPort(443).build();
    DiscoveryResult s = DiscoveryResult.from(instanceInfo, true);
    SocketAddress addr = DefaultClientChannelManager.pickAddressInternal(s, OriginName.fromVip("vip"));
    Truth.assertThat(addr).isInstanceOf(InetSocketAddress.class);
    InetSocketAddress socketAddress = (InetSocketAddress) addr;
    assertEquals(InetAddresses.forString("192.168.0.1"), socketAddress.getAddress());
    assertEquals(443, socketAddress.getPort());
}
Also used : DiscoveryResult(com.netflix.zuul.discovery.DiscoveryResult) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 7 with DiscoveryResult

use of com.netflix.zuul.discovery.DiscoveryResult in project zuul by Netflix.

the class DefaultClientChannelManager method acquire.

@Override
public Promise<PooledConnection> acquire(EventLoop eventLoop, @Nullable Object key, CurrentPassport passport, AtomicReference<DiscoveryResult> selectedServer, AtomicReference<? super InetAddress> selectedHostAddr) {
    if (shuttingDown) {
        Promise<PooledConnection> promise = eventLoop.newPromise();
        promise.setFailure(SHUTTING_DOWN_ERR);
        return promise;
    }
    // Choose the next load-balanced server.
    final DiscoveryResult chosenServer = dynamicServerResolver.resolve(key);
    // (argha-c): Always ensure the selected server is updated, since the call chain relies on this mutation.
    selectedServer.set(chosenServer);
    if (chosenServer == DiscoveryResult.EMPTY) {
        Promise<PooledConnection> promise = eventLoop.newPromise();
        promise.setFailure(new OriginConnectException("No servers available", OutboundErrorType.NO_AVAILABLE_SERVERS));
        return promise;
    }
    // Now get the connection-pool for this server.
    IConnectionPool pool = perServerPools.computeIfAbsent(chosenServer, s -> {
        SocketAddress finalServerAddr = pickAddress(chosenServer);
        final ClientChannelManager clientChannelMgr = this;
        PooledConnectionFactory pcf = createPooledConnectionFactory(chosenServer, clientChannelMgr, closeConnCounter, closeWrtBusyConnCounter);
        // Create a new pool for this server.
        return createConnectionPool(chosenServer, finalServerAddr, clientConnFactory, pcf, connPoolConfig, clientConfig, createNewConnCounter, createConnSucceededCounter, createConnFailedCounter, requestConnCounter, reuseConnCounter, connTakenFromPoolIsNotOpen, closeAbovePoolHighWaterMarkCounter, maxConnsPerHostExceededCounter, connEstablishTimer, connsInPool, connsInUse);
    });
    return pool.acquire(eventLoop, passport, selectedHostAddr);
}
Also used : DiscoveryResult(com.netflix.zuul.discovery.DiscoveryResult) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

DiscoveryResult (com.netflix.zuul.discovery.DiscoveryResult)7 Test (org.junit.Test)5 InstanceInfo (com.netflix.appinfo.InstanceInfo)4 InetSocketAddress (java.net.InetSocketAddress)4 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)3 DynamicServerResolver (com.netflix.zuul.discovery.DynamicServerResolver)3 OriginName (com.netflix.zuul.origins.OriginName)3 DefaultEventLoop (io.netty.channel.DefaultEventLoop)3 SocketAddress (java.net.SocketAddress)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Registry (com.netflix.spectator.api.Registry)1 EventLoop (io.netty.channel.EventLoop)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 ServerSocket (java.net.ServerSocket)1