@Test public void testGetDatacentersWithNetworkTopologyStrategy() { replicationMap.put("class", "org.apache.cassandra.locator.NetworkTopologyStrategy"); replicationMap.put("dc1", "3"); replicationMap.put("dc2", "3"); Collection<String> datacenters = KeyspaceHelper.getDatacentersForKeyspace(metadata, keyspaceName); assertThat(datacenters).containsOnly("dc1", "dc2"); }
public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; }
KeyspaceHelper { public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; } }
KeyspaceHelper { public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; } private  KeyspaceHelper(); }
KeyspaceHelper { public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; } private  KeyspaceHelper(); static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace); static Set<String> getDatacenters(Metadata metadata); }
KeyspaceHelper { public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; } private  KeyspaceHelper(); static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace); static Set<String> getDatacenters(Metadata metadata);  }