public static boolean isInstanceSetup(ZkClient zkclient, String clusterName, String instanceName, InstanceType type) { if (type == InstanceType.PARTICIPANT || type == InstanceType.CONTROLLER_PARTICIPANT) { ArrayList<String> requiredPaths = new ArrayList<>(); requiredPaths.add(PropertyPathBuilder.instanceConfig(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceMessage(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceCurrentState(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceStatusUpdate(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceError(clusterName, instanceName)); boolean isValid = true; for (String path : requiredPaths) { if (!zkclient.exists(path)) { isValid = false; logger.error("Invalid instance setup, missing znode path: {}", path); } } if (isValid) { // Create the instance history node if it does not exist. // This is for back-compatibility. String historyPath = PropertyPathBuilder.instanceHistory(clusterName, instanceName); if (!zkclient.exists(historyPath)) { zkclient.createPersistent(historyPath, true); } } return isValid; } return true; }
public static boolean isInstanceSetup(HelixZkClient zkclient, String clusterName, String instanceName, InstanceType type) { if (type == InstanceType.PARTICIPANT || type == InstanceType.CONTROLLER_PARTICIPANT) { ArrayList<String> requiredPaths = new ArrayList<>(); requiredPaths.add(PropertyPathBuilder.instanceConfig(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceMessage(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceCurrentState(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceStatusUpdate(clusterName, instanceName)); requiredPaths.add(PropertyPathBuilder.instanceError(clusterName, instanceName)); boolean isValid = true; for (String path : requiredPaths) { if (!zkclient.exists(path)) { isValid = false; logger.error("Invalid instance setup, missing znode path: {}", path); } } if (isValid) { // Create the instance history node if it does not exist. // This is for back-compatibility. String historyPath = PropertyPathBuilder.instanceHistory(clusterName, instanceName); if (!zkclient.exists(historyPath)) { zkclient.createPersistent(historyPath, true); } } return isValid; } return true; }
String path = PropertyPathBuilder.instanceCurrentState( _clusterName, "localhost_8901", "session_0", "TestDB" + k); ZNRecord record = new ZNRecord("TestDB" + k);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_1", "TestDB" + i); boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertTrue(success, "Should succeed in create: " + path); String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_1", "TestDB" + i); boolean success = accessor.create(path, new ZNRecord("TestDB" + i), AccessOption.PERSISTENT); Assert.assertFalse(success, "Should fail in create due to NodeExists: " + path);
@Override public Boolean call() throws Exception { // create 10 current states in 2 steps List<String> paths = new ArrayList<String>(); List<DataUpdater<ZNRecord>> updaters = new ArrayList<DataUpdater<ZNRecord>>(); for (int j = 0; j < 10; j++) { paths.clear(); updaters.clear(); for (int i = 0; i < 10; i++) { String path = PropertyPathBuilder.instanceCurrentState( _clusterName, "localhost_8901", "session_0", "TestDB" + i); ZNRecord newRecord = new ZNRecord("TestDB" + i); newRecord.setSimpleField("" + j, "" + j); DataUpdater<ZNRecord> updater = new ZNRecordUpdater(newRecord); paths.add(path); updaters.add(updater); } boolean[] success = _accessor.updateChildren(paths, updaters, AccessOption.PERSISTENT); // System.out.println("thread-" + _id + " updates " + j + ": " + Arrays.toString(success)); for (int i = 0; i < 10; i++) { Assert.assertEquals(success[i], true, "Should be all succeed"); } } return true; } }
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName); List<ZNRecord> records = new ArrayList<ZNRecord>(); for (int i = 0; i < 10; i++) { String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_1", "TestDB" + i); ZNRecord record = new ZNRecord("TestDB" + i);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName); List<ZNRecord> records = new ArrayList<ZNRecord>(); for (int i = 0; i < 10; i++) { String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i); ZNRecord record = new ZNRecord("TestDB" + i); String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i); paths.add(path);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName); List<ZNRecord> records = new ArrayList<ZNRecord>(); for (int i = 0; i < 10; i++) { String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i); ZNRecord record = new ZNRecord("TestDB" + i);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName); List<ZNRecord> records = new ArrayList<ZNRecord>(); for (int i = 0; i < 10; i++) { String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i); ZNRecord record = new ZNRecord("TestDB" + i);
String curStatePath = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901"); String extViewPath = PropertyPathBuilder.externalView(clusterName); String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_8901", "session_0", "TestDB" + i);
@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"); } }
String path = PropertyPathBuilder.instanceCurrentState(clusterName, "localhost_12918", "session_0", "TestDB0"); _gZkClient.createPersistent(path, true); _gZkClient.writeData(path, badCurState);
@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); }
@Override public void addInstance(String clusterName, InstanceConfig instanceConfig) { String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName); String nodeId = instanceConfig.getId(); if (!_baseDataAccessor.exists(instanceConfigsPath, 0)) { _baseDataAccessor.create(instanceConfigsPath, new ZNRecord(nodeId), 0); } String instanceConfigPath = instanceConfigsPath + "/" + nodeId; _baseDataAccessor.create(instanceConfigPath, instanceConfig.getRecord(), 0); _baseDataAccessor .set(PropertyPathBuilder.instanceMessage(clusterName, nodeId), new ZNRecord(nodeId), 0); _baseDataAccessor .set(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), new ZNRecord(nodeId), 0); _baseDataAccessor .set(PropertyPathBuilder.instanceError(clusterName, nodeId), new ZNRecord(nodeId), 0); _baseDataAccessor .set(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), new ZNRecord(nodeId), 0); _baseDataAccessor .set(PropertyPathBuilder.instanceHistory(clusterName, nodeId), new ZNRecord(nodeId), 0); }