Search in sources :

Example 1 with MasterPayload

use of water.zookeeper.nodes.MasterPayload in project h2o-2 by h2oai.

the class h2odriver method doWait.

public MasterPayload doWait() throws Exception {
    ZooKeeper z = ZooKeeperFactory.makeZk(_zk);
    byte[] payload;
    payload = z.getData(_zkroot, null, null);
    ClusterPayload cp = ClusterPayload.fromPayload(payload, ClusterPayload.class);
    z.close();
    assert (cp.numNodes > 0);
    long startMillis = System.currentTimeMillis();
    while (true) {
        z = ZooKeeperFactory.makeZk(_zk);
        if (z.exists(_zkroot, false) == null) {
            z.close();
            throw new Exception("ZooKeeper node does not exist: " + _zkroot);
        }
        try {
            payload = z.getData(_zkroot + "/master", null, null);
            MasterPayload mp = MasterPayload.fromPayload(payload, MasterPayload.class);
            z.close();
            Thread.sleep(CLOUD_FORMATION_SETTLE_DOWN_SECONDS);
            return mp;
        } catch (KeeperException.NoNodeException e) {
        // This is OK, do nothing
        }
        long now = System.currentTimeMillis();
        if (Math.abs(now - startMillis) > (_cloudFormationTimeoutSeconds * 1000)) {
            z.close();
            throw new TimeoutException("Timed out waiting for cloud to form");
        }
        Thread.sleep(1000);
    }
}
Also used : ClusterPayload(water.zookeeper.nodes.ClusterPayload) MasterPayload(water.zookeeper.nodes.MasterPayload) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)1 ClusterPayload (water.zookeeper.nodes.ClusterPayload)1 MasterPayload (water.zookeeper.nodes.MasterPayload)1