Skip to content

Commit 108db3a

Browse files
committed
Changes to allow stream storage to use hostname instead of IP address
1 parent 44a1a4e commit 108db3a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

stream/server/src/main/java/org/apache/bookkeeper/stream/server/StorageServer.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ private static class ServerArguments {
8282
@Parameter(names = {"-p", "--port"}, description = "Port to listen on for gPRC server")
8383
private int port = 4181;
8484

85+
@Parameter(names = {"-u", "--useHostname"}, description = "Use hostname instead of IP for server ID")
86+
private boolean useHostname = false;
87+
8588
@Parameter(names = {"-h", "--help"}, description = "Show this help message")
8689
private boolean help = false;
8790

@@ -105,11 +108,14 @@ private static void loadConfFile(CompositeConfiguration conf, String confFile)
105108

106109
public static Endpoint createLocalEndpoint(int port, boolean useHostname) throws UnknownHostException {
107110
String hostname;
111+
log.warn("Determining hostname for stream storage");
108112
if (useHostname) {
109113
hostname = InetAddress.getLocalHost().getHostName();
110114
} else {
111115
hostname = InetAddress.getLocalHost().getHostAddress();
112116
}
117+
118+
log.warn("Decided to use hostname {}", hostname);
113119
return Endpoint.newBuilder()
114120
.setHostname(hostname)
115121
.setPort(port)
@@ -143,12 +149,14 @@ static int doMain(String[] args) {
143149
}
144150

145151
int grpcPort = arguments.port;
152+
boolean grpcUseHostname = arguments.useHostname;
146153

147154
LifecycleComponent storageServer;
148155
try {
149156
storageServer = buildStorageServer(
150157
conf,
151-
grpcPort);
158+
grpcPort,
159+
grpcUseHostname);
152160
} catch (ConfigurationException e) {
153161
log.error("Invalid storage configuration", e);
154162
return ExitCode.INVALID_CONF.code();
@@ -174,11 +182,18 @@ static int doMain(String[] args) {
174182
public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
175183
int grpcPort)
176184
throws UnknownHostException, ConfigurationException {
177-
return buildStorageServer(conf, grpcPort, true, NullStatsLogger.INSTANCE);
185+
return buildStorageServer(conf, grpcPort, false, true, NullStatsLogger.INSTANCE);
186+
}
187+
188+
public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
189+
int grpcPort, boolean useHostname)
190+
throws UnknownHostException, ConfigurationException {
191+
return buildStorageServer(conf, grpcPort, false, useHostname, NullStatsLogger.INSTANCE);
178192
}
179193

180194
public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
181195
int grpcPort,
196+
boolean useHostname,
182197
boolean startBookieAndStartProvider,
183198
StatsLogger externalStatsLogger)
184199
throws ConfigurationException, UnknownHostException {
@@ -199,7 +214,7 @@ public static LifecycleComponent buildStorageServer(CompositeConfiguration conf,
199214
storageConf.validate();
200215

201216
// Get my local endpoint
202-
Endpoint myEndpoint = createLocalEndpoint(grpcPort, false);
217+
Endpoint myEndpoint = createLocalEndpoint(grpcPort, useHostname);
203218

204219
// Create shared resources
205220
StorageResources storageResources = StorageResources.create();

stream/server/src/main/java/org/apache/bookkeeper/stream/server/StreamStorageLifecycleComponent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public StreamStorageLifecycleComponent(BookieConfiguration conf, StatsLogger sta
4242
this.streamStorage = StorageServer.buildStorageServer(
4343
conf.getUnderlyingConf(),
4444
ssConf.getGrpcPort(),
45+
ssConf.getGrpcUseHostname(),
4546
false,
4647
statsLogger.scope("stream"));
4748
}

stream/server/src/main/java/org/apache/bookkeeper/stream/server/conf/StorageServerConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class StorageServerConfiguration extends ComponentConfiguration {
2525
private static final String COMPONENT_PREFIX = "storageserver" + DELIMITER;
2626

2727
private static final String GRPC_PORT = "grpc.port";
28+
private static final String GRPC_USE_HOSTNAME = "grpc.useHostname";
29+
2830

2931
public static StorageServerConfiguration of(CompositeConfiguration conf) {
3032
return new StorageServerConfiguration(conf);
@@ -42,4 +44,14 @@ private StorageServerConfiguration(CompositeConfiguration conf) {
4244
public int getGrpcPort() {
4345
return getInt(GRPC_PORT, 4181);
4446
}
47+
48+
/**
49+
* Returns the grpc flag that indicates to use hostname instead of IP address
50+
* for the stream storage server
51+
*
52+
* @return grpc useHostname flag
53+
*/
54+
public boolean getGrpcUseHostname() {
55+
return getBoolean(GRPC_USE_HOSTNAME, false);
56+
}
4557
}

0 commit comments

Comments
 (0)