Beispiel #1
0
def kill_job(request, job):
    if request.method != "POST":
        raise Exception(
            _("kill_job may only be invoked with a POST (got a %(method)s).") %
            dict(method=request.method))

    if job.user != request.user.username and not request.user.is_superuser:
        access_warn(request, _('Insufficient permission'))
        raise MessageException(
            _("Permission denied.  User %(username)s cannot delete user %(user)s's job."
              ) % dict(username=request.user.username, user=job.user))

    job.kill()
    cur_time = time.time()
    while time.time() - cur_time < 15:
        job = Job.from_id(jt=request.jt, jobid=job.jobId)

        if job.status not in ["RUNNING", "QUEUED"]:
            if request.REQUEST.get("next"):
                return HttpResponseRedirect(request.REQUEST.get("next"))
            else:
                raise MessageException("Job Killed")
        time.sleep(1)
        job = Job.from_id(jt=request.jt, jobid=job.jobId)

    raise Exception(_("Job did not appear as killed within 15 seconds"))
def kill_job(request, jobid):
  """
  We get here from /jobs/jobid/kill
  """
  if request.method != "POST":
    raise Exception(_("kill_job may only be invoked with a POST (got a %(method)s)") % dict(method=request.method))
  job = Job.from_id(jt=request.jt, jobid=jobid)
  if job.user != request.user.username and not request.user.is_superuser:
    access_warn(request, _('Insufficient permission'))
    raise MessageException(_("Permission denied.  User %(username)s cannot delete user %(user)s's job.") %
                           dict(username=request.user.username, user=job.user))

  job.kill()
  cur_time = time.time()
  while time.time() - cur_time < 15:
    job = Job.from_id(jt=request.jt, jobid=jobid)

    if job.status not in ["RUNNING", "QUEUED"]:
      if request.REQUEST.get("next"):
        return HttpResponseRedirect(request.REQUEST.get("next"))
      else:
        raise MessageException("Job Killed")
    time.sleep(1)
    job = Job.from_id(jt=request.jt, jobid=jobid)

  raise Exception(_("Job did not appear as killed within 15 seconds"))
Beispiel #3
0
def kill_job(request, job):
  if request.method != "POST":
    raise Exception(_("kill_job may only be invoked with a POST (got a %(method)s).") % dict(method=request.method))

  if job.user != request.user.username and not request.user.is_superuser:
    access_warn(request, _('Insufficient permission'))
    raise MessageException(_("Permission denied.  User %(username)s cannot delete user %(user)s's job.") %
                           dict(username=request.user.username, user=job.user))

  job.kill()
  cur_time = time.time()
  while time.time() - cur_time < 15:
    job = Job.from_id(jt=request.jt, jobid=job.jobId)

    if job.status not in ["RUNNING", "QUEUED"]:
      if request.REQUEST.get("next"):
        return HttpResponseRedirect(request.REQUEST.get("next"))
      elif request.REQUEST.get("format") == "json":
        return HttpResponse(encode_json_for_js({'status': 0}), mimetype="application/json")
      else:
        raise MessageException("Job Killed")
    time.sleep(1)
    job = Job.from_id(jt=request.jt, jobid=job.jobId)

  raise Exception(_("Job did not appear as killed within 15 seconds."))
Beispiel #4
0
def get_matching_jobs(request, **kwargs):
    """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.
  """
    jobfunc = {
        "completed": request.jt.completed_jobs,
        # Succeeded and completed are synonyms here.
        "succeeded": request.jt.completed_jobs,
        "running": request.jt.running_jobs,
        "failed": request.jt.failed_jobs,
        "killed": request.jt.killed_jobs,
        "all": request.jt.all_jobs
    }
    if 'state' in kwargs:
        selection = kwargs['state']
    else:
        selection = request.GET.get("state", "all")

    joblist = jobfunc[selection]().jobs

    return [
        Job.from_thriftjob(request.jt, j)
        for j in _filter_jobs_by_req(joblist, request, **kwargs)
    ]
def job_single_logs(request, jobid):
  """
  We get here from /jobs/jobid/logs
  """
  job = Job.from_id(jt=request.jt, jobid=jobid)

  def cmp_exec_time(task1, task2):
    return cmp(task1.execStartTimeMs, task2.execStartTimeMs)

  task = None

  failed_tasks = job.filter_tasks(task_states=('failed',))
  failed_tasks.sort(cmp_exec_time)
  if failed_tasks:
    task = failed_tasks[0]
  else:
    recent_tasks = job.filter_tasks(task_states=('running', 'succeeded',), task_types=('map', 'reduce',))
    recent_tasks.sort(cmp_exec_time, reverse=True)
    if recent_tasks:
      task = recent_tasks[0]

  if task is None:
    raise PopupException(_("No tasks found for job %(id)s") % dict(id=jobid))

  return single_task_attempt_logs(request, **{'jobid': jobid, 'taskid': task.taskId, 'attemptid': task.taskAttemptIds[-1]})
Beispiel #6
0
def get_matching_jobs(request, **kwargs):
    """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.
  """
    jobfunc = {
        "completed": request.jt.completed_jobs,
        # Succeeded and completed are synonyms here.
        "succeeded": request.jt.completed_jobs,
        "running": request.jt.running_jobs,
        "failed": request.jt.failed_jobs,
        "killed": request.jt.killed_jobs,
        "all": request.jt.all_jobs
    }
    if 'state' in kwargs:
        selection = kwargs['state']
    else:
        selection = request.GET.get("state", "all")

    joblist = jobfunc[selection]().jobs

    return [
        Job.from_thriftjob(request.jt, j)
        for j in _filter_jobs_by_req(joblist, request, **kwargs)
    ]
Beispiel #7
0
def get_matching_jobs(request, check_permission=False, **kwargs):
  """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.

  Filter by user ownership if check_permission is set to true.
  """
  jobfunc = {"completed" : (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
             # Succeeded and completed are synonyms here.
             "succeeded" : (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
             "running" : (request.jt.running_jobs, ThriftJobState.RUNNING),
             "failed" : (request.jt.failed_jobs, ThriftJobState.FAILED),
             "killed" : (request.jt.killed_jobs, ThriftJobState.KILLED),
             "all" : (request.jt.all_jobs, None)}
  if 'state' in kwargs:
    selection = kwargs['state']
  else:
    selection = request.GET.get("state", "all")

  joblist = jobfunc[selection][0]().jobs + request.jt.retired_jobs(jobfunc[selection][1]).jobs

  return [Job.from_thriftjob(request.jt, j)
          for j in _filter_jobs_by_req(joblist, request, **kwargs)
          if not check_permission or request.user.is_superuser or j.profile.user == request.user]
 def decorate(request, *args, **kwargs):
   jobid = kwargs['jobid']
   job = Job.from_id(jt=request.jt, jobid=jobid)
   if not conf.SHARE_JOBS.get() and not request.user.is_superuser \
     and job.user != request.user.username:
     raise PopupException(_("You don't have the permissions to access"
                            " job %(id)s") % dict(id=jobid))
   return view_func(request, *args, **kwargs)
Beispiel #9
0
  def filter_jobs(self, user, jobs, **kwargs):
    check_permission = not SHARE_JOBS.get() and not user.is_superuser

    limit = kwargs.pop('limit', 10000)

    return [Job.from_thriftjob(self.jt, j)
            for j in self._filter_jobs(jobs, **kwargs)
            if not check_permission or user.is_superuser or j.profile.user == user.username][:limit]
Beispiel #10
0
    def filter_jobs(self, user, jobs, **kwargs):
        check_permission = not SHARE_JOBS.get() and not user.is_superuser

        return [
            Job.from_thriftjob(self.jt, j)
            for j in self._filter_jobs(jobs, **kwargs) if not check_permission
            or user.is_superuser or j.profile.user == user.username
        ]
Beispiel #11
0
 def decorate(request, *args, **kwargs):
     jobid = kwargs['jobid']
     job = Job.from_id(jt=request.jt, jobid=jobid)
     if not conf.SHARE_JOBS.get() and not request.user.is_superuser \
       and job.user != request.user.username:
         raise PopupException(
             _("You don't have the permissions to access"
               " job %(id)s.") % dict(id=jobid))
     return view_func(request, *args, **kwargs)
Beispiel #12
0
def kill_job(request, jobid):
  """
  We get here from /jobs/jobid/kill
  """
  if request.method != "POST":
    raise Exception("kill_job may only be invoked with a POST (got a %s)" % request.method)
  job = Job.from_id(jt=request.jt, jobid=jobid)
  if job.user != request.user.username and not request.user.is_superuser:
    access_warn(request, 'Insufficient permission')
    raise MessageException("Permission denied.  User %s cannot delete user %s's job." %
                           (request.user.username, job.profile.user))

  job.kill()
  cur_time = time.time()
  while time.time() - cur_time < 15:
    job = Job.from_id(jt=request.jt, jobid=jobid)

    if job.status not in ["RUNNING", "QUEUED"]:
      return render_json({})
    time.sleep(1)
    job = Job.from_id(jt=request.jt, jobid=jobid)

  raise Exception("Job did not appear as killed within 15 seconds")
Beispiel #13
0
def get_matching_jobs(request, check_permission=False, **kwargs):
    """
  Returns an array of jobs where the returned
  jobs are matched by the provided filter arguments.

  If a filter argument is in kwargs it will supersede the same argument
  in the request object.

  Filter arguments may be jobid, pools, user, tasks, text and state.

  Filter by user ownership if check_permission is set to true.
  """
    jobfunc = {
        "completed": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        # Succeeded and completed are synonyms here.
        "succeeded": (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
        "running": (request.jt.running_jobs, ThriftJobState.RUNNING),
        "failed": (request.jt.failed_jobs, ThriftJobState.FAILED),
        "killed": (request.jt.killed_jobs, ThriftJobState.KILLED),
        "all": (request.jt.all_jobs, None)
    }
    if 'state' in kwargs:
        selection = kwargs['state']
    else:
        selection = request.GET.get("state", "all")

    if 'retired' in kwargs:
        retired_arg = kwargs['retired']
    else:
        retired_arg = request.GET.get("retired", None)

    retired = coerce_bool(retired_arg)

    joblist = jobfunc[selection][0]().jobs

    if retired == True:
        joblist += request.jt.retired_jobs(jobfunc[selection][1]).jobs

    return [
        Job.from_thriftjob(request.jt, j)
        for j in _filter_jobs_by_req(joblist, request, **kwargs)
        if not check_permission or request.user.is_superuser
        or j.profile.user == request.user.username
    ]
Beispiel #14
0
def single_job(request, jobid):
    """
  We get here from /jobs/jobid
  """
    job = Job.from_id(jt=request.jt, jobid=jobid)

    def cmp_exec_time(task1, task2):
        return cmp(task1.execStartTimeMs, task2.execStartTimeMs)

    failed_tasks = job.filter_tasks(task_states=("failed",))
    failed_tasks.sort(cmp_exec_time)
    recent_tasks = job.filter_tasks(task_states=("running", "succeeded"))
    recent_tasks.sort(cmp_exec_time, reverse=True)

    return render(
        "job.mako",
        request,
        {"request": request, "job": job, "failed_tasks": failed_tasks[:5], "recent_tasks": recent_tasks[:5]},
    )
def single_job(request, jobid):
  """
  We get here from /jobs/jobid
  """
  job = Job.from_id(jt=request.jt, jobid=jobid)

  def cmp_exec_time(task1, task2):
    return cmp(task1.execStartTimeMs, task2.execStartTimeMs)

  failed_tasks = job.filter_tasks(task_states=('failed',))
  failed_tasks.sort(cmp_exec_time)
  recent_tasks = job.filter_tasks(task_states=('running', 'succeeded',))
  recent_tasks.sort(cmp_exec_time, reverse=True)

  return render("job.mako", request, {
    'request': request,
    'job': job,
    'failed_tasks': failed_tasks[:5],
    'recent_tasks': recent_tasks[:5]
  })
Beispiel #16
0
def single_job(request, jobid):
    """
  We get here from /jobs/jobid
  """
    job = Job.from_id(jt=request.jt, jobid=jobid)

    def cmp_exec_time(foo, bar):
        return cmp(foo.execStartTimeMs, bar.execStartTimeMs)

    failed_tasks = job.filter_tasks(task_states=set(['failed']))
    failed_tasks.sort(cmp_exec_time)
    recent_tasks = job.filter_tasks(task_states=set(['running', 'succeeded']))
    recent_tasks.sort(cmp_exec_time, reverse=True)

    return render(
        "job.mako", request, {
            'request': request,
            'job': job,
            'failed_tasks': failed_tasks[:5],
            'recent_tasks': recent_tasks[:5]
        })
Beispiel #17
0
def job_single_logs(request, jobid):
    """
  We get here from /jobs/jobid/logs
  """
    job = Job.from_id(jt=request.jt, jobid=jobid)

    def cmp_exec_time(task1, task2):
        return cmp(task1.execStartTimeMs, task2.execStartTimeMs)

    task = None

    failed_tasks = job.filter_tasks(task_states=('failed', ))
    failed_tasks.sort(cmp_exec_time)
    if failed_tasks:
        task = failed_tasks[0]
    else:
        recent_tasks = job.filter_tasks(task_states=(
            'running',
            'succeeded',
        ),
                                        task_types=(
                                            'map',
                                            'reduce',
                                        ))
        recent_tasks.sort(cmp_exec_time, reverse=True)
        if recent_tasks:
            task = recent_tasks[0]

    if task is None:
        raise PopupException(
            _("No tasks found for job %(id)s") % dict(id=jobid))

    return single_task_attempt_logs(
        request, **{
            'jobid': jobid,
            'taskid': task.taskId,
            'attemptid': task.taskAttemptIds[-1]
        })
Beispiel #18
0
def get_single_job(request, jobid):
    """
  Returns the job which matches jobid.
  """
    return Job.from_id(jt=request.jt, jobid=jobid)
Beispiel #19
0
 def get_job(self, jobid):
   return Job.from_id(jt=self.jt, jobid=jobid)
def job_counters(request, jobid):
  """
  We get here from /jobs/jobid/counters
  """
  job = Job.from_id(jt=request.jt, jobid=jobid)
  return render("counters.html", request, {"counters":job.counters})
def get_single_job(request, jobid):
  """
  Returns the job which matches jobid.
  """
  return Job.from_id(jt=request.jt, jobid=jobid)
Beispiel #22
0
def job_counters(request, jobid):
    """
  We get here from /jobs/jobid/counters
  """
    job = Job.from_id(jt=request.jt, jobid=jobid)
    return render("counters.html", request, {"counters": job.counters})
Beispiel #23
0
 def get_job(self, jobid):
     return Job.from_id(jt=self.jt, jobid=jobid)