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