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;
}
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());
}
Aggregations