This is an automated email from the ASF dual-hosted git repository. zhaijia pushed a commit to branch branch-2.5 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 0e9d448341e83e0daab8f853ae91c9e6d1c6f5c7 Author: Yijie Shen <[email protected]> AuthorDate: Tue Mar 3 03:22:14 2020 +0800 [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. (cherry picked from commit 3e1b8f644446e4f63969be621798f14628e53065) --- .../java/org/apache/pulsar/PulsarStandalone.java | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java index 7c82cbe..7c76257 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandalone.java @@ -319,16 +319,28 @@ public class PulsarStandalone implements AutoCloseable { 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 ---"); @@ -352,14 +364,12 @@ public class PulsarStandalone implements AutoCloseable { } } - 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 {
