Skip to content

Commit

Permalink
[Broker] Create namespace failed when TLS is enabled in PulsarStandal…
Browse files Browse the repository at this point in the history
…one (#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.
  • Loading branch information
yjshen committed Mar 2, 2020
1 parent c3672a2 commit 3e1b8f6
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,28 @@ public void start() throws Exception {

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

URL webServiceUrl = new URL(
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort().get()));
final String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(),
config.getBrokerServicePort().get());
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl.toString()).authentication(
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();

final String cluster = config.getClusterName();

createSampleNameSpace(webServiceUrl, brokerServiceUrl, cluster);
if (!config.isTlsEnabled()) {
URL webServiceUrl = new URL(
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort().get()));
String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(),
config.getBrokerServicePort().get());
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl.toString()).authentication(
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, brokerServiceUrl, null);
createSampleNameSpace(clusterData, cluster);
} else {
URL webServiceUrlTls = new URL(
String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePortTls().get()));
String brokerServiceUrlTls = String.format("pulsar+ssl://%s:%d", config.getAdvertisedAddress(),
config.getBrokerServicePortTls().get());
admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrlTls.toString()).authentication(
config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters()).build();
ClusterData clusterData = new ClusterData(null, webServiceUrlTls.toString(), null, brokerServiceUrlTls);
createSampleNameSpace(clusterData, cluster);
}

createDefaultNameSpace(cluster);

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

private void createSampleNameSpace(URL webServiceUrl, String brokerServiceUrl, String cluster) {
private void createSampleNameSpace(ClusterData clusterData, String cluster) {
// Create a sample namespace
final String property = "sample";
final String globalCluster = "global";
final String namespace = property + "/" + cluster + "/ns1";
try {
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null /* serviceUrlTls */,
brokerServiceUrl, null /* brokerServiceUrlTls */);
if (!admin.clusters().getClusters().contains(cluster)) {
admin.clusters().createCluster(cluster, clusterData);
} else {
Expand Down

0 comments on commit 3e1b8f6

Please sign in to comment.