Search in sources :

Example 1 with GetChildrenBuilder

use of org.apache.curator.framework.api.GetChildrenBuilder in project hadoop by apache.

the class CuratorService method zkList.

/**
   * List all children of a path
   * @param path path of operation
   * @return a possibly empty list of children
   * @throws IOException
   */
public List<String> zkList(String path) throws IOException {
    checkServiceLive();
    String fullpath = createFullPath(path);
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("ls {}", fullpath);
        }
        GetChildrenBuilder builder = curator.getChildren();
        List<String> children = builder.forPath(fullpath);
        return children;
    } catch (Exception e) {
        throw operationFailure(path, "ls()", e);
    }
}
Also used : GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) NoChildrenForEphemeralsException(org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException) AuthenticationFailedException(org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException) FileAlreadyExistsException(org.apache.hadoop.fs.FileAlreadyExistsException) KeeperException(org.apache.zookeeper.KeeperException) PathNotFoundException(org.apache.hadoop.fs.PathNotFoundException) IOException(java.io.IOException) RegistryIOException(org.apache.hadoop.registry.client.exceptions.RegistryIOException) PathIsNotEmptyDirectoryException(org.apache.hadoop.fs.PathIsNotEmptyDirectoryException) ServiceStateException(org.apache.hadoop.service.ServiceStateException) NoPathPermissionsException(org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)

Example 2 with GetChildrenBuilder

use of org.apache.curator.framework.api.GetChildrenBuilder in project hadoop by apache.

the class ZKPathDumper method expand.

/**
   * Recursively expand the path into the supplied string builder, increasing
   * the indentation by {@link #INDENT} as it proceeds (depth first) down
   * the tree
   * @param builder string build to append to
   * @param path path to examine
   * @param indent current indentation
   */
private void expand(StringBuilder builder, String path, int indent) {
    try {
        GetChildrenBuilder childrenBuilder = curator.getChildren();
        List<String> children = childrenBuilder.forPath(path);
        for (String child : children) {
            String childPath = path + "/" + child;
            String body;
            Stat stat = curator.checkExists().forPath(childPath);
            StringBuilder bodyBuilder = new StringBuilder(256);
            bodyBuilder.append("  [").append(stat.getDataLength()).append("]");
            if (stat.getEphemeralOwner() > 0) {
                bodyBuilder.append("*");
            }
            if (verbose) {
                // verbose: extract ACLs
                builder.append(" -- ");
                List<ACL> acls = curator.getACL().forPath(childPath);
                for (ACL acl : acls) {
                    builder.append(RegistrySecurity.aclToString(acl));
                    builder.append(" ");
                }
            }
            body = bodyBuilder.toString();
            // print each child
            append(builder, indent, ' ');
            builder.append('/').append(child);
            builder.append(body);
            builder.append('\n');
            // recurse
            expand(builder, childPath, indent + INDENT);
        }
    } catch (Exception e) {
        builder.append(e.toString()).append("\n");
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) ACL(org.apache.zookeeper.data.ACL)

Example 3 with GetChildrenBuilder

use of org.apache.curator.framework.api.GetChildrenBuilder in project nakadi by zalando.

the class KafkaTopicRepositoryTest method createZooKeeperHolder.

private ZooKeeperHolder createZooKeeperHolder() throws Exception {
    // GetChildrenBuilder
    final GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);
    when(getChildrenBuilder.forPath("/brokers/topics")).thenReturn(allTopics());
    // Curator Framework
    final CuratorFramework curatorFramework = mock(CuratorFramework.class);
    when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
    // ZooKeeperHolder
    final ZooKeeperHolder zkHolder = mock(ZooKeeperHolder.class);
    when(zkHolder.get()).thenReturn(curatorFramework);
    return zkHolder;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) ZooKeeperHolder(org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)

Example 4 with GetChildrenBuilder

use of org.apache.curator.framework.api.GetChildrenBuilder in project pinpoint by naver.

the class CuratorZookeeperClient method getChildNodeList.

@Override
public List<String> getChildNodeList(String value, boolean watch) throws PinpointZookeeperException {
    checkState();
    String path = getPath(value, true);
    logger.debug("getChildNodeList() started. path:{}, watch:{}", path, watch);
    try {
        CuratorFramework curator = connectionManager.getCuratorFramework();
        final GetChildrenBuilder children = curator.getChildren();
        if (watch) {
            return children.usingWatcher(zookeeperEventWatcher).forPath(path);
        } else {
            return children.forPath(path);
        }
    } catch (KeeperException.NoNodeException noNode) {
    // skip
    } catch (Exception e) {
        ZookeeperExceptionResolver.resolveAndThrow(e);
    }
    return Collections.emptyList();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) KeeperException(org.apache.zookeeper.KeeperException) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) KeeperException(org.apache.zookeeper.KeeperException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)

Example 5 with GetChildrenBuilder

use of org.apache.curator.framework.api.GetChildrenBuilder in project metron by apache.

the class ConfigurationTest method testCanReadFromZookeeper.

@Test
public void testCanReadFromZookeeper() throws Exception {
    CuratorFramework curatorFramework = mock(CuratorFramework.class);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    GetDataBuilder getDataBuilder = mock(GetDataBuilder.class);
    GetChildrenBuilder getChildrenBuilder = mock(GetChildrenBuilder.class);
    when(getDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot())).thenReturn(mockGlobalData());
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(curatorFramework.getData()).thenReturn(getDataBuilder);
    when(curatorFramework.getChildren()).thenReturn(getChildrenBuilder);
    when(getChildrenBuilder.forPath(any())).thenReturn(Collections.emptyList());
    Configuration configuration = new Configuration(Paths.get("foo"));
    configuration.curatorFramework = curatorFramework;
    configuration.update();
    checkResult(configuration);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) ExistsBuilder(org.apache.curator.framework.api.ExistsBuilder) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

GetChildrenBuilder (org.apache.curator.framework.api.GetChildrenBuilder)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 KeeperException (org.apache.zookeeper.KeeperException)2 ConnectionException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)1 PinpointZookeeperException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)1 IOException (java.io.IOException)1 ExistsBuilder (org.apache.curator.framework.api.ExistsBuilder)1 GetDataBuilder (org.apache.curator.framework.api.GetDataBuilder)1 FileAlreadyExistsException (org.apache.hadoop.fs.FileAlreadyExistsException)1 PathIsNotEmptyDirectoryException (org.apache.hadoop.fs.PathIsNotEmptyDirectoryException)1 PathNotFoundException (org.apache.hadoop.fs.PathNotFoundException)1 AuthenticationFailedException (org.apache.hadoop.registry.client.exceptions.AuthenticationFailedException)1 NoChildrenForEphemeralsException (org.apache.hadoop.registry.client.exceptions.NoChildrenForEphemeralsException)1 NoPathPermissionsException (org.apache.hadoop.registry.client.exceptions.NoPathPermissionsException)1 RegistryIOException (org.apache.hadoop.registry.client.exceptions.RegistryIOException)1 ServiceStateException (org.apache.hadoop.service.ServiceStateException)1 ACL (org.apache.zookeeper.data.ACL)1 Stat (org.apache.zookeeper.data.Stat)1 Test (org.junit.jupiter.api.Test)1 ZooKeeperHolder (org.zalando.nakadi.repository.zookeeper.ZooKeeperHolder)1