use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.
the class BookKeeperCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.
the class ContainerCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@Override
protected Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val containerConfig = getCommandArgs().getState().getConfigBuilder().build().getConfig(ContainerConfig::builder);
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin(factory.getBookKeeperClient());
return new Context(serviceConfig, containerConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of org.apache.bookkeeper.client.BookKeeperAdmin in project bookkeeper by apache.
the class AdvertisedAddressTest method testSetAdvertisedAddress.
/**
* Test starting bookie with clean state.
*/
@Test
public void testSetAdvertisedAddress() throws Exception {
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setJournalDirName(newDirectory(false)).setLedgerDirNames(new String[] { newDirectory(false) }).setBookiePort(bookiePort).setZkServers(zkUtil.getZooKeeperConnectString());
conf.setAdvertisedAddress("10.0.0.1");
assertEquals("10.0.0.1", conf.getAdvertisedAddress());
BookieSocketAddress bkAddress = new BookieSocketAddress("10.0.0.1", bookiePort);
assertEquals(bkAddress, Bookie.getBookieAddress(conf));
Bookie b = new Bookie(conf);
b.start();
BookKeeperAdmin bka = new BookKeeperAdmin(baseClientConf);
Collection<BookieSocketAddress> bookies = bka.getAvailableBookies();
assertEquals(1, bookies.size());
BookieSocketAddress address = bookies.iterator().next();
assertEquals(bkAddress, address);
b.shutdown();
bka.close();
}
use of org.apache.bookkeeper.client.BookKeeperAdmin in project pravega by pravega.
the class BookKeeperCommand method createContext.
/**
* Creates a new Context to be used by the BookKeeper command.
*
* @return A new Context.
* @throws DurableDataLogException If the BookKeeperLogFactory could not be initialized.
*/
@VisibleForTesting
public Context createContext() throws DurableDataLogException {
val serviceConfig = getServiceConfig();
val bkConfig = getCommandArgs().getState().getConfigBuilder().include(BookKeeperConfig.builder().with(BookKeeperConfig.ZK_ADDRESS, serviceConfig.getZkURL())).build().getConfig(BookKeeperConfig::builder);
val zkClient = createZKClient();
val factory = new BookKeeperLogFactory(bkConfig, zkClient, getCommandArgs().getState().getExecutor());
try {
factory.initialize();
} catch (DurableDataLogException ex) {
zkClient.close();
throw ex;
}
val bkAdmin = new BookKeeperAdmin((BookKeeper) factory.getBookKeeperClient());
return new Context(serviceConfig, bkConfig, zkClient, factory, bkAdmin);
}
use of org.apache.bookkeeper.client.BookKeeperAdmin in project incubator-pulsar by apache.
the class ManagedLedgerOfflineBacklog method tryGetMDPosition.
private PositionImpl tryGetMDPosition(BookKeeper bookKeeper, long ledgerId, String cursorName) {
BookKeeperAdmin bookKeeperAdmin = null;
long lastEntry = LedgerHandle.INVALID_ENTRY_ID;
PositionImpl lastAckedMessagePosition = null;
try {
bookKeeperAdmin = new BookKeeperAdmin(bookKeeper);
Iterator<LedgerEntry> entries = bookKeeperAdmin.readEntries(ledgerId, 0, lastEntry).iterator();
while (entries.hasNext()) {
LedgerEntry ledgerEntry = entries.next();
lastEntry = ledgerEntry.getEntryId();
if (log.isDebugEnabled()) {
log.debug(" Read entry {} from ledger {} for cursor {}", lastEntry, ledgerId, cursorName);
}
MLDataFormats.PositionInfo positionInfo = MLDataFormats.PositionInfo.parseFrom(ledgerEntry.getEntry());
lastAckedMessagePosition = new PositionImpl(positionInfo);
if (log.isDebugEnabled()) {
log.debug("Cursor {} read position {}", cursorName, lastAckedMessagePosition);
}
}
} catch (Exception e) {
log.warn("Unable to determine LAC for ledgerId {} for cursor {}: {}", ledgerId, cursorName, e);
} finally {
if (bookKeeperAdmin != null) {
try {
bookKeeperAdmin.close();
} catch (Exception e) {
log.warn("Unable to close bk admin for ledgerId {} for cursor {}", ledgerId, cursorName, e);
}
}
}
return lastAckedMessagePosition;
}
Aggregations