예제 #1
0
def job_id_GET(request, v):
    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    return JSONResponse(job.to_dict(), http.OK)
예제 #2
0
def job_files_PUT(request, v):
    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    if v['type'] == "files":
        file_path = job.input_path(v['path'])
    elif v['type'] == "output":
        file_path = job.output_path(v['path'])
    elif v['type'] == "executable":
        file_path = job.executable_path(v['path'])
    else:
        return JSONResponse({'error_msg': "Invalid file type."},
                            http.BAD_REQUEST)

    job.create_file_path(file_path)
    request.raw_to_file(file_path)

    if v['type'] == "executable":
        job.add_executable(v['path'])
    else:
        job.add_file(v['path'])

    return JSONResponse(v)
예제 #3
0
def job_POST(request):
    d = request.json
    if not validate_request(
            d, ['wall_time', 'deadline', 'flags', 'budget', 'job_type']):
        return JSONResponse({'error_msg': 'Invalid Job JSON received.'},
                            http.BAD_REQUEST)
    try:
        name = "Unknown"
        if d.has_key("name"):
            name = d["name"]

        job = model.grid.add_job(flags=d['flags'],
                                 wall_time=d['wall_time'],
                                 deadline=d['deadline'],
                                 budget=d['budget'],
                                 job_type=d['job_type'],
                                 name=name)
    except InvalidJobParameterException as e:
        return JSONResponse({'error_msg': "%s" % e.args[0]}, http.BAD_REQUEST)

    return JSONResponse(
        {
            'success': "Job added successfully.",
            'id': job.job_id
        }, http.OK)
예제 #4
0
def node_id_GET(request, v):
    try:
        node = model.grid.get_node(v['id'])
    except NodeNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    return JSONResponse(model.grid.node_to_dict(node), http.OK)
예제 #5
0
def node_POST(request):
    if not validate_request(request.json,
                            ['host', 'port', 'cores', 'programs', 'cost']):
        return JSONResponse({'error_msg': 'Invalid Node JSON received.'},
                            http.BAD_REQUEST)

    node = request.json
    node_id = model.grid.add_node(node)

    return JSONResponse({'node_id': node_id}, http.OK)
예제 #6
0
def task_id_DELETE(request, v):

    try:
        task = model.server.get_task(v['id'])
    except (TaskNotFoundException) as e:
        return JSONResponse({'error_msg': e.args[0]}, http.BAD_REQUEST)

    model.server.kill_task(task)

    return JSONResponse({'success': 'Task killed.'}, 200)
예제 #7
0
def node_id_POST(request, v):
    if not validate_request(request.json, []):
        return JSONResponse({'error_msg': 'Invalid Node JSON received.'},
                            http.BAD_REQUEST)

    try:
        node = model.grid.update_node(v['id'], request.json)
    except NodeNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    return JSONResponse(model.grid.node_to_dict(node), http.OK)
예제 #8
0
def job_id_DELETE(request, v):
    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    job.kill_msg = "Killed on request by client."
    try:
        model.grid.kill_job(job)
    except NodeUnavailableException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.BAD_REQUEST)

    return JSONResponse({'success': "Job killed successfully."}, http.OK)
예제 #9
0
def job_status_PUT(request, v):
    d = request.json

    if not validate_request(d, ['status']):
        return JSONResponse({'error_msg': 'Invalid status JSON received.'},
                            http.BAD_REQUEST)

    try:
        job = model.grid.update_job_status(v['id'], d['status'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)
    except InvalidJobParameterException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.BAD_REQUEST)

    return JSONResponse(job.to_dict(), http.OK)
예제 #10
0
def nodes_GET(request):
    nodeList = model.grid.nodes.values()

    jsonNodes = []
    for node in nodeList:
        try:
            cpu = node['cpu']
        except KeyError:
            cpu = 0
        if node['status'] != "DEAD":
            n = {
                "host": node['host'],
                "port": node['port'],
                "node_id": node['node_id'],
                "status": node['status'],
                "work_units": [],
                "type": node['type'],
                "node_ident": node['node_ident'],
                "cores": node['cores'],
                "cpu": cpu,
                "cost": node['cost']
            }
            for unit in node["work_units"]:
                n["work_units"].append(unit.to_dict())

            jsonNodes.append(n)

    return JSONResponse({'nodes': jsonNodes}, 200)
예제 #11
0
def job_GET(request):
    jobs = model.grid.jobs

    safe_jobs = {}
    for key, job in jobs.items():
        safe_jobs.update({key: job.to_dict()})

    return JSONResponse(safe_jobs, http.OK)
예제 #12
0
def job_workunit_POST(request, v):
    if not validate_request(request.json, ['work_unit_id', 'kill_msg']):
        return JSONResponse({'error_msg': 'Invalid Work Unit JSON received.'},
                            http.BAD_REQUEST)

    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    unit = model.grid.finish_work_unit(job, request.json['work_unit_id'])

    if request.json['kill_msg'] != None:
        unit.kill_msg = request.json['kill_msg']
        unit.kill()

    return JSONResponse(unit.to_dict(), http.OK)
예제 #13
0
def node_GET(request):
    nodes = model.grid.nodes

    safe_nodes = {}
    for key, node in nodes.items():
        safe_nodes.update({key: model.grid.node_to_dict(node)})

    return JSONResponse(safe_nodes, http.OK)
예제 #14
0
def job_submit_executable_POST(request, v):
    file_name = request.query["qqfile"][0]
    try:
        job = model.grid.get_job(v['tmp_job_id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    file_path = job.executable_path(file_name)

    job.create_file_path(file_path)
    request.raw_to_file(file_path)

    job.add_executable(file_name)

    return JSONResponse({
        'tmp_job_id': v['tmp_job_id'],
        'filename': file_path
    }, 200)
예제 #15
0
def scheduler_PUT(request):
    d = request.json

    if not validate_request(d, ['scheduler']):
        return JSONResponse({'error_msg': 'Invalid Scheduler JSON Received'},
                            http.BAD_REQUEST)

    try:
        model.grid.scheduler = request.json['scheduler']
    except InvalidSchedulerException as e:
        return JSONResponse(
            {
                'error_msg':
                "Invalid Scheduler %s. Valid Schedulers: %s" %
                (request.json['scheduler'], ", ".join(model.grid.SCHEDULERS))
            }, http.BAD_REQUEST)

    return JSONResponse({'success': 'Scheduler changed.'}, http.OK)
예제 #16
0
def jobs_GET(request):
    queued_jobs = model.grid.get_queued()
    queued_jobs = model.grid.jobs

    ljobs = []
    for j in queued_jobs.values():
        ljobs.append(j.to_dict())

    return JSONResponse({'jobs': ljobs}, 200)
예제 #17
0
def job_output_file_GET(request, v):
    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    file_path = "%s/%s" % (job.output_dir, v['file_name'])

    try:
        f = open(file_path, "r")
        f.close()
    except IOError as e:
        return JSONResponse(
            {
                'error_msg':
                "Unable to open file %s for Job %s; File does not exist" %
                (v['file_name'], v['id'])
            }, http.BAD_REQUEST)

    return FileResponse(file_path)
예제 #18
0
def log_GET(request):

    # We also want to track an "id" so that we can make UI updates
    # more efficiently (so we don't redraw stuff thats already drawn)
    start = len(model.grid.scheduler.mem_log) - 100
    if start < 0:
        start = 0

    logs = []
    for i in xrange(start, len(model.grid.scheduler.mem_log)):
        logs.append({"id": i, "log": model.grid.scheduler.mem_log[i]})

    return JSONResponse({'log': logs}, 200)
예제 #19
0
def job_output_files_GET(request, v):
    try:
        job = model.grid.get_job(v['id'])
    except JobNotFoundException as e:
        return JSONResponse({'error_msg': e.args[0]}, http.NOT_FOUND)

    if job.status == "READY":
        return JSONResponse(
            {
                'error_msg':
                "Job %s is still waiting to be scheduled." % v['id']
            }, http.BAD_REQUEST)
    elif job.status == "PENDING":
        return JSONResponse(
            {'error_msg': "The Grid is still initialising Job %s." % v['id']},
            http.BAD_REQUEST)
    elif job.status == "RUNNING":
        info_msg = "Warning: Job %s is still running. Output files for running portions of the job will be missing." % v[
            'id']
    elif job.status == "KILLED":
        info_msg = "Warning: Job %s has been killed: %s Output returned will be incomplete." % (
            v['id'], job.kill_msg)
    else:
        info_msg = ""

    files_list = []
    for unit in job.work_units:
        if unit.status == "FINISHED" or unit.status == "KILLED":
            files_list.append("%s_%s.o" % (job.job_id, unit.work_unit_id))
            files_list.append("%s_%s.e" % (job.job_id, unit.work_unit_id))
        if unit.status == "KILLED" and job.status != "KILLED":
            info_msg += "Warning: Work unit %s has been killed:" % unit.work_unit_id
            info_msg += " %s Output returned will be incomplete for this work unit.\n" % unit.kill_msg

    return JSONResponse({
        'output_URIs': files_list,
        'info_msg': info_msg
    }, http.OK)
예제 #20
0
def route(routes, env):
    request = Request(env)

    #print "Request: " + str( request.raw )

    route = route_find(routes, env)
    if route:
        func, func_vars = route
        if func_vars:
            return func(request, func_vars)
        else:
            return func(request)
    else:
        return JSONResponse({'error_msg': 'Request not found'}, http.NOT_FOUND)
예제 #21
0
def task_POST(request):
    d = request.json
    if not gridservice.utils.validate_request(d, [
            'work_unit_id', 'job_id', 'executable', 'filename', 'flags',
            'wall_time', 'deadline'
    ]):
        return JSONResponse({'error_msg': 'Invalid Job JSON received.'},
                            http.BAD_REQUEST)

    try:
        task = model.server.add_task(job_id=d['job_id'],
                                     work_unit_id=d['work_unit_id'],
                                     executable=d['executable'],
                                     filename=d['filename'],
                                     flags=d['flags'],
                                     wall_time=d['wall_time'],
                                     deadline=d['deadline'])
    except (InputFileNotFoundException, ExecutableNotFoundException) as e:
        return JSONResponse({'error_msg': e.args[0]}, http.BAD_REQUEST)

    return JSONResponse({
        'success': 'Task created.',
        'task_id': task.task_id
    }, 200)