Search in sources :

Example 41 with StatsTrack

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;
}
Also used : StatsTrack(org.apache.zookeeper.StatsTrack) KeeperException(org.apache.zookeeper.KeeperException)

Example 42 with StatsTrack

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;
}
Also used : StatsTrack(org.apache.zookeeper.StatsTrack) KeeperException(org.apache.zookeeper.KeeperException)

Example 43 with StatsTrack

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);
    }
}
Also used : StatsTrack(org.apache.zookeeper.StatsTrack)

Aggregations

StatsTrack (org.apache.zookeeper.StatsTrack)43 Test (org.junit.jupiter.api.Test)25 OldStatsTrack (org.apache.zookeeper.test.StatsTrackTest.OldStatsTrack)19 QuotaExceededException (org.apache.zookeeper.KeeperException.QuotaExceededException)14 KeeperException (org.apache.zookeeper.KeeperException)9 Stat (org.apache.zookeeper.data.Stat)6 DataTree (org.apache.zookeeper.server.DataTree)3 Op (org.apache.zookeeper.Op)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1 MalformedPathException (org.apache.zookeeper.cli.MalformedPathException)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1