private void addAndRemoveNewInstanceConfig(ZkClient zkClient) throws Exception { int biggerRandomNumber = NUM_INSTANCES + new Random().nextInt(NUM_INSTANCES); String instanceName = "Server_localhost_" + String.valueOf(biggerRandomNumber); String instanceConfigPath = PropertyPathBuilder.instanceConfig(_helixClusterName, instanceName); Assert.assertFalse(zkClient.exists(instanceConfigPath)); List<String> instances = _helixResourceManager.getAllInstances(); Assert.assertFalse(instances.contains(instanceName)); // Add new ZNode. ZNRecord znRecord = new ZNRecord(instanceName); zkClient.createPersistent(instanceConfigPath, znRecord); List<String> latestAllInstances = _helixResourceManager.getAllInstances(); long maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND; while (!latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) { Thread.sleep(100L); latestAllInstances = _helixResourceManager.getAllInstances(); } Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for adding instance config"); // Remove new ZNode. zkClient.delete(instanceConfigPath); latestAllInstances = _helixResourceManager.getAllInstances(); maxTime = System.currentTimeMillis() + MAX_TIMEOUT_IN_MILLISECOND; while (latestAllInstances.contains(instanceName) && System.currentTimeMillis() < maxTime) { Thread.sleep(100L); latestAllInstances = _helixResourceManager.getAllInstances(); } Assert.assertTrue(System.currentTimeMillis() < maxTime, "Timeout when waiting for removing instance config"); }
requiredPaths.add(PropertyPathBuilder.idealState(clusterName)); requiredPaths.add(PropertyPathBuilder.clusterConfig(clusterName)); requiredPaths.add(PropertyPathBuilder.instanceConfig(clusterName)); requiredPaths.add(PropertyPathBuilder.resourceConfig(clusterName)); 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)); requiredPaths.add(PropertyPathBuilder.stateModelDef(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerMessage(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerError(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerStatusUpdate(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerHistory(clusterName)); boolean isValid = true;
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; }
@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 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);
@Override public void run() { // For each record in status update and error node // TODO: for now the status updates are dumped to cluster manager log4j log. // We need to think if we should create per-instance log files that contains // per-instance statusUpdates // and errors LOG.info("Scan statusUpdates and errors for cluster: " + _manager.getClusterName() + ", by controller: " + _manager); HelixDataAccessor accessor = _manager.getHelixDataAccessor(); Builder keyBuilder = accessor.keyBuilder(); BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor(); List<String> instances = accessor.getChildNames(keyBuilder.instanceConfigs()); for (String instance : instances) { // dump participant status updates String statusUpdatePath = PropertyPathBuilder.instanceStatusUpdate(_manager.getClusterName(), instance); dump(baseAccessor, statusUpdatePath, _thresholdNoChangeMsForStatusUpdates, _maxLeafCount); // dump participant errors String errorPath = PropertyPathBuilder.instanceError(_manager.getClusterName(), instance); dump(baseAccessor, errorPath, _thresholdNoChangeMsForErrors, _maxLeafCount); } // dump controller status updates String controllerStatusUpdatePath = PropertyPathBuilder.controllerStatusUpdate(_manager.getClusterName()); dump(baseAccessor, controllerStatusUpdatePath, _thresholdNoChangeMsForStatusUpdates, _maxLeafCount); // dump controller errors String controllerErrorPath = PropertyPathBuilder.controllerError(_manager.getClusterName()); dump(baseAccessor, controllerErrorPath, _thresholdNoChangeMsForErrors, _maxLeafCount); }
List<String> resourcesInIdealState = zkClient.getChildren(PropertyPathBuilder.idealState(clusterId)); List<String> resourcesInExternalView = zkClient.getChildren(PropertyPathBuilder.externalView(clusterId));
@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); }
enabled ? "Enable" : "Disable", HelixUtil.serializeByComma(partitionNames), resourceName, instanceName, clusterName); String path = PropertyPathBuilder.instanceConfig(clusterName, instanceName); String idealStatePath = PropertyPathBuilder.idealState(clusterName, resourceName);
@Override public List<String> getResourcesInCluster(String clusterName) { return _zkClient.getChildren(PropertyPathBuilder.idealState(clusterName)); }
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 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 testParticipantStartUp() throws Exception { setupCluster(); String controllerMsgPath = PropertyPathBuilder.controllerMessage(CLUSTER_NAME); _gZkClient.deleteRecursively(controllerMsgPath); HelixManager manager = null; String stateModelPath = PropertyPathBuilder.stateModelDef(CLUSTER_NAME); _gZkClient.deleteRecursively(stateModelPath); PropertyPathBuilder.instanceStatusUpdate(CLUSTER_NAME, "localhost_" + (START_PORT + 1)); _gZkClient.deleteRecursively(instanceStatusUpdatePath);
String controllerStatusPath = PropertyPathBuilder.controllerStatusUpdate(manager.getClusterName()); List<String> subPaths = _gZkClient.getChildren(controllerStatusPath); Assert.assertTrue(subPaths.size() > 0); PropertyPathBuilder.instanceStatusUpdate(manager.getClusterName(), "localhost_" + (START_PORT)); subPaths = _gZkClient.getChildren(instanceStatusPath); Assert.assertTrue(subPaths.size() == 0);
String path = PropertyPathBuilder.externalView(_clusterName, "TestDB" + k); ZNRecord record = new ZNRecord("TestDB" + k);
resultMap.put("StatusUpdatePath", PropertyPathBuilder.controllerStatusUpdate( clusterName, MessageType.SCHEDULER_MSG.name(), schedulerMessage.getMsgId())); resultMap.put("MessageType", Message.MessageType.SCHEDULER_MSG.name());
@Override public boolean createControllerLeader(LiveInstance leader) { return _baseDataAccessor.create(PropertyPathBuilder.controllerLeader(_clusterName), leader.getRecord(), AccessOption.EPHEMERAL); }
@Override public boolean createControllerMessage(Message message) { return _baseDataAccessor.create(PropertyPathBuilder.controllerMessage(_clusterName, message.getMsgId()), message.getRecord(), AccessOption.PERSISTENT); }
String path = PropertyPathBuilder.clusterConfig(clusterName);
requiredPaths.add(PropertyPathBuilder.idealState(clusterName)); requiredPaths.add(PropertyPathBuilder.clusterConfig(clusterName)); requiredPaths.add(PropertyPathBuilder.instanceConfig(clusterName)); requiredPaths.add(PropertyPathBuilder.resourceConfig(clusterName)); 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)); requiredPaths.add(PropertyPathBuilder.stateModelDef(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerMessage(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerError(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerStatusUpdate(clusterName)); requiredPaths.add(PropertyPathBuilder.controllerHistory(clusterName)); boolean isValid = true;