use of org.apache.cassandra.locator.AbstractNetworkTopologySnitch in project cassandra by apache.
the class MoveTest method addNetworkTopologyKeyspace.
private static void addNetworkTopologyKeyspace(String keyspaceName, Integer... replicas) throws Exception {
DatabaseDescriptor.setEndpointSnitch(new AbstractNetworkTopologySnitch() {
//Odd IPs are in DC1 and Even are in DC2. Endpoints upto .14 will have unique racks and
// then will be same for a set of three.
@Override
public String getRack(InetAddress endpoint) {
int ipLastPart = getIPLastPart(endpoint);
if (ipLastPart <= 14)
return UUID.randomUUID().toString();
else
return "RAC" + (ipLastPart % 3);
}
@Override
public String getDatacenter(InetAddress endpoint) {
if (getIPLastPart(endpoint) % 2 == 0)
return "DC2";
else
return "DC1";
}
private int getIPLastPart(InetAddress endpoint) {
String str = endpoint.toString();
int index = str.lastIndexOf(".");
return Integer.parseInt(str.substring(index + 1).trim());
}
});
final TokenMetadata tmd = StorageService.instance.getTokenMetadata();
tmd.clearUnsafe();
tmd.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.0.0.1"));
tmd.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.0.0.2"));
KeyspaceMetadata keyspace = KeyspaceMetadata.create(keyspaceName, KeyspaceParams.nts(configOptions(replicas)), Tables.of(TableMetadata.builder(keyspaceName, "CF1").addPartitionKeyColumn("key", BytesType.instance).build()));
MigrationManager.announceNewKeyspace(keyspace);
}
Aggregations