Esempio n. 1
0
def delete_job(request, machine_name, job_id):
    """Gets the information of a job, given the id

    Keyword arguments:
    machine_name -- name of the machine
    job_id -- the job id
    """
    machine = gridutil.GRID_RESOURCE_TABLE.get(machine_name, None)
    if not machine:
        return json_response(status="ERROR", status_code=400, error="Invalid machine name: %s" % machine_name)

    flags = ""
    jobmanager = machine['jobmanagers']['fork']['url']
    qdel = machine['qdel']['bin']
    scheduler = machine['qdel']['scheduler']
    cmd = "%s %s" % (qdel, job_id)

    # Set environment flags for qsub
    if scheduler == "sge":
        sge_env_str = "-env SGE_ROOT=%s -env SGE_QMASTER_PORT=%s -env SGE_EXECD_PORT=%s" % (gridutil.SGE_ROOT, gridutil.SGE_QMASTER_PORT, gridutil.SGE_EXECD_PORT)
        flags += " " + sge_env_str

    if scheduler != "sge":
        cmd = '/bin/bash -l -c "%s"' % cmd

    try:
        runner = GlobusHelper(request.user)
        (output, error, retcode) = runner.run_job(cmd, jobmanager, flags)
    except Exception, ex:
        return json_response(status="ERROR", 
                             status_code=500, 
                             error="qsub failed with error: %s" % str(ex))
Esempio n. 2
0
def submit_job(request, machine_name):
    """Submits a job to the queue

    Keyword arguments:
    request -- Django HttpRequest
    machine_name -- name of the machine
    """
    machine = gridutil.GRID_RESOURCE_TABLE.get(machine_name, None)
    if not machine:
        return json_response(status="ERROR",
                             status_code=400,
                             error="Invalid machine name: %s" % machine_name)

    flags = ""
    jobmanager = machine['jobmanagers']['fork']['url']
    qsub = machine['qsub']['bin']
    scheduler = machine['qsub']['scheduler']

    # Set environment flags for qsub
    if scheduler == "sge":
        sge_env_str = "-env SGE_ROOT=%s -env SGE_QMASTER_PORT=%s -env SGE_EXECD_PORT=%s" % (
            gridutil.SGE_ROOT, gridutil.SGE_QMASTER_PORT,
            gridutil.SGE_EXECD_PORT)
        flags += " " + sge_env_str

    if request.POST.get("jobfile", False):
        # Create command for qsub on an existing pbs file
        job_file_path = request.POST.get("jobfile")
        cmd = "%s %s" % (qsub, job_file_path)
    elif request.POST.get("jobscript", False):
        # Create command for qsub from stdin data
        job_script = request.POST.get("jobscript")

        # Creates a temporary job file
        tmp_job_file = tempfile.NamedTemporaryFile(prefix="newt_")
        tmp_job_file.write(job_script)
        tmp_job_file.flush()

        # Stages the temporary job file and pass it as to stdin to qsub
        flags += " -stdin -s %s" % tmp_job_file.name
        cmd = qsub
    else:
        return json_response(status="ERROR",
                             status_code=400,
                             error="No data received")

    if scheduler != "sge":
        cmd = '/bin/bash -l -c "%s"' % cmd

    try:
        runner = GlobusHelper(request.user)
        (output, error, retcode) = runner.run_job(cmd, jobmanager, flags)
    except Exception, ex:
        return json_response(status="ERROR",
                             status_code=500,
                             error="qsub failed with error: %s" % str(ex))
Esempio n. 3
0
def submit_job(request, machine_name):
    """Submits a job to the queue

    Keyword arguments:
    request -- Django HttpRequest
    machine_name -- name of the machine
    """
    machine = gridutil.GRID_RESOURCE_TABLE.get(machine_name, None)
    if not machine:
        return json_response(status="ERROR", status_code=400, error="Invalid machine name: %s" % machine_name)

    flags = ""
    jobmanager = machine['jobmanagers']['fork']['url']
    qsub = machine['qsub']['bin']
    scheduler = machine['qsub']['scheduler']

    # Set environment flags for qsub
    if scheduler == "sge":
        sge_env_str = "-env SGE_ROOT=%s -env SGE_QMASTER_PORT=%s -env SGE_EXECD_PORT=%s" % (gridutil.SGE_ROOT, gridutil.SGE_QMASTER_PORT, gridutil.SGE_EXECD_PORT)
        flags += " " + sge_env_str

    if request.POST.get("jobfile", False):
        # Create command for qsub on an existing pbs file
        job_file_path = request.POST.get("jobfile")
        cmd = "%s %s" % (qsub, job_file_path)
    elif request.POST.get("jobscript", False):
        # Create command for qsub from stdin data
        job_script = request.POST.get("jobscript")

        # Creates a temporary job file
        tmp_job_file = tempfile.NamedTemporaryFile(prefix="newt_")
        tmp_job_file.write(job_script)
        tmp_job_file.flush()

        # Stages the temporary job file and pass it as to stdin to qsub
        flags += " -stdin -s %s" % tmp_job_file.name
        cmd = qsub
    else:
        return json_response(status="ERROR", 
                             status_code=400, 
                             error="No data received")

    if scheduler != "sge":
        cmd = '/bin/bash -l -c "%s"' % cmd

    try:
        runner = GlobusHelper(request.user)
        (output, error, retcode) = runner.run_job(cmd, jobmanager, flags)
    except Exception, ex:
        return json_response(status="ERROR", 
                             status_code=500, 
                             error="qsub failed with error: %s" % str(ex))
Esempio n. 4
0
def delete_job(request, machine_name, job_id):
    """Gets the information of a job, given the id

    Keyword arguments:
    machine_name -- name of the machine
    job_id -- the job id
    """
    machine = gridutil.GRID_RESOURCE_TABLE.get(machine_name, None)
    if not machine:
        return json_response(status="ERROR",
                             status_code=400,
                             error="Invalid machine name: %s" % machine_name)

    flags = ""
    jobmanager = machine['jobmanagers']['fork']['url']
    qdel = machine['qdel']['bin']
    scheduler = machine['qdel']['scheduler']
    cmd = "%s %s" % (qdel, job_id)

    # Set environment flags for qsub
    if scheduler == "sge":
        sge_env_str = "-env SGE_ROOT=%s -env SGE_QMASTER_PORT=%s -env SGE_EXECD_PORT=%s" % (
            gridutil.SGE_ROOT, gridutil.SGE_QMASTER_PORT,
            gridutil.SGE_EXECD_PORT)
        flags += " " + sge_env_str

    if scheduler != "sge":
        cmd = '/bin/bash -l -c "%s"' % cmd

    try:
        runner = GlobusHelper(request.user)
        (output, error, retcode) = runner.run_job(cmd, jobmanager, flags)
    except Exception, ex:
        return json_response(status="ERROR",
                             status_code=500,
                             error="qsub failed with error: %s" % str(ex))