superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Add https support for Druid (#4480)
Date Wed, 28 Feb 2018 18:12:20 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 849a2ce  Add https support for Druid (#4480)
849a2ce is described below

commit 849a2cecee2737a8392049e29daecb4154249f6a
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Feb 28 10:12:17 2018 -0800

    Add https support for Druid (#4480)
    
    * Add https support for Druid
    
    * addressing comment
---
 superset/connectors/druid/models.py | 24 +++++++++++++++---------
 tests/druid_tests.py                | 33 ++++++++++++++++++++++++++-------
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py
index 339dd69..a16baf1 100644
--- a/superset/connectors/druid/models.py
+++ b/superset/connectors/druid/models.py
@@ -11,6 +11,7 @@ from datetime import datetime, timedelta
 import json
 import logging
 from multiprocessing.pool import ThreadPool
+import re
 
 from dateutil.parser import parse as dparse
 from flask import escape, Markup
@@ -107,24 +108,29 @@ class DruidCluster(Model, AuditMixinNullable, ImportMixin):
             'backend': 'druid',
         }
 
+    @staticmethod
+    def get_base_url(host, port):
+        if not re.match('http(s)?://', host):
+            host = 'http://' + host
+        return '{0}:{1}'.format(host, port)
+
+    def get_base_coordinator_url(self):
+        base_url = self.get_base_url(
+            self.coordinator_host, self.coordinator_port)
+        return '{base_url}/{self.coordinator_endpoint}'.format(**locals())
+
     def get_pydruid_client(self):
         cli = PyDruid(
-            'http://{0}:{1}/'.format(self.broker_host, self.broker_port),
+            self.get_base_url(self.broker_host, self.broker_port),
             self.broker_endpoint)
         return cli
 
     def get_datasources(self):
-        endpoint = (
-            'http://{obj.coordinator_host}:{obj.coordinator_port}/'
-            '{obj.coordinator_endpoint}/datasources'
-        ).format(obj=self)
-
+        endpoint = self.get_base_coordinator_url() + '/datasources'
         return json.loads(requests.get(endpoint).text)
 
     def get_druid_version(self):
-        endpoint = (
-            'http://{obj.coordinator_host}:{obj.coordinator_port}/status'
-        ).format(obj=self)
+        endpoint = self.get_base_coordinator_url() + '/status'
         return json.loads(requests.get(endpoint).text)['version']
 
     def refresh_datasources(
diff --git a/tests/druid_tests.py b/tests/druid_tests.py
index d2a44f9..fc360b6 100644
--- a/tests/druid_tests.py
+++ b/tests/druid_tests.py
@@ -77,6 +77,16 @@ class DruidTests(SupersetTestCase):
     def __init__(self, *args, **kwargs):
         super(DruidTests, self).__init__(*args, **kwargs)
 
+    def get_test_cluster_obj(self):
+        return DruidCluster(
+            cluster_name='test_cluster',
+            coordinator_host='localhost',
+            coordinator_endpoint='druid/coordinator/v1/metadata',
+            coordinator_port=7979,
+            broker_host='localhost',
+            broker_port=7980,
+            metadata_last_refreshed=datetime.now())
+
     @patch('superset.connectors.druid.models.PyDruid')
     def test_client(self, PyDruid):
         self.login(username='admin')
@@ -95,13 +105,7 @@ class DruidTests(SupersetTestCase):
             db.session.delete(cluster)
         db.session.commit()
 
-        cluster = DruidCluster(
-            cluster_name='test_cluster',
-            coordinator_host='localhost',
-            coordinator_port=7979,
-            broker_host='localhost',
-            broker_port=7980,
-            metadata_last_refreshed=datetime.now())
+        cluster = self.get_test_cluster_obj()
 
         db.session.add(cluster)
         cluster.get_datasources = PickableMock(return_value=['test_datasource'])
@@ -323,6 +327,21 @@ class DruidTests(SupersetTestCase):
             permission=permission, view_menu=view_menu).first()
         assert pv is not None
 
+    def test_urls(self):
+        cluster = self.get_test_cluster_obj()
+        self.assertEquals(
+            cluster.get_base_url('localhost', '9999'), 'http://localhost:9999')
+        self.assertEquals(
+            cluster.get_base_url('http://localhost', '9999'),
+            'http://localhost:9999')
+        self.assertEquals(
+            cluster.get_base_url('https://localhost', '9999'),
+            'https://localhost:9999')
+
+        self.assertEquals(
+            cluster.get_base_coordinator_url(),
+            'http://localhost:7979/druid/coordinator/v1/metadata')
+
 
 if __name__ == '__main__':
     unittest.main()

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message