use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project pulsar by yahoo.
the class ZkBookieRackAffinityMapping method getAndSetZkCache.
private ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> getAndSetZkCache(Configuration conf) {
ZooKeeperCache zkCache = null;
if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
} else {
int zkTimeout;
String zkServers;
if (conf instanceof ClientConfiguration) {
zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
zkServers = ((ClientConfiguration) conf).getZkServers();
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(zkTimeout) {
};
try {
ZooKeeper zkClient = ZkUtils.createConnectedZookeeperClient(zkServers, w);
zkCache = new ZooKeeperCache(zkClient) {
};
conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
} catch (Exception e) {
LOG.error("Error creating zookeeper client", e);
}
} else {
LOG.error("No zk configurations available");
}
}
ZooKeeperDataCache<Map<String, Map<BookieSocketAddress, BookieInfo>>> zkDataCache = getZkBookieRackMappingCache(zkCache);
if (zkDataCache != null) {
zkDataCache.registerListener(this);
}
return zkDataCache;
}
use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project pulsar by yahoo.
the class ZkIsolatedBookieEnsemblePlacementPolicy method getAndSetZkCache.
private ZooKeeperCache getAndSetZkCache(Configuration conf) {
ZooKeeperCache zkCache = null;
if (conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) != null) {
zkCache = (ZooKeeperCache) conf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE);
} else {
int zkTimeout;
String zkServers;
if (conf instanceof ClientConfiguration) {
zkTimeout = ((ClientConfiguration) conf).getZkTimeout();
zkServers = ((ClientConfiguration) conf).getZkServers();
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(zkTimeout) {
};
try {
ZooKeeper zkClient = ZkUtils.createConnectedZookeeperClient(zkServers, w);
zkCache = new ZooKeeperCache(zkClient) {
};
conf.addProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, zkCache);
} catch (Exception e) {
LOG.error("Error creating zookeeper client", e);
}
} else {
LOG.error("No zk configurations available");
}
}
return zkCache;
}
use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project pulsar by yahoo.
the class ZkIsolatedBookieEnsemblePlacementPolicyTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
localZkS = new ZookeeperServerTest(LOCAL_ZOOKEEPER_PORT);
localZkS.start();
ZooKeeperWatcherBase zkWatcherBase = new ZooKeeperWatcherBase(10000);
localZkc = ZkUtils.createConnectedZookeeperClient("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT, zkWatcherBase);
writableBookies.add(new BookieSocketAddress(BOOKIE1));
writableBookies.add(new BookieSocketAddress(BOOKIE2));
writableBookies.add(new BookieSocketAddress(BOOKIE3));
writableBookies.add(new BookieSocketAddress(BOOKIE4));
isolationGroups.add("group1");
}
use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project bookkeeper by apache.
the class ZooKeeperUtil method expireSession.
public void expireSession(ZooKeeper zk) throws Exception {
long id = zk.getSessionId();
byte[] password = zk.getSessionPasswd();
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
ZooKeeper zk2 = new ZooKeeper(getZooKeeperConnectString(), zk.getSessionTimeout(), w, id, password);
w.waitForConnection();
zk2.close();
}
use of org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase in project pulsar by yahoo.
the class ZooKeeperUtil method startServer.
public void startServer() throws Exception {
// create a ZooKeeper server(dataDir, dataLogDir, port)
LOG.debug("Running ZK server");
// ServerStats.registerAsConcrete();
ClientBase.setupTestEnv();
ZkTmpDir = File.createTempFile("zookeeper", "test");
ZkTmpDir.delete();
ZkTmpDir.mkdir();
zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
serverFactory = new NIOServerCnxnFactory();
serverFactory.configure(zkaddr, 100);
serverFactory.startup(zks);
boolean b = ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
LOG.debug("Server up: " + b);
// create a zookeeper client
LOG.debug("Instantiate ZK Client");
ZooKeeperWatcherBase w = new ZooKeeperWatcherBase(10000);
zkc = ZkUtils.createConnectedZookeeperClient(getZooKeeperConnectString(), w);
// initialize the zk client with values
zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
Aggregations