Java Code Examples for backtype.storm.utils.Utils#newCurator()

The following examples show how to use backtype.storm.utils.Utils#newCurator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlobStoreUtils.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static CuratorFramework createZKClient(Map conf) throws Exception {
    CuratorFramework zkClient = null;
    try {
        List<String> zkServers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);
        Object port = conf.get(Config.STORM_ZOOKEEPER_PORT);
        zkClient = Utils.newCurator(conf, zkServers, port, (String) conf.get(Config.STORM_ZOOKEEPER_ROOT));
        zkClient.start();
    } catch (Exception e) {
        if (zkClient != null) {
            zkClient.close();
            zkClient = null;
        }
        throw e;
    }
    return zkClient;
}
 
Example 2
Source File: ThriftClient.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static String getMasterByZk(Map conf) throws Exception {

        CuratorFramework zkobj = null;
        String masterHost = null;

        try {
            String root = String.valueOf(conf.get(Config.STORM_ZOOKEEPER_ROOT));
            String zkMasterDir = root + Cluster.MASTER_SUBTREE;

            zkobj = Utils.newCurator(conf, (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS), conf.get(Config.STORM_ZOOKEEPER_PORT), zkMasterDir);
            zkobj.start();
            if (zkobj.checkExists().forPath("/") == null) {
                throw new RuntimeException("!!!!!!!!!!! \n\n\n No alive nimbus !!!!!!!!!!! \n\n\n");
            }

            masterHost = new String(zkobj.getData().forPath("/"));

            LOG.info("masterHost:" + masterHost);
            return masterHost;
        } finally {
            if (zkobj != null) {
                zkobj.close();
                zkobj = null;
            }
        }
    }
 
Example 3
Source File: Zookeeper.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * connect ZK, register watchers
 */
public CuratorFramework mkClient(Map conf, List<String> servers, Object port,
                                 String root, final WatcherCallBack watcher) {

    CuratorFramework fk = Utils.newCurator(conf, servers, port, root);

    fk.getCuratorListenable().addListener(new CuratorListener() {
        @Override
        public void eventReceived(CuratorFramework _fk, CuratorEvent e) throws Exception {
            if (e.getType().equals(CuratorEventType.WATCHED)) {
                WatchedEvent event = e.getWatchedEvent();

                watcher.execute(event.getState(), event.getType(), event.getPath());
            }

        }
    });

    fk.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() {
        @Override
        public void unhandledError(String msg, Throwable error) {
            String errmsg = "Unrecoverable zookeeper error, halting process: " + msg;
            LOG.error(errmsg, error);
            JStormUtils.halt_process(1, "Unrecoverable zookeeper error");

        }
    });
    fk.start();
    return fk;
}