Search in sources :

Example 1 with ClientConfiguration

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

the class MockedPulsarServiceBaseTest method init.

protected final void init() throws Exception {
    mockZookKeeper = createMockZooKeeper();
    mockBookKeeper = new NonClosableMockBookKeeper(new ClientConfiguration(), mockZookKeeper);
    sameThreadOrderedSafeExecutor = new SameThreadOrderedSafeExecutor();
    startBroker();
    brokerUrl = new URL("http://" + pulsar.getAdvertisedAddress() + ":" + BROKER_WEBSERVICE_PORT);
    brokerUrlTls = new URL("https://" + pulsar.getAdvertisedAddress() + ":" + BROKER_WEBSERVICE_PORT_TLS);
    admin = spy(new PulsarAdmin(brokerUrl, (Authentication) null));
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) URL(java.net.URL)

Example 2 with ClientConfiguration

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

the class ZkBookieRackAffinityMappingTest method testBasic.

@Test
public void testBasic() throws Exception {
    String data = "{\"group1\": {\"" + BOOKIE1 + "\": {\"rack\": \"/rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2 + "\": {\"rack\": \"/rack1\", \"hostname\": \"bookie2.example.com\"}}}";
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    // Case1: ZKCache is given
    ZkBookieRackAffinityMapping mapping1 = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf1 = new ClientConfiguration();
    bkClientConf1.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
    });
    mapping1.setConf(bkClientConf1);
    List<String> racks1 = mapping1.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks1.get(0), "/rack0");
    assertEquals(racks1.get(1), "/rack1");
    assertEquals(racks1.get(2), NetworkTopology.DEFAULT_RACK);
    // Case 2: ZkServers and ZkTimeout are given (ZKCache will be constructed in
    // ZkBookieRackAffinityMapping#setConf)
    ZkBookieRackAffinityMapping mapping2 = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf2 = new ClientConfiguration();
    bkClientConf2.setZkServers("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT);
    bkClientConf2.setZkTimeout(1000);
    mapping2.setConf(bkClientConf2);
    List<String> racks2 = mapping2.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks2.get(0), "/rack0");
    assertEquals(racks2.get(1), "/rack1");
    assertEquals(racks2.get(2), NetworkTopology.DEFAULT_RACK);
    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
Also used : ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 3 with ClientConfiguration

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

the class ZkBookieRackAffinityMappingTest method testNoBookieInfo.

@Test
public void testNoBookieInfo() throws Exception {
    ZkBookieRackAffinityMapping mapping = new ZkBookieRackAffinityMapping();
    ClientConfiguration bkClientConf = new ClientConfiguration();
    bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(localZkc, null) {
    });
    mapping.setConf(bkClientConf);
    List<String> racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(1), NetworkTopology.DEFAULT_RACK);
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);
    Map<String, Map<BookieSocketAddress, BookieInfo>> bookieMapping = new HashMap<>();
    Map<BookieSocketAddress, 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);
    bookieMapping.put("group1", mainBookieGroup);
    ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    Thread.sleep(100);
    racks = mapping.resolve(Lists.newArrayList(BOOKIE1, BOOKIE2, BOOKIE3));
    assertEquals(racks.get(0), "/rack0");
    assertEquals(racks.get(1), "/rack1");
    assertEquals(racks.get(2), NetworkTopology.DEFAULT_RACK);
    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
}
Also used : HashMap(java.util.HashMap) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HashMap(java.util.HashMap) Map(java.util.Map) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test)

Example 4 with ClientConfiguration

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

the class ZkIsolatedBookieEnsemblePlacementPolicyTest method testBookieInfoChange.

@Test
public void testBookieInfoChange() throws Exception {
    Map<String, Map<String, BookieInfo>> bookieMapping = new HashMap<>();
    Map<String, BookieInfo> mainBookieGroup = new HashMap<>();
    Map<String, BookieInfo> secondaryBookieGroup = new HashMap<>();
    BookieInfo bookieInfo0 = new BookieInfo();
    bookieInfo0.setRack("rack0");
    mainBookieGroup.put(BOOKIE1, bookieInfo0);
    BookieInfo bookieInfo1 = new BookieInfo();
    bookieInfo1.setRack("rack1");
    mainBookieGroup.put(BOOKIE2, bookieInfo1);
    BookieInfo bookieInfo2 = new BookieInfo();
    bookieInfo2.setRack("rack0");
    secondaryBookieGroup.put(BOOKIE3, bookieInfo2);
    BookieInfo bookieInfo3 = new BookieInfo();
    bookieInfo3.setRack("rack2");
    secondaryBookieGroup.put(BOOKIE4, bookieInfo3);
    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.setZkServers("127.0.0.1" + ":" + LOCAL_ZOOKEEPER_PORT);
    bkClientConf.setZkTimeout(1000);
    bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups);
    isolationPolicy.initialize(bkClientConf);
    isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies);
    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
    }
    mainBookieGroup.put(BOOKIE3, bookieInfo2);
    secondaryBookieGroup.remove(BOOKIE3);
    bookieMapping.put("group1", mainBookieGroup);
    bookieMapping.put("group2", secondaryBookieGroup);
    localZkc.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), -1);
    // wait for the zk to notify and update the mappings
    Thread.sleep(100);
    ensemble = isolationPolicy.newEnsemble(3, 3, new HashSet<>());
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2)));
    assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE3)));
    localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1);
    Thread.sleep(100);
    isolationPolicy.newEnsemble(1, 1, new HashSet<>());
}
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 5 with ClientConfiguration

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

the class BookKeeperClientFactoryImpl method create.

@Override
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient) throws IOException {
    ClientConfiguration bkConf = new ClientConfiguration();
    if (conf.getBookkeeperClientAuthenticationPlugin() != null && conf.getBookkeeperClientAuthenticationPlugin().trim().length() > 0) {
        bkConf.setClientAuthProviderFactoryClass(conf.getBookkeeperClientAuthenticationPlugin());
        bkConf.setProperty(conf.getBookkeeperClientAuthenticationParametersName(), conf.getBookkeeperClientAuthenticationParameters());
    }
    bkConf.setThrottleValue(0);
    bkConf.setAddEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setReadEntryTimeout((int) conf.getBookkeeperClientTimeoutInSeconds());
    bkConf.setSpeculativeReadTimeout(conf.getBookkeeperClientSpeculativeReadTimeoutInMillis());
    bkConf.setNumChannelsPerBookie(16);
    bkConf.setUseV2WireProtocol(true);
    bkConf.setLedgerManagerFactoryClassName(HierarchicalLedgerManagerFactory.class.getName());
    if (conf.isBookkeeperClientHealthCheckEnabled()) {
        bkConf.enableBookieHealthCheck();
        bkConf.setBookieHealthCheckInterval(conf.getBookkeeperHealthCheckIntervalSec(), TimeUnit.SECONDS);
        bkConf.setBookieErrorThresholdPerInterval(conf.getBookkeeperClientHealthCheckErrorThresholdPerInterval());
        bkConf.setBookieQuarantineTime((int) conf.getBookkeeperClientHealthCheckQuarantineTimeInSeconds(), TimeUnit.SECONDS);
    }
    if (conf.isBookkeeperClientRackawarePolicyEnabled()) {
        bkConf.setEnsemblePlacementPolicy(RackawareEnsemblePlacementPolicy.class);
        bkConf.setProperty(RackawareEnsemblePlacementPolicy.REPP_DNS_RESOLVER_CLASS, ZkBookieRackAffinityMapping.class.getName());
        bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(zkClient) {
        });
    }
    if (conf.getBookkeeperClientIsolationGroups() != null && !conf.getBookkeeperClientIsolationGroups().isEmpty()) {
        bkConf.setEnsemblePlacementPolicy(ZkIsolatedBookieEnsemblePlacementPolicy.class);
        bkConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, conf.getBookkeeperClientIsolationGroups());
        if (bkConf.getProperty(ZooKeeperCache.ZK_CACHE_INSTANCE) == null) {
            bkConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache(zkClient) {
            });
        }
    }
    try {
        return new BookKeeper(bkConf, zkClient);
    } catch (InterruptedException | KeeperException e) {
        throw new IOException(e);
    }
}
Also used : BookKeeper(org.apache.bookkeeper.client.BookKeeper) HierarchicalLedgerManagerFactory(org.apache.bookkeeper.meta.HierarchicalLedgerManagerFactory) IOException(java.io.IOException) ZkBookieRackAffinityMapping(com.yahoo.pulsar.zookeeper.ZkBookieRackAffinityMapping) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) ZooKeeperCache(com.yahoo.pulsar.zookeeper.ZooKeeperCache) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)13 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 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 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1