use of com.twitter.distributedlog.acl.AccessControlManager 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.acl.AccessControlManager in project distributedlog by twitter.
the class BKDistributedLogNamespace method close.
/**
* Close the distributed log manager factory, freeing any resources it may hold.
*/
@Override
public void close() {
ZooKeeperClient writerZKC;
ZooKeeperClient readerZKC;
AccessControlManager acm;
synchronized (this) {
if (closed) {
return;
}
closed = true;
writerZKC = sharedWriterZKCForBK;
readerZKC = sharedReaderZKCForBK;
acm = accessControlManager;
}
if (null != acm) {
acm.close();
LOG.info("Access Control Manager Stopped.");
}
// Close the allocator
if (null != allocator) {
Utils.closeQuietly(allocator);
LOG.info("Ledger Allocator stopped.");
}
// Shutdown log segment metadata stores
Utils.close(writerSegmentMetadataStore);
Utils.close(readerSegmentMetadataStore);
// Shutdown the schedulers
SchedulerUtils.shutdownScheduler(scheduler, conf.getSchedulerShutdownTimeoutMs(), TimeUnit.MILLISECONDS);
LOG.info("Executor Service Stopped.");
if (scheduler != readAheadExecutor) {
SchedulerUtils.shutdownScheduler(readAheadExecutor, conf.getSchedulerShutdownTimeoutMs(), TimeUnit.MILLISECONDS);
LOG.info("ReadAhead Executor Service Stopped.");
}
writerBKC.close();
readerBKC.close();
sharedWriterZKCForDL.close();
sharedReaderZKCForDL.close();
// Close shared zookeeper clients for bk
if (null != writerZKC) {
writerZKC.close();
}
if (null != readerZKC) {
readerZKC.close();
}
channelFactory.releaseExternalResources();
LOG.info("Release external resources used by channel factory.");
requestTimer.stop();
LOG.info("Stopped request timer");
SchedulerUtils.shutdownScheduler(lockStateExecutor, 5000, TimeUnit.MILLISECONDS);
LOG.info("Stopped lock state executor");
}
Aggregations