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

guangning pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-manager.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d9c057  fix pulsar with multiple admin httpserver (#423)
6d9c057 is described below

commit 6d9c0574cbce51f32282c794c9d0e81e502f4ec8
Author: asagjj <[email protected]>
AuthorDate: Thu Nov 25 11:55:17 2021 +0800

    fix pulsar with multiple admin httpserver (#423)
---
 .../service/impl/EnvironmentCacheServiceImpl.java      | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/pulsar/manager/service/impl/EnvironmentCacheServiceImpl.java
 
b/src/main/java/org/apache/pulsar/manager/service/impl/EnvironmentCacheServiceImpl.java
index 490282c..cce6ba0 100644
--- 
a/src/main/java/org/apache/pulsar/manager/service/impl/EnvironmentCacheServiceImpl.java
+++ 
b/src/main/java/org/apache/pulsar/manager/service/impl/EnvironmentCacheServiceImpl.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ThreadLocalRandom;
 import javax.servlet.http.HttpServletRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -87,10 +88,25 @@ public class EnvironmentCacheServiceImpl implements 
EnvironmentCacheService {
             EnvironmentEntity environmentEntity = 
environmentEntityOptional.get();
             return environmentEntity.getBroker();
         } else {
-            return getServiceUrl(environment, cluster, 0);
+            String webServiceUrl = getServiceUrl(environment, cluster, 0);
+            return pickOneServiceUrl(webServiceUrl);
         }
     }
 
+    private String pickOneServiceUrl(String webServiceUrl) {
+        if (webServiceUrl.contains(",")) {
+            String[] webServiceUrlList = webServiceUrl.split(",");
+            int index = ThreadLocalRandom.current().nextInt(0, 
webServiceUrlList.length);
+            String url = webServiceUrlList[index];
+            if (!url.contains("http://";)) {
+                url = "http://"; + url;
+            }
+            log.info("pick web url:{}", url);
+            return url;
+        }
+        return webServiceUrl;
+    }
+
     private String getServiceUrl(String environment, String cluster, int 
numReloads) {
         // if there is a cluster specified, lookup the cluster.
         Map<String, ClusterData> clusters = environments.get(environment);

Reply via email to