Search in sources :

Example 1 with DNSToSwitchMapping

use of org.apache.bookkeeper.net.DNSToSwitchMapping in project distributedlog by twitter.

the class BookKeeperClient method commonInitialization.

@SuppressWarnings("deprecation")
private synchronized void commonInitialization(DistributedLogConfiguration conf, String ledgersPath, ClientSocketChannelFactory channelFactory, StatsLogger statsLogger, HashedWheelTimer requestTimer, boolean registerExpirationHandler) throws IOException, InterruptedException, KeeperException {
    ClientConfiguration bkConfig = new ClientConfiguration();
    bkConfig.setAddEntryTimeout(conf.getBKClientWriteTimeout());
    bkConfig.setReadTimeout(conf.getBKClientReadTimeout());
    bkConfig.setZkLedgersRootPath(ledgersPath);
    bkConfig.setZkTimeout(conf.getBKClientZKSessionTimeoutMilliSeconds());
    bkConfig.setNumWorkerThreads(conf.getBKClientNumberWorkerThreads());
    bkConfig.setEnsemblePlacementPolicy(RegionAwareEnsemblePlacementPolicy.class);
    bkConfig.setZkRequestRateLimit(conf.getBKClientZKRequestRateLimit());
    bkConfig.setProperty(RegionAwareEnsemblePlacementPolicy.REPP_DISALLOW_BOOKIE_PLACEMENT_IN_REGION_FEATURE_NAME, DistributedLogConstants.DISALLOW_PLACEMENT_IN_REGION_FEATURE_NAME);
    // reload configuration from dl configuration with settings prefixed with 'bkc.'
    ConfUtils.loadConfiguration(bkConfig, conf, "bkc.");
    Class<? extends DNSToSwitchMapping> dnsResolverCls;
    try {
        dnsResolverCls = conf.getEnsemblePlacementDnsResolverClass();
    } catch (ConfigurationException e) {
        LOG.error("Failed to load bk dns resolver : ", e);
        throw new IOException("Failed to load bk dns resolver : ", e);
    }
    final DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(dnsResolverCls, conf.getBkDNSResolverOverrides());
    this.bkc = BookKeeper.newBuilder().config(bkConfig).zk(zkc.get()).channelFactory(channelFactory).statsLogger(statsLogger).dnsResolver(dnsResolver).requestTimer(requestTimer).featureProvider(featureProvider.orNull()).build();
    if (registerExpirationHandler) {
        sessionExpireWatcher = this.zkc.registerExpirationHandler(this);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) DNSToSwitchMapping(org.apache.bookkeeper.net.DNSToSwitchMapping) IOException(java.io.IOException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration)

Example 2 with DNSToSwitchMapping

use of org.apache.bookkeeper.net.DNSToSwitchMapping in project distributedlog by twitter.

the class TestNetUtils method testGetDNSResolverWithOverrides.

@Test(timeout = 20000)
public void testGetDNSResolverWithOverrides() throws Exception {
    DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(DNSResolverForRacks.class, "");
    assertEquals("Should succeed to load " + DNSResolverForRacks.class, dnsResolver.getClass(), DNSResolverForRacks.class);
}
Also used : DNSToSwitchMapping(org.apache.bookkeeper.net.DNSToSwitchMapping) Test(org.junit.Test)

Example 3 with DNSToSwitchMapping

use of org.apache.bookkeeper.net.DNSToSwitchMapping in project distributedlog by twitter.

the class TestNetUtils method testGetDNSResolverWithDefaultConstructor.

@Test(timeout = 20000)
public void testGetDNSResolverWithDefaultConstructor() throws Exception {
    DNSToSwitchMapping dnsResolver = NetUtils.getDNSResolver(DNSResolverWithDefaultConstructor.class, "");
    assertEquals("Should succeed to load " + DNSResolverWithDefaultConstructor.class, dnsResolver.getClass(), DNSResolverWithDefaultConstructor.class);
}
Also used : DNSToSwitchMapping(org.apache.bookkeeper.net.DNSToSwitchMapping) Test(org.junit.Test)

Aggregations

DNSToSwitchMapping (org.apache.bookkeeper.net.DNSToSwitchMapping)3 Test (org.junit.Test)2 IOException (java.io.IOException)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1