Search in sources :

Example 81 with Stat

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

the class ZooKeeperMigrator method retrieveNode.

private DataStatAclNode retrieveNode(ZooKeeper zooKeeper, String path) {
    Preconditions.checkNotNull(zooKeeper, "ZooKeeper client must not be null");
    Preconditions.checkNotNull(path, "path must not be null");
    final Stat stat = new Stat();
    final byte[] data;
    final List<ACL> acls;
    final long ephemeralOwner;
    try {
        data = zooKeeper.getData(path, false, stat);
        acls = zooKeeper.getACL(path, stat);
        ephemeralOwner = stat.getEphemeralOwner();
    } catch (InterruptedException | KeeperException e) {
        if (e instanceof InterruptedException) {
            Thread.currentThread().interrupt();
        }
        throw new RuntimeException(String.format("unable to get data, ACLs, and stats from %s for node at path %s", zooKeeper, path), e);
    }
    return new DataStatAclNode(path, data, stat, acls, ephemeralOwner);
}
Also used : Stat(org.apache.zookeeper.data.Stat) ACL(org.apache.zookeeper.data.ACL) KeeperException(org.apache.zookeeper.KeeperException)

Example 82 with Stat

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

the class ZooKeeperStateProvider method getState.

@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();
    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);
        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) StateMap(org.apache.nifi.components.state.StateMap) StandardStateMap(org.apache.nifi.controller.state.StandardStateMap) IOException(java.io.IOException) Code(org.apache.zookeeper.KeeperException.Code) StandardStateMap(org.apache.nifi.controller.state.StandardStateMap) KeeperException(org.apache.zookeeper.KeeperException)

Example 83 with Stat

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

the class DelQuotaCommand method delQuota.

/**
 * this method deletes quota for a node.
 *
 * @param zk the zookeeper client
 * @param path the path to delete quota for
 * @param bytes true if number of bytes needs to be unset
 * @param numNodes true if number of nodes needs to be unset
 * @return true if quota deletion is successful
 * @throws KeeperException
 * @throws IOException
 * @throws InterruptedException
 */
public static boolean delQuota(ZooKeeper zk, String path, boolean bytes, boolean numNodes) throws KeeperException, IOException, InterruptedException, MalformedPathException {
    String parentPath = Quotas.quotaZookeeper + path;
    String quotaPath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
    if (zk.exists(quotaPath, false) == null) {
        System.out.println("Quota does not exist for " + path);
        return true;
    }
    byte[] data = null;
    try {
        data = zk.getData(quotaPath, false, new Stat());
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException.NoNodeException ne) {
        System.err.println("quota does not exist for " + path);
        return true;
    }
    StatsTrack strack = new StatsTrack(new String(data));
    if (bytes && !numNodes) {
        strack.setBytes(-1L);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (!bytes && numNodes) {
        strack.setCount(-1);
        zk.setData(quotaPath, strack.toString().getBytes(), -1);
    } else if (bytes && numNodes) {
        // delete till you can find a node with more than
        // one child
        List<String> children = zk.getChildren(parentPath, false);
        // / delete the direct children first
        for (String child : children) {
            zk.delete(parentPath + "/" + child, -1);
        }
        // cut the tree till their is more than one child
        trimProcQuotas(zk, parentPath);
    }
    return true;
}
Also used : Stat(org.apache.zookeeper.data.Stat) StatsTrack(org.apache.zookeeper.StatsTrack) KeeperException(org.apache.zookeeper.KeeperException)

Example 84 with Stat

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

the class Ls2Command method exec.

@Override
public boolean exec() throws CliException {
    err.println("'ls2' has been deprecated. " + "Please use 'ls [-s] path' instead.");
    String path = args[1];
    boolean watch = args.length > 2;
    Stat stat = new Stat();
    List<String> children;
    try {
        children = zk.getChildren(path, watch, stat);
    } catch (IllegalArgumentException ex) {
        throw new MalformedPathException(ex.getMessage());
    } catch (KeeperException | InterruptedException ex) {
        throw new CliWrapperException(ex);
    }
    out.println(children);
    new StatPrinter(out).print(stat);
    return watch;
}
Also used : Stat(org.apache.zookeeper.data.Stat) KeeperException(org.apache.zookeeper.KeeperException)

Example 85 with Stat

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

the class MultiTransactionTest method testOpResultEquals.

/**
 * Exercise the equals methods of OpResult classes.
 */
@Test
public void testOpResultEquals() {
    opEquals(new CreateResult("/foo"), new CreateResult("/foo"), new CreateResult("nope"));
    opEquals(new CreateResult("/foo"), new CreateResult("/foo"), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("nope", new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111)));
    opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo"));
    opEquals(new CheckResult(), new CheckResult(), null);
    opEquals(new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new SetDataResult(new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111)));
    opEquals(new ErrorResult(1), new ErrorResult(1), new ErrorResult(2));
    opEquals(new DeleteResult(), new DeleteResult(), null);
    opEquals(new ErrorResult(1), new ErrorResult(1), new ErrorResult(2));
}
Also used : SetDataResult(org.apache.zookeeper.OpResult.SetDataResult) Stat(org.apache.zookeeper.data.Stat) CreateResult(org.apache.zookeeper.OpResult.CreateResult) CheckResult(org.apache.zookeeper.OpResult.CheckResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) DeleteResult(org.apache.zookeeper.OpResult.DeleteResult) Test(org.junit.Test)

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