Search in sources :

Example 1 with BKDLConfig

use of com.twitter.distributedlog.metadata.BKDLConfig 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 BKDLConfig

use of com.twitter.distributedlog.metadata.BKDLConfig in project distributedlog by twitter.

the class DistributedLogCluster method start.

public void start() throws Exception {
    this.dlmEmulator.start();
    BKDLConfig bkdlConfig = new BKDLConfig(this.dlmEmulator.getZkServers(), "/ledgers").setACLRootPath(".acl");
    DLMetadata.create(bkdlConfig).update(this.dlmEmulator.getUri());
    if (shouldStartProxy) {
        this.dlServer = new DLServer(dlConf, this.dlmEmulator.getUri(), proxyPort);
    } else {
        this.dlServer = null;
    }
}
Also used : BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig)

Example 3 with BKDLConfig

use of com.twitter.distributedlog.metadata.BKDLConfig in project distributedlog by twitter.

the class TestZKLogMetadataForWriter method testCreateLogMetadataWithCustomMetadata.

@Test(timeout = 60000)
public void testCreateLogMetadataWithCustomMetadata() throws Exception {
    URI uri = DLMTestUtil.createDLMURI(zkPort, "");
    String logName = testName.getMethodName();
    String logIdentifier = "<default>";
    List<String> pathsToDelete = Lists.newArrayList();
    DLMetadata.create(new BKDLConfig(zkServers, "/ledgers")).update(uri);
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(new DistributedLogConfiguration()).uri(uri).build();
    DistributedLogManager dlm = namespace.openLog(logName);
    dlm.createOrUpdateMetadata(logName.getBytes("UTF-8"));
    dlm.close();
    testCreateLogMetadataWithMissingPaths(uri, logName, logIdentifier, pathsToDelete, true, false);
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) DistributedLogNamespace(com.twitter.distributedlog.namespace.DistributedLogNamespace) DistributedLogManager(com.twitter.distributedlog.DistributedLogManager) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) URI(java.net.URI) Test(org.junit.Test)

Example 4 with BKDLConfig

use of com.twitter.distributedlog.metadata.BKDLConfig in project distributedlog by twitter.

the class DLAuditor method calculateLedgerSpaceUsage.

public long calculateLedgerSpaceUsage(URI uri) throws IOException {
    List<URI> uris = Lists.newArrayList(uri);
    String zkServers = validateAndGetZKServers(uris);
    RetryPolicy retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), Integer.MAX_VALUE);
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().name("DLAuditor-ZK").zkServers(zkServers).sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryPolicy(retryPolicy).zkAclId(conf.getZkAclId()).build();
    ExecutorService executorService = Executors.newCachedThreadPool();
    try {
        BKDLConfig bkdlConfig = resolveBKDLConfig(zkc, uris);
        logger.info("Resolved bookkeeper config : {}", bkdlConfig);
        BookKeeperClient bkc = BookKeeperClientBuilder.newBuilder().name("DLAuditor-BK").dlConfig(conf).zkServers(bkdlConfig.getBkZkServersForWriter()).ledgersPath(bkdlConfig.getBkLedgersPath()).build();
        try {
            return calculateLedgerSpaceUsage(bkc, executorService);
        } finally {
            bkc.close();
        }
    } finally {
        zkc.close();
        executorService.shutdown();
    }
}
Also used : ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) BookKeeperClient(com.twitter.distributedlog.BookKeeperClient) ExecutorService(java.util.concurrent.ExecutorService) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) URI(java.net.URI) RetryPolicy(org.apache.bookkeeper.zookeeper.RetryPolicy) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)

Example 5 with BKDLConfig

use of com.twitter.distributedlog.metadata.BKDLConfig in project distributedlog by twitter.

the class DLAuditor method collectLedgers.

public Pair<Set<Long>, Set<Long>> collectLedgers(List<URI> uris, List<List<String>> allocationPaths) throws IOException {
    Preconditions.checkArgument(uris.size() > 0, "No uri provided to audit");
    String zkServers = validateAndGetZKServers(uris);
    RetryPolicy retryPolicy = new BoundExponentialBackoffRetryPolicy(conf.getZKRetryBackoffStartMillis(), conf.getZKRetryBackoffMaxMillis(), Integer.MAX_VALUE);
    ZooKeeperClient zkc = ZooKeeperClientBuilder.newBuilder().name("DLAuditor-ZK").zkServers(zkServers).sessionTimeoutMs(conf.getZKSessionTimeoutMilliseconds()).retryPolicy(retryPolicy).zkAclId(conf.getZkAclId()).build();
    ExecutorService executorService = Executors.newCachedThreadPool();
    try {
        BKDLConfig bkdlConfig = resolveBKDLConfig(zkc, uris);
        logger.info("Resolved bookkeeper config : {}", bkdlConfig);
        BookKeeperClient bkc = BookKeeperClientBuilder.newBuilder().name("DLAuditor-BK").dlConfig(conf).zkServers(bkdlConfig.getBkZkServersForWriter()).ledgersPath(bkdlConfig.getBkLedgersPath()).build();
        try {
            Set<Long> bkLedgers = collectLedgersFromBK(bkc, executorService);
            Set<Long> dlLedgers = collectLedgersFromDL(uris, allocationPaths);
            return Pair.of(bkLedgers, dlLedgers);
        } finally {
            bkc.close();
        }
    } finally {
        zkc.close();
        executorService.shutdown();
    }
}
Also used : ZooKeeperClient(com.twitter.distributedlog.ZooKeeperClient) BookKeeperClient(com.twitter.distributedlog.BookKeeperClient) ExecutorService(java.util.concurrent.ExecutorService) AtomicLong(java.util.concurrent.atomic.AtomicLong) BKDLConfig(com.twitter.distributedlog.metadata.BKDLConfig) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy) RetryPolicy(org.apache.bookkeeper.zookeeper.RetryPolicy) BoundExponentialBackoffRetryPolicy(org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)

Aggregations

BKDLConfig (com.twitter.distributedlog.metadata.BKDLConfig)10 URI (java.net.URI)5 ZooKeeperClient (com.twitter.distributedlog.ZooKeeperClient)4 BookKeeperClient (com.twitter.distributedlog.BookKeeperClient)2 DistributedLogManager (com.twitter.distributedlog.DistributedLogManager)2 DistributedLogNamespace (com.twitter.distributedlog.namespace.DistributedLogNamespace)2 ExecutorService (java.util.concurrent.ExecutorService)2 BoundExponentialBackoffRetryPolicy (org.apache.bookkeeper.zookeeper.BoundExponentialBackoffRetryPolicy)2 RetryPolicy (org.apache.bookkeeper.zookeeper.RetryPolicy)2 Test (org.junit.Test)2 Stopwatch (com.google.common.base.Stopwatch)1 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 LogSegmentMetadata (com.twitter.distributedlog.LogSegmentMetadata)1 AccessControlManager (com.twitter.distributedlog.acl.AccessControlManager)1 ZKAccessControl (com.twitter.distributedlog.acl.ZKAccessControl)1 DLException (com.twitter.distributedlog.exceptions.DLException)1 AccessControlEntry (com.twitter.distributedlog.thrift.AccessControlEntry)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1