Sfoglia il codice sorgente

[jb] Make Kill job button configurable

Yixiao Lin 10 anni fa
parent
commit
e281668

+ 7 - 0
apps/jobbrowser/src/jobbrowser/conf.py

@@ -25,3 +25,10 @@ SHARE_JOBS = Config(
   type=coerce_bool,
   help=_('Share submitted jobs information with all users. If set to false, '
        'submitted jobs are visible only to the owner and administrators.'))
+
+DISABLE_KILLING_JOBS = Config(
+  key='disable_killing_jobs',
+  default=False,
+  type=coerce_bool,
+  help=_('Disable the job kill button for all users in the job browser.'))
+

+ 15 - 1
apps/jobbrowser/src/jobbrowser/models.py

@@ -36,7 +36,7 @@ import hadoop.api.jobtracker.ttypes as ttypes
 from desktop.lib.exceptions_renderable import PopupException
 
 from django.utils.translation import ugettext as _
-
+from jobbrowser.conf import DISABLE_KILLING_JOBS
 
 LOGGER = logging.getLogger(__name__)
 
@@ -55,6 +55,20 @@ def get_acls(job):
   else:
     return job.full_job_conf
 
+def can_kill_job(self, user):
+  if DISABLE_KILLING_JOBS.get():
+    return False
+
+  if self.status.lower() not in ('running', 'pending', 'accepted'):
+    return False
+
+  if user.is_superuser:
+    return True
+
+  if can_modify_job(user.username, self):
+    return True
+
+  return user.username == self.user
 
 class JobLinkage(object):
   """

+ 5 - 4
apps/jobbrowser/src/jobbrowser/views.py

@@ -43,9 +43,10 @@ from hadoop.api.jobtracker.ttypes import ThriftJobPriority, TaskTrackerNotFoundE
 from hadoop.yarn.clients import get_log_client
 import hadoop.yarn.resource_manager_api as resource_manager_api
 
-from jobbrowser import conf
+from jobbrowser.conf import SHARE_JOBS
+from jobbrowser.conf import DISABLE_KILLING_JOBS
 from jobbrowser.api import get_api, ApplicationNotRunning, JobExpired
-from jobbrowser.models import Job, JobLinkage, Tracker, Cluster, can_view_job, can_modify_job, LinkJobLogs
+from jobbrowser.models import Job, JobLinkage, Tracker, Cluster, can_view_job, can_modify_job, LinkJobLogs, can_kill_job
 from jobbrowser.yarn_models import Application
 
 import urllib2
@@ -75,7 +76,7 @@ def check_job_permission(view_func):
     except Exception, e:
       raise PopupException(_('Could not find job %s.') % jobid, detail=e)
 
-    if not conf.SHARE_JOBS.get() and not request.user.is_superuser \
+    if not SHARE_JOBS.get() and not request.user.is_superuser \
         and job.user != request.user.username and not can_view_job(request.user.username, job):
       raise PopupException(_("You don't have permission to access job %(id)s.") % {'id': jobid})
     kwargs['job'] = job
@@ -166,7 +167,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() in ('running', 'pending', 'accepted') and (request.user.is_superuser or request.user.username == job.user or can_modify_job(request.user.username, job)),
+    'canKill': can_kill_job(job, request.user),
     'killUrl': job.jobId and reverse('jobbrowser.views.kill_job', kwargs={'job': job.jobId}) or ''
   }
   return job

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

@@ -1014,6 +1014,8 @@
   # submitted jobs are visible only to the owner and administrators.
   ## share_jobs=true
 
+  # Whether to disalbe the job kill button for all users in the jobbrowser
+  ## disable_killing_jobs=false
 
 ###########################################################################
 # Settings to configure the Zookeeper application.

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

@@ -1021,6 +1021,8 @@
   # submitted jobs are visible only to the owner and administrators.
   ## share_jobs=true
 
+  # Whether to disalbe the job kill button for all users in the jobbrowser
+  ## disable_killing_jobs=false
 
 ###########################################################################
 # Settings to configure the Zookeeper application.