use of org.apache.zookeeper.client.ConnectStringParser in project zookeeper by apache.
the class ConnectStringParserTest method testSingleServerChrootPath.
@Test
public void testSingleServerChrootPath() {
String chrootPath = "/hallo/welt";
String servers = "10.10.10.1";
assertChrootPath(chrootPath, new ConnectStringParser(servers + chrootPath));
servers = "[2001:db8:1::242:ac11:2]";
assertChrootPath(chrootPath, new ConnectStringParser(servers + chrootPath));
}
use of org.apache.zookeeper.client.ConnectStringParser in project zookeeper by apache.
the class ConnectStringParserTest method testParseServersWithoutPort.
@Test
public void testParseServersWithoutPort() {
String servers = "10.10.10.1,10.10.10.2";
ConnectStringParser parser = new ConnectStringParser(servers);
assertEquals("10.10.10.1", parser.getServerAddresses().get(0).getHostString());
assertEquals(DEFAULT_PORT, parser.getServerAddresses().get(0).getPort());
assertEquals("10.10.10.2", parser.getServerAddresses().get(1).getHostString());
assertEquals(DEFAULT_PORT, parser.getServerAddresses().get(1).getPort());
servers = "[2001:db8:1::242:ac11:2],[2001:db8:85a3:8d3:1319:8a2e:370:7348]";
parser = new ConnectStringParser(servers);
assertEquals("2001:db8:1::242:ac11:2", parser.getServerAddresses().get(0).getHostString());
assertEquals(DEFAULT_PORT, parser.getServerAddresses().get(0).getPort());
assertEquals("2001:db8:85a3:8d3:1319:8a2e:370:7348", parser.getServerAddresses().get(1).getHostString());
assertEquals(DEFAULT_PORT, parser.getServerAddresses().get(1).getPort());
}
use of org.apache.zookeeper.client.ConnectStringParser in project canal by alibaba.
the class ZooKeeperx method configMutliCluster.
// ===============================
public void configMutliCluster(ZooKeeper zk) {
if (_serversList.size() == 1) {
return;
}
String cluster1 = _serversList.get(0);
try {
if (_serversList.size() > 1) {
// 强制的声明accessible
ReflectionUtils.makeAccessible(clientCnxnField);
ReflectionUtils.makeAccessible(hostProviderField);
ReflectionUtils.makeAccessible(serverAddressesField);
// 添加第二组集群列表
for (int i = 1; i < _serversList.size(); i++) {
String cluster = _serversList.get(i);
// 强制获取zk中的地址信息
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField, hostProvider);
// 添加第二组集群列表
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
}
}
} catch (Exception e) {
try {
if (zk != null) {
zk.close();
}
} catch (InterruptedException ie) {
// ignore interrupt
}
throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
}
}
use of org.apache.zookeeper.client.ConnectStringParser in project samza by apache.
the class ZkCoordinationServiceFactory method createZkPath.
/**
* if ZkConnectString contains some path at the end, it needs to be created when connecting for the first time.
* @param zkConnect - connect string
* @param zkClient - zkClient object to talk to the ZK
*/
public static void createZkPath(String zkConnect, ZkClient zkClient) {
ConnectStringParser parser = new ConnectStringParser(zkConnect);
String path = parser.getChrootPath();
LOG.info("path =" + path);
if (!Strings.isNullOrEmpty(path)) {
// create this path in zk
LOG.info("first connect. creating path =" + path + " in ZK " + parser.getServerAddresses());
if (!zkClient.exists(path)) {
// will create parents if needed and will not throw exception if exists
zkClient.createPersistent(path, true);
}
}
}
use of org.apache.zookeeper.client.ConnectStringParser in project otter by alibaba.
the class ZooKeeperx method configMutliCluster.
// ===============================
public void configMutliCluster(ZooKeeper zk) {
if (_serversList.size() == 1) {
return;
}
String cluster1 = _serversList.get(0);
try {
if (_serversList.size() > 1) {
// 强制的声明accessible
ReflectionUtils.makeAccessible(clientCnxnField);
ReflectionUtils.makeAccessible(hostProviderField);
ReflectionUtils.makeAccessible(serverAddressesField);
// 添加第二组集群列表
for (int i = 1; i < _serversList.size(); i++) {
String cluster = _serversList.get(i);
// 强制获取zk中的地址信息
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField, hostProvider);
// 添加第二组集群列表
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
}
}
} catch (Exception e) {
try {
if (zk != null) {
zk.close();
}
} catch (InterruptedException ie) {
// ignore interrupt
}
throw new ZkException("zookeeper_create_error, serveraddrs=" + cluster1, e);
}
}
Aggregations