public static void dropChildren(ZkClient client, String parentPath, List<ZNRecord> list) { // TODO: check if parentPath exists if (list != null) { for (ZNRecord record : list) { dropChildren(client, parentPath, record); } } }
public static void dropChildren(HelixZkClient client, String parentPath, List<ZNRecord> list) { // TODO: check if parentPath exists if (list != null) { for (ZNRecord record : list) { dropChildren(client, parentPath, record); } } }
@Test() public void testChildrenOperations() { List<ZNRecord> list = new ArrayList<ZNRecord>(); list.add(new ZNRecord("id1")); list.add(new ZNRecord("id2")); String path = PropertyPathBuilder.instanceConfig(clusterName); ZKUtil.createChildren(_gZkClient, path, list); list = ZKUtil.getChildren(_gZkClient, path); AssertJUnit.assertEquals(2, list.size()); ZKUtil.dropChildren(_gZkClient, path, list); ZKUtil.dropChildren(_gZkClient, path, new ZNRecord("id1")); list = ZKUtil.getChildren(_gZkClient, path); AssertJUnit.assertEquals(0, list.size()); ZKUtil.dropChildren(_gZkClient, path, (List<ZNRecord>) null); }
@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 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); }