Search in sources :

Example 51 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project lucene-solr by apache.

the class ZkStateReader method fetchCollectionState.

private DocCollection fetchCollectionState(String coll, Watcher watcher) throws KeeperException, InterruptedException {
    String collectionPath = getCollectionPath(coll);
    while (true) {
        try {
            Stat stat = new Stat();
            byte[] data = zkClient.getData(collectionPath, watcher, stat, true);
            ClusterState state = ClusterState.load(stat.getVersion(), data, Collections.<String>emptySet(), collectionPath);
            ClusterState.CollectionRef collectionRef = state.getCollectionStates().get(coll);
            return collectionRef == null ? null : collectionRef.get();
        } catch (KeeperException.NoNodeException e) {
            if (watcher != null) {
                // Leave an exists watch in place in case a state.json is created later.
                Stat exists = zkClient.exists(collectionPath, watcher, true);
                if (exists != null) {
                    // Loop and try again.
                    continue;
                }
            }
            return null;
        }
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 52 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project phoenix by apache.

the class PhoenixMRJobUtil method getActiveResourceManagerHost.

public static String getActiveResourceManagerHost(Configuration config, String zkQuorum) throws IOException, InterruptedException, JSONException, KeeperException, InvalidProtocolBufferException, ZooKeeperConnectionException {
    ZooKeeperWatcher zkw = null;
    ZooKeeper zk = null;
    String activeRMHost = null;
    try {
        zkw = new ZooKeeperWatcher(config, "get-active-yarnmanager", null);
        zk = new ZooKeeper(zkQuorum, 30000, zkw, false);
        List<String> children = zk.getChildren(YARN_LEADER_ELECTION, zkw);
        for (String subEntry : children) {
            List<String> subChildern = zk.getChildren(YARN_LEADER_ELECTION + "/" + subEntry, zkw);
            for (String eachEntry : subChildern) {
                if (eachEntry.contains(ACTIVE_STANDBY_ELECTOR_LOCK)) {
                    String path = YARN_LEADER_ELECTION + "/" + subEntry + "/" + ACTIVE_STANDBY_ELECTOR_LOCK;
                    byte[] data = zk.getData(path, zkw, new Stat());
                    ActiveRMInfoProto proto = ActiveRMInfoProto.parseFrom(data);
                    proto.getRmId();
                    LOG.info("Active RmId : " + proto.getRmId());
                    activeRMHost = config.get(YarnConfiguration.RM_HOSTNAME + "." + proto.getRmId());
                    LOG.info("activeResourceManagerHostname = " + activeRMHost);
                }
            }
        }
    } finally {
        if (zkw != null)
            zkw.close();
        if (zk != null)
            zk.close();
    }
    return activeRMHost;
}
Also used : ActiveRMInfoProto(org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.ActiveRMInfoProto) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 53 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project asterixdb by apache.

the class ZookeeperUtil method getAsterixInstances.

@Override
public List<AsterixInstance> getAsterixInstances() throws Exception {
    List<String> instanceNames = zk.getChildren(ASTERIX_INSTANCE_BASE_PATH, false);
    List<AsterixInstance> asterixInstances = new ArrayList<AsterixInstance>();
    String path;
    for (String instanceName : instanceNames) {
        path = ASTERIX_INSTANCE_BASE_PATH + File.separator + instanceName;
        byte[] asterixInstanceBytes = zk.getData(path, false, new Stat());
        asterixInstances.add(readAsterixInstanceObject(asterixInstanceBytes));
    }
    return asterixInstances;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) AsterixInstance(org.apache.asterix.event.model.AsterixInstance)

Example 54 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project camel by apache.

the class ZooKeeperGroup method getDataAndStat.

void getDataAndStat(final String fullPath) throws Exception {
    Stat stat = new Stat();
    byte[] data = client.getData().storingStatIn(stat).usingWatcher(dataWatcher).forPath(fullPath);
    applyNewData(fullPath, KeeperException.Code.OK.intValue(), stat, data);
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Example 55 with Stat

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.Stat in project camel by apache.

the class ExistenceChangedOperation method getResult.

@Override
public OperationResult<String> getResult() {
    try {
        String path = getNode();
        Stat statistics = connection.exists(path, true);
        return new OperationResult<String>(path, statistics);
    } catch (Exception e) {
        return new OperationResult<String>(e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat)

Aggregations

Stat (org.apache.zookeeper.data.Stat)799 KeeperException (org.apache.zookeeper.KeeperException)266 Test (org.junit.Test)124 IOException (java.io.IOException)120 ZooKeeper (org.apache.zookeeper.ZooKeeper)88 ArrayList (java.util.ArrayList)67 Test (org.testng.annotations.Test)58 Test (org.junit.jupiter.api.Test)53 Watcher (org.apache.zookeeper.Watcher)49 AsyncCallback (org.apache.zookeeper.AsyncCallback)48 ACL (org.apache.zookeeper.data.ACL)47 List (java.util.List)43 CountDownLatch (java.util.concurrent.CountDownLatch)43 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)39 WatchedEvent (org.apache.zookeeper.WatchedEvent)38 CuratorFramework (org.apache.curator.framework.CuratorFramework)37 Map (java.util.Map)34 HashMap (java.util.HashMap)32 WebApplicationException (javax.ws.rs.WebApplicationException)29 ExecutionException (java.util.concurrent.ExecutionException)27