use of org.apache.bookkeeper.discover.RegistrationClient in project 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 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(addresses.size(), result.getValue().size());
}
use of org.apache.bookkeeper.discover.RegistrationClient in project pulsar by apache.
the class PulsarRegistrationClientTest method testGetReadonlyBookies.
@Test(dataProvider = "impl")
public void testGetReadonlyBookies(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());
rm.registerBookie(address, true, new BookieServiceInfo());
}
Versioned<Set<BookieId>> result = result(rc.getReadOnlyBookies());
assertEquals(addresses.size(), result.getValue().size());
}
use of org.apache.bookkeeper.discover.RegistrationClient in project pulsar by apache.
the class PulsarRegistrationClientTest method testGetWritableBookies.
@Test(dataProvider = "impl")
public void testGetWritableBookies(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());
rm.registerBookie(address, false, new BookieServiceInfo());
}
Versioned<Set<BookieId>> result = result(rc.getWritableBookies());
assertEquals(addresses.size(), result.getValue().size());
}
use of org.apache.bookkeeper.discover.RegistrationClient in project pulsar by yahoo.
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);
});
}
Aggregations