Skip to content

Commit

Permalink
HUE-5415 [metadata] API Skeleton to poll for upload status
Browse files Browse the repository at this point in the history
  • Loading branch information
romainr committed Dec 5, 2016
1 parent 4facc9b commit 7b68581
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
17 changes: 16 additions & 1 deletion desktop/libs/metadata/src/metadata/optimizer_api.py
Expand Up @@ -284,7 +284,7 @@ def upload_history(request):

queries = [
(doc.uuid, 1000, Notebook(document=doc).get_data()['snippets'][0]['statement'])
for doc in Document2.objects.get_history(doc_type='query-%s' % query_type, user=request.user)[:25]
for doc in Document2.objects.get_history(doc_type='query-%s' % query_type, user=request.user)[:10]
]

api = OptimizerApi()
Expand All @@ -295,6 +295,21 @@ def upload_history(request):
return JsonResponse(response)


@require_POST
@error_handler
def upload_status(request):
response = {'status': -1}

workload_id = request.POST.get('workloadId')

api = OptimizerApi()

response['upload_status'] = api.upload_status(workload_id=workload_id)
response['status'] = 0

return JsonResponse(response)


def _get_table_name(path):
if '.' in path:
database, table = path.split('.', 1)
Expand Down
10 changes: 9 additions & 1 deletion desktop/libs/metadata/src/metadata/optimizer_client.py
Expand Up @@ -97,7 +97,8 @@ def _exec(self, command, args):

if data:
response = json.loads(data)
response['status'] = 'success'
if 'status' not in response:
response['status'] = 'success'
return response


Expand Down Expand Up @@ -174,6 +175,13 @@ def upload(self, queries, source_platform='generic', workload_id=None):
raise PopupException(e, title=_('Error while accessing Optimizer'))


def upload_status(self, workload_id):
return self._exec('upload-status', [
'--tenant', self._product_name,
'--workload-id', workload_id
])


def top_tables(self, workfloadId=None, database_name='default'):
return self._exec('get-top-tables', [
'--tenant', self._product_name,
Expand Down
14 changes: 12 additions & 2 deletions desktop/libs/metadata/src/metadata/optimizer_client_tests.py
Expand Up @@ -110,7 +110,17 @@ def test_upload(self):
]

resp = self.api.upload(queries=queries)
assert_equal('success', resp['status'], resp)

assert_equal('status' in resp, resp)
assert_equal('state' in resp['status'], resp)
assert_equal('workloadId' in resp['status'], resp)

assert_true(resp['status']['state'] in ('WAITING', 'FINISHED', 'FAILED'), resp['status']['state'])

resp = self.api.upload_status(workfload_id=resp['status']['workloadId'])
assert_equal('status' in resp, resp)
assert_equal('state' in resp['status'], resp)
assert_equal('workloadId' in resp['status'], resp)


def test_top_tables(self):
Expand Down Expand Up @@ -223,7 +233,7 @@ def test_top_columns(self):
assert_true('tables' in resp['results'][0], resp)


def test_top_databases(self):
def test_top_databases(self):
resp = self.api.top_databases()

assert_equal('success', resp['status'], resp)
Expand Down
1 change: 1 addition & 0 deletions desktop/libs/metadata/src/metadata/urls.py
Expand Up @@ -37,6 +37,7 @@
# Optimizer API
urlpatterns += patterns('metadata.optimizer_api',
url(r'^api/optimizer/upload_history/?$', 'upload_history', name='upload_history'),
url(r'^api/optimizer/upload_status/?$', 'upload_status', name='upload_status'),

#v2
url(r'^api/optimizer/get_tenant/?$', 'get_tenant', name='get_tenant'),
Expand Down
Expand Up @@ -1389,6 +1389,20 @@ var EditorViewModel = (function() {
});
};

self._getUploadStatus = function (workloadId) {
logGA('get_upload_status');

$.post("/metadata/api/optimizer/upload_status", {
workloadId: workloadId,
}, function(data) {
if (data.status == 0) {
$(document).trigger("info", data.upload_status.status.state);
} else {
$(document).trigger("error", data.message);
}
});
};

self.getSimilarQueries = function () {
logGA('get_query_similarity');

Expand Down

0 comments on commit 7b68581

Please sign in to comment.