Skip to content

Commit

Permalink
Closes #553: Port data source version code to an extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Sep 14, 2018
1 parent b4209b1 commit 3df207c
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 117 deletions.
19 changes: 0 additions & 19 deletions client/app/pages/data-sources/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,11 @@ function DataSourceCtrl(
});
}

function getDataSourceVersion(callback) {
DataSource.version({ id: $scope.dataSource.id }, (httpResponse) => {
if (httpResponse.ok) {
const versionNumber = httpResponse.message;
toastr.success(`Success. Version: ${versionNumber}`);
} else {
toastr.error(httpResponse.message, 'Version Test Failed:', { timeOut: 10000 });
}
callback();
}, (httpResponse) => {
logger('Failed to get data source version: ', httpResponse.status, httpResponse.statusText, httpResponse);
toastr.error('Unknown error occurred while performing data source version test. Please try again later.', 'Data Source Version Test Failed:', { timeOut: 10000 });
callback();
});
}

$scope.actions = [
{ name: 'Delete', class: 'btn-danger', callback: deleteDataSource },
{
name: 'Test Connection', class: 'btn-default pull-right', callback: testConnection, disableWhenDirty: true,
},
{
name: 'Test Data Source Version', class: 'btn-default', callback: getDataSourceVersion, disableWhenDirty: true,
},
];
}

Expand Down
19 changes: 0 additions & 19 deletions client/app/pages/queries/get-data-source-version.js

This file was deleted.

2 changes: 1 addition & 1 deletion client/app/pages/queries/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h3>
</ui-select-choices>
</ui-select>
<datasource-link datasource-id="query.data_source_id"></datasource-link>
<get-data-source-version id='data-source-version'></get-data-source-version>
<datasource-version datasource-id="query.data_source_id"></datasource-version>
</div>

<div class="editor__left__schema" ng-if="sourceMode">
Expand Down
1 change: 0 additions & 1 deletion client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ function QueryViewCtrl(
}

$scope.dataSource = find($scope.dataSources, ds => ds.id === $scope.query.data_source_id);
document.getElementById('data-source-version').innerHTML = '<span class=\'fa fa-refresh\' data-toggle=\'tooltip\' data-placement=\'right\' tooltip title=\'It seems the data source was changed since the page loaded, refresh page to get version\'></span>';
getSchema();
};

Expand Down
3 changes: 0 additions & 3 deletions client/app/services/data-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ function DataSource($q, $resource, $http) {
isArray: false,
url: 'api/data_sources/:id/test',
},
version: {
method: 'GET', cache: false, isArray: false, url: 'api/data_sources/:id/version',
},
};

const DataSourceResource = $resource('api/data_sources/:id', { id: '@id' }, actions);
Expand Down
24 changes: 0 additions & 24 deletions redash/cli/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,6 @@ def test(name, organization='default'):
print("Couldn't find data source named: {}".format(name))
exit(1)

@manager.command()
@click.argument('name')
@click.option('--org', 'organization', default='default',
help="The organization the user belongs to "
"(leave blank for 'default').")
def get_data_source_version(name, organization='default'):
"""Get version of data source connection by issuing a trivial query."""
try:
org = models.Organization.get_by_slug(organization)
data_source = models.DataSource.query.filter(
models.DataSource.name == name,
models.DataSource.org == org).one()
print("Testing get connection data source version: {} (id={})".format(
name, data_source.id))
try:
info = data_source.query_runner.get_data_source_version()
except Exception as e:
print("Failure: {}".format(e))
exit(1)
else:
print(info)
except NoResultFound:
print("Couldn't find data source named: {}".format(name))
exit(1)

@manager.command()
@click.argument('name', default=None, required=False)
Expand Down
3 changes: 1 addition & 2 deletions redash/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from redash.handlers.permissions import ObjectPermissionsListResource, CheckPermissionResource
from redash.handlers.alerts import AlertResource, AlertListResource, AlertSubscriptionListResource, AlertSubscriptionResource
from redash.handlers.dashboards import DashboardListResource, DashboardResource, DashboardShareResource, PublicDashboardResource
from redash.handlers.data_sources import DataSourceTypeListResource, DataSourceListResource, DataSourceSchemaResource, DataSourceResource, DataSourcePauseResource, DataSourceTestResource, DataSourceVersionResource
from redash.handlers.data_sources import DataSourceTypeListResource, DataSourceListResource, DataSourceSchemaResource, DataSourceResource, DataSourcePauseResource, DataSourceTestResource
from redash.handlers.events import EventsResource
from redash.handlers.queries import QueryForkResource, QueryRefreshResource, QueryListResource, QueryRecentResource, QuerySearchResource, QueryResource, MyQueriesResource, QueryVersionListResource, ChangeResource
from redash.handlers.query_results import QueryResultListResource, QueryResultResource, JobResource, QueryResultSetResource
Expand Down Expand Up @@ -58,7 +58,6 @@ def json_representation(data, code, headers=None):
api.add_org_resource(DataSourceSchemaResource, '/api/data_sources/<data_source_id>/schema')
api.add_org_resource(DataSourcePauseResource, '/api/data_sources/<data_source_id>/pause')
api.add_org_resource(DataSourceTestResource, '/api/data_sources/<data_source_id>/test')
api.add_org_resource(DataSourceVersionResource, '/api/data_sources/<data_source_id>/version')
api.add_org_resource(DataSourceResource, '/api/data_sources/<data_source_id>', endpoint='data_source')

api.add_org_resource(GroupListResource, '/api/groups', endpoint='groups')
Expand Down
18 changes: 0 additions & 18 deletions redash/handlers/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,3 @@ def post(self, data_source_id):
return {"message": unicode(e), "ok": False}
else:
return {"message": "success", "ok": True}

class DataSourceVersionResource(BaseResource):
def get(self, data_source_id):
data_source = get_object_or_404(models.DataSource.get_by_id_and_org, data_source_id, self.current_org)
require_access(data_source.groups, self.current_user, view_only)
self.record_event({
'action': 'test',
'object_id': data_source_id,
'object_type': 'data_source_version',
})
try:
version_info = data_source.query_runner.get_data_source_version()
except Exception as e:
return {"message": unicode(e), "ok": False}
else:
return {"message": version_info, "ok": True}


23 changes: 0 additions & 23 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class NotSupported(Exception):

class BaseQueryRunner(object):
noop_query = None
data_source_version_query = None
configuration_properties = None

def __init__(self, configuration):
Expand Down Expand Up @@ -86,28 +85,6 @@ def add_configuration_property(cls, property, value):
raise NotImplementedError()
cls.configuration_properties[property] = value

def get_data_source_version(self):
if self.data_source_version_query is None:
raise NotImplementedError
data, error = self.run_query(self.data_source_version_query, None)

if error is not None:
raise Exception(error)

try:
version = json.loads(data)['rows'][0]['version']
except KeyError as e:
raise Exception(e)

if self.data_source_version_post_process == "split by space take second":
version = version.split(" ")[1]
elif self.data_source_version_post_process == "split by space take last":
version = version.split(" ")[-1]
elif self.data_source_version_post_process == "none":
version = version

return version

def test_connection(self):
if self.noop_query is None:
raise NotImplementedError()
Expand Down
2 changes: 0 additions & 2 deletions redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class Mysql(BaseSQLQueryRunner):
"info": "This string will be used to toggle visibility of tables in the schema browser when editing a query in order to remove non-useful tables from sight."
}
}
data_source_version_query = "select version()"
data_source_version_post_process = "none"

@classmethod
def configuration_schema(cls):
Expand Down
4 changes: 0 additions & 4 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def _wait(conn, timeout=None):

class PostgreSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"
data_source_version_query = "select version()"
data_source_version_post_process = "split by space take second"
configuration_properties = {
"user": {
"type": "string"
Expand Down Expand Up @@ -222,8 +220,6 @@ class Redshift(PostgreSQL):
"default": "prefer"
}
}
data_source_version_query = "select version()"
data_source_version_post_process = "split by space take last"

@classmethod
def type(cls):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ disposable-email-domains
# Uncomment the requirement for ldap3 if using ldap.
# It is not included by default because of the GPL license conflict.
# ldap3==2.2.4
redash-stmo>=2018.9.0
redash-stmo>=2018.9.1

0 comments on commit 3df207c

Please sign in to comment.