You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/02/28 18:12:19 UTC
[GitHub] mistercrunch closed pull request #4480: Add https support for Druid
mistercrunch closed pull request #4480: Add https support for Druid
URL: https://github.com/apache/incubator-superset/pull/4480
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/run_specific_test.sh b/run_specific_test.sh
index 47e8307440..f267e08226 100755
--- a/run_specific_test.sh
+++ b/run_specific_test.sh
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
echo $DB
rm -f .coverage
+export PYTHONPATH=./
export SUPERSET_CONFIG=tests.superset_test_config
set -e
superset/bin/superset version -v
diff --git a/run_tests.sh b/run_tests.sh
index 448a750fdf..de40d6c75c 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -4,6 +4,7 @@ rm ~/.superset/unittests.db
rm ~/.superset/celerydb.sqlite
rm ~/.superset/celery_results.sqlite
rm -f .coverage
+export PYTHONPATH=./
export SUPERSET_CONFIG=tests.superset_test_config
set -e
superset/bin/superset db upgrade
diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py
index 339dd6986b..a16baf1039 100644
--- a/superset/connectors/druid/models.py
+++ b/superset/connectors/druid/models.py
@@ -11,6 +11,7 @@
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 @@ def data(self):
'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 d2a44f968d..fc360b6656 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 @@ def test_client(self, PyDruid):
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 @@ def test_sync_druid_perm(self, PyDruid):
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()
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services