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; }
@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); }
PropertyPathBuilder.instanceStatusUpdate(manager.getClusterName(), "localhost_" + (START_PORT)); subPaths = _gZkClient.getChildren(instanceStatusPath); Assert.assertTrue(subPaths.size() == 0);
@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 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); }
@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); }
PropertyPathBuilder.instanceStatusUpdate(CLUSTER_NAME, "localhost_" + (START_PORT + 1)); _gZkClient.deleteRecursively(instanceStatusUpdatePath);
@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); }