HBASE-7111 hbase zkcli will not start if the zookeeper server chosen to connect to is unavailable (Zhou wenjian)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1452554 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-03-04 21:55:40 +00:00
parent d17d84ed77
commit 2634cc1855
2 changed files with 17 additions and 6 deletions

View File

@ -19,8 +19,10 @@
package org.apache.hadoop.hbase.zookeeper;
import java.util.Properties;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
@ -40,18 +42,26 @@ public class ZooKeeperMainServerArg {
Properties zkProps = ZKConfig.makeZKProps(c);
String host = null;
String clientPort = null;
List<String> hosts = new ArrayList<String>();
for (Entry<Object, Object> entry: zkProps.entrySet()) {
String key = entry.getKey().toString().trim();
String value = entry.getValue().toString().trim();
if (key.startsWith("server.") && host == null) {
if (key.startsWith("server.")) {
String[] parts = value.split(":");
host = parts[0];
hosts.add(parts[0]);
} else if (key.endsWith("clientPort")) {
clientPort = value;
}
if (host != null && clientPort != null) break;
}
return host != null && clientPort != null? host + ":" + clientPort: null;
if (hosts.isEmpty() || clientPort == null)
return null;
for (int i = 0; i < hosts.size(); i++) {
if (i > 0)
host += "," + hosts.get(i);
else
host = hosts.get(i);
}
return host != null ? host + ":" + clientPort : null;
}
/**

View File

@ -39,7 +39,8 @@ public class TestZooKeeperMainServerArg {
c.set("hbase.zookeeper.quorum", "example.com");
assertEquals("example.com:" + port, parser.parse(c));
c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
assertTrue(port, parser.parse(c).matches("example[1-3]\\.com:" + port));
assertTrue(port,
parser.parse(c).matches("(example[1-3]\\.com,){2}example[1-3]\\.com:" + port));
}
}