You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zh...@apache.org on 2019/05/26 08:23:41 UTC

[pulsar] branch master updated: fix cluster_url which may be set as a list (#4349)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ddb100a  fix cluster_url which may be set as a list (#4349)
ddb100a is described below

commit ddb100a6e0dc81f5c5db6624c855d93851e51b5a
Author: se7enkings <se...@users.noreply.github.com>
AuthorDate: Sun May 26 16:23:35 2019 +0800

    fix cluster_url which may be set as a list (#4349)
    
    If the service_url is set to http://{server-1}:8080,{server-2}:8080,{server-3}:8080 when initialize-cluster-metadata, the cluster_url will be "{server-1}:8080,{server-2}:8080,{server-3}:8080".
    And the string "{server-1}:8080,{server-2}:8080,{server-3}:8080" isn't a standard url.
    
    * fix culster_url which may be set as a list
    
    * use random to select service_url
---
 dashboard/django/collector.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/dashboard/django/collector.py b/dashboard/django/collector.py
index 40061ba..3ce0064 100755
--- a/dashboard/django/collector.py
+++ b/dashboard/django/collector.py
@@ -32,6 +32,7 @@ from django.utils.dateparse import parse_datetime
 from django.db import connection
 import time
 import argparse
+import random
 
 current_milli_time = lambda: int(round(time.time() * 1000))
 logger = logging.getLogger(__name__)
@@ -355,6 +356,15 @@ def fetch_stats():
         if cluster_name == 'global': continue
 
         cluster_url = get(args.serviceUrl, '/admin/v2/clusters/' + cluster_name)['serviceUrl']
+        if cluster_url.find(',')>=0:
+            cluster_url_list = cluster_url.split(',')
+            index = random.randint(0,len(cluster_url_list)-1)
+            if index==0:
+                cluster_url = cluster_url_list[index]
+            else:
+                protocol = ("https://" if(cluster_url.find("https")>=0) else "http://")
+                cluster_url = protocol+cluster_url_list[index]
+
         logger.info('Cluster:{} -> {}'.format(cluster_name, cluster_url))
         cluster, created = Cluster.objects.get_or_create(name=cluster_name)
         if cluster_url != cluster.serviceUrl: