You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by ay...@apache.org on 2021/01/27 20:12:16 UTC

[bookkeeper] branch master-stream-hostname created (now 0631dc4)

This is an automated email from the ASF dual-hosted git repository.

ayegorov pushed a change to branch master-stream-hostname
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git.


      at 0631dc4  Changes to allow stream storage to use hostname instead of IP address

This branch includes the following new commits:

     new 0631dc4  Changes to allow stream storage to use hostname instead of IP address

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[bookkeeper] 01/01: Changes to allow stream storage to use hostname instead of IP address

Posted by ay...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ayegorov pushed a commit to branch master-stream-hostname
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit 0631dc49b1faf73707a6d5407287df45ce58ffd6
Author: Chris Bartholomew <c_...@yahoo.com>
AuthorDate: Wed Dec 4 17:17:36 2019 -0500

    Changes to allow stream storage to use hostname instead of IP address
---
 .../bookkeeper/stream/server/StorageServer.java    | 24 ++++++++++++++++++----
 .../server/StreamStorageLifecycleComponent.java    |  1 +
 .../server/conf/StorageServerConfiguration.java    | 12 +++++++++++
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java
index 024343e..d5b1e50 100644
--- a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java
+++ b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java
@@ -89,6 +89,9 @@ public class StorageServer {
         @Parameter(names = {"-p", "--port"}, description = "Port to listen on for gPRC server")
         private int port = 4181;
 
+        @Parameter(names = {"-u", "--useHostname"}, description = "Use hostname instead of IP for server ID")
+        private boolean useHostname = false;
+
         @Parameter(names = {"-h", "--help"}, description = "Show this help message")
         private boolean help = false;
 
@@ -112,11 +115,14 @@ public class StorageServer {
 
     public static Endpoint createLocalEndpoint(int port, boolean useHostname) throws UnknownHostException {
         String hostname;
+        log.warn("Determining hostname for stream storage");
         if (useHostname) {
             hostname = InetAddress.getLocalHost().getHostName();
         } else {
             hostname = InetAddress.getLocalHost().getHostAddress();
         }
+
+        log.warn("Decided to use hostname {}", hostname);
         return Endpoint.newBuilder()
             .setHostname(hostname)
             .setPort(port)
@@ -150,12 +156,14 @@ public class StorageServer {
         }
 
         int grpcPort = arguments.port;
+        boolean grpcUseHostname = arguments.useHostname;
 
         LifecycleComponent storageServer;
         try {
             storageServer = buildStorageServer(
                 conf,
-                grpcPort);
+                grpcPort,
+                grpcUseHostname);
         } catch (Exception e) {
             log.error("Invalid storage configuration", e);
             return ExitCode.INVALID_CONF.code();
@@ -178,14 +186,22 @@ public class StorageServer {
     public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
                                                         int grpcPort)
             throws Exception {
-        return buildStorageServer(conf, grpcPort, true, NullStatsLogger.INSTANCE);
+        return buildStorageServer(conf, grpcPort, false, true, NullStatsLogger.INSTANCE);
+    }
+
+    public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
+                                                        int grpcPort, boolean useHostname)
+            throws Exception {
+        return buildStorageServer(conf, grpcPort, false, useHostname, NullStatsLogger.INSTANCE);
     }
 
     public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
                                                         int grpcPort,
+                                                        boolean useHostname,
                                                         boolean startBookieAndStartProvider,
                                                         StatsLogger externalStatsLogger)
-        throws Exception {
+            throws Exception {
+
         final ComponentInfoPublisher componentInfoPublisher = new ComponentInfoPublisher();
 
         final Supplier<BookieServiceInfo> bookieServiceInfoProvider =
@@ -208,7 +224,7 @@ public class StorageServer {
         storageConf.validate();
 
         // Get my local endpoint
-        Endpoint myEndpoint = createLocalEndpoint(grpcPort, false);
+        Endpoint myEndpoint = createLocalEndpoint(grpcPort, useHostname);
 
         // Create shared resources
         StorageResources storageResources = StorageResources.create();
diff --git a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StreamStorageLifecycleComponent.java b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StreamStorageLifecycleComponent.java
index 60c60a3..29c6b7f 100644
--- a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StreamStorageLifecycleComponent.java
+++ b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/StreamStorageLifecycleComponent.java
@@ -40,6 +40,7 @@ public class StreamStorageLifecycleComponent extends ServerLifecycleComponent {
         this.streamStorage = StorageServer.buildStorageServer(
             conf.getUnderlyingConf(),
             ssConf.getGrpcPort(),
+            ssConf.getGrpcUseHostname(),
             false,
             statsLogger.scope("stream"));
     }
diff --git a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/conf/StorageServerConfiguration.java b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/conf/StorageServerConfiguration.java
index bc300c9..a7599a4 100644
--- a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/conf/StorageServerConfiguration.java
+++ b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/conf/StorageServerConfiguration.java
@@ -25,6 +25,8 @@ public class StorageServerConfiguration extends ComponentConfiguration {
     private static final String COMPONENT_PREFIX = "storageserver" + DELIMITER;
 
     private static final String GRPC_PORT = "grpc.port";
+    private static final String GRPC_USE_HOSTNAME = "grpc.useHostname";
+
 
     public static StorageServerConfiguration of(CompositeConfiguration conf) {
         return new StorageServerConfiguration(conf);
@@ -42,4 +44,14 @@ public class StorageServerConfiguration extends ComponentConfiguration {
     public int getGrpcPort() {
         return getInt(GRPC_PORT, 4181);
     }
+
+    /**
+     * Returns the grpc flag that indicates to use hostname instead of IP address
+     * for the stream storage server
+     *
+     * @return grpc useHostname flag
+     */
+    public boolean getGrpcUseHostname() {
+        return getBoolean(GRPC_USE_HOSTNAME, false);
+    }
 }