gpt4 book ai didi

org.apache.helix.manager.zk.ZKUtil类的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 13:48:31 27 4
gpt4 key购买 nike

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

ZKUtil介绍

暂无

代码示例

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

@Test()
public void testChildrenOperations() {
 List<ZNRecord> list = new ArrayList<ZNRecord>();
 list.add(new ZNRecord("id1"));
 list.add(new ZNRecord("id2"));
 String path = PropertyPathBuilder.instanceConfig(clusterName);
 ZKUtil.createChildren(_gZkClient, path, list);
 list = ZKUtil.getChildren(_gZkClient, path);
 AssertJUnit.assertEquals(2, list.size());
 ZKUtil.dropChildren(_gZkClient, path, list);
 ZKUtil.dropChildren(_gZkClient, path, new ZNRecord("id1"));
 list = ZKUtil.getChildren(_gZkClient, path);
 AssertJUnit.assertEquals(0, list.size());
 ZKUtil.dropChildren(_gZkClient, path, (List<ZNRecord>) null);
}

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

/**
 * Remove multiple configs
 *
 * @param scope          scope specification of the entity set to query (e.g. cluster, resource,
 *                       participant, etc.)
 * @param recordToRemove the ZNRecord that holds the entries that needs to be removed
 */
public void remove(HelixConfigScope scope, ZNRecord recordToRemove) {
 if (scope == null || scope.getType() == null || !scope.isFullKey()) {
  LOG.error("fail to remove. invalid scope: " + scope);
  return;
 }
 String clusterName = scope.getClusterName();
 if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
  throw new HelixException("fail to remove. cluster " + clusterName + " is not setup yet");
 }
 String zkPath = scope.getZkPath();
 ZKUtil.subtract(zkClient, zkPath, recordToRemove);
}

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

@Override
public List<String> getClusters() {
 List<String> zkToplevelPathes = _zkClient.getChildren("/");
 List<String> result = new ArrayList<String>();
 for (String pathName : zkToplevelPathes) {
  if (ZKUtil.isClusterSetup(pathName, _zkClient)) {
   result.add(pathName);
  }
 }
 return result;
}

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

if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
 throw new HelixException("cluster: " + clusterName + " is NOT setup.");
 String scopeStr = scope.getScopeStr();
 String instanceName = scopeStr.substring(scopeStr.lastIndexOf('/') + 1);
 if (!ZKUtil.isInstanceSetup(zkClient, scope.getClusterName(), instanceName,
   InstanceType.PARTICIPANT)) {
  throw new HelixException("instance: " + instanceName + " is NOT setup in cluster: "
ZKUtil.createOrMerge(zkClient, splits[0], update, true, true);

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

@Override
public void addInstanceTag(String clusterName, String instanceName, String tag) {
 logger
   .info("Add instance tag {} for instance {} in cluster {}.", tag, instanceName, clusterName);
 if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  throw new HelixException("cluster " + clusterName + " is not setup yet");
 }
 if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet");
 }
 HelixDataAccessor accessor =
   new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
 Builder keyBuilder = accessor.keyBuilder();
 InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
 config.addTag(tag);
 accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
}

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

@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);
}

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

public static void createChildren(ZkClient client, String parentPath, List<ZNRecord> list) {
 client.createPersistent(parentPath, true);
 if (list != null) {
  for (ZNRecord record : list) {
   createChildren(client, parentPath, record);
  }
 }
}

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

if (!ZKUtil.isInstanceSetup(_zkclient, _clusterName, _instanceName, _instanceType)) {
 if (!autoJoin) {
  throw new HelixException("Initial cluster structure is not set up for instance: "

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

String path = PropertyPathBuilder.instanceConfig(clusterName, "id7");
ZNRecord record = new ZNRecord("id7");
ZKUtil.createOrMerge(_gZkClient, path, record, true, true);
record = _gZkClient.readData(path);
AssertJUnit.assertEquals("id7", record.getId());
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>() {{

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

public static void dropChildren(ZkClient client, String parentPath, List<ZNRecord> list) {
 // TODO: check if parentPath exists
 if (list != null) {
  for (ZNRecord record : list) {
   dropChildren(client, parentPath, record);
  }
 }
}

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

/**
 * Selectively removes fields appearing in the given IdealState (input) from the IdealState in ZK.
 * @param clusterName
 * @param resourceName
 * @param idealState
 */
@Override
public void removeFromIdealState(String clusterName, String resourceName, IdealState idealState) {
 String zkPath = PropertyPathBuilder.idealState(clusterName, resourceName);
 ZKUtil.subtract(_zkClient, zkPath, idealState.getRecord());
}

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

@Test()
public void testCreateOrMerge() {
 String path = PropertyPathBuilder.instanceConfig(clusterName, "id7");
 ZNRecord record = new ZNRecord("id7");
 List<String> list = Arrays.asList("value1");
 record.setListField("list", list);
 ZKUtil.createOrMerge(_gZkClient, path, record, true, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals(list, record.getListField("list"));
 record = new ZNRecord("id7");
 List<String> list2 = Arrays.asList("value2");
 record.setListField("list", list2);
 ZKUtil.createOrMerge(_gZkClient, path, record, true, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals(Arrays.asList("value1", "value2"), record.getListField("list"));
 Map<String, String> map = new HashMap<String, String>() {{put("k1", "v1");}};
 record.setMapField("map", map);
 ZKUtil.createOrMerge(_gZkClient, path, record, true, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals(map, record.getMapField("map"));
 record = new ZNRecord("id7");
 Map<String, String> map2 = new HashMap<String, String>() {{put("k2", "v2");}};
 record.setMapField("map", map2);
 ZKUtil.createOrMerge(_gZkClient, path, record, true, true);
 record = _gZkClient.readData(path);
 AssertJUnit.assertEquals(new HashMap<String, String>() {{
  put("k1", "v1");
  put("k2", "v2");
 }}, record.getMapField("map"));
}

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

private boolean isClusterExist(String cluster) {
  HelixZkClient zkClient = getHelixZkClient();
  if (ZKUtil.isClusterSetup(cluster, zkClient)) {
   return true;
  }
  return false;
 }
}

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

if (!ZKUtil.isClusterSetup(clusterName, zkClient)) {
 throw new HelixException("cluster: " + clusterName + " is NOT setup.");
 String scopeStr = scope.getScopeStr();
 String instanceName = scopeStr.substring(scopeStr.lastIndexOf('/') + 1);
 if (!ZKUtil.isInstanceSetup(zkClient, scope.getClusterName(), instanceName,
   InstanceType.PARTICIPANT)) {
  throw new HelixException("instance: " + instanceName + " is NOT setup in cluster: "
ZKUtil.createOrMerge(zkClient, splits[0], update, true, true);

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

@Override
public void removeInstanceTag(String clusterName, String instanceName, String tag) {
 logger.info("Remove instance tag {} for instance {} in cluster {}.", tag, instanceName,
   clusterName);
 if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
  throw new HelixException("cluster " + clusterName + " is not setup yet");
 }
 if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
  throw new HelixException(
    "cluster " + clusterName + " instance " + instanceName + " is not setup yet");
 }
 ZKHelixDataAccessor accessor =
   new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
 Builder keyBuilder = accessor.keyBuilder();
 InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
 config.removeTag(tag);
 accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
}

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

@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);
}

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

public static void createChildren(HelixZkClient client, String parentPath, List<ZNRecord> list) {
 client.createPersistent(parentPath, true);
 if (list != null) {
  for (ZNRecord record : list) {
   createChildren(client, parentPath, record);
  }
 }
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com