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

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

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

ZKUtil.createOrUpdate介绍

暂无

代码示例

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

  1. /**
  2. * Partially updates the fields appearing in the given IdealState (input).
  3. * @param clusterName
  4. * @param resourceName
  5. * @param idealState
  6. */
  7. @Override
  8. public void updateIdealState(String clusterName, String resourceName, IdealState idealState) {
  9. if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  10. throw new HelixException(
  11. "updateIdealState failed. Cluster: " + clusterName + " is NOT setup properly.");
  12. }
  13. String zkPath = PropertyPathBuilder.idealState(clusterName, resourceName);
  14. if (!_zkClient.exists(zkPath)) {
  15. throw new HelixException(String.format(
  16. "updateIdealState failed. The IdealState for the given resource does not already exist. Resource name: %s",
  17. resourceName));
  18. }
  19. // Update by way of merge
  20. ZKUtil.createOrUpdate(_zkClient, zkPath, idealState.getRecord(), true, true);
  21. }

代码示例来源: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. 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. 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: apache/helix

  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 (!zkClient.exists(zkPath)) {
  11. throw new HelixException(
  12. "updateInstanceConfig failed. Given InstanceConfig does not already exist. instance: "
  13. + instanceName);
  14. }
  15. if (overwrite) {
  16. ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true);
  17. } else {
  18. ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true);
  19. }
  20. }
  21. }

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

  1. List<String> list = Arrays.asList("value1", "value2");
  2. record.setListField("list", list);
  3. ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
  4. record = _gZkClient.readData(path);
  5. AssertJUnit.assertEquals(list, record.getListField("list"));
  6. List<String> list2 = Arrays.asList("value3", "value4");
  7. record.setListField("list", list2);
  8. ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
  9. record = _gZkClient.readData(path);
  10. AssertJUnit.assertEquals(list2, record.getListField("list"));
  11. ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
  12. record = _gZkClient.readData(path);
  13. AssertJUnit.assertEquals(map, record.getMapField("map"));
  14. Map<String, String> map2 = new HashMap<String, String>() {{put("k2", "v2");}};
  15. record.setMapField("map", map2);
  16. ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
  17. record = _gZkClient.readData(path);
  18. AssertJUnit.assertEquals(new HashMap<String, String>() {{

相关文章