Search in sources :

Example 1 with BookKeeperClientFactoryImpl

use of org.apache.pulsar.broker.BookKeeperClientFactoryImpl in project incubator-pulsar by apache.

the class CompactorTool method main.

public static void main(String[] args) throws Exception {
    Arguments arguments = new Arguments();
    JCommander jcommander = new JCommander(arguments);
    jcommander.setProgramName("PulsarTopicCompactor");
    // parse args by JCommander
    jcommander.parse(args);
    if (arguments.help) {
        jcommander.usage();
        System.exit(-1);
    }
    // init broker config
    ServiceConfiguration brokerConfig;
    if (isBlank(arguments.brokerConfigFile)) {
        jcommander.usage();
        throw new IllegalArgumentException("Need to specify a configuration file for broker");
    } else {
        brokerConfig = PulsarConfigurationLoader.create(arguments.brokerConfigFile, ServiceConfiguration.class);
    }
    String pulsarServiceUrl = PulsarService.brokerUrl(brokerConfig);
    ClientConfiguration clientConfig = new ClientConfiguration();
    if (isNotBlank(brokerConfig.getBrokerClientAuthenticationPlugin())) {
        clientConfig.setAuthentication(brokerConfig.getBrokerClientAuthenticationPlugin(), brokerConfig.getBrokerClientAuthenticationParameters());
    }
    clientConfig.setUseTls(brokerConfig.isTlsEnabled());
    clientConfig.setTlsAllowInsecureConnection(brokerConfig.isTlsAllowInsecureConnection());
    clientConfig.setTlsTrustCertsFilePath(brokerConfig.getTlsCertificateFilePath());
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("compaction-%d").setDaemon(true).build());
    OrderedScheduler executor = OrderedScheduler.newSchedulerBuilder().build();
    ZooKeeperClientFactory zkClientFactory = new ZookeeperBkClientFactoryImpl(executor);
    ZooKeeper zk = zkClientFactory.create(brokerConfig.getZookeeperServers(), ZooKeeperClientFactory.SessionType.ReadWrite, (int) brokerConfig.getZooKeeperSessionTimeoutMillis()).get();
    BookKeeperClientFactory bkClientFactory = new BookKeeperClientFactoryImpl();
    BookKeeper bk = bkClientFactory.create(brokerConfig, zk);
    try (PulsarClient pulsar = PulsarClient.create(pulsarServiceUrl, clientConfig)) {
        Compactor compactor = new TwoPhaseCompactor(brokerConfig, pulsar, bk, scheduler);
        long ledgerId = compactor.compact(arguments.topic).get();
        log.info("Compaction of topic {} complete. Compacted to ledger {}", arguments.topic, ledgerId);
    } finally {
        bk.close();
        bkClientFactory.close();
        zk.close();
        scheduler.shutdownNow();
        executor.shutdown();
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BookKeeperClientFactoryImpl(org.apache.pulsar.broker.BookKeeperClientFactoryImpl) BookKeeper(org.apache.bookkeeper.client.BookKeeper) ZooKeeperClientFactory(org.apache.pulsar.zookeeper.ZooKeeperClientFactory) BookKeeperClientFactory(org.apache.pulsar.broker.BookKeeperClientFactory) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) JCommander(com.beust.jcommander.JCommander) ZookeeperBkClientFactoryImpl(org.apache.pulsar.zookeeper.ZookeeperBkClientFactoryImpl) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) PulsarClient(org.apache.pulsar.client.api.PulsarClient) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler)

Aggregations

JCommander (com.beust.jcommander.JCommander)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 BookKeeper (org.apache.bookkeeper.client.BookKeeper)1 OrderedScheduler (org.apache.bookkeeper.common.util.OrderedScheduler)1 BookKeeperClientFactory (org.apache.pulsar.broker.BookKeeperClientFactory)1 BookKeeperClientFactoryImpl (org.apache.pulsar.broker.BookKeeperClientFactoryImpl)1 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)1 ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)1 PulsarClient (org.apache.pulsar.client.api.PulsarClient)1 ZooKeeperClientFactory (org.apache.pulsar.zookeeper.ZooKeeperClientFactory)1 ZookeeperBkClientFactoryImpl (org.apache.pulsar.zookeeper.ZookeeperBkClientFactoryImpl)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1