@Test public void testParseJson() throws Exception { List<Host> hostList = new ArrayList<>(); hostList.add(new HostBuilder().setHostname("ec2-54-237-143-4.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-50-17-65-2.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-83-87-174.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-81-138-73.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-82-176-215.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-82-83-115.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-211-220-55.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); hostList.add(new HostBuilder().setHostname("ec2-54-80-65-203.compute-1.amazonaws.com").setRack("rack").setStatus(Status.Up).createHost()); List<HostToken> hTokens = testTokenMapSupplier.getTokens(new HashSet<>(hostList)); Collections.sort(hTokens, new Comparator<HostToken>() { @Override public int compare(HostToken o1, HostToken o2) { return o1.getToken().compareTo(o2.getToken()); } }); Assert.assertTrue(validateHostToken(hTokens.get(0), 188627880L, "ec2-50-17-65-2.compute-1.amazonaws.com", "50.17.65.2", 11211, "us-east-1d", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(1), 237822755L, "ec2-54-211-220-55.compute-1.amazonaws.com", "54.211.220.55", 11211, "us-east-1e", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(2), 587531700L, "ec2-54-82-176-215.compute-1.amazonaws.com", "54.82.176.215", 11211, "us-east-1c", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(3), 1669478519L, "ec2-54-80-65-203.compute-1.amazonaws.com", "54.80.65.203", 11211, "us-east-1e", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(4), 2019187467L, "ec2-54-83-87-174.compute-1.amazonaws.com", "54.83.87.174", 11211, "us-east-1c", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(5), 3051939411L, "ec2-54-237-143-4.compute-1.amazonaws.com", "54.237.143.4", 11211, "us-east-1d", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(6), 3101134286L, "ec2-54-82-83-115.compute-1.amazonaws.com", "54.82.83.115", 11211, "us-east-1e", "us-east-1")); Assert.assertTrue(validateHostToken(hTokens.get(7), 3450843231L, "ec2-54-81-138-73.compute-1.amazonaws.com", "54.81.138.73", 11211, "us-east-1c", "us-east-1")); }
@Override public List<HostToken> getTokens(Set<Host> activeHosts) { Set<HostToken> allTokens = new HashSet<HostToken>(); Set<Host> remainingHosts = new HashSet<>(activeHosts); for (Host host : activeHosts) { try { List<HostToken> hostTokens = parseTokenListFromJson(getTopologyJsonPayload((host.getHostAddress()))); for (HostToken hToken : hostTokens) { allTokens.add(hToken); remainingHosts.remove(hToken.getHost()); } if (remainingHosts.size() == 0) { Logger.info("Received token information for " + allTokens.size() + " hosts. Not querying other hosts"); break; } } catch (Exception e) { Logger.warn("Could not get json response for token topology [" + e.getMessage() + "]"); } } return new ArrayList<>(allTokens); }
AbstractTokenMapSupplier implements TokenMapSupplier { @Override public List<HostToken> getTokens(Set<Host> activeHosts) { Set<HostToken> allTokens = new HashSet<HostToken>(); Set<Host> remainingHosts = new HashSet<>(activeHosts); for (Host host : activeHosts) { try { List<HostToken> hostTokens = parseTokenListFromJson(getTopologyJsonPayload((host.getHostAddress()))); for (HostToken hToken : hostTokens) { allTokens.add(hToken); remainingHosts.remove(hToken.getHost()); } if (remainingHosts.size() == 0) { Logger.info("Received token information for " + allTokens.size() + " hosts. Not querying other hosts"); break; } } catch (Exception e) { Logger.warn("Could not get json response for token topology [" + e.getMessage() + "]"); } } return new ArrayList<>(allTokens); } }
AbstractTokenMapSupplier implements TokenMapSupplier { @Override public List<HostToken> getTokens(Set<Host> activeHosts) { Set<HostToken> allTokens = new HashSet<HostToken>(); Set<Host> remainingHosts = new HashSet<>(activeHosts); for (Host host : activeHosts) { try { List<HostToken> hostTokens = parseTokenListFromJson(getTopologyJsonPayload((host.getHostAddress()))); for (HostToken hToken : hostTokens) { allTokens.add(hToken); remainingHosts.remove(hToken.getHost()); } if (remainingHosts.size() == 0) { Logger.info("Received token information for " + allTokens.size() + " hosts. Not querying other hosts"); break; } } catch (Exception e) { Logger.warn("Could not get json response for token topology [" + e.getMessage() + "]"); } } return new ArrayList<>(allTokens); } AbstractTokenMapSupplier(String localRack);  AbstractTokenMapSupplier(String localRack, int port);  AbstractTokenMapSupplier();  AbstractTokenMapSupplier(int port); }
AbstractTokenMapSupplier implements TokenMapSupplier { @Override public List<HostToken> getTokens(Set<Host> activeHosts) { Set<HostToken> allTokens = new HashSet<HostToken>(); Set<Host> remainingHosts = new HashSet<>(activeHosts); for (Host host : activeHosts) { try { List<HostToken> hostTokens = parseTokenListFromJson(getTopologyJsonPayload((host.getHostAddress()))); for (HostToken hToken : hostTokens) { allTokens.add(hToken); remainingHosts.remove(hToken.getHost()); } if (remainingHosts.size() == 0) { Logger.info("Received token information for " + allTokens.size() + " hosts. Not querying other hosts"); break; } } catch (Exception e) { Logger.warn("Could not get json response for token topology [" + e.getMessage() + "]"); } } return new ArrayList<>(allTokens); } AbstractTokenMapSupplier(String localRack);  AbstractTokenMapSupplier(String localRack, int port);  AbstractTokenMapSupplier();  AbstractTokenMapSupplier(int port); abstract String getTopologyJsonPayload(Set<Host> activeHosts); abstract String getTopologyJsonPayload(String hostname); @Override List<HostToken> getTokens(Set<Host> activeHosts); @Override HostToken getTokenForHost(final Host host, final Set<Host> activeHosts); }
AbstractTokenMapSupplier implements TokenMapSupplier { @Override public List<HostToken> getTokens(Set<Host> activeHosts) { Set<HostToken> allTokens = new HashSet<HostToken>(); Set<Host> remainingHosts = new HashSet<>(activeHosts); for (Host host : activeHosts) { try { List<HostToken> hostTokens = parseTokenListFromJson(getTopologyJsonPayload((host.getHostAddress()))); for (HostToken hToken : hostTokens) { allTokens.add(hToken); remainingHosts.remove(hToken.getHost()); } if (remainingHosts.size() == 0) { Logger.info("Received token information for " + allTokens.size() + " hosts. Not querying other hosts"); break; } } catch (Exception e) { Logger.warn("Could not get json response for token topology [" + e.getMessage() + "]"); } } return new ArrayList<>(allTokens); } AbstractTokenMapSupplier(String localRack);  AbstractTokenMapSupplier(String localRack, int port);  AbstractTokenMapSupplier();  AbstractTokenMapSupplier(int port); abstract String getTopologyJsonPayload(Set<Host> activeHosts); abstract String getTopologyJsonPayload(String hostname); @Override List<HostToken> getTokens(Set<Host> activeHosts); @Override HostToken getTokenForHost(final Host host, final Set<Host> activeHosts);  }