This is an automated email from the ASF dual-hosted git repository.

zixuan pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/branch-2.10 by this push:
     new 54966c92a46 [fix][broker] Fix geo-replication admin client url (#22584)
54966c92a46 is described below

commit 54966c92a465316798c52830f19cac3d1d647fc5
Author: Kai Wang <kw...@apache.org>
AuthorDate: Thu May 9 13:53:02 2024 +0800

    [fix][broker] Fix geo-replication admin client url (#22584)
    
    (cherry picked from commit bd4c57d27c4acd37206a4f5ffdad3705cdc96c8c)
---
 .../org/apache/pulsar/broker/service/BrokerService.java    |  8 +++-----
 .../apache/pulsar/broker/service/ReplicatorTestBase.java   | 14 ++++++++++++--
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
index 11840f3c89a..96e1ca358ff 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
@@ -1377,13 +1377,11 @@ public class BrokerService implements Closeable {
                 }
 
                 boolean isTlsEnabled = data.isBrokerClientTlsEnabled() || 
conf.isBrokerClientTlsEnabled();
-                if (isTlsEnabled && 
StringUtils.isEmpty(data.getServiceUrlTls())) {
-                    throw new IllegalArgumentException("serviceUrlTls is 
empty, brokerClientTlsEnabled: "
+                final String adminApiUrl = isTlsEnabled ? 
data.getServiceUrlTls() : data.getServiceUrl();
+                if (StringUtils.isEmpty(adminApiUrl)) {
+                    throw new IllegalArgumentException("The adminApiUrl is 
empty, brokerClientTlsEnabled: "
                             + isTlsEnabled);
-                } else if (StringUtils.isEmpty(data.getServiceUrl())) {
-                    throw new IllegalArgumentException("serviceUrl is empty, 
brokerClientTlsEnabled: " + isTlsEnabled);
                 }
-                String adminApiUrl = isTlsEnabled ? data.getServiceUrlTls() : 
data.getServiceUrl();
                 builder.serviceHttpUrl(adminApiUrl);
                 if (data.isBrokerClientTlsEnabled()) {
                     configAdminTlsSettings(builder,
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
index 824af6b71e3..86be2cd5698 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTestBase.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.broker.service;
 import com.google.common.io.Resources;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
 
 import com.google.common.collect.Sets;
 
@@ -243,9 +244,7 @@ public abstract class ReplicatorTestBase extends 
TestRetrySupport {
                 .brokerClientTlsTrustStoreType(keyStoreType)
                 .build());
         admin4.clusters().createCluster(cluster4, ClusterData.builder()
-                .serviceUrl(url4.toString())
                 .serviceUrlTls(urlTls4.toString())
-                .brokerServiceUrl(pulsar4.getBrokerServiceUrl())
                 .brokerServiceUrlTls(pulsar4.getBrokerServiceUrlTls())
                 .brokerClientTlsEnabled(true)
                 .brokerClientTrustCertsFilePath(caCertFilePath)
@@ -263,9 +262,20 @@ public abstract class ReplicatorTestBase extends 
TestRetrySupport {
         assertEquals(admin2.clusters().getCluster(cluster1).getServiceUrl(), 
url1.toString());
         assertEquals(admin2.clusters().getCluster(cluster2).getServiceUrl(), 
url2.toString());
         assertEquals(admin2.clusters().getCluster(cluster3).getServiceUrl(), 
url3.toString());
+        assertNull(admin2.clusters().getCluster(cluster4).getServiceUrl());
         
assertEquals(admin2.clusters().getCluster(cluster1).getBrokerServiceUrl(), 
pulsar1.getBrokerServiceUrl());
         
assertEquals(admin2.clusters().getCluster(cluster2).getBrokerServiceUrl(), 
pulsar2.getBrokerServiceUrl());
         
assertEquals(admin2.clusters().getCluster(cluster3).getBrokerServiceUrl(), 
pulsar3.getBrokerServiceUrl());
+        
assertNull(admin2.clusters().getCluster(cluster4).getBrokerServiceUrl());
+
+        
assertEquals(admin2.clusters().getCluster(cluster1).getServiceUrlTls(), 
urlTls1.toString());
+        
assertEquals(admin2.clusters().getCluster(cluster2).getServiceUrlTls(), 
urlTls2.toString());
+        
assertEquals(admin2.clusters().getCluster(cluster3).getServiceUrlTls(), 
urlTls3.toString());
+        
assertEquals(admin2.clusters().getCluster(cluster4).getServiceUrlTls(), 
urlTls4.toString());
+        
assertEquals(admin2.clusters().getCluster(cluster1).getBrokerServiceUrlTls(), 
pulsar1.getBrokerServiceUrlTls());
+        
assertEquals(admin2.clusters().getCluster(cluster2).getBrokerServiceUrlTls(), 
pulsar2.getBrokerServiceUrlTls());
+        
assertEquals(admin2.clusters().getCluster(cluster3).getBrokerServiceUrlTls(), 
pulsar3.getBrokerServiceUrlTls());
+        
assertEquals(admin2.clusters().getCluster(cluster4).getBrokerServiceUrlTls(), 
pulsar4.getBrokerServiceUrlTls());
 
         // Also create V1 namespace for compatibility check
         admin1.clusters().createCluster("global", ClusterData.builder()

Reply via email to