@Override public List<String> getInstancesInCluster(String clusterName) { String memberInstancesPath = PropertyPathBuilder.instance(clusterName); return _zkClient.getChildren(memberInstancesPath); }
requiredPaths.add(PropertyPathBuilder.propertyStore(clusterName)); requiredPaths.add(PropertyPathBuilder.liveInstance(clusterName)); requiredPaths.add(PropertyPathBuilder.instance(clusterName)); requiredPaths.add(PropertyPathBuilder.externalView(clusterName)); requiredPaths.add(PropertyPathBuilder.controller(clusterName));
@Test public void testGetPath() { String actual; actual = PropertyPathBuilder.idealState("test_cluster"); AssertJUnit.assertEquals(actual, "/test_cluster/IDEALSTATES"); actual = PropertyPathBuilder.idealState("test_cluster", "resource"); AssertJUnit.assertEquals(actual, "/test_cluster/IDEALSTATES/resource"); actual = PropertyPathBuilder.instance("test_cluster", "instanceName1"); AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1"); actual = PropertyPathBuilder.instanceCurrentState("test_cluster", "instanceName1"); AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1/CURRENTSTATES"); actual = PropertyPathBuilder.instanceCurrentState("test_cluster", "instanceName1", "sessionId"); AssertJUnit.assertEquals(actual, "/test_cluster/INSTANCES/instanceName1/CURRENTSTATES/sessionId"); actual = PropertyPathBuilder.controller("test_cluster"); AssertJUnit.assertEquals(actual, "/test_cluster/CONTROLLER"); actual = PropertyPathBuilder.controllerMessage("test_cluster"); AssertJUnit.assertEquals(actual, "/test_cluster/CONTROLLER/MESSAGES"); } }
requiredPaths.add(PropertyPathBuilder.propertyStore(clusterName)); requiredPaths.add(PropertyPathBuilder.liveInstance(clusterName)); requiredPaths.add(PropertyPathBuilder.instance(clusterName)); requiredPaths.add(PropertyPathBuilder.externalView(clusterName)); requiredPaths.add(PropertyPathBuilder.controller(clusterName));
@Override public List<String> getInstancesInCluster(String clusterName) { String memberInstancesPath = PropertyPathBuilder.instance(clusterName); return _zkClient.getChildren(memberInstancesPath); }
public void verifyInstance(HelixZkClient zkClient, String clusterName, String instance, boolean wantExists) { // String instanceConfigsPath = HelixUtil.getConfigPath(clusterName); String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); String instanceConfigPath = instanceConfigsPath + "/" + instance; String instancePath = PropertyPathBuilder.instance(clusterName, instance); AssertJUnit.assertEquals(wantExists, zkClient.exists(instanceConfigPath)); AssertJUnit.assertEquals(wantExists, zkClient.exists(instancePath)); }
@Override public List<String> getInstancesInClusterWithTag(String clusterName, String tag) { String memberInstancesPath = PropertyPathBuilder.instance(clusterName); List<String> instances = _zkClient.getChildren(memberInstancesPath); List<String> result = new ArrayList<String>(); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); for (String instanceName : instances) { InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); if (config == null) { throw new IllegalStateException(String .format("Instance %s does not have a config, cluster might be in bad state", instanceName)); } if (config.containsTag(tag)) { result.add(instanceName); } } return result; }
@Override public void dropInstance(String clusterName, InstanceConfig instanceConfig) { logger.info("Drop instance {} from cluster {}.", instanceConfig.getInstanceName(), clusterName); String instanceName = instanceConfig.getInstanceName(); String instanceConfigPath = PropertyPathBuilder.instanceConfig(clusterName, instanceName); if (!_zkClient.exists(instanceConfigPath)) { throw new HelixException( "Node " + instanceName + " does not exist in config for cluster " + clusterName); } String instancePath = PropertyPathBuilder.instance(clusterName, instanceName); if (!_zkClient.exists(instancePath)) { throw new HelixException( "Node " + instanceName + " does not exist in instances for cluster " + clusterName); } String liveInstancePath = PropertyPathBuilder.liveInstance(clusterName, instanceName); if (_zkClient.exists(liveInstancePath)) { throw new HelixException( "Node " + instanceName + " is still alive for cluster " + clusterName + ", can't drop."); } // delete config path String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); ZKUtil.dropChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord()); // delete instance path _zkClient.deleteRecursively(instancePath); }
@Override public List<String> getInstancesInClusterWithTag(String clusterName, String tag) { String memberInstancesPath = PropertyPathBuilder.instance(clusterName); List<String> instances = _zkClient.getChildren(memberInstancesPath); List<String> result = new ArrayList<String>(); HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = accessor.keyBuilder(); for (String instanceName : instances) { InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName)); if (config == null) { throw new IllegalStateException(String .format("Instance %s does not have a config, cluster might be in bad state", instanceName)); } if (config.containsTag(tag)) { result.add(instanceName); } } return result; }
@Override public void dropInstance(String clusterName, InstanceConfig instanceConfig) { logger.info("Drop instance {} from cluster {}.", instanceConfig.getInstanceName(), clusterName); String instanceName = instanceConfig.getInstanceName(); String instanceConfigPath = PropertyPathBuilder.instanceConfig(clusterName, instanceName); if (!_zkClient.exists(instanceConfigPath)) { throw new HelixException( "Node " + instanceName + " does not exist in config for cluster " + clusterName); } String instancePath = PropertyPathBuilder.instance(clusterName, instanceName); if (!_zkClient.exists(instancePath)) { throw new HelixException( "Node " + instanceName + " does not exist in instances for cluster " + clusterName); } String liveInstancePath = PropertyPathBuilder.liveInstance(clusterName, instanceName); if (_zkClient.exists(liveInstancePath)) { throw new HelixException( "Node " + instanceName + " is still alive for cluster " + clusterName + ", can't drop."); } // delete config path String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); ZKUtil.dropChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord()); // delete instance path _zkClient.deleteRecursively(instancePath); }
"Instance config should be dropped"); Assert.assertFalse( _gZkClient.exists(PropertyPathBuilder.instance(clusterName, "localhost_12918")), "Instance/host should be dropped");
_zkClient.createPersistent(PropertyPathBuilder.instance(clusterName));
String path = PropertyPathBuilder.instance(clusterName, instanceName); AssertJUnit.assertTrue(_gZkClient.exists(path));
_zkClient.createPersistent(PropertyPathBuilder.instance(clusterName));
.create(PropertyPathBuilder.instance(clusterName), new ZNRecord(clusterName), 0);