if (args.length < 1) {
System.err.println("Usage: " + CleanZookeeper.class.getName() + " hostname[:port] [auth]");
System.exit(1);
}
String root = Constants.ZROOT;
IZooReaderWriter zk = ZooReaderWriter.getInstance();
if (args.length == 2) {
zk.getZooKeeper().addAuthInfo("digest", args[1].getBytes());
}
try {
for (String child : zk.getChildren(root)) {
if (Constants.ZINSTANCES.equals("/" + child)) {
for (String instanceName : zk.getChildren(root + Constants.ZINSTANCES)) {
String instanceNamePath = root + Constants.ZINSTANCES + "/" + instanceName;
byte[] id = zk.getData(instanceNamePath, null);
if (id != null && !new String(id).equals(HdfsZooInstance.getInstance().getInstanceID())) {
try {
zk.recursiveDelete(instanceNamePath, NodeMissingPolicy.SKIP);
} catch (KeeperException.NoAuthException ex) {
log.warn("Unable to delete " + instanceNamePath);
}
}
}
} else if (!child.equals(HdfsZooInstance.getInstance().getInstanceID())) {
String path = root + "/" + child;
try {
zk.recursiveDelete(path, NodeMissingPolicy.SKIP);
} catch (KeeperException.NoAuthException ex) {
log.warn("Unable to delete " + path);
}
}
}