Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)