未验证 提交 64ff3e10 编写于 作者: Y Yijie Shen 提交者: guangning

[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 3e1b8f64)
上级 f6db479d
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册