Kaynağa Gözat

[jb] Also show jobs according to acl modify permissions

e.g.
set mapreduce.job.acl-modify-job=UserA; : kill job
Romain Rigaux 11 yıl önce
ebeveyn
işleme
dabe214526

+ 9 - 0
apps/jobbrowser/src/jobbrowser/models.py

@@ -38,6 +38,15 @@ from django.utils.translation import ugettext as _
 LOGGER = logging.getLogger(__name__)
 
 
+def can_view_job(username, job_conf):
+  acl_modify = job_conf.get('mapreduce.job.acl-view-job', '')
+  return acl_modify == '*' or username in acl_modify.split(',')
+
+def can_modify_job(username, job_conf):
+  acl_modify = job_conf.get('mapreduce.job.acl-modify-job', '')
+  return acl_modify == '*' or username in acl_modify.split(',')
+
+
 class JobLinkage(object):
   """
   A thin representation of a job, without much of the details.

+ 13 - 14
apps/jobbrowser/src/jobbrowser/templates/job.mako

@@ -526,20 +526,19 @@ $(document).ready(function () {
     var _this = $(this);
     _this.attr("data-loading-text", _this.text() + " ...");
     _this.button("loading");
-    $.post(_this.data("killurl"),
-            {
-              "format": "json"
-            },
-            function (response) {
-              _this.button("reset");
-              $("#killModal").modal("hide");
-              if (response.status != 0) {
-                $(document).trigger("error", "${ _('There was a problem killing this job.') }");
-              }
-              else {
-                callJobDetails({ url: _this.data("url")});
-              }
-            }
+    $.post(_this.data("killurl"), {
+          "format": "json"
+        },
+        function (response) {
+          _this.button("reset");
+          $("#killModal").modal("hide");
+          if (response.status != 0) {
+            $(document).trigger("error", "${ _('There was a problem killing this job.') }");
+          }
+          else {
+            callJobDetails({ url: _this.data("url")});
+          }
+        }
     );
   });
 

+ 3 - 2
apps/jobbrowser/src/jobbrowser/views.py

@@ -42,7 +42,8 @@ from hadoop.yarn.clients import get_log_client
 
 from jobbrowser import conf
 from jobbrowser.api import get_api, ApplicationNotRunning
-from jobbrowser.models import Job, JobLinkage, Tracker, Cluster
+from jobbrowser.models import Job, JobLinkage, Tracker, Cluster, can_view_job,\
+  can_modify_job
 
 import urllib2
 
@@ -139,7 +140,7 @@ def massage_job_for_json(job, request):
     'finishTimeFormatted': hasattr(job, 'finishTimeFormatted') and job.finishTimeFormatted or '',
     'durationFormatted': hasattr(job, 'durationFormatted') and job.durationFormatted or '',
     'durationMs': hasattr(job, 'durationInMillis') and job.durationInMillis or '',
-    'canKill': (job.status.lower() == 'running' or job.status.lower() == 'pending') and not job.is_mr2 and (request.user.is_superuser or request.user.username == job.user),
+    'canKill': (job.status.lower() == 'running' or job.status.lower() == 'pending') and not job.is_mr2 and (request.user.is_superuser or request.user.username == job.user or can_modify_job(request.user.username, job.full_job_conf)),
     'killUrl': job.jobId and reverse('jobbrowser.views.kill_job', kwargs={'job': job.jobId}) or ''
   }
   return job