use of com.palantir.atlasdb.cassandra.CassandraServersConfigs.ThriftHostsExtractingVisitor in project atlasdb by palantir.
the class CassandraService method getAddressForHost.
@VisibleForTesting
InetSocketAddress getAddressForHost(String inputHost) throws UnknownHostException {
if (config.addressTranslation().containsKey(inputHost)) {
return config.addressTranslation().get(inputHost);
}
Map<String, String> hostnamesByIp = hostnameByIpSupplier.get();
String host = hostnamesByIp.getOrDefault(inputHost, inputHost);
InetAddress resolvedHost = InetAddress.getByName(host);
Set<InetSocketAddress> allKnownHosts = Sets.union(currentPools.keySet(), config.servers().accept(new ThriftHostsExtractingVisitor()));
for (InetSocketAddress address : allKnownHosts) {
if (Objects.equals(address.getAddress(), resolvedHost)) {
return address;
}
}
Set<Integer> allKnownPorts = allKnownHosts.stream().map(InetSocketAddress::getPort).collect(Collectors.toSet());
if (allKnownPorts.size() == 1) {
// if everyone is on one port, try and use that
return new InetSocketAddress(resolvedHost, Iterables.getOnlyElement(allKnownPorts));
} else {
throw new UnknownHostException("Couldn't find the provided host in server list or current servers");
}
}
use of com.palantir.atlasdb.cassandra.CassandraServersConfigs.ThriftHostsExtractingVisitor in project atlasdb by palantir.
the class CassandraClientPoolTest method setup.
@Before
public void setup() {
config = mock(CassandraKeyValueServiceConfig.class);
runtimeConfig = mock(CassandraKeyValueServiceRuntimeConfig.class);
refreshableRuntimeConfig = Refreshable.only(runtimeConfig);
when(config.poolRefreshIntervalSeconds()).thenReturn(POOL_REFRESH_INTERVAL_SECONDS);
when(config.timeBetweenConnectionEvictionRunsSeconds()).thenReturn(TIME_BETWEEN_EVICTION_RUNS_SECONDS);
when(runtimeConfig.unresponsiveHostBackoffTimeSeconds()).thenReturn(UNRESPONSIVE_HOST_BACKOFF_SECONDS);
when(config.credentials()).thenReturn(mock(CassandraCredentialsConfig.class));
when(config.getKeyspaceOrThrow()).thenReturn("ks");
blacklist = new Blacklist(config, Refreshable.only(runtimeConfig.unresponsiveHostBackoffTimeSeconds()));
doAnswer(invocation -> {
Set<InetSocketAddress> inetSocketAddresses = runtimeConfig.servers().accept(new ThriftHostsExtractingVisitor());
return inetSocketAddresses.stream().map(CassandraServer::of).collect(Collectors.toSet());
}).when(cassandra).getCurrentServerListFromConfig();
doAnswer(invocation -> poolServers.add(getInvocationAddress(invocation))).when(cassandra).addPool(any());
doAnswer(invocation -> poolServers.add(getInvocationAddress(invocation))).when(cassandra).returnOrCreatePool(any(), any());
doAnswer(invocation -> {
poolServers.remove(getInvocationAddress(invocation));
return mock(CassandraClientPoolingContainer.class);
}).when(cassandra).removePool(any());
doAnswer(invocation -> poolServers.stream().collect(Collectors.toMap(x -> x, x -> mock(CassandraClientPoolingContainer.class)))).when(cassandra).getPools();
when(config.socketTimeoutMillis()).thenReturn(1);
}
use of com.palantir.atlasdb.cassandra.CassandraServersConfigs.ThriftHostsExtractingVisitor in project atlasdb by palantir.
the class CassandraService method cacheInitialCassandraHosts.
public void cacheInitialCassandraHosts() {
Set<InetSocketAddress> thriftSocket = config.servers().accept(new ThriftHostsExtractingVisitor());
cassandraHosts = thriftSocket.stream().sorted(Comparator.comparing(InetSocketAddress::toString)).collect(Collectors.toList());
cassandraHosts.forEach(this::addPool);
}
Aggregations