IdealState dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
Set<String> hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config =
accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag1"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 2);
command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
// re-add and rebalance
command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command =
"-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config =
accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag2"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 4);
command = "-zkSvr " + ZK_ADDR + " -dropResource " + clusterName + " db_11 ";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
for (int i = 3; i <= 3; i++) {
command =
"-zkSvr " + ZK_ADDR + " -removeInstanceTag " + clusterName + " localhost_123" + i
+ " tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
}
// re-add and rebalance
command = "-zkSvr " + ZK_ADDR + " -addResource " + clusterName + " db_11 48 MasterSlave";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
command =
"-zkSvr " + ZK_ADDR + " -rebalance " + clusterName + " db_11 3 -instanceGroupTag tag2";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
dbIs = accessor.getProperty(accessor.keyBuilder().idealStates("db_11"));
hosts = new HashSet<String>();
for (String p : dbIs.getPartitionSet()) {
for (String hostName : dbIs.getInstanceStateMap(p).keySet()) {
InstanceConfig config =
accessor.getProperty(accessor.keyBuilder().instanceConfig(hostName));
Assert.assertTrue(config.containsTag("tag2"));
hosts.add(hostName);
}
}
Assert.assertEquals(hosts.size(), 3);