use of org.apache.helix.model.InstanceConfig in project helix by apache.
the class TestRoutingTable method testStateUnitGroupDeletion.
@Test()
public void testStateUnitGroupDeletion() throws InterruptedException {
List<InstanceConfig> instances;
RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
externalViewList.clear();
routingTable.onExternalViewChange(externalViewList, changeContext);
Thread.sleep(100);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 0);
}
use of org.apache.helix.model.InstanceConfig in project helix by apache.
the class TestRoutingTable method testGetInstanceForAllStateUnits.
@Test()
public void testGetInstanceForAllStateUnits() {
List<InstanceConfig> instancesList;
Set<InstanceConfig> instancesSet;
InstanceConfig[] instancesArray;
RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
add(record, "TESTDB_1", "localhost_8900", "MASTER");
add(record, "TESTDB_2", "localhost_8900", "MASTER");
add(record, "TESTDB_3", "localhost_8900", "SLAVE");
add(record, "TESTDB_4", "localhost_8900", "SLAVE");
add(record, "TESTDB_5", "localhost_8900", "SLAVE");
add(record, "TESTDB_0", "localhost_8901", "SLAVE");
add(record, "TESTDB_1", "localhost_8901", "SLAVE");
add(record, "TESTDB_2", "localhost_8901", "SLAVE");
add(record, "TESTDB_3", "localhost_8901", "MASTER");
add(record, "TESTDB_4", "localhost_8901", "MASTER");
add(record, "TESTDB_5", "localhost_8901", "MASTER");
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instancesList = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instancesList);
AssertJUnit.assertEquals(instancesList.size(), 1);
instancesSet = routingTable.getInstances("TESTDB", "MASTER");
AssertJUnit.assertNotNull(instancesSet);
AssertJUnit.assertEquals(instancesSet.size(), 2);
instancesSet = routingTable.getInstances("TESTDB", "SLAVE");
AssertJUnit.assertNotNull(instancesSet);
AssertJUnit.assertEquals(instancesSet.size(), 2);
instancesArray = new InstanceConfig[instancesSet.size()];
instancesSet.toArray(instancesArray);
AssertJUnit.assertEquals(instancesArray[0].getHostName(), "localhost");
AssertJUnit.assertEquals(instancesArray[0].getPort(), "8900");
AssertJUnit.assertEquals(instancesArray[1].getHostName(), "localhost");
AssertJUnit.assertEquals(instancesArray[1].getPort(), "8901");
}
use of org.apache.helix.model.InstanceConfig in project helix by apache.
the class ZKHelixAdmin method setInstanceZoneId.
@Override
public void setInstanceZoneId(String clusterName, String instanceName, String zoneId) {
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("cluster " + clusterName + " is not setup yet");
}
if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet");
}
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
config.setZoneId(zoneId);
accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
}
use of org.apache.helix.model.InstanceConfig in project helix by apache.
the class ZKHelixAdmin method getInstancesByDomain.
@Override
public List<String> getInstancesByDomain(String clusterName, String domain) {
List<String> instances = new ArrayList<>();
String path = PropertyPathBuilder.instanceConfig(clusterName);
BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<>(_zkClient);
List<ZNRecord> znRecords = baseAccessor.getChildren(path, null, 0);
for (ZNRecord record : znRecords) {
if (record != null) {
InstanceConfig instanceConfig = new InstanceConfig(record);
if (instanceConfig.isInstanceInDomain(domain)) {
instances.add(instanceConfig.getInstanceName());
}
}
}
return instances;
}
use of org.apache.helix.model.InstanceConfig in project helix by apache.
the class ZKHelixAdmin method removeInstanceTag.
@Override
public void removeInstanceTag(String clusterName, String instanceName, String tag) {
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("cluster " + clusterName + " is not setup yet");
}
if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet");
}
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
config.removeTag(tag);
accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
}
Aggregations