本文整理了Java中org.apache.helix.manager.zk.ZkClient.deleteRecursively()
方法的一些代码示例,展示了ZkClient.deleteRecursively()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.deleteRecursively()
方法的具体详情如下:
包路径:org.apache.helix.manager.zk.ZkClient
类名称:ZkClient
方法名:deleteRecursively
暂无
代码示例来源:origin: org.apache.helix/helix-core
private void delete(String zkPath) {
client.deleteRecursively(zkPath);
}
代码示例来源:origin: org.apache.helix/helix-core
public static void dropChildren(ZkClient client, String parentPath, ZNRecord nodeRecord) {
// TODO: check if parentPath exists
String id = nodeRecord.getId();
String temp = parentPath + "/" + id;
client.deleteRecursively(temp);
}
代码示例来源:origin: org.apache.helix/helix-core
if (recreateIfExists) {
logger.warn("Root directory exists.Cleaning the root directory:" + root);
_zkClient.deleteRecursively(root);
} else {
logger.info("Cluster " + clusterName + " already exists");
代码示例来源:origin: org.apache.helix/helix-core
@Override
public void addStateModelDef(String clusterName, String stateModelDef,
StateModelDefinition stateModel, boolean recreateIfExists) {
logger
.info("Add StateModelDef {} in cluster {} with StateModel {}.", stateModelDef, clusterName,
stateModel == null ? "NULL" : stateModel.toString());
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("cluster " + clusterName + " is not setup yet");
}
String stateModelDefPath = PropertyPathBuilder.stateModelDef(clusterName);
String stateModelPath = stateModelDefPath + "/" + stateModelDef;
if (_zkClient.exists(stateModelPath)) {
if (recreateIfExists) {
logger.info(
"Operation.State Model directory exists:" + stateModelPath + ", remove and recreate.");
_zkClient.deleteRecursively(stateModelPath);
} else {
logger.info("Skip the operation. State Model directory exists:" + stateModelPath);
return;
}
}
HelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.stateModelDef(stateModelDef), stateModel);
}
代码示例来源:origin: org.apache.helix/helix-core
@Override
public void dropCluster(String clusterName) {
logger.info("Deleting cluster {}.", clusterName);
HelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
Builder keyBuilder = accessor.keyBuilder();
String root = "/" + clusterName;
if (accessor.getChildNames(keyBuilder.liveInstances()).size() > 0) {
throw new HelixException(
"There are still live instances in the cluster, shut them down first.");
}
if (accessor.getProperty(keyBuilder.controllerLeader()) != null) {
throw new HelixException("There are still LEADER in the cluster, shut them down first.");
}
_zkClient.deleteRecursively(root);
}
代码示例来源:origin: apache/helix
@Override
public Representation delete() {
String zkPath = getZKPath();
try {
ZkClient zkClient =
(ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
zkClient.deleteRecursively(zkPath);
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in delete zkPath: " + zkPath, e);
}
return null;
}
代码示例来源:origin: apache/helix
@Override
public Representation delete() {
String zkPath = getZKPath();
try {
ZkClient zkClient =
(ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
List<String> childNames = zkClient.getChildren(zkPath);
if (childNames != null) {
for (String childName : childNames) {
String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
zkClient.deleteRecursively(childPath);
}
}
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in delete zkChild: " + zkPath, e);
}
return null;
}
}
代码示例来源:origin: apache/helix
@Override
public Representation post(Representation entity) {
String zkPath = getZKPath();
try {
JsonParameters jsonParameters = new JsonParameters(entity);
String command = jsonParameters.getCommand();
ZkClient zkClient =
(ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
if (command.equalsIgnoreCase(JsonParameters.ZK_DELETE_CHILDREN)) {
List<String> childNames = zkClient.getChildren(zkPath);
if (childNames != null) {
for (String childName : childNames) {
String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
zkClient.deleteRecursively(childPath);
}
}
} else {
throw new HelixException("Unsupported command: " + command + ". Should be one of ["
+ JsonParameters.ZK_DELETE_CHILDREN + "]");
}
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in post zkPath: " + zkPath, e);
}
return null;
}
代码示例来源:origin: org.apache.helix/helix-core
_zkclient.deleteRecursively(path);
代码示例来源:origin: org.apache.helix/helix-core
@Override
public void dropInstance(String clusterName, InstanceConfig instanceConfig) {
logger.info("Drop instance {} from cluster {}.", instanceConfig.getInstanceName(), clusterName);
String instanceName = instanceConfig.getInstanceName();
String instanceConfigPath = PropertyPathBuilder.instanceConfig(clusterName, instanceName);
if (!_zkClient.exists(instanceConfigPath)) {
throw new HelixException(
"Node " + instanceName + " does not exist in config for cluster " + clusterName);
}
String instancePath = PropertyPathBuilder.instance(clusterName, instanceName);
if (!_zkClient.exists(instancePath)) {
throw new HelixException(
"Node " + instanceName + " does not exist in instances for cluster " + clusterName);
}
String liveInstancePath = PropertyPathBuilder.liveInstance(clusterName, instanceName);
if (_zkClient.exists(liveInstancePath)) {
throw new HelixException(
"Node " + instanceName + " is still alive for cluster " + clusterName + ", can't drop.");
}
// delete config path
String instanceConfigsPath = PropertyPathBuilder.instanceConfig(clusterName);
ZKUtil.dropChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord());
// delete instance path
_zkClient.deleteRecursively(instancePath);
}
代码示例来源:origin: apache/helix
@Test()
void testGetStat() {
String path = "/tmp/getStatTest";
_zkClient.deleteRecursively(path);
Stat stat, newStat;
stat = _zkClient.getStat(path);
AssertJUnit.assertNull(stat);
_zkClient.createPersistent(path, true);
stat = _zkClient.getStat(path);
AssertJUnit.assertNotNull(stat);
newStat = _zkClient.getStat(path);
AssertJUnit.assertEquals(stat, newStat);
_zkClient.writeData(path, new ZNRecord("Test"));
newStat = _zkClient.getStat(path);
AssertJUnit.assertNotSame(stat, newStat);
}
内容来源于网络,如有侵权,请联系作者删除!