Search in sources :

Example 1 with ZooKeeperWatcherBase

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;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) Map(java.util.Map) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with ZooKeeperWatcherBase

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;
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) KeeperException(org.apache.zookeeper.KeeperException) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)

Example 3 with ZooKeeperWatcherBase

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");
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with ZooKeeperWatcherBase

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();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase)

Example 5 with ZooKeeperWatcherBase

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);
}
Also used : ZooKeeperWatcherBase(org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Aggregations

ZooKeeperWatcherBase (org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase)7 ZooKeeper (org.apache.zookeeper.ZooKeeper)4 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)3 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 KeeperException (org.apache.zookeeper.KeeperException)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Map (java.util.Map)1 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)1 AddCallbackFuture (org.apache.bookkeeper.test.TestCallbacks.AddCallbackFuture)1 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1 Test (org.junit.Test)1