瀏覽代碼

HUE-1176 [jb] Offer to filter YARN job tasks by name

Romain Rigaux 8 年之前
父節點
當前提交
98a4086

+ 2 - 1
apps/jobbrowser/src/jobbrowser/api2.py

@@ -111,11 +111,12 @@ def profile(request):
   app_id = json.loads(request.POST.get('app_id'))
   app_id = json.loads(request.POST.get('app_id'))
   app_type = json.loads(request.POST.get('app_type'))
   app_type = json.loads(request.POST.get('app_type'))
   app_property = json.loads(request.POST.get('app_property'))
   app_property = json.loads(request.POST.get('app_property'))
+  app_filters = dict([(key, value) for _filter in json.loads(request.POST.get('app_filters', '[]')) for key, value in _filter.items() if value])
 
 
   api = get_api(request.user, interface)
   api = get_api(request.user, interface)
   api._set_request(request) # For YARN
   api._set_request(request) # For YARN
 
 
-  response[app_property] = api.profile(app_id, app_type, app_property)
+  response[app_property] = api.profile(app_id, app_type, app_property, app_filters)
   response['status'] = 0
   response['status'] = 0
 
 
   return JsonResponse(response)
   return JsonResponse(response)

+ 1 - 1
apps/jobbrowser/src/jobbrowser/apis/base_api.py

@@ -58,7 +58,7 @@ class Api(object):
 
 
   def logs(self, appid, app_type, log_name): return {'progress': 0, 'logs': ''}
   def logs(self, appid, app_type, log_name): return {'progress': 0, 'logs': ''}
 
 
-  def profile(self, appid, app_type, app_property): return {} # Tasks, XML, counters...
+  def profile(self, appid, app_type, app_property, app_filters): return {} # Tasks, XML, counters...
 
 
   def _set_request(self, request):
   def _set_request(self, request):
     self.request = request
     self.request = request

+ 1 - 1
apps/jobbrowser/src/jobbrowser/apis/bundle_api.py

@@ -86,7 +86,7 @@ class BundleApi(Api):
     return {'logs': json.loads(data.content)['log']}
     return {'logs': json.loads(data.content)['log']}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if app_property == 'xml':
     if app_property == 'xml':
       oozie_api = get_oozie(self.user)
       oozie_api = get_oozie(self.user)
       workflow = oozie_api.get_bundle(jobid=appid)
       workflow = oozie_api.get_bundle(jobid=appid)

+ 12 - 7
apps/jobbrowser/src/jobbrowser/apis/job_api.py

@@ -60,8 +60,8 @@ class JobApi(Api):
   def logs(self, appid, app_type, log_name):
   def logs(self, appid, app_type, log_name):
     return self._get_api(appid).logs(appid, app_type, log_name)
     return self._get_api(appid).logs(appid, app_type, log_name)
 
 
-  def profile(self, appid, app_type, app_property):
-    return self._get_api(appid).profile(appid, app_type, app_property)
+  def profile(self, appid, app_type, app_property, app_filters):
+    return self._get_api(appid).profile(appid, app_type, app_property, app_filters)
 
 
   def _get_api(self, appid):
   def _get_api(self, appid):
     if type(appid) == list:
     if type(appid) == list:
@@ -194,11 +194,11 @@ class YarnApi(Api):
     return {'logs': logs}
     return {'logs': logs}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if app_type == 'MAPREDUCE':
     if app_type == 'MAPREDUCE':
       if app_property == 'tasks':
       if app_property == 'tasks':
         return {
         return {
-          'task_list': YarnMapReduceTaskApi(self.user, appid).apps()['apps'],
+          'task_list': YarnMapReduceTaskApi(self.user, appid).apps(app_filters)['apps'],
           'filter_text': ''
           'filter_text': ''
         }
         }
       elif app_property == 'metadata':
       elif app_property == 'metadata':
@@ -224,7 +224,7 @@ class YarnMapReduceTaskApi(Api):
     self.app_id = '_'.join(app_id.replace('task_', 'application_').split('_')[:3])
     self.app_id = '_'.join(app_id.replace('task_', 'application_').split('_')[:3])
 
 
 
 
-  def apps(self):
+  def apps(self, filters):
     filter_params = {
     filter_params = {
       'task_types': None,
       'task_types': None,
       'task_states': None,
       'task_states': None,
@@ -233,6 +233,11 @@ class YarnMapReduceTaskApi(Api):
       'pagenum': 1
       'pagenum': 1
     }
     }
 
 
+    filters = _extract_query_params(filters)
+
+    if filters.get('text'):
+      filter_params['task_text'] = filters['text']
+
 #     filter_params.update(_extract_query_params(filters)
 #     filter_params.update(_extract_query_params(filters)
 #
 #
 #     #filter_params['text']
 #     #filter_params['text']
@@ -290,7 +295,7 @@ class YarnMapReduceTaskApi(Api):
     return {'progress': 0, 'logs': logs}
     return {'progress': 0, 'logs': logs}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if app_property == 'attempts':
     if app_property == 'attempts':
       return {
       return {
           'task_list': YarnMapReduceTaskAttemptApi(self.user, appid).apps()['apps'],
           'task_list': YarnMapReduceTaskAttemptApi(self.user, appid).apps()['apps'],
@@ -350,7 +355,7 @@ class YarnMapReduceTaskAttemptApi(Api):
     return {'progress': 0, 'logs': syslog if log_name == 'syslog' else stderr if log_name == 'stderr' else stdout}
     return {'progress': 0, 'logs': syslog if log_name == 'syslog' else stderr if log_name == 'stderr' else stdout}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if app_property == 'counters':
     if app_property == 'counters':
       return NativeYarnApi(self.user).get_task(jobid=self.app_id, task_id=self.task_id).get_attempt(self.attempt_id).counters
       return NativeYarnApi(self.user).get_task(jobid=self.app_id, task_id=self.task_id).get_attempt(self.attempt_id).counters
 
 

+ 1 - 1
apps/jobbrowser/src/jobbrowser/apis/schedule_api.py

@@ -90,7 +90,7 @@ class ScheduleApi(Api):
     return {'logs': json.loads(data.content)['log']}
     return {'logs': json.loads(data.content)['log']}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if app_property == 'xml':
     if app_property == 'xml':
       oozie_api = get_oozie(self.user)
       oozie_api = get_oozie(self.user)
       workflow = oozie_api.get_coordinator(jobid=appid)
       workflow = oozie_api.get_coordinator(jobid=appid)

+ 1 - 1
apps/jobbrowser/src/jobbrowser/apis/workflow_api.py

@@ -133,7 +133,7 @@ class WorkflowApi(Api):
     return {'logs': json.loads(data.content)['log']}
     return {'logs': json.loads(data.content)['log']}
 
 
 
 
-  def profile(self, appid, app_type, app_property):
+  def profile(self, appid, app_type, app_property, app_filters):
     if '@' in appid:
     if '@' in appid:
       return WorkflowActionApi(self.self.user).profile(appid, app_type, app_property)
       return WorkflowActionApi(self.self.user).profile(appid, app_type, app_property)
 
 

+ 14 - 2
apps/jobbrowser/src/jobbrowser/templates/job_browser.mako

@@ -418,7 +418,8 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
     </div>
     </div>
 
 
     <div class="tab-pane" id="job-mapreduce-page-tasks">
     <div class="tab-pane" id="job-mapreduce-page-tasks">
-      ${_('Filter')} <input type="text" class="input-xlarge search-query" placeholder="${_('Filter by id, name, user...')}">
+      ${_('Filter')}
+      <input data-bind="value: textFilter" type="text" class="input-xlarge search-query" placeholder="${_('Filter by id, name, user...')}">
       <span class="btn-group">
       <span class="btn-group">
         <class="btn-group">
         <class="btn-group">
           <a class="btn btn-status btn-success" data-value="completed">${ _('MAP') }</a>
           <a class="btn btn-status btn-success" data-value="completed">${ _('MAP') }</a>
@@ -1000,6 +1001,16 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
       self.properties = ko.mapping.fromJS(job.properties || {});
       self.properties = ko.mapping.fromJS(job.properties || {});
       self.mainType = ko.observable(vm.interface());
       self.mainType = ko.observable(vm.interface());
 
 
+      self.textFilter = ko.observable('').extend({ rateLimit: { method: "notifyWhenChangesStop", timeout: 1000 } });
+      self.filters = ko.computed(function() {
+        return [
+          {'text': self.textFilter()},
+        ];
+      });
+      self.filters.subscribe(function(value) {
+        self.fetchProfile('tasks');
+      });
+
       self.hasKill = ko.pureComputed(function() {
       self.hasKill = ko.pureComputed(function() {
         return ['MAPREDUCE', 'SPARK', 'workflow', 'schedule', 'bundle'].indexOf(self.type()) != -1;
         return ['MAPREDUCE', 'SPARK', 'workflow', 'schedule', 'bundle'].indexOf(self.type()) != -1;
       });
       });
@@ -1144,7 +1155,8 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
           app_id: ko.mapping.toJSON(self.id),
           app_id: ko.mapping.toJSON(self.id),
           interface: ko.mapping.toJSON(vm.interface),
           interface: ko.mapping.toJSON(vm.interface),
           app_type: ko.mapping.toJSON(self.type),
           app_type: ko.mapping.toJSON(self.type),
-          app_property: ko.mapping.toJSON(name)
+          app_property: ko.mapping.toJSON(name),
+          app_filters: ko.mapping.toJSON(self.filters),
         }, function (data) {
         }, function (data) {
           if (data.status == 0) {
           if (data.status == 0) {
             self.properties[name](data[name]);
             self.properties[name](data[name]);