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