Explorar o código

HUE-9478 [api] Job browser proxy

sreenaths %!s(int64=5) %!d(string=hai) anos
pai
achega
181021b8c5

+ 15 - 3
apps/jobbrowser/src/jobbrowser/api2.py

@@ -19,15 +19,16 @@ import json
 import logging
 
 from django.http import HttpResponse
+from django.utils.translation import ugettext as _
 
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.django_util import JsonResponse
-from django.utils.translation import ugettext as _
+from desktop.lib.rest.http_client import HttpClient
+from desktop.lib.rest.resource import Resource
 from desktop.views import serve_403_error
 
 from jobbrowser.apis.base_api import get_api
-from jobbrowser.conf import DISABLE_KILLING_JOBS
-
+from jobbrowser.conf import DISABLE_KILLING_JOBS, QUERY_STORE
 
 LOG = logging.getLogger(__name__)
 
@@ -161,3 +162,14 @@ def profile(request):
     response[app_property] = resp
     response['status'] = 0
     return JsonResponse(response)
+
+
+@api_error_handler
+def query_store_proxy(request, path=None):
+  content_type = 'application/json; charset=UTF-8'
+  headers = {'X-Requested-By': 'das', 'Content-Type': content_type}
+
+  client = HttpClient(QUERY_STORE.SERVER_URL.get())
+  resource = Resource(client)
+
+  return JsonResponse(resource.invoke(request.method, path, request.GET.dict(), request.body, headers));

+ 1 - 1
apps/jobbrowser/src/jobbrowser/conf.py

@@ -96,4 +96,4 @@ QUERY_STORE = ConfigSection(
       help=_("URL of Query Store API server.")
     )
   )
-)
+)

+ 15 - 4
apps/jobbrowser/src/jobbrowser/urls.py

@@ -20,6 +20,8 @@ from django.conf.urls import url
 from jobbrowser import views as jobbrowser_views
 from jobbrowser import api2 as jobbrowser_api2
 
+from jobbrowser.conf import QUERY_STORE
+
 urlpatterns = [
   # "Default"
   url(r'^$', jobbrowser_views.jobs),
@@ -30,16 +32,20 @@ urlpatterns = [
   url(r'^jobs/(?P<job>\w+)/single_logs$', jobbrowser_views.job_single_logs, name='jobbrowser.views.job_single_logs'),
   url(r'^jobs/(?P<job>\w+)/tasks$', jobbrowser_views.tasks, name='jobbrowser.views.tasks'),
   url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)$', jobbrowser_views.single_task, name='jobbrowser.views.single_task'), # TODO s/single// ?
-  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)$', jobbrowser_views.single_task_attempt, name='single_task_attempt'),
-  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)/counters$', jobbrowser_views.task_attempt_counters, name='task_attempt_counters'),
-  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)/logs$', jobbrowser_views.single_task_attempt_logs, name='single_task_attempt_logs'),
+  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)$',
+  jobbrowser_views.single_task_attempt, name='single_task_attempt'),
+  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)/counters$',
+  jobbrowser_views.task_attempt_counters, name='task_attempt_counters'),
+  url(r'^jobs/(?P<job>\w+)/tasks/(?P<taskid>\w+)/attempts/(?P<attemptid>\w+)/logs$',
+  jobbrowser_views.single_task_attempt_logs, name='single_task_attempt_logs'),
   url(r'^jobs/(\w+)/tasks/(\w+)/attempts/(?P<attemptid>\w+)/kill$', jobbrowser_views.kill_task_attempt, name='kill_task_attempt'),
   url(r'^trackers/(?P<trackerid>.+)$', jobbrowser_views.single_tracker, name='single_tracker'),
   url(r'^container/(?P<node_manager_http_address>.+)/(?P<containerid>.+)$', jobbrowser_views.container, name='jobbrowser.views.container'),
 
   # MR2 specific
   url(r'^jobs/(?P<job>\w+)/job_attempt_logs/(?P<attempt_index>\d+)$', jobbrowser_views.job_attempt_logs, name='job_attempt_logs'),
-  url(r'^jobs/(?P<job>\w+)/job_attempt_logs_json/(?P<attempt_index>\d+)(?:/(?P<name>\w+))?(?:/(?P<offset>[\d-]+))?/?$', jobbrowser_views.job_attempt_logs_json, name='job_attempt_logs_json'),
+  url(r'^jobs/(?P<job>\w+)/job_attempt_logs_json/(?P<attempt_index>\d+)(?:/(?P<name>\w+))?(?:/(?P<offset>[\d-]+))?/?$',
+  jobbrowser_views.job_attempt_logs_json, name='job_attempt_logs_json'),
   url(r'^jobs/(?P<jobid>\w+)/job_not_assigned/(?P<path>.+)$', jobbrowser_views.job_not_assigned, name='job_not_assigned'),
 
   # Unused
@@ -63,3 +69,8 @@ urlpatterns += [
   url(r'api/job/action(?:/(?P<interface>.+))?(?:/(?P<action>.+))?/?', jobbrowser_api2.action, name='action'),
   url(r'api/job(?:/(?P<interface>.+))?/?', jobbrowser_api2.job, name='job'),
 ]
+
+if QUERY_STORE.SERVER_URL.get():
+  urlpatterns += [
+    url(r'^query-proxy/(?P<path>.*)$', jobbrowser_api2.query_store_proxy),
+  ]

+ 2 - 2
desktop/conf.dist/hue.ini

@@ -1656,8 +1656,8 @@
   ## enable_queries_list=false
 
   [[query_store]]
-# URL of Query Store API server.
-##server_url=http://localhost:8080/
+    # URL of Query Store API server.
+    ##server_url=http://localhost:8080/
 
 ###########################################################################
 # Settings to configure Sentry / Security App.

+ 2 - 2
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1642,8 +1642,8 @@
   ## enable_queries_list=false
 
   [[query_store]]
-# URL of Query Store API server.
-##server_url=http://localhost:8080/
+    # URL of Query Store API server.
+    ##server_url=http://localhost:8080/
 
 ###########################################################################
 # Settings to configure Sentry / Security App.