Search in sources :

Example 16 with BookieServiceInfo

use of org.apache.bookkeeper.discover.BookieServiceInfo 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());
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) AbstractConfiguration(org.apache.bookkeeper.conf.AbstractConfiguration) RegistrationClient(org.apache.bookkeeper.discover.RegistrationClient) BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Test(org.testng.annotations.Test) BaseMetadataStoreTest(org.apache.pulsar.metadata.BaseMetadataStoreTest)

Example 17 with BookieServiceInfo

use of org.apache.bookkeeper.discover.BookieServiceInfo in project pulsar by yahoo.

the class BookieServiceInfoSerde method serialize.

@Override
public byte[] serialize(String path, BookieServiceInfo bookieServiceInfo) throws IOException {
    if (log.isDebugEnabled()) {
        log.debug("serialize BookieServiceInfo {}", bookieServiceInfo);
    }
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        BookieServiceInfoFormat.Builder builder = BookieServiceInfoFormat.newBuilder();
        List<BookieServiceInfoFormat.Endpoint> bsiEndpoints = bookieServiceInfo.getEndpoints().stream().map(e -> BookieServiceInfoFormat.Endpoint.newBuilder().setId(e.getId()).setPort(e.getPort()).setHost(e.getHost()).setProtocol(e.getProtocol()).addAllAuth(e.getAuth()).addAllExtensions(e.getExtensions()).build()).collect(Collectors.toList());
        builder.addAllEndpoints(bsiEndpoints);
        builder.putAllProperties(bookieServiceInfo.getProperties());
        builder.build().writeTo(os);
        return os.toByteArray();
    }
}
Also used : BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) Stat(org.apache.pulsar.metadata.api.Stat) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BookieServiceInfoFormat(org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat) MetadataSerde(org.apache.pulsar.metadata.api.MetadataSerde) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BookieServiceInfoFormat(org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 18 with BookieServiceInfo

use of org.apache.bookkeeper.discover.BookieServiceInfo in project pulsar by yahoo.

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(result.getValue().size(), addresses.size());
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) AbstractConfiguration(org.apache.bookkeeper.conf.AbstractConfiguration) RegistrationClient(org.apache.bookkeeper.discover.RegistrationClient) BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Test(org.testng.annotations.Test) BaseMetadataStoreTest(org.apache.pulsar.metadata.BaseMetadataStoreTest)

Example 19 with BookieServiceInfo

use of org.apache.bookkeeper.discover.BookieServiceInfo in project pulsar by yahoo.

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(result.getValue().size(), addresses.size());
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) AbstractConfiguration(org.apache.bookkeeper.conf.AbstractConfiguration) RegistrationClient(org.apache.bookkeeper.discover.RegistrationClient) BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Test(org.testng.annotations.Test) BaseMetadataStoreTest(org.apache.pulsar.metadata.BaseMetadataStoreTest)

Example 20 with BookieServiceInfo

use of org.apache.bookkeeper.discover.BookieServiceInfo in project pulsar by yahoo.

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());
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Cleanup(lombok.Cleanup) AbstractConfiguration(org.apache.bookkeeper.conf.AbstractConfiguration) RegistrationClient(org.apache.bookkeeper.discover.RegistrationClient) BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Test(org.testng.annotations.Test) BaseMetadataStoreTest(org.apache.pulsar.metadata.BaseMetadataStoreTest)

Aggregations

BookieServiceInfo (org.apache.bookkeeper.discover.BookieServiceInfo)25 BookieId (org.apache.bookkeeper.net.BookieId)20 RegistrationManager (org.apache.bookkeeper.discover.RegistrationManager)14 ArrayList (java.util.ArrayList)13 RegistrationClient (org.apache.bookkeeper.discover.RegistrationClient)13 HashSet (java.util.HashSet)12 Set (java.util.Set)12 Cleanup (lombok.Cleanup)12 AbstractConfiguration (org.apache.bookkeeper.conf.AbstractConfiguration)12 BaseMetadataStoreTest (org.apache.pulsar.metadata.BaseMetadataStoreTest)12 MetadataStoreExtended (org.apache.pulsar.metadata.api.extended.MetadataStoreExtended)12 Test (org.testng.annotations.Test)12 List (java.util.List)6 Slf4j (lombok.extern.slf4j.Slf4j)6 IOException (java.io.IOException)5 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)4 BookieServiceInfoFormat (org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 Queue (java.util.Queue)3