Search in sources :

Example 1 with Node

use of com.yahoo.vespa.curator.mock.MemoryFileSystem.Node in project vespa by vespa-engine.

the class MockCurator method createNode.

// ----- Start of adaptor methods from Curator to the mock file system -----
/**
 * Creates a node below the given directory root
 */
private String createNode(String pathString, byte[] content, boolean createParents, CreateMode createMode, Node root, Listeners listeners) throws KeeperException.NodeExistsException, KeeperException.NoNodeException {
    validatePath(pathString);
    Path path = Path.fromString(pathString);
    // the root already exists
    if (path.isRoot())
        return "/";
    Node parent = root.getNode(Paths.get(path.getParentPath().toString()), createParents);
    String name = nodeName(path.getName(), createMode);
    if (parent == null)
        throw new KeeperException.NoNodeException(path.getParentPath().toString());
    if (parent.children().containsKey(path.getName()))
        throw new KeeperException.NodeExistsException(path.toString());
    parent.add(name).setContent(content);
    String nodePath = "/" + path.getParentPath().toString() + "/" + name;
    listeners.notify(Path.fromString(nodePath), content, PathChildrenCacheEvent.Type.CHILD_ADDED);
    return nodePath;
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with Node

use of com.yahoo.vespa.curator.mock.MemoryFileSystem.Node in project vespa by vespa-engine.

the class MockCurator method getNode.

/**
 * Returns a node or throws the appropriate exception if it doesn't exist
 */
private Node getNode(String pathString, Node root) throws KeeperException.NoNodeException {
    validatePath(pathString);
    Path path = Path.fromString(pathString);
    Node parent = root.getNode(Paths.get(path.getParentPath().toString()), false);
    if (parent == null)
        throw new KeeperException.NoNodeException(path.toString());
    Node node = parent.children().get(path.getName());
    if (node == null)
        throw new KeeperException.NoNodeException(path.toString());
    return node;
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with Node

use of com.yahoo.vespa.curator.mock.MemoryFileSystem.Node in project vespa by vespa-engine.

the class MockCurator method deleteNode.

/**
 * Deletes a node below the given directory root
 */
private void deleteNode(String pathString, boolean deleteChildren, Node root, Listeners listeners) throws KeeperException.NoNodeException, KeeperException.NotEmptyException {
    validatePath(pathString);
    Path path = Path.fromString(pathString);
    Node parent = root.getNode(Paths.get(path.getParentPath().toString()), false);
    if (parent == null)
        throw new KeeperException.NoNodeException(path.toString());
    Node node = parent.children().get(path.getName());
    if (node == null)
        throw new KeeperException.NoNodeException(path.getName() + " under " + parent);
    if (!node.children().isEmpty() && !deleteChildren)
        throw new KeeperException.NotEmptyException(path.toString());
    parent.remove(path.getName());
    listeners.notify(path, new byte[0], PathChildrenCacheEvent.Type.CHILD_REMOVED);
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with Node

use of com.yahoo.vespa.curator.mock.MemoryFileSystem.Node in project vespa by vespa-engine.

the class MockCurator method exists.

private boolean exists(String path, Node root) {
    validatePath(path);
    Node parent = root.getNode(Paths.get(Path.fromString(path).getParentPath().toString()), false);
    if (parent == null)
        return false;
    Node node = parent.children().get(Path.fromString(path).getName());
    return node != null;
}
Also used : Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node)

Example 5 with Node

use of com.yahoo.vespa.curator.mock.MemoryFileSystem.Node in project vespa by vespa-engine.

the class MockCurator method getChildren.

private List<String> getChildren(String path, Node root) throws KeeperException.NoNodeException {
    validatePath(path);
    Node node = root.getNode(Paths.get(path), false);
    if (node == null)
        throw new KeeperException.NoNodeException(path);
    List<String> children = new ArrayList<>(node.children().keySet());
    if (!stableOrdering)
        Collections.shuffle(children);
    return children;
}
Also used : Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

Node (com.yahoo.vespa.curator.mock.MemoryFileSystem.Node)5 KeeperException (org.apache.zookeeper.KeeperException)4 Path (com.yahoo.path.Path)3 ArrayList (java.util.ArrayList)1