public static void createChildren(HelixZkClient client, String parentPath, List<ZNRecord> list) { client.createPersistent(parentPath, true); if (list != null) { for (ZNRecord record : list) { createChildren(client, parentPath, record); } } }
public static void createChildren(ZkClient client, String parentPath, List<ZNRecord> list) { client.createPersistent(parentPath, true); if (list != null) { for (ZNRecord record : list) { createChildren(client, parentPath, record); } } }
@Test() public void testNullChildren() { String path = PropertyPathBuilder.instanceConfig(clusterName, "id6"); ZKUtil.createChildren(_gZkClient, path, (List<ZNRecord>) null); }
@Override public void addResource(String clusterName, String resourceName, IdealState idealstate) { logger.info("Add resource {} in cluster {}.", resourceName, clusterName); String stateModelRef = idealstate.getStateModelDefRef(); String stateModelDefPath = PropertyPathBuilder.stateModelDef(clusterName, stateModelRef); if (!_zkClient.exists(stateModelDefPath)) { throw new HelixException( "State model " + stateModelRef + " not found in the cluster STATEMODELDEFS path"); } String idealStatePath = PropertyPathBuilder.idealState(clusterName); String resourceIdealStatePath = idealStatePath + "/" + resourceName; if (_zkClient.exists(resourceIdealStatePath)) { throw new HelixException("Skip the operation. Resource ideal state directory already exists:" + resourceIdealStatePath); } ZKUtil.createChildren(_zkClient, idealStatePath, idealstate.getRecord()); }
@Override public void addResource(String clusterName, String resourceName, IdealState idealstate) { logger.info("Add resource {} in cluster {}.", resourceName, clusterName); String stateModelRef = idealstate.getStateModelDefRef(); String stateModelDefPath = PropertyPathBuilder.stateModelDef(clusterName, stateModelRef); if (!_zkClient.exists(stateModelDefPath)) { throw new HelixException( "State model " + stateModelRef + " not found in the cluster STATEMODELDEFS path"); } String idealStatePath = PropertyPathBuilder.idealState(clusterName); String resourceIdealStatePath = idealStatePath + "/" + resourceName; if (_zkClient.exists(resourceIdealStatePath)) { throw new HelixException("Skip the operation. Resource ideal state directory already exists:" + resourceIdealStatePath); } ZKUtil.createChildren(_zkClient, idealStatePath, idealstate.getRecord()); }
@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 addInstance(String clusterName, InstanceConfig instanceConfig) { logger.info("Add instance {} to cluster {}.", instanceConfig.getInstanceName(), clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); String nodeId = instanceConfig.getId(); String instanceConfigPath = instanceConfigsPath + "/" + nodeId; if (_zkClient.exists(instanceConfigPath)) { throw new HelixException("Node " + nodeId + " already exists in cluster " + clusterName); } ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord()); _zkClient.createPersistent(PropertyPathBuilder.instanceMessage(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceError(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceHistory(clusterName, nodeId), true); }
@Override public void addInstance(String clusterName, InstanceConfig instanceConfig) { logger.info("Add instance {} to cluster {}.", instanceConfig.getInstanceName(), clusterName); if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) { throw new HelixException("cluster " + clusterName + " is not setup yet"); } String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); String nodeId = instanceConfig.getId(); String instanceConfigPath = instanceConfigsPath + "/" + nodeId; if (_zkClient.exists(instanceConfigPath)) { throw new HelixException("Node " + nodeId + " already exists in cluster " + clusterName); } ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord()); _zkClient.createPersistent(PropertyPathBuilder.instanceMessage(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceError(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), true); _zkClient.createPersistent(PropertyPathBuilder.instanceHistory(clusterName, nodeId), true); }