Search in sources :

Example 1 with AccessControlManager

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());
    }
}
Also used : AccessControlManager(com.twitter.distributedlog.acl.AccessControlManager) ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) DLException(com.twitter.distributedlog.exceptions.DLException) AccessControlEntry(com.twitter.distributedlog.thrift.AccessControlEntry) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) ZKAccessControl(com.twitter.distributedlog.acl.ZKAccessControl) Test(org.junit.Test)

Example 2 with AccessControlManager

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");
}
Also used : AccessControlManager(com.twitter.distributedlog.acl.AccessControlManager) ZKAccessControlManager(com.twitter.distributedlog.acl.ZKAccessControlManager) DefaultAccessControlManager(com.twitter.distributedlog.acl.DefaultAccessControlManager)

Aggregations

AccessControlManager (com.twitter.distributedlog.acl.AccessControlManager)2 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)1 DefaultAccessControlManager (com.twitter.distributedlog.acl.DefaultAccessControlManager)1 ZKAccessControl (com.twitter.distributedlog.acl.ZKAccessControl)1 ZKAccessControlManager (com.twitter.distributedlog.acl.ZKAccessControlManager)1 DLException (com.twitter.distributedlog.exceptions.DLException)1 BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)1 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)1 AccessControlEntry (com.twitter.distributedlog.thrift.AccessControlEntry)1 Test (org.junit.Test)1