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);
}
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);
}
}
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;
}
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;
}
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));
}
Aggregations