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

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

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

ZKUtil.createOrReplace介绍

暂无

代码示例

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

@Test()
public void testCreateOrReplace() {
 String path = PropertyPathBuilder.instanceConfig(clusterName, "id8");
 ZNRecord record = new ZNRecord("id8");
 ZKUtil.createOrReplace(_gZkClient, path, record, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals("id8", record.getId());
 record = new ZNRecord("id9");
 ZKUtil.createOrReplace(_gZkClient, path, record, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals("id9", record.getId());
}

代码示例来源: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);
  }
 }
}

相关文章