use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.
the class DLMetadata method create.
public void create(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = serialize();
try {
Utils.zkCreateFullPathOptimistic(zkc, uri.getPath(), data, zkc.getDefaultACL(), CreateMode.PERSISTENT);
} catch (KeeperException e) {
throw new IOException("Fail to write dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} catch (InterruptedException e) {
throw new IOException("Interrupted when writing dl metadata " + new String(data, UTF_8) + " to uri " + uri, e);
} finally {
zkc.close();
}
}
use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.
the class DLMetadata method unbind.
public static void unbind(URI uri) throws IOException {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryThreadCount(conf.getZKClientNumberRetryThreads()).requestRateLimit(conf.getZKRequestRateLimit()).zkAclId(conf.getZkAclId()).uri(uri).build();
byte[] data = new byte[0];
try {
zkc.get().setData(uri.getPath(), data, -1);
} catch (KeeperException ke) {
throw new IOException("Fail to unbound dl metadata on uri " + uri, ke);
} catch (InterruptedException ie) {
throw new IOException("Interrupted when unbinding dl metadata on uri " + uri, ie);
} finally {
zkc.close();
}
}
use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.
the class TestDistributedLogServer method testRequestDenied.
@Test(timeout = 60000)
public void testRequestDenied() throws Exception {
String name = "request-denied";
dlClient.routingService.addHost(name, dlServer.getAddress());
AccessControlEntry ace = new AccessControlEntry();
ace.setDenyWrite(true);
ZooKeeperClient zkc = TestZooKeeperClientBuilder.newBuilder().uri(getUri()).connectionTimeoutMs(60000).sessionTimeoutMs(60000).build();
DistributedLogNamespace dlNamespace = dlServer.dlServer.getLeft().getDistributedLogNamespace();
BKDLConfig bkdlConfig = BKDLConfig.resolveDLConfig(zkc, getUri());
String zkPath = getUri().getPath() + "/" + bkdlConfig.getACLRootPath() + "/" + name;
ZKAccessControl accessControl = new ZKAccessControl(ace, zkPath);
accessControl.create(zkc);
AccessControlManager acm = dlNamespace.createAccessControlManager();
while (acm.allowWrite(name)) {
Thread.sleep(100);
}
try {
Await.result(dlClient.dlClient.write(name, ByteBuffer.wrap("1".getBytes(UTF_8))));
fail("Should fail with request denied exception");
} catch (DLException dle) {
assertEquals(StatusCode.REQUEST_DENIED, dle.getCode());
}
}
use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.
the class TestZKTransaction method testProcessNullResults.
@Test(timeout = 60000)
public void testProcessNullResults() throws Exception {
ZooKeeperClient zkc = mock(ZooKeeperClient.class);
ZKTransaction transaction = new ZKTransaction(zkc);
int numOps = 3;
final CountDownLatch commitLatch = new CountDownLatch(numOps);
final CountDownLatch abortLatch = new CountDownLatch(numOps);
for (int i = 0; i < numOps; i++) {
transaction.addOp(new CountDownZKOp(commitLatch, abortLatch));
}
transaction.processResult(KeeperException.Code.CONNECTIONLOSS.intValue(), "test-path", null, null);
abortLatch.await();
assertEquals(0, abortLatch.getCount());
assertEquals(numOps, commitLatch.getCount());
}
use of com.twitter.distributedlog.ZooKeeperClient in project distributedlog by twitter.
the class TestFederatedZKLogMetadataStore method testCreateLog.
@Test(timeout = 60000)
public void testCreateLog() throws Exception {
DistributedLogConfiguration conf = new DistributedLogConfiguration();
conf.addConfiguration(baseConf);
ZooKeeperClient anotherZkc = TestZooKeeperClientBuilder.newBuilder().uri(uri).sessionTimeoutMs(zkSessionTimeoutMs).build();
FederatedZKLogMetadataStore anotherMetadataStore = new FederatedZKLogMetadataStore(conf, uri, anotherZkc, scheduler);
for (int i = 0; i < 2 * maxLogsPerSubnamespace; i++) {
LogMetadataStore createStore, checkStore;
if (i % 2 == 0) {
createStore = metadataStore;
checkStore = anotherMetadataStore;
} else {
createStore = anotherMetadataStore;
checkStore = metadataStore;
}
String logName = "test-create-log-" + i;
URI logUri = FutureUtils.result(createStore.createLog(logName));
Optional<URI> logLocation = FutureUtils.result(checkStore.getLogLocation(logName));
assertTrue("Log " + logName + " doesn't exist", logLocation.isPresent());
assertEquals("Different log location " + logLocation.get() + " is found", logUri, logLocation.get());
}
assertEquals(2, metadataStore.getSubnamespaces().size());
assertEquals(2, anotherMetadataStore.getSubnamespaces().size());
}
Aggregations