private ManagedLedgerFactoryImpl(ZooKeeper zkc, ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config) throws Exception { this(new BookKeeper(bkClientConfiguration, zkc), true /* isBookkeeperManaged */, zkc, config); }
private ManagedLedgerFactoryImpl(ZooKeeper zkc, ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config) throws Exception { this(new BookKeeper(bkClientConfiguration, zkc), true /* isBookkeeperManaged */, zkc, config); }
public BookKeeper build() throws IOException, InterruptedException, BKException { checkNotNull(statsLogger, "No stats logger provided"); return new BookKeeper(conf, zk, eventLoopGroup, allocator, statsLogger, dnsResolver, requestTimer, featureProvider); } }
/** * Constructor that takes in a configuration object so we know * how to connect to ZooKeeper to retrieve information about the BookKeeper * cluster. We need this before we can do any type of admin operations on * the BookKeeper cluster. * * @param conf * Client Configuration Object * @throws IOException * throws this exception if there is an error instantiating the * ZooKeeper client. * @throws InterruptedException * Throws this exception if there is an error instantiating the * BookKeeper client. * @throws BKException * Throws this exception if there is an error instantiating the * BookKeeper client. */ public BookKeeperAdmin(ClientConfiguration conf) throws IOException, InterruptedException, BKException { // Create the BookKeeper client instance bkc = new BookKeeper(conf); ownsBK = true; this.lfr = new LedgerFragmentReplicator(bkc, NullStatsLogger.INSTANCE); this.mFactory = bkc.ledgerManagerFactory; }
BookKeeper bkclient = new BookKeeper(conf);
public ManagedLedgerFactoryImpl(ClientConfiguration bkClientConfiguration, ManagedLedgerFactoryConfig config) throws Exception { final CountDownLatch counter = new CountDownLatch(1); final String zookeeperQuorum = checkNotNull(bkClientConfiguration.getZkServers()); zookeeper = new ZooKeeper(zookeeperQuorum, bkClientConfiguration.getZkTimeout(), event -> { if (event.getState().equals(Watcher.Event.KeeperState.SyncConnected)) { log.info("Connected to zookeeper"); counter.countDown(); } else { log.error("Error connecting to zookeeper {}", event); } }); if (!counter.await(bkClientConfiguration.getZkTimeout(), TimeUnit.MILLISECONDS) || zookeeper.getState() != States.CONNECTED) { throw new ManagedLedgerException("Error connecting to ZooKeeper at '" + zookeeperQuorum + "'"); } this.bookKeeper = new BookKeeper(bkClientConfiguration, zookeeper); this.isBookkeeperManaged = true; this.store = new MetaStoreImplZookeeper(zookeeper, orderedExecutor); this.config = config; this.mbean = new ManagedLedgerFactoryMBeanImpl(this); this.entryCacheManager = new EntryCacheManager(this); this.statsTask = executor.scheduleAtFixedRate(() -> refreshStats(), 0, StatsPeriodSeconds, TimeUnit.SECONDS); }
final BookKeeper bk = new BookKeeper(conf); final BookKeeperAdmin admin = new BookKeeperAdmin(conf); final UpdateLedgerOp updateLedgerOp = new UpdateLedgerOp(bk, admin);
@Override public int runCmd(CommandLine cmdLine) throws Exception { final long lid = getOptionLedgerIdValue(cmdLine, "ledgerid", -1); if (lid == -1) { System.err.println("Must specify a ledger id"); return -1; } boolean force = cmdLine.hasOption("f"); boolean confirm = false; if (!force) { confirm = IOUtils.confirmPrompt( "Are you sure to delete Ledger : " + ledgerIdFormatter.formatLedgerId(lid) + "?"); } BookKeeper bk = null; try { if (force || confirm) { ClientConfiguration conf = new ClientConfiguration(); conf.addConfiguration(bkConf); bk = new BookKeeper(conf); bk.deleteLedger(lid); } } finally { if (bk != null) { bk.close(); } } return 0; }
@Override public int runCmd(CommandLine cmdLine) throws Exception { ClientConfiguration clientConf = new ClientConfiguration(bkConf); clientConf.setDiskWeightBasedPlacementEnabled(true); BookKeeper bk = new BookKeeper(clientConf); Map<BookieSocketAddress, BookieInfo> map = bk.getBookieInfo(); if (map.size() == 0) { System.out.println("Failed to retrieve bookie information from any of the bookies"); bk.close(); return 0; } System.out.println("Free disk space info:"); long totalFree = 0, total = 0; for (Map.Entry<BookieSocketAddress, BookieInfo> e : map.entrySet()) { BookieInfo bInfo = e.getValue(); BookieSocketAddress bookieId = e.getKey(); System.out.println(getBookieSocketAddrStringRepresentation(bookieId) + ":\tFree: " + bInfo.getFreeDiskSpace() + getReadable(bInfo.getFreeDiskSpace()) + "\tTotal: " + bInfo.getTotalDiskSpace() + getReadable(bInfo.getTotalDiskSpace())); totalFree += bInfo.getFreeDiskSpace(); total += bInfo.getTotalDiskSpace(); } System.out.println("Total free disk space in the cluster:\t" + totalFree + getReadable(totalFree)); System.out.println("Total disk capacity in the cluster:\t" + total + getReadable(total)); bk.close(); return 0; } }
conf.setReadEntryTimeout(timeoutSecs); BookKeeper bk = new BookKeeper(conf); LedgerHandle lh = null; try {
ClientConfiguration clientConf = new ClientConfiguration(); clientConf.addConfiguration(conf); BookKeeper bk = new BookKeeper(clientConf); Long ledgerId = Long.parseLong(params.get("ledger_id"));
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() .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()); config.setTLSTrustStorePasswordPath(this.config.getTlsTrustStorePasswordPath()); } String metadataServiceUri = "zk://" + this.config.getZkAddress(); if (this.config.getBkLedgerPath().isEmpty()) { metadataServiceUri += "/" + this.namespace + "/bookkeeper/ledgers"; } else { metadataServiceUri += this.config.getBkLedgerPath(); } config.setMetadataServiceUri(metadataServiceUri); return new BookKeeper(config); }
ClientConfiguration clientConf = new ClientConfiguration(conf); clientConf.setDiskWeightBasedPlacementEnabled(true); BookKeeper bk = new BookKeeper(clientConf);
return new BookKeeper(bkConf, zkClient); } catch (InterruptedException | BKException e) { throw new IOException(e);
return new BookKeeper(bkConf, zkClient); } catch (InterruptedException | KeeperException e) { throw new IOException(e);