use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class ListQuotaCommand method exec.
@Override
public boolean exec() throws CliException {
String path = args[1];
String absolutePath = Quotas.limitPath(path);
try {
err.println("absolute path is " + absolutePath);
List<StatsTrack> statsTracks = listQuota(zk, path);
for (int i = 0; i < statsTracks.size(); i++) {
StatsTrack st = statsTracks.get(i);
if (i == 0) {
out.println("Output quota for " + path + " " + st.toString());
} else {
out.println("Output stat for " + path + " " + st.toString());
}
}
} catch (IllegalArgumentException ex) {
throw new MalformedPathException(ex.getMessage());
} catch (KeeperException.NoNodeException ne) {
err.println("quota for " + path + " does not exist.");
} catch (KeeperException | InterruptedException ex) {
throw new CliWrapperException(ex);
}
return false;
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class SetQuotaCommand method exec.
@Override
public boolean exec() throws CliException {
// get the args
String path = args[1];
if (path.startsWith(Quotas.quotaZookeeper)) {
err.println("cannot set a quota under the path: " + Quotas.quotaZookeeper);
return false;
}
StatsTrack quota = new StatsTrack();
quota.setCount(-1);
quota.setBytes(-1L);
quota.setCountHardLimit(-1);
quota.setByteHardLimit(-1L);
if (!checkOptionValue(quota)) {
return false;
}
boolean flagSet = (cl.hasOption("n") || cl.hasOption("N") || cl.hasOption("b") || cl.hasOption("B"));
if (flagSet) {
try {
createQuota(zk, path, quota);
} catch (IllegalArgumentException ex) {
throw new MalformedPathException(ex.getMessage());
} catch (KeeperException | InterruptedException ex) {
throw new CliWrapperException(ex);
}
} else {
err.println(getUsageStr());
}
return false;
}
use of org.apache.zookeeper.StatsTrack in project zookeeper by apache.
the class DataTree method updateQuotaForPath.
/**
* update the quota for the given path
*
* @param path
* the path to be used
*/
private void updateQuotaForPath(String path) {
Counts c = new Counts();
getCounts(path, c);
StatsTrack strack = new StatsTrack();
strack.setBytes(c.bytes);
strack.setCount(c.count);
String statPath = Quotas.statPath(path);
DataNode node = getNode(statPath);
// it should exist
if (node == null) {
LOG.warn("Missing quota stat node {}", statPath);
return;
}
synchronized (node) {
nodes.preChange(statPath, node);
node.data = strack.getStatsBytes();
nodes.postChange(statPath, node);
}
}
Aggregations