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