Search in sources :

Example 11 with Path

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;
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 12 with Path

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;
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 13 with Path

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);
}
Also used : Path(com.yahoo.path.Path) Node(com.yahoo.vespa.curator.mock.MemoryFileSystem.Node) KeeperException(org.apache.zookeeper.KeeperException)

Example 14 with Path

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);
    }
}
Also used : Path(com.yahoo.path.Path) CuratorTransaction(org.apache.curator.framework.api.transaction.CuratorTransaction) CuratorTransactionFinal(org.apache.curator.framework.api.transaction.CuratorTransactionFinal)

Example 15 with Path

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());
}
Also used : Path(com.yahoo.path.Path) ApplicationId(com.yahoo.config.provision.ApplicationId) Test(org.junit.Test)

Aggregations

Path (com.yahoo.path.Path)32 Test (org.junit.Test)10 ApplicationFile (com.yahoo.config.application.api.ApplicationFile)4 ConfigCurator (com.yahoo.vespa.config.server.zookeeper.ConfigCurator)4 File (java.io.File)4 ApplicationPackage (com.yahoo.config.application.api.ApplicationPackage)3 Node (com.yahoo.vespa.curator.mock.MemoryFileSystem.Node)3 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)3 KeeperException (org.apache.zookeeper.KeeperException)3 RankingConstant (com.yahoo.searchdefinition.RankingConstant)2 Curator (com.yahoo.vespa.curator.Curator)2 NullConfigModelRegistry (com.yahoo.config.model.NullConfigModelRegistry)1 FilesApplicationPackage (com.yahoo.config.model.application.provider.FilesApplicationPackage)1 ApplicationId (com.yahoo.config.provision.ApplicationId)1 TenantName (com.yahoo.config.provision.TenantName)1 NamedReader (com.yahoo.io.reader.NamedReader)1 RankProfile (com.yahoo.searchdefinition.RankProfile)1 Tensor (com.yahoo.tensor.Tensor)1 TensorType (com.yahoo.tensor.TensorType)1 NestedTransaction (com.yahoo.transaction.NestedTransaction)1