use of org.apache.bookkeeper.discover.RegistrationClient in project incubator-pulsar by apache.
the class PulsarRegistrationClientTest method testWatchBookiesSuccess.
private void testWatchBookiesSuccess(String provider, Supplier<String> urlSupplier, boolean isWritable) throws Exception {
@Cleanup MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
String ledgersRoot = "/test/ledgers-" + UUID.randomUUID();
@Cleanup RegistrationManager rm = new PulsarRegistrationManager(store, ledgersRoot, mock(AbstractConfiguration.class));
@Cleanup RegistrationClient rc = new PulsarRegistrationClient(store, ledgersRoot);
//
// 1. test watch bookies with a listener
//
Queue<Versioned<Set<BookieId>>> updates = new ConcurrentLinkedQueue<>();
Map<BookieId, Boolean> bookies = new ConcurrentHashMap<>();
RegistrationClient.RegistrationListener listener = (b) -> {
updates.add(b);
b.getValue().forEach(x -> bookies.put(x, true));
};
int BOOKIES = 10;
Set<BookieId> addresses = prepareNBookies(BOOKIES);
if (isWritable) {
result(rc.watchWritableBookies(listener));
} else {
result(rc.watchReadOnlyBookies(listener));
}
for (BookieId address : addresses) {
rm.registerBookie(address, !isWritable, new BookieServiceInfo());
}
Awaitility.await().untilAsserted(() -> {
assertFalse(updates.isEmpty());
assertEquals(bookies.size(), BOOKIES);
});
}
use of org.apache.bookkeeper.discover.RegistrationClient in project incubator-pulsar by apache.
the class PulsarRegistrationClientTest method testGetAllBookies.
@Test(dataProvider = "impl")
public void testGetAllBookies(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup MetadataStoreExtended store = MetadataStoreExtended.create(urlSupplier.get(), MetadataStoreConfig.builder().build());
String ledgersRoot = "/test/ledgers-" + UUID.randomUUID();
@Cleanup RegistrationManager rm = new PulsarRegistrationManager(store, ledgersRoot, mock(AbstractConfiguration.class));
@Cleanup RegistrationClient rc = new PulsarRegistrationClient(store, ledgersRoot);
Set<BookieId> addresses = prepareNBookies(10);
List<String> children = new ArrayList<>();
for (BookieId address : addresses) {
children.add(address.toString());
boolean isReadOnly = children.size() % 2 == 0;
rm.registerBookie(address, isReadOnly, new BookieServiceInfo());
}
Versioned<Set<BookieId>> result = result(rc.getAllBookies());
assertEquals(result.getValue().size(), addresses.size());
}
use of org.apache.bookkeeper.discover.RegistrationClient in project incubator-pulsar by apache.
the class Bookies method getAllBookies.
@GET
@Path("/all")
@ApiOperation(value = "Gets raw information for all the bookies in the cluster", response = BookiesClusterInfo.class)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public BookiesClusterInfo getAllBookies() throws Exception {
validateSuperUserAccess();
BookKeeper bookKeeper = bookKeeper();
MetadataClientDriver metadataClientDriver = bookKeeper.getMetadataClientDriver();
RegistrationClient registrationClient = metadataClientDriver.getRegistrationClient();
Set<BookieId> allBookies = registrationClient.getAllBookies().get().getValue();
List<RawBookieInfo> result = new ArrayList<>(allBookies.size());
for (BookieId bookieId : allBookies) {
RawBookieInfo bookieInfo = new RawBookieInfo(bookieId.toString());
result.add(bookieInfo);
}
return BookiesClusterInfo.builder().bookies(result).build();
}
use of org.apache.bookkeeper.discover.RegistrationClient in project pulsar by yahoo.
the class Bookies method getAllBookies.
@GET
@Path("/all")
@ApiOperation(value = "Gets raw information for all the bookies in the cluster", response = BookiesClusterInfo.class)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
public BookiesClusterInfo getAllBookies() throws Exception {
validateSuperUserAccess();
BookKeeper bookKeeper = bookKeeper();
MetadataClientDriver metadataClientDriver = bookKeeper.getMetadataClientDriver();
RegistrationClient registrationClient = metadataClientDriver.getRegistrationClient();
Set<BookieId> allBookies = registrationClient.getAllBookies().get().getValue();
List<RawBookieInfo> result = new ArrayList<>(allBookies.size());
for (BookieId bookieId : allBookies) {
RawBookieInfo bookieInfo = new RawBookieInfo(bookieId.toString());
result.add(bookieInfo);
}
return BookiesClusterInfo.builder().bookies(result).build();
}
use of org.apache.bookkeeper.discover.RegistrationClient in project pulsar by yahoo.
the class PulsarRegistrationManager method nukeExistingCluster.
@Override
public boolean nukeExistingCluster() throws Exception {
log.info("Nuking metadata of existing cluster, ledger root path: {}", ledgersRootPath);
if (!store.exists(ledgersRootPath + "/" + INSTANCEID).join()) {
log.info("There is no existing cluster with ledgersRootPath: {}, so exiting nuke operation", ledgersRootPath);
return true;
}
@Cleanup RegistrationClient registrationClient = new PulsarRegistrationClient(store, ledgersRootPath);
Collection<BookieId> rwBookies = registrationClient.getWritableBookies().join().getValue();
if (rwBookies != null && !rwBookies.isEmpty()) {
log.error("Bookies are still up and connected to this cluster, " + "stop all bookies before nuking the cluster");
return false;
}
Collection<BookieId> roBookies = registrationClient.getReadOnlyBookies().join().getValue();
if (roBookies != null && !roBookies.isEmpty()) {
log.error("Readonly Bookies are still up and connected to this cluster, " + "stop all bookies before nuking the cluster");
return false;
}
LayoutManager layoutManager = new PulsarLayoutManager(store, ledgersRootPath);
LedgerManagerFactory ledgerManagerFactory = new PulsarLedgerManagerFactory();
ledgerManagerFactory.initialize(conf, layoutManager, LegacyHierarchicalLedgerManagerFactory.CUR_VERSION);
return ledgerManagerFactory.validateAndNukeExistingCluster(conf, layoutManager);
}
Aggregations