示例#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).") %
            {'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."
              ) % {
                  'username': request.user.username,
                  'user': job.user
              })

    job.kill()

    cur_time = time.time()
    api = get_api(request.user, request.jt)

    while time.time() - cur_time < 15:
        job = api.get_job(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 JsonResponse({'status': 0}, encoder=JSONEncoderForHTML)
            else:
                raise MessageException("Job Killed")
        time.sleep(1)

    raise Exception(_("Job did not appear as killed within 15 seconds."))
示例#2
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"))
示例#3
0
def proxy(request, host, port, path):
    """
  Proxies an HTTP request by fetching the data
  and re-writing links.
  """
    port = int(port)

    if not check_host_port(host, port):
        raise MessageException((
            "%s:%d is not whitelisted for reverse proxying, nor a daemon that Cluster Health "
            + "is aware of.  Contact your administrator.") % (host, port))
    if not check_blacklist(host, port, path):
        raise MessageException(
            "Access to %s:%s%s is blocked. Contact your administrator." %
            (host, port, path))

    # The tuple here is: (scheme, netloc, path, params, query, fragment).
    # We don't support params or fragment.
    url = urlunparse(("http", "%s:%d" % (host, port), path, None,
                      request.META.get("QUERY_STRING"), None))
    LOGGER.info("Retrieving %s." % url)
    if request.method == 'POST':
        post_data = request.POST.urlencode()
    else:
        post_data = None
    data = urlopen(url, data=post_data)
    content_type = data.headers.get("content-type", "text/plain")
    if not re.match(r'^text/html\s*(?:;.*)?$', content_type):
        resp_text = data.read(1024 * 1024)  # read 1MB
    else:
        resp_text = _rewrite_links(data)
    request.path = _reverse(host, port, path)
    return HttpResponse(resp_text, mimetype=data.headers.get("content-type"))
示例#4
0
文件: views.py 项目: soongxin/hhue
def kill_job(request, job):
    if request.method != "POST":
        raise Exception(
            _("kill_job may only be invoked with a POST (got a %(method)s).") %
            {'method': request.method})

    if not can_kill_job(job, request.user):
        raise PopupException(_("Kill operation is forbidden."))

    try:
        job.kill()
    except Exception as e:
        LOG.exception('Killing job')
        raise PopupException(e)

    cur_time = time.time()
    api = get_api(request.user, request.jt)

    while time.time() - cur_time < 15:
        try:
            job = api.get_job(jobid=job.jobId)
        except Exception as e:
            LOG.warn('Failed to get job with ID %s: %s' % (job.jobId, e))
        else:
            if job.status not in ["RUNNING", "QUEUED"]:
                if request.GET.get("next"):
                    return HttpResponseRedirect(request.GET.get("next"))
                elif request.GET.get("format") == "json":
                    return JsonResponse({'status': 0},
                                        encoder=JSONEncoderForHTML)
                else:
                    raise MessageException("Job Killed")
        time.sleep(1)

    raise Exception(_("Job did not appear as killed within 15 seconds."))
示例#5
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).") % {'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.") % {'username': request.user.username, 'user': job.user})

  try:
    job.kill()
  except Exception, e:
    LOGGER.exception('Killing job')
    raise PopupException(e)
示例#6
0
    api = get_api(request.user, request.jt)

    while time.time() - cur_time < 15:
        try:
            job = api.get_job(jobid=job.jobId)
        except Exception, e:
            LOG.warn('Failed to get job with ID %s: %s' % (job.jobId, e))
        else:
            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 JsonResponse({'status': 0},
                                        encoder=JSONEncoderForHTML)
                else:
                    raise MessageException("Job Killed")
        time.sleep(1)

    raise Exception(_("Job did not appear as killed within 15 seconds."))


@check_job_permission
def job_attempt_logs(request, job, attempt_index=0):
    return render("job_attempt_logs.mako", request, {
        "attempt_index": attempt_index,
        "job": job,
        "log_offset": LOG_OFFSET_BYTES
    })


@check_job_permission