From a035dee017ce347a5e554fbbdd4ceed20830f2d0 Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Mon, 25 Jun 2012 16:54:07 +0200 Subject: [PATCH] Corrected GetReservedNodes. --- sfa/senslab/LDAPapi.py | 2 +- sfa/senslab/OARrestapi.py | 8 +++++ sfa/senslab/slabaggregate.py | 2 +- sfa/senslab/slabdriver.py | 64 +++++++++++++++++++----------------- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/sfa/senslab/LDAPapi.py b/sfa/senslab/LDAPapi.py index 63b4431f..766da7c5 100644 --- a/sfa/senslab/LDAPapi.py +++ b/sfa/senslab/LDAPapi.py @@ -112,7 +112,7 @@ class LDAPapi : 'A','B','C','D','E','F','G','H','I','J',\ 'K','L','M','N','O','P','Q','R','S','T',\ 'U','V','W','X','Y','Z','_','a','b','c',\ - 'd','error','f','g','h','i','j','k','l','m',\ + 'd','e','f','g','h','i','j','k','l','m',\ 'n','o','p','q','r','s','t','u','v','w',\ 'x','y','z','\''] diff --git a/sfa/senslab/OARrestapi.py b/sfa/senslab/OARrestapi.py index 3ca883a6..3aa158ab 100644 --- a/sfa/senslab/OARrestapi.py +++ b/sfa/senslab/OARrestapi.py @@ -25,6 +25,7 @@ OARrequests_get_uri_dict = { 'GET_version': '/oarapi/version.json', 'GET_jobs_table': '/oarapi/jobs/table.json', 'GET_jobs_details': '/oarapi/jobs/details.json', 'GET_reserved_nodes': '/oarapi/jobs/details.json?state=Running,Waiting,Launching', + 'GET_running_jobs': '/oarapi/jobs/details.json?state=Running', 'GET_resources_full': '/oarapi/resources/full.json', 'GET_resources':'/oarapi/resources.json', 'GET_sites' : '/oarapi/resources/full.json', @@ -275,6 +276,12 @@ class OARGETParser: #resources are listed inside the 'items' list from the json return self.raw_json + def ParseRunningJobs(self): + print>>sys.stderr, " \r\n \t\t\t ParseRunningJobs__________________________ " + #resources are listed inside the 'items' list from the json + return self.raw_json + + def ParseDeleteJobs(self): return @@ -396,6 +403,7 @@ class OARGETParser: 'GET_jobs_table': {'uri':'/oarapi/jobs/table.json','parse_func': ParseJobsTable}, 'GET_jobs_details': {'uri':'/oarapi/jobs/details.json','parse_func': ParseJobsDetails}, 'GET_reserved_nodes':{'uri':'/oarapi/jobs/details.json?state=Running,Waiting,Launching','parse_func':ParseReservedNodes}, + 'GET_running_jobs': {'uri':'/oarapi/jobs/details.json?state=Running','parse_func':ParseRunningJobs}, 'GET_resources_full': {'uri':'/oarapi/resources/full.json','parse_func': ParseResourcesFull}, 'GET_sites':{'uri':'/oarapi/resources/full.json','parse_func': ParseResourcesFullSites}, 'GET_resources':{'uri':'/oarapi/resources.json' ,'parse_func': ParseResources}, diff --git a/sfa/senslab/slabaggregate.py b/sfa/senslab/slabaggregate.py index 5b1eeeda..379e0c1f 100644 --- a/sfa/senslab/slabaggregate.py +++ b/sfa/senslab/slabaggregate.py @@ -24,7 +24,7 @@ from sfa.rspecs.version_manager import VersionManager from sfa.util.sfatime import datetime_to_epoch def hostname_to_hrn(root_auth,login_base,hostname): - return PlXrn(auth=root_auth,hostname=login_base + '_'+hostname).get_hrn() + return PlXrn(auth=root_auth,hostname=login_base + '_' +hostname).get_hrn() class SlabAggregate: diff --git a/sfa/senslab/slabdriver.py b/sfa/senslab/slabdriver.py index bb3b1b82..fc509624 100644 --- a/sfa/senslab/slabdriver.py +++ b/sfa/senslab/slabdriver.py @@ -475,7 +475,7 @@ class SlabDriver(Driver): node_list_k = 'assigned_network_address' #Get job info from OAR job_info = self.oar.parser.SendRequest(req, job_id, username) - + logger.debug("SLABDRIVER \t GetJobs %s " %(job_info)) try: if job_info['state'] == 'Terminated': @@ -500,7 +500,7 @@ class SlabDriver(Driver): return job_info - def GetJobsResources(self,job_id, return_fields_list=None, username = None): + def GetJobsResources(self,job_id, username = None): #job_resources=['reserved_resources', 'assigned_resources','job_id', 'job_uri', 'assigned_nodes',\ #'api_timestamp'] #assigned_res = ['resource_id', 'resource_uri'] @@ -547,14 +547,15 @@ class SlabDriver(Driver): def GetReservedNodes(self): # this function returns a list of all the nodes already involved in an oar job - #jobs=self.oar.parser.SendRequest("GET_reserved_nodes") - jobs=self.oar.parser.SendRequest("GET_jobs_details") - nodes=[] + jobs = self.oar.parser.SendRequest("GET_running_jobs") + print>>sys.stderr, "\r\n \r\n GetReservedNodes jobs %s" %(jobs) + #jobs=self.oar.parser.SendRequest("GET_jobs_details") + nodes = [] if jobs['total'] == 0: return [] for j in jobs : - nodes=j['assigned_network_address']+nodes + nodes = j['assigned_network_address']+nodes return nodes def GetNodes(self,node_filter_dict = None, return_fields_list = None): @@ -644,7 +645,8 @@ class SlabDriver(Driver): %(login,rec)) if slicerec.oar_job_id is not -1: #Check with OAR the status of the job if a job id is in - #the slice record + #the slice record + #rslt = self.GetJobsResources(slicerec.oar_job_id,username = login) rslt = self.GetJobsId(slicerec.oar_job_id,username = login) if rslt : rec.update(rslt) @@ -774,32 +776,33 @@ class SlabDriver(Driver): slice_name = slice_dict['name'] try: slot = slice_dict['timeslot'] - print>>sys.stderr, "\r\n \r\n \t\tLaunchExperimentOnOAR slot %s " %(slot) + logger.debug("SLABDRIVER.PY \tLaunchExperimentOnOAR slot %s" %(slot)) except KeyError: #Running on default parameters #XP immediate , 10 mins slot = {'date':None,'start_time':None, 'timezone':None,'duration':None }#10 min - - - reqdict['property'] ="network_address in (" - for node in added_nodes: + + reqdict['workdir']= '/tmp' + reqdict['resource'] ="{network_address in (" + #reqdict['property'] ="network_address in (" + for node in added_nodes: + print>>sys.stderr, "\r\n \r\n \t\tLaunchExperimentOnOAR node %s" %(node) + #Get the ID of the node : remove the root auth and put the site in a separate list - s=node.split(".") + #s=node.split(".") # NT: it's not clear for me if the nodenames will have the senslab prefix # so lets take the last part only, for now. - lastpart=s[-1] + #lastpart=s[-1] #if s[0] == self.root_auth : # Again here it's not clear if nodes will be prefixed with _, lets split and tanke the last part for now. - s=lastpart.split("_") - nodeid=s[-1] - reqdict['property'] += "'"+ nodeid +"', " + #s=lastpart.split("_") + #nodeid=s[-1] + nodeid = node + reqdict['resource'] += "'"+ nodeid +"', " nodeid_list.append(nodeid) - #site_list.append( l[0] ) - - - reqdict['property'] = reqdict['property'][0: len( reqdict['property'])-2] +")" - reqdict['resource'] ="network_address="+ str(len(nodeid_list)) - + + + reqdict['resource'] = reqdict['resource'][0: len( reqdict['resource'])-2] +")}/nodes=" + str(len(nodeid_list)) if slot['duration']: walltime = slot['duration'].split(":") # Fixing the walltime by adding a few delays. First put the walltime in seconds @@ -829,11 +832,11 @@ class SlabDriver(Driver): reqdict['script_path'] = "/bin/sleep 620" #+20 sec #In case of a scheduled experiment (not immediate) #To run an XP immediately, don't specify date and time in RSpec - #They will be set to None. + #They will be set to None. + server_timestamp,server_tz = self.GetTimezone() if slot['date'] and slot['start_time']: if slot['timezone'] is '' or slot['timezone'] is None: #assume it is server timezone - server_timestamp,server_tz = self.GetTimezone() from_zone=tz.gettz(server_tz) print>>sys.stderr, "\r\n \r\n \t\tLaunchExperimentOnOAR timezone not specified server_tz %s from_zone %s" %(server_tz,from_zone) else: @@ -844,11 +847,12 @@ class SlabDriver(Driver): user_datetime = datetime.strptime(date, self.time_format) user_datetime = user_datetime.replace(tzinfo = from_zone) - #Convert to UTC zone - to_zone = tz.tzutc() - utc_date = user_datetime.astimezone(to_zone) + #Convert to server zone + #to_zone = tz.tzutc() + to_zone = tz.gettz(server_tz) + reservation_date = user_datetime.astimezone(to_zone) #Readable time accpeted by OAR - reqdict['reservation']= utc_date.strftime(self.time_format) + reqdict['reservation']= reservation_date.strftime(self.time_format) print>>sys.stderr, "\r\n \r\n \t\tLaunchExperimentOnOAR reqdict['reservation'] %s " %(reqdict['reservation']) @@ -879,7 +883,7 @@ class SlabDriver(Driver): # first step : start the OAR job and update the job - print>>sys.stderr, "\r\n \r\n LaunchExperimentOnOAR reqdict %s \r\n site_list %s" %(reqdict,site_list) + logger.debug("SLABDRIVER.PY \tLaunchExperimentOnOAR reqdict %s \r\n site_list %s" %(reqdict,site_list) ) answer = self.oar.POSTRequestToOARRestAPI('POST_job',reqdict,slice_user) print>>sys.stderr, "\r\n \r\n LaunchExperimentOnOAR jobid %s " %(answer) -- 2.43.0