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());
}
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);
}
Aggregations