String serviceName) throws IOException {
String connection = conf.get(FSConstants.FS_HA_ZOOKEEPER_QUORUM);
if (connection == null) {
return;
}
AvatarZooKeeperClient zk = new AvatarZooKeeperClient(conf, null);
// Clear NameNode address in ZK
InetSocketAddress defaultAddr;
String[] aliases;
defaultAddr = NameNode.getClientProtocolAddress(originalConf);
String defaultName = defaultAddr.getHostName() + ":"
+ defaultAddr.getPort();
LOG.info("Clear Client Address information in ZooKeeper: " + defaultName);
zk.clearPrimary(defaultName);
aliases = conf.getStrings(FSConstants.FS_NAMENODE_ALIASES);
if (aliases != null) {
for (String alias : aliases) {
zk.clearPrimary(alias);
}
}
LOG.info("Clear Service Address information in ZooKeeper");
defaultAddr = NameNode.getDNProtocolAddress(originalConf);
if (defaultAddr != null) {
String defaultServiceName = defaultAddr.getHostName() + ":"
+ defaultAddr.getPort();
zk.clearPrimary(defaultServiceName);
}
aliases = conf.getStrings(FSConstants.DFS_NAMENODE_DN_ALIASES);
if (aliases != null) {
for (String alias : aliases) {
zk.clearPrimary(alias);
}
}
LOG.info("Clear Http Address information in ZooKeeper");
// Clear http address in ZK
// Stolen from NameNode so we have the same code in both places
defaultAddr = NetUtils.createSocketAddr(originalConf
.get(FSConstants.DFS_NAMENODE_HTTP_ADDRESS_KEY));
String defaultHttpAddress = defaultAddr.getHostName() + ":"
+ defaultAddr.getPort();
zk.clearPrimary(defaultHttpAddress);
aliases = conf.getStrings(FSConstants.DFS_HTTP_ALIASES);
if (aliases != null) {
for (String alias : aliases) {
zk.clearPrimary(alias);
}
}
for(Avatar avatar : Avatar.avatars) {
for (ZookeeperKey key : ZookeeperKey.values()) {
zk.clearPrimary(getZnodeName(conf, serviceName, avatar, key));
}
}
}