Skip to content

Commit 3e1b8f6

Browse files
authored
[Broker] Create namespace failed when TLS is enabled in PulsarStandalone (#6457)
When starting Pulsar in standalone mode with TLS enabled, it will fail to create two namespaces during start. This is because it's using the unencrypted URL/port while constructing the PulsarAdmin client.
1 parent c3672a2 commit 3e1b8f6

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,28 @@ public void start() throws Exception {
319319

320320
broker.getTransactionMetadataStoreService().addTransactionMetadataStore(TransactionCoordinatorID.get(0));
321321

322-
URL webServiceUrl = new URL(
323-
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort().get()));
324-
final String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(),
325-
config.getBrokerServicePort().get());
326-
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl.toString()).authentication(
327-
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
328-
329322
final String cluster = config.getClusterName();
330323

331-
createSampleNameSpace(webServiceUrl, brokerServiceUrl, cluster);
324+
if (!config.isTlsEnabled()) {
325+
URL webServiceUrl = new URL(
326+
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort().get()));
327+
String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(),
328+
config.getBrokerServicePort().get());
329+
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl.toString()).authentication(
330+
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
331+
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, brokerServiceUrl, null);
332+
createSampleNameSpace(clusterData, cluster);
333+
} else {
334+
URL webServiceUrlTls = new URL(
335+
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePortTls().get()));
336+
String brokerServiceUrlTls = String.format("pulsar+ssl://%s:%d", config.getAdvertisedAddress(),
337+
config.getBrokerServicePortTls().get());
338+
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrlTls.toString()).authentication(
339+
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
340+
ClusterData clusterData = new ClusterData(null, webServiceUrlTls.toString(), null, brokerServiceUrlTls);
341+
createSampleNameSpace(clusterData, cluster);
342+
}
343+
332344
createDefaultNameSpace(cluster);
333345

334346
log.debug("--- setup completed ---");
@@ -352,14 +364,12 @@ private void createDefaultNameSpace(String cluster) {
352364
}
353365
}
354366

355-
private void createSampleNameSpace(URL webServiceUrl, String brokerServiceUrl, String cluster) {
367+
private void createSampleNameSpace(ClusterData clusterData, String cluster) {
356368
// Create a sample namespace
357369
final String property = "sample";
358370
final String globalCluster = "global";
359371
final String namespace = property + "/" + cluster + "/ns1";
360372
try {
361-
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null /* serviceUrlTls */,
362-
brokerServiceUrl, null /* brokerServiceUrlTls */);
363373
if (!admin.clusters().getClusters().contains(cluster)) {
364374
admin.clusters().createCluster(cluster, clusterData);
365375
} else {

0 commit comments

Comments
 (0)