use of com.yahoo.path.Path 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.path.Path 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.path.Path 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.path.Path in project vespa by vespa-engine.
the class Curator method createAtomically.
/**
* Creates all the given paths in a single transaction. Any paths which already exists are ignored.
*/
public void createAtomically(Path... paths) {
try {
CuratorTransaction transaction = framework().inTransaction();
for (Path path : paths) {
if (!exists(path)) {
transaction = transaction.create().forPath(path.getAbsolute(), new byte[0]).and();
}
}
((CuratorTransactionFinal) transaction).commit();
} catch (Exception e) {
throw new RuntimeException("Could not create " + Arrays.toString(paths), e);
}
}
use of com.yahoo.path.Path in project vespa by vespa-engine.
the class NodeRepositoryTest method applicationDefaultFlavor.
@Test
public void applicationDefaultFlavor() {
NodeRepositoryTester tester = new NodeRepositoryTester();
ApplicationId application = ApplicationId.from(TenantName.from("a"), ApplicationName.from("b"), InstanceName.from("c"));
Path path = Path.fromString("/provision/v1/defaultFlavor").append(application.serializedForm());
String flavor = "example-flavor";
tester.curator().create(path);
tester.curator().set(path, flavor.getBytes(StandardCharsets.UTF_8));
assertEquals(Optional.of(flavor), tester.nodeRepository().getDefaultFlavorOverride(application));
ApplicationId applicationWithoutDefaultFlavor = ApplicationId.from(TenantName.from("does"), ApplicationName.from("not"), InstanceName.from("exist"));
assertFalse(tester.nodeRepository().getDefaultFlavorOverride(applicationWithoutDefaultFlavor).isPresent());
}
Aggregations