@Override public List<Host> get() { Host host = new Host(SEEDS, -1); return Collections.singletonList(host); } };
@Override public String apply(Host input) { if (input != null) { return input.getHostName(); } return null; } });
@Override public String apply(HostConnectionPool<?> host) { return host.getHost().getName(); } }), ",");
@Override public boolean apply(Host host) { Host foundHost = lookup.get(host.getHostName()); if (foundHost == null) { for (String addr : host.getAlternateIpAddresses()) { foundHost = lookup.get(addr); if (foundHost != null) { break; } } } if (foundHost != null) { host.setTokenRanges(foundHost.getTokenRanges()); return true; } return false; } }));
public static String getRingDetails(List<Host> hosts) { StringBuilder sb = new StringBuilder(); for (Host host : hosts) { sb.append(host.toString()) .append("\n"); for (TokenRange range : host.getTokenRanges()) { sb.append(" ").append(range.toString()).append("\n"); } } return sb.toString(); }
@Override public Host apply(InstanceInfo info) { String[] parts = StringUtils.split( StringUtils.split(info.getHostName(), ".")[0], '-'); Host host = new Host(info.getHostName(), info.getPort()) .addAlternateIpAddress( StringUtils.join(new String[] { parts[1], parts[2], parts[3], parts[4] }, ".")) .addAlternateIpAddress(info.getIPAddr()) .setId(info.getId()); try { if (info.getDataCenterInfo() instanceof AmazonInfo) { AmazonInfo amazonInfo = (AmazonInfo)info.getDataCenterInfo(); host.setRack(amazonInfo.get(MetaDataKey.availabilityZone)); } } catch (Throwable t) { LOG.error("Error getting rack for host " + host.getName(), t); } return host; } }));
@Override public synchronized List<Host> get() { try { Map<String, Host> ipToHost = Maps.newHashMap(); for (TokenRange range : keyspace.describeRing(dc, rack)) { for (String endpoint : range.getEndpoints()) { Host host = ipToHost.get(endpoint); if (host == null) { host = new Host(endpoint, defaultPort); ipToHost.put(endpoint, host); } host.getTokenRanges().add(range); } } previousHosts = Lists.newArrayList(ipToHost.values()); return previousHosts; } catch (ConnectionException e) { if (previousHosts == null) { throw new RuntimeException(e); } LOG.warn("Failed to get hosts from " + keyspace.getKeyspaceName() + " via ring describe. Will use previously known ring instead"); return previousHosts; } }
@Override public Supplier<List<Host>> getSupplier(String clusterName) { final List<Host> hosts = new ArrayList<Host>(); String bootCluster = config.getCassandraClusterName(); if (bootCluster.equals(clusterName)) { String seeds = System.getenv("DM_CASSANDRA_CLUSTER_SEEDS"); if (seeds == null || "".equals(seeds)) throw new RuntimeException(errMsg); List<String> cassHostnames = new ArrayList<String>(Arrays.asList(StringUtils.split(seeds, ","))); if (cassHostnames.size() == 0) throw new RuntimeException(errMsg); for (String cassHost : cassHostnames) { hosts.add(new Host(cassHost, 9160)); } } else { hosts.add(new Host("127.0.0.1", 9160).setRack("localdc")); } return new Supplier<List<Host>>() { @Override public List<Host> get() { return hosts; } }; }
params.setTrustStore(sslCxt.getSslTruststore(), sslCxt.getSslTruststorePassword()); socket = TSSLTransportFactory.getClientSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getSocketTimeout(), params); } else { socket = new TSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getConnectTimeout());
lookup.put(host.getIpAddress(), host); for (String addr : host.getAlternateIpAddresses()) { lookup.put(addr, host);
TestHostType type = TestHostType.get(getHost().getPort()); OperationResult<R> result = type.execute(pool, op); long now = System.nanoTime();
if (existingHost.getTokenRanges().size() != host.getTokenRanges().size()) { existingHost.setTokenRanges(host.getTokenRanges()); return true; ArrayList<TokenRange> currentTokens = Lists.newArrayList(existingHost.getTokenRanges()); ArrayList<TokenRange> newTokens = Lists.newArrayList(host.getTokenRanges()); Collections.sort(currentTokens, compareByStartToken); Collections.sort(newTokens, compareByStartToken); existingHost.setTokenRanges(host.getTokenRanges()); return true;
@Override public List<Host> get() { Map<BigInteger, List<Host>> tokenHostMap = source.get(); Set<Host> hosts = Sets.newHashSet(); for (Entry<BigInteger, List<Host>> entry : tokenHostMap.entrySet()) { for (Host host : entry.getValue()) { if (!hosts.contains(host)) { hosts.add(host); } String token = entry.getKey().toString(); host.getTokenRanges().add(new TokenRangeImpl(token, token, null)); } } return Lists.newArrayList(hosts); }
@Override public String getMessage() { return new StringBuilder() .append(getClass().getSimpleName()) .append(": [") .append( "host=" ).append(host.toString()) .append(", latency=" ).append(latency).append("(").append(latencyWithPool).append(")") .append(", attempts=").append(attemptCount) .append("]") .append(super.getMessage()) .toString(); }
@Override public boolean apply(Host host) { Host foundHost = lookup.get(host.getHostName()); if (foundHost == null) { for (String addr : host.getAlternateIpAddresses()) { foundHost = lookup.get(addr); if (foundHost != null) { break; } } } if (foundHost != null) { host.setTokenRanges(foundHost.getTokenRanges()); return true; } return false; } }));
public static List<Host> makeRing( int nHosts, int replication_factor, int id, BigInteger minInitialToken, BigInteger maxInitialToken) { List<Host> hosts = Lists.newArrayList(); for (int i = 0; i < nHosts; i++) { hosts.add(new Host("127.0." + id + "." + i + ":" + TestHostType.GOOD_FAST.ordinal(), 9160)); } for (int i = 0; i < nHosts; i++) { String startToken = TokenGenerator.initialToken(nHosts, i, minInitialToken, maxInitialToken); String endToken = TokenGenerator.initialToken(nHosts, i+1, minInitialToken, maxInitialToken); if (endToken.equals(maxInitialToken.toString())) endToken = minInitialToken.toString(); TokenRange range = new TokenRangeImpl(startToken, endToken, null); for (int j = 0; j < replication_factor; j++) { hosts.get((i+j)%nHosts).getTokenRanges().add(range); } } return hosts; }
private Host parseHostInfo(ResultSet rs) { if (rs == null) { return null; } com.datastax.driver.core.Host fromHost = rs.getExecutionInfo().getQueriedHost(); InetAddress add = fromHost.getAddress(); Host toHost = new Host(add.getHostAddress(), -1); toHost.setRack(fromHost.getRack()); return toHost; }
params.setTrustStore(sslCxt.getSslTruststore(), sslCxt.getSslTruststorePassword()); socket = TSSLTransportFactory.getClientSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getSocketTimeout(), params); } else { socket = new TSocket(getHost().getIpAddress(), getHost().getPort(), cpConfig.getConnectTimeout());
public static String getRingDetails(List<Host> hosts) { StringBuilder sb = new StringBuilder(); for (Host host : hosts) { sb.append(host.toString()) .append("\n"); for (TokenRange range : host.getTokenRanges()) { sb.append(" ").append(range.toString()).append("\n"); } } return sb.toString(); }
lookup.put(host.getIpAddress(), host); for (String addr : host.getAlternateIpAddresses()) { lookup.put(addr, host);