def wall_time_parsed(args): if not args.list and not (args.resource and args.appkernel and args.nodes and args.walltime): parser.error( 'Please provide a resource, app, node count and wall time.') exit(1) listing = args.list resource = args.resource app = args.appkernel nodes = args.nodes walltime = args.walltime comments = args.comments node_list = [node.strip() for node in nodes.split(',')] if ',' in nodes else list(nodes) for nodes in node_list: data = { 'resource_params': "{'nnodes':%d}" % (int(nodes),) if nodes else "{}", 'app_param':'{}', 'walltime': walltime, 'comments':comments } try: result = akrrrestclient.post( '/walltime/%s/%s'%(resource,app), data=data) if not listing else \ akrrrestclient.get( '/walltime/%s/%s'%(resource,app), data=data) if result.status_code == 200: if not listing: log.info('Successfully updated wall time (resource %s: application kernel: %s nodes: %d).'%(resource,app,nodes)) else: log.info( 'Successfully queried walltime records. \n{0}', result.text) else: log.error('something went wrong. {0}:{1}', result.status_code, result.text) except StandardError, e: import traceback log.error(''' An error occured while communicating with the REST API. {0}: {1} '''.strip(), e.args[0] if len(e.args) > 0 else '', e.args[1] if len(e.args) > 1 else '') print traceback.print_exc()
def new_task_parsed(args): """ Handles the appropriate execution of a 'New Task' mode request given the provided command line arguments. """ if not (args.resource and args.appkernel and args.nodes): parser.error( 'Please provide a resource, application and node count.') exit(1) resource = args.resource app = args.appkernel time_to_start=args.start_time time_start = args.time_start# if args.time_start else '01:00' time_end = args.time_end# if args.time_end else '05:00' repeat_in = args.periodicity nodes = args.nodes node_list = [node.strip() for node in nodes.split(',')] if ',' in nodes else list(nodes) for node in node_list: if time_start!=None and time_end!=None: time_to_start = calculate_random_start_time( args.start_time, repeat_in, time_start, time_end) data = { 'resource': resource, 'app': app, 'time_to_start': time_to_start, 'repeat_in': repeat_in, 'resource_param': "{'nnodes':%s}" % (node,) } try: result = akrrrestclient.post( '/scheduled_tasks', data=data) if result.status_code == 200: log.info('Successfully submitted new task') else: log.error( 'something went wrong. {0}:{1}', result.status_code, result.text) except StandardError, e: log.error(''' An error occured while communicating with the REST API. {0}: {1} ''', e.args[0] if len(e.args) > 0 else '', e.args[1] if len(e.args) > 1 else '')
def process_request(request): method = request[0] url = request[1] if method not in RESTCompleter.keywords: raise AssertionError("Invalid method. Please provide a valid method to continue.") if len(url) < 1: raise AssertionError("Must supply a url.") akrrrestclient.get_token() if method == "GET": return akrrrestclient.get(url) elif method == "PUT": return akrrrestclient.put(url) elif method == "POST": return akrrrestclient.post(url) elif method == "DELETE": return akrrrestclient.delete(url)
def process_request(request): method = request[0] url = request[1] if method not in RESTCompleter.keywords: raise AssertionError( "Invalid method. Please provide a valid method to continue.") if len(url) < 1: raise AssertionError("Must supply a url.") akrrrestclient.get_token() if method == 'GET': return akrrrestclient.get(url) elif method == 'PUT': return akrrrestclient.put(url) elif method == 'POST': return akrrrestclient.post(url) elif method == 'DELETE': return akrrrestclient.delete(url)
if r.status_code!=200: task_id=None else: log("\nWARNING %d: Seems this is rerun of this script, will monitor task with task_id = "%(warningCount+1)+str(task_id),highlight="warning") log("To submit new task delete "+test_job_lock_filename+"\n",highlight="warning") warningCount+=1 #check how old is it #submit test job if task_id==None: try: payload={'resource':resource_name, 'app':app_name, 'resource_param':"{'nnodes':2}", 'task_param':"{'test_run':True}" } r = akrrrestclient.post('/scheduled_tasks', data=payload) if r.status_code!=200: logerr("Can not submit task through AKRR REST API ( """+akrrrestclient.restapi_host+" )\n"+ "See server response below",json.dumps(r.json(),indent=4)) exit() task_id=r.json()['data']['task_id'] except Exception,e: logerr("Can not submit task through AKRR REST API ( """+akrrrestclient.restapi_host+" )\n"+ "Is it still running?\n"+ "See full error report below",traceback.format_exc()) exit() #write file with tast_id fout=open(os.path.join(test_job_lock_filename),"w") print >>fout,task_id fout.close() log("\nSubmitted test job to AKRR, task_id is "+str(task_id)+"\n")