Search in sources :

Example 11 with ClientConfiguration

use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.

the class ZkIsolatedBookieEnsemblePlacementPolicyTest method testBasic.

@Test
public void testBasic() throws Exception {
    Map<String, Map<String, BookieInfo>> bookieMapping = new HashMap<>();
    Map<String, BookieInfo> mainBookieGroup = new HashMap<>();
    BookieInfo bookieInfo0 = new BookieInfo();
    bookieInfo0.setRack("rack0");
    mainBookieGroup.put(BOOKIE1, bookieInfo0);
    BookieInfo bookieInfo1 = new BookieInfo();
    bookieInfo1.setRack("rack1");
    mainBookieGroup.put(BOOKIE2, bookieInfo1);
    Map<String, BookieInfo> secondaryBookieGroup = new HashMap<>();
    BookieInfo bookieInfo2 = new BookieInfo();
    bookieInfo2.setRack("rack0");
    secondaryBookieGroup.put(BOOKIE3, bookieInfo2);
    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Thread.sleep(100);
    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
    });
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);
    ArrayList<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(3, 3, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE4)));
    ensemble = isolationPolicy.newEnsemble(1, 1, new HashSet<>());
    assertFalse(ensemble.contains(new BookieSocketAddress(BOOKIE3)));
    try {
        isolationPolicy.newEnsemble(4, 4, new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
    // ok
    }
    Set<BookieSocketAddress> bookieToExclude = new HashSet<>();
    bookieToExclude.add(new BookieSocketAddress(BOOKIE1));
    ensemble = isolationPolicy.newEnsemble(2, 2, bookieToExclude);
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE4)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    BookieInfo bookieInfo3 = new BookieInfo();
    bookieInfo3.setRack("rack0");
    secondaryBookieGroup.put(BOOKIE4, bookieInfo3);
    bookieMapping.put("group2", secondaryBookieGroup);
    localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), -1);
    Thread.sleep(100);
    ensemble = isolationPolicy.newEnsemble(2, 2, null);
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    try {
        isolationPolicy.newEnsemble(3, 3, new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
    // ok
    }
    try {
        isolationPolicy.replaceBookie(new BookieSocketAddress(BOOKIE5), new HashSet<>(ensemble), new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
    // ok
    }
    bookieToExclude = new HashSet<>();
    bookieToExclude.add(new BookieSocketAddress(BOOKIE1));
    ensemble = isolationPolicy.newEnsemble(1, 1, bookieToExclude);
    BookieSocketAddress chosenBookie = isolationPolicy.replaceBookie(new BookieSocketAddress(BOOKIE5), new HashSet<>(ensemble), null);
    assertTrue(chosenBookie.equals(new BookieSocketAddress(BOOKIE1)));
    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
Also used : HashMap(java.util.HashMap) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashMap(java.util.HashMap) Map(java.util.Map) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with ClientConfiguration

use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.

the class ZkIsolatedBookieEnsemblePlacementPolicyTest method testNoBookieInfo.

@Test
public void testNoBookieInfo() throws Exception {
    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
    });
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);
    isolationPolicy.newEnsemble(4, 4, new HashSet<>());
    String data = "{\"group1\": {\"" + BOOKIE1 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2 + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4 + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}";
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Thread.sleep(100);
    ArrayList<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    try {
        isolationPolicy.newEnsemble(3, 3, new HashSet<>());
        fail("should not pass");
    } catch (BKNotEnoughBookiesException e) {
    // ok
    }
    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
Also used : BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) BKNotEnoughBookiesException(org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 13 with ClientConfiguration

use of org.apache.bookkeeper.conf.ClientConfiguration in project pulsar by yahoo.

the class ZkIsolatedBookieEnsemblePlacementPolicyTest method testNoIsolationGroup.

@Test
public void testNoIsolationGroup() throws Exception {
    String data = "{\"group1\": {\"" + BOOKIE1 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2 + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4 + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}";
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Thread.sleep(100);
    ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
    });
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);
    isolationPolicy.newEnsemble(4, 4, new HashSet<>());
}
Also used : ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 14 with ClientConfiguration

use of org.apache.bookkeeper.conf.ClientConfiguration in project pravega by pravega.

the class BookKeeperLogFactory method startBookKeeperClient.

// endregion
// region Initialization
private BookKeeper startBookKeeperClient() throws Exception {
    // These two are in Seconds, not Millis.
    int writeTimeout = (int) Math.ceil(this.config.getBkWriteTimeoutMillis() / 1000.0);
    int readTimeout = (int) Math.ceil(this.config.getBkReadTimeoutMillis() / 1000.0);
    ClientConfiguration config = new ClientConfiguration().setZkServers(this.config.getZkAddress()).setClientTcpNoDelay(true).setAddEntryTimeout(writeTimeout).setReadEntryTimeout(readTimeout).setGetBookieInfoTimeout(readTimeout).setClientConnectTimeoutMillis((int) this.config.getZkConnectionTimeout().toMillis()).setZkTimeout((int) this.config.getZkConnectionTimeout().toMillis());
    if (this.config.isTLSEnabled()) {
        config = (ClientConfiguration) config.setTLSProvider("OpenSSL");
        config = config.setTLSTrustStore(this.config.getTlsTrustStore());
    }
    if (this.config.getBkLedgerPath().isEmpty()) {
        config.setZkLedgersRootPath("/" + this.namespace + "/bookkeeper/ledgers");
    } else {
        config.setZkLedgersRootPath(this.config.getBkLedgerPath());
    }
    return new BookKeeper(config);
}
Also used : BookKeeper(org.apache.bookkeeper.client.BookKeeper) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Aggregations

ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)14 Test (org.testng.annotations.Test)7 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 BKNotEnoughBookiesException (org.apache.bookkeeper.client.BKException.BKNotEnoughBookiesException)4 IOException (java.io.IOException)3 KeeperException (org.apache.zookeeper.KeeperException)3 ZooKeeper (org.apache.zookeeper.ZooKeeper)3 HashSet (java.util.HashSet)2 BookKeeper (org.apache.bookkeeper.client.BookKeeper)2 ZooKeeperWatcherBase (org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase)2 JCommander (com.beust.jcommander.JCommander)1 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)1 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)1 ZkBookieRackAffinityMapping (com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping)1 ZooKeeperCache (com.yahoo.pulsar.zookeeper.ZooKeeperCache)1 ZooKeeperClientFactory (com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory)1 ZookeeperClientFactoryImpl (com.yahoo.pulsar.zookeeper.ZookeeperClientFactoryImpl)1 URL (java.net.URL)1