org.apache.helix.manager.zk.ZKUtil.isClusterSetup()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中org.apache.helix.manager.zk.ZKUtil.isClusterSetup()方法的一些代码示例,展示了ZKUtil.isClusterSetup()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.isClusterSetup()方法的具体详情如下:
包路径:org.apache.helix.manager.zk.ZKUtil
类名称:ZKUtil
方法名:isClusterSetup

ZKUtil.isClusterSetup介绍

暂无

代码示例

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public List<String> getClusters() {
  3. List<String> zkToplevelPathes = _zkClient.getChildren("/");
  4. List<String> result = new ArrayList<String>();
  5. for (String pathName : zkToplevelPathes) {
  6. if (ZKUtil.isClusterSetup(pathName, _zkClient)) {
  7. result.add(pathName);
  8. }
  9. }
  10. return result;
  11. }

代码示例来源:origin: apache/helix

  1. private boolean isClusterExist(String cluster) {
  2. HelixZkClient zkClient = getHelixZkClient();
  3. if (ZKUtil.isClusterSetup(cluster, zkClient)) {
  4. return true;
  5. }
  6. return false;
  7. }
  8. }

代码示例来源:origin: apache/helix

  1. @Override
  2. public List<String> getClusters() {
  3. List<String> zkToplevelPathes = _zkClient.getChildren("/");
  4. List<String> result = new ArrayList<String>();
  5. for (String pathName : zkToplevelPathes) {
  6. if (ZKUtil.isClusterSetup(pathName, _zkClient)) {
  7. result.add(pathName);
  8. }
  9. }
  10. return result;
  11. }

代码示例来源:origin: apache/helix

  1. @Test()
  2. public void testIsClusterSetup() {
  3. boolean result = ZKUtil.isClusterSetup(clusterName, _gZkClient);
  4. AssertJUnit.assertTrue(result);
  5. }

代码示例来源:origin: apache/helix

  1. @BeforeClass()
  2. public void beforeClass() throws Exception {
  3. boolean result = ZKUtil.isClusterSetup(clusterName, _gZkClient);
  4. AssertJUnit.assertFalse(result);
  5. result = ZKUtil.isClusterSetup(null, _gZkClient);
  6. AssertJUnit.assertFalse(result);
  7. result = ZKUtil.isClusterSetup(null, null);
  8. AssertJUnit.assertFalse(result);
  9. result = ZKUtil.isClusterSetup(clusterName, null);
  10. AssertJUnit.assertFalse(result);
  11. TestHelper.setupEmptyCluster(_gZkClient, clusterName);
  12. }

代码示例来源:origin: apache/helix

  1. @Override
  2. public void enableBatchMessageMode(String clusterName, boolean enabled) {
  3. logger
  4. .info("{} batch message mode for cluster {}.", enabled ? "Enable" : "Disable", clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. ConfigAccessor accessor = new ConfigAccessor(_zkClient);
  9. ClusterConfig clusterConfig = accessor.getClusterConfig(clusterName);
  10. clusterConfig.setBatchMessageMode(enabled);
  11. accessor.setClusterConfig(clusterName, clusterConfig);
  12. }

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public void enableBatchMessageMode(String clusterName, boolean enabled) {
  3. logger
  4. .info("{} batch message mode for cluster {}.", enabled ? "Enable" : "Disable", clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. ConfigAccessor accessor = new ConfigAccessor(_zkClient);
  9. ClusterConfig clusterConfig = accessor.getClusterConfig(clusterName);
  10. clusterConfig.setBatchMessageMode(enabled);
  11. accessor.setClusterConfig(clusterName, clusterConfig);
  12. }

代码示例来源:origin: apache/helix

  1. private ZNRecord getConfigZnRecord(HelixConfigScope scope) {
  2. String clusterName = scope.getClusterName();
  3. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  4. throw new HelixException("fail to get configs. cluster " + clusterName + " is not setup yet");
  5. }
  6. return zkClient.readData(scope.getZkPath(), true);
  7. }

代码示例来源:origin: org.apache.helix/helix-core

  1. private ZNRecord getConfigZnRecord(HelixConfigScope scope) {
  2. String clusterName = scope.getClusterName();
  3. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  4. throw new HelixException("fail to get configs. cluster " + clusterName + " is not setup yet");
  5. }
  6. return zkClient.readData(scope.getZkPath(), true);
  7. }

代码示例来源:origin: apache/helix

  1. private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) {
  2. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  3. throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
  4. }
  5. HelixConfigScope scope =
  6. new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
  7. String zkPath = scope.getZkPath();
  8. if (overwrite) {
  9. ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true);
  10. } else {
  11. ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true);
  12. }
  13. }

代码示例来源:origin: org.apache.helix/helix-core

  1. private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) {
  2. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  3. throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
  4. }
  5. HelixConfigScope scope =
  6. new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
  7. String zkPath = scope.getZkPath();
  8. if (overwrite) {
  9. ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true);
  10. } else {
  11. ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true);
  12. }
  13. }

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public void addInstanceTag(String clusterName, String instanceName, String tag) {
  3. logger
  4. .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  9. throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet");
  10. }
  11. HelixDataAccessor accessor =
  12. new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  13. Builder keyBuilder = accessor.keyBuilder();
  14. InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  15. config.addTag(tag);
  16. accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
  17. }

代码示例来源:origin: apache/helix

  1. @Override
  2. public void addInstanceTag(String clusterName, String instanceName, String tag) {
  3. logger
  4. .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  9. throw new HelixException(
  10. "cluster " + clusterName + " instance " + instanceName + " is not setup yet");
  11. }
  12. HelixDataAccessor accessor =
  13. new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  14. Builder keyBuilder = accessor.keyBuilder();
  15. InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  16. config.addTag(tag);
  17. accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
  18. }

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public void removeInstanceTag(String clusterName, String instanceName, String tag) {
  3. logger.info("Remove instance tag {} for instance {} in cluster {}.", tag, instanceName,
  4. clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  9. throw new HelixException(
  10. "cluster " + clusterName + " instance " + instanceName + " is not setup yet");
  11. }
  12. ZKHelixDataAccessor accessor =
  13. new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  14. Builder keyBuilder = accessor.keyBuilder();
  15. InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  16. config.removeTag(tag);
  17. accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
  18. }

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public void setInstanceZoneId(String clusterName, String instanceName, String zoneId) {
  3. logger.info("Set instance zoneId {} for instance {} in cluster {}.", zoneId, instanceName,
  4. clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  9. throw new HelixException(
  10. "cluster " + clusterName + " instance " + instanceName + " is not setup yet");
  11. }
  12. HelixDataAccessor accessor =
  13. new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  14. Builder keyBuilder = accessor.keyBuilder();
  15. InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  16. config.setZoneId(zoneId);
  17. accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
  18. }

代码示例来源:origin: apache/helix

  1. @Override
  2. public void removeInstanceTag(String clusterName, String instanceName, String tag) {
  3. logger.info("Remove instance tag {} for instance {} in cluster {}.", tag, instanceName,
  4. clusterName);
  5. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  6. throw new HelixException("cluster " + clusterName + " is not setup yet");
  7. }
  8. if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  9. throw new HelixException(
  10. "cluster " + clusterName + " instance " + instanceName + " is not setup yet");
  11. }
  12. ZKHelixDataAccessor accessor =
  13. new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  14. Builder keyBuilder = accessor.keyBuilder();
  15. InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
  16. config.removeTag(tag);
  17. accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
  18. }

代码示例来源:origin: org.apache.helix/helix-core

  1. private void updateResourceConfig(String clusterName, String resourceName,
  2. ResourceConfig resourceConfig, boolean overwrite) {
  3. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  4. throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  5. }
  6. HelixConfigScope scope =
  7. new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
  8. .forResource(resourceName).build();
  9. String zkPath = scope.getZkPath();
  10. if (overwrite) {
  11. ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true);
  12. } else {
  13. ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true);
  14. }
  15. }

代码示例来源:origin: apache/helix

  1. private void updateResourceConfig(String clusterName, String resourceName,
  2. ResourceConfig resourceConfig, boolean overwrite) {
  3. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  4. throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  5. }
  6. HelixConfigScope scope =
  7. new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
  8. .forResource(resourceName).build();
  9. String zkPath = scope.getZkPath();
  10. if (overwrite) {
  11. ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true);
  12. } else {
  13. ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true);
  14. }
  15. }

代码示例来源:origin: org.apache.helix/helix-core

  1. private void updateInstanceConfig(String clusterName, String instanceName,
  2. InstanceConfig instanceConfig, boolean overwrite) {
  3. if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  4. throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  5. }
  6. HelixConfigScope scope =
  7. new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName)
  8. .forParticipant(instanceName).build();
  9. String zkPath = scope.getZkPath();
  10. if (overwrite) {
  11. ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true);
  12. } else {
  13. ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true);
  14. }
  15. }
  16. }

代码示例来源:origin: org.apache.helix/helix-core

  1. @Override
  2. public void addInstance(String clusterName, InstanceConfig instanceConfig) {
  3. logger.info("Add instance {} to cluster {}.", instanceConfig.getInstanceName(), clusterName);
  4. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  5. throw new HelixException("cluster " + clusterName + " is not setup yet");
  6. }
  7. String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName);
  8. String nodeId = instanceConfig.getId();
  9. String instanceConfigPath = instanceConfigsPath + "/" + nodeId;
  10. if (_zkClient.exists(instanceConfigPath)) {
  11. throw new HelixException("Node " + nodeId + " already exists in cluster " + clusterName);
  12. }
  13. ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord());
  14. _zkClient.createPersistent(PropertyPathBuilder.instanceMessage(clusterName, nodeId), true);
  15. _zkClient.createPersistent(PropertyPathBuilder.instanceCurrentState(clusterName, nodeId), true);
  16. _zkClient.createPersistent(PropertyPathBuilder.instanceError(clusterName, nodeId), true);
  17. _zkClient.createPersistent(PropertyPathBuilder.instanceStatusUpdate(clusterName, nodeId), true);
  18. _zkClient.createPersistent(PropertyPathBuilder.instanceHistory(clusterName, nodeId), true);
  19. }

相关文章