use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.
the class TestDistributedLogTool method testToolCreateZkAclId.
@Test(timeout = 60000)
public void testToolCreateZkAclId() throws Exception {
createStream(defaultUri, "0", "CreateAclStream", defaultPrivilegedZkAclId);
try {
DistributedLogManager dlm = DLMTestUtil.createNewDLM("0CreateAclStream", conf, defaultUri);
DLMTestUtil.generateCompletedLogSegments(dlm, conf, 3, 1000);
dlm.close();
} catch (ZKException ex) {
assertEquals(KeeperException.Code.NOAUTH, ex.getKeeperExceptionCode());
}
}
use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.
the class ZKLogMetadataStore method getLogs.
@Override
public CompletableFuture<Iterator<String>> getLogs(String logNamePrefix) {
final CompletableFuture<Iterator<String>> promise = new CompletableFuture<Iterator<String>>();
final String nsRootPath;
if (StringUtils.isEmpty(logNamePrefix)) {
nsRootPath = namespace.getPath();
} else {
nsRootPath = namespace.getPath() + "/" + logNamePrefix;
}
try {
final ZooKeeper zk = zkc.get();
zk.sync(nsRootPath, new AsyncCallback.VoidCallback() {
@Override
public void processResult(int syncRc, String syncPath, Object ctx) {
if (KeeperException.Code.OK.intValue() == syncRc) {
zk.getChildren(nsRootPath, false, new AsyncCallback.Children2Callback() {
@Override
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
if (KeeperException.Code.OK.intValue() == rc) {
List<String> results = Lists.newArrayListWithExpectedSize(children.size());
for (String child : children) {
if (!isReservedStreamName(child)) {
results.add(child);
}
}
promise.complete(results.iterator());
} else if (KeeperException.Code.NONODE.intValue() == rc) {
List<String> streams = Lists.newLinkedList();
promise.complete(streams.iterator());
} else {
promise.completeExceptionally(new ZKException("Error reading namespace " + nsRootPath, KeeperException.Code.get(rc)));
}
}
}, null);
} else if (KeeperException.Code.NONODE.intValue() == syncRc) {
List<String> streams = Lists.newLinkedList();
promise.complete(streams.iterator());
} else {
promise.completeExceptionally(new ZKException("Error reading namespace " + nsRootPath, KeeperException.Code.get(syncRc)));
}
}
}, null);
zkc.get();
} catch (ZooKeeperClient.ZooKeeperConnectionException e) {
promise.completeExceptionally(e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
promise.completeExceptionally(e);
}
return promise;
}
use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method deleteLogSegment.
@Override
public void deleteLogSegment(Transaction<Object> txn, final LogSegmentMetadata segment, final OpListener<Void> listener) {
Op deleteOp = Op.delete(segment.getZkPath(), -1);
logger.info("Delete segment : {}", segment);
txn.addOp(DefaultZKOp.of(deleteOp, new OpListener<Void>() {
@Override
public void onCommit(Void r) {
if (null != listener) {
listener.onCommit(r);
}
}
@Override
public void onAbort(Throwable t) {
logger.info("Aborted transaction on deleting segment {}", segment);
KeeperException.Code kc;
if (t instanceof KeeperException) {
kc = ((KeeperException) t).code();
} else if (t instanceof ZKException) {
kc = ((ZKException) t).getKeeperExceptionCode();
} else {
abortListener(t);
return;
}
if (KeeperException.Code.NONODE == kc) {
abortListener(new LogSegmentNotFoundException(segment.getZkPath()));
return;
}
abortListener(t);
}
private void abortListener(Throwable t) {
if (null != listener) {
listener.onAbort(t);
}
}
}));
}
use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method processResult.
@Override
@SuppressWarnings("unchecked")
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
CompletableFuture<Versioned<List<String>>> result = ((CompletableFuture<Versioned<List<String>>>) ctx);
if (KeeperException.Code.OK.intValue() == rc) {
/**
* cversion: the number of changes to the children of this znode *
*/
LongVersion zkVersion = new LongVersion(stat.getCversion());
result.complete(new Versioned(children, zkVersion));
} else if (KeeperException.Code.NONODE.intValue() == rc) {
result.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
} else {
result.completeExceptionally(new ZKException("Failed to get log segments from " + path, KeeperException.Code.get(rc)));
}
}
use of org.apache.distributedlog.exceptions.ZKException in project bookkeeper by apache.
the class ZKLogStreamMetadataStore method existPath.
private static void existPath(ZooKeeper zk, String path, String basePath, LinkedList<String> missingPaths, CompletableFuture<List<String>> future) {
if (basePath.equals(path)) {
future.complete(missingPaths);
return;
}
zk.exists(path, false, (rc, path1, ctx, stat) -> {
if (Code.OK.intValue() != rc && Code.NONODE.intValue() != rc) {
future.completeExceptionally(new ZKException("Failed to check existence of path " + path1, Code.get(rc)));
return;
}
if (Code.OK.intValue() == rc) {
future.complete(missingPaths);
return;
}
missingPaths.addLast(path);
String parentPath = Utils.getParent(path);
existPath(zk, parentPath, basePath, missingPaths, future);
}, null);
}
Aggregations