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

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

本文整理了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

/**
 * Partially updates the fields appearing in the given IdealState (input).
 * @param clusterName
 * @param resourceName
 * @param idealState
 */
@Override
public void updateIdealState(String clusterName, String resourceName, IdealState idealState) {
 if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  throw new HelixException(
    "updateIdealState failed. Cluster: " + clusterName + " is NOT setup properly.");
 }
 String zkPath = PropertyPathBuilder.idealState(clusterName, resourceName);
 if (!_zkClient.exists(zkPath)) {
  throw new HelixException(String.format(
    "updateIdealState failed. The IdealState for the given resource does not already exist. Resource name: %s",
    resourceName));
 }
 // Update by way of merge
 ZKUtil.createOrUpdate(_zkClient, zkPath, idealState.getRecord(), true, true);
}

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

private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) {
 if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
 }
 HelixConfigScope scope =
   new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
 String zkPath = scope.getZkPath();
 if (overwrite) {
  ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true);
 } else {
  ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true);
 }
}

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

private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig, boolean overwrite) {
 if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
 }
 HelixConfigScope scope =
   new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
 String zkPath = scope.getZkPath();
 if (overwrite) {
  ZKUtil.createOrReplace(zkClient, zkPath, clusterConfig.getRecord(), true);
 } else {
  ZKUtil.createOrUpdate(zkClient, zkPath, clusterConfig.getRecord(), true, true);
 }
}

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

private void updateInstanceConfig(String clusterName, String instanceName,
   InstanceConfig instanceConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
   throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
    new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName)
      .forParticipant(instanceName).build();
  String zkPath = scope.getZkPath();

  if (overwrite) {
   ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true);
  } else {
   ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true);
  }
 }
}

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

private void updateResourceConfig(String clusterName, String resourceName,
  ResourceConfig resourceConfig, boolean overwrite) {
 if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
 }
 HelixConfigScope scope =
   new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
     .forResource(resourceName).build();
 String zkPath = scope.getZkPath();
 if (overwrite) {
  ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true);
 } else {
  ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true);
 }
}

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

private void updateResourceConfig(String clusterName, String resourceName,
  ResourceConfig resourceConfig, boolean overwrite) {
 if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
 }
 HelixConfigScope scope =
   new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
     .forResource(resourceName).build();
 String zkPath = scope.getZkPath();
 if (overwrite) {
  ZKUtil.createOrReplace(zkClient, zkPath, resourceConfig.getRecord(), true);
 } else {
  ZKUtil.createOrUpdate(zkClient, zkPath, resourceConfig.getRecord(), true, true);
 }
}

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

private void updateInstanceConfig(String clusterName, String instanceName,
   InstanceConfig instanceConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
   throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
    new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName)
      .forParticipant(instanceName).build();
  String zkPath = scope.getZkPath();

  if (!zkClient.exists(zkPath)) {
   throw new HelixException(
     "updateInstanceConfig failed. Given InstanceConfig does not already exist. instance: "
       + instanceName);
  }

  if (overwrite) {
   ZKUtil.createOrReplace(zkClient, zkPath, instanceConfig.getRecord(), true);
  } else {
   ZKUtil.createOrUpdate(zkClient, zkPath, instanceConfig.getRecord(), true, true);
  }
 }
}

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

List<String> list = Arrays.asList("value1", "value2");
record.setListField("list", list);
ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
record = _gZkClient.readData(path);
AssertJUnit.assertEquals(list, record.getListField("list"));
List<String> list2 = Arrays.asList("value3", "value4");
record.setListField("list", list2);
ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
record = _gZkClient.readData(path);
AssertJUnit.assertEquals(list2, record.getListField("list"));
ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
record = _gZkClient.readData(path);
AssertJUnit.assertEquals(map, record.getMapField("map"));
Map<String, String> map2 = new HashMap<String, String>() {{put("k2", "v2");}};
record.setMapField("map", map2);
ZKUtil.createOrUpdate(_gZkClient, path, record, true, true);
record = _gZkClient.readData(path);
AssertJUnit.assertEquals(new HashMap<String, String>() {{

相关文章