Search in sources :

Example 1 with BookieServiceInfoFormat

use of org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat in project bookkeeper by apache.

the class ZKRegistrationClient method deserializeBookieServiceInfo.

@SuppressWarnings("unchecked")
@VisibleForTesting
static BookieServiceInfo deserializeBookieServiceInfo(BookieId bookieId, byte[] bookieServiceInfo) throws IOException {
    if (bookieServiceInfo == null || bookieServiceInfo.length == 0) {
        return BookieServiceInfoUtils.buildLegacyBookieServiceInfo(bookieId.toString());
    }
    BookieServiceInfoFormat builder = BookieServiceInfoFormat.parseFrom(bookieServiceInfo);
    BookieServiceInfo bsi = new BookieServiceInfo();
    List<BookieServiceInfo.Endpoint> endpoints = builder.getEndpointsList().stream().map(e -> {
        BookieServiceInfo.Endpoint endpoint = new BookieServiceInfo.Endpoint();
        endpoint.setId(e.getId());
        endpoint.setPort(e.getPort());
        endpoint.setHost(e.getHost());
        endpoint.setProtocol(e.getProtocol());
        endpoint.setAuth(e.getAuthList());
        endpoint.setExtensions(e.getExtensionsList());
        return endpoint;
    }).collect(Collectors.toList());
    bsi.setEndpoints(endpoints);
    bsi.setProperties(builder.getPropertiesMap());
    return bsi;
}
Also used : LongVersion(org.apache.bookkeeper.versioning.LongVersion) Occurred(org.apache.bookkeeper.versioning.Version.Occurred) Getter(lombok.Getter) ZKException(org.apache.bookkeeper.client.BKException.ZKException) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) READONLY(org.apache.bookkeeper.util.BookKeeperConstants.READONLY) AccessLevel(lombok.AccessLevel) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) Versioned(org.apache.bookkeeper.versioning.Versioned) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) ZooKeeper(org.apache.zookeeper.ZooKeeper) AVAILABLE_NODE(org.apache.bookkeeper.util.BookKeeperConstants.AVAILABLE_NODE) KeeperException(org.apache.zookeeper.KeeperException) BookieServiceInfoFormat(org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat) Watcher(org.apache.zookeeper.Watcher) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) IOException(java.io.IOException) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) WatchedEvent(org.apache.zookeeper.WatchedEvent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) BKException(org.apache.bookkeeper.client.BKException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) SafeRunnable(org.apache.bookkeeper.common.util.SafeRunnable) COOKIE_NODE(org.apache.bookkeeper.util.BookKeeperConstants.COOKIE_NODE) EventType(org.apache.zookeeper.Watcher.Event.EventType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BookieId(org.apache.bookkeeper.net.BookieId) Version(org.apache.bookkeeper.versioning.Version) BookieServiceInfoFormat(org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with BookieServiceInfoFormat

use of org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat in project bookkeeper by apache.

the class BookieInitializationTest method testBookieRegistrationBookieServiceInfo.

@Test(timeout = 20000)
public void testBookieRegistrationBookieServiceInfo() throws Exception {
    final ServerConfiguration conf = TestBKConfiguration.newServerConfiguration().setMetadataServiceUri(metadataServiceUri).setUseHostNameAsBookieID(true).setUseShortHostName(true).setListeningInterface(null);
    final BookieId bookieId = BookieId.parse(InetAddress.getLocalHost().getCanonicalHostName().split("\\.", 2)[0] + ":" + conf.getBookiePort());
    String bkRegPath = ZKMetadataDriverBase.resolveZkLedgersRootPath(conf) + "/" + AVAILABLE_NODE + "/" + bookieId;
    MetadataBookieDriver metadataDriver = BookieResources.createMetadataDriver(conf, NullStatsLogger.INSTANCE);
    Endpoint endpoint = new Endpoint("test", 1281, "localhost", "bookie-rpc", Collections.emptyList(), Collections.emptyList());
    BookieServiceInfo bsi = new BookieServiceInfo(Collections.emptyMap(), Arrays.asList(endpoint));
    Supplier<BookieServiceInfo> supplier = () -> bsi;
    DiskChecker diskChecker = new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold());
    LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), diskChecker);
    try (RegistrationManager rm = metadataDriver.createRegistrationManager();
        StateManager manager = new BookieStateManager(conf, NullStatsLogger.INSTANCE, rm, ledgerDirsManager, supplier)) {
        manager.registerBookie(true).get();
        assertTrue("Bookie registration node doesn't exists!", rm.isBookieRegistered(bookieId));
    }
    Stat bkRegNode = zkc.exists(bkRegPath, false);
    assertNotNull("Bookie registration has been failed", bkRegNode);
    byte[] bkRegNodeData = zkc.getData(bkRegPath, null, null);
    assertFalse("Bookie service info not written", bkRegNodeData == null || bkRegNodeData.length == 0);
    BookieServiceInfoFormat serializedBookieServiceInfo = BookieServiceInfoFormat.parseFrom(bkRegNodeData);
    BookieServiceInfoFormat.Endpoint serializedEndpoint = serializedBookieServiceInfo.getEndpoints(0);
    assertNotNull("Serialized Bookie endpoint not found", serializedEndpoint);
    assertEquals(endpoint.getId(), serializedEndpoint.getId());
    assertEquals(endpoint.getHost(), serializedEndpoint.getHost());
    assertEquals(endpoint.getPort(), serializedEndpoint.getPort());
}
Also used : BookieId(org.apache.bookkeeper.net.BookieId) RegistrationManager(org.apache.bookkeeper.discover.RegistrationManager) MetadataDrivers.runFunctionWithRegistrationManager(org.apache.bookkeeper.meta.MetadataDrivers.runFunctionWithRegistrationManager) BookieServiceInfoFormat(org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) ZKMetadataBookieDriver(org.apache.bookkeeper.meta.zk.ZKMetadataBookieDriver) MetadataBookieDriver(org.apache.bookkeeper.meta.MetadataBookieDriver) DiskChecker(org.apache.bookkeeper.util.DiskChecker) Matchers.containsString(org.hamcrest.Matchers.containsString) Stat(org.apache.zookeeper.data.Stat) Endpoint(org.apache.bookkeeper.discover.BookieServiceInfo.Endpoint) BookieServiceInfo(org.apache.bookkeeper.discover.BookieServiceInfo) Test(org.junit.Test)

Aggregations

BookieId (org.apache.bookkeeper.net.BookieId)2 BookieServiceInfoFormat (org.apache.bookkeeper.proto.DataFormats.BookieServiceInfoFormat)2 Stat (org.apache.zookeeper.data.Stat)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 AccessLevel (lombok.AccessLevel)1 Getter (lombok.Getter)1