+ def GetPeers (self,auth = None, peer_filter=None, return_fields_list=None):
+
+ existing_records = {}
+ existing_hrns_by_types= {}
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers auth = %s, peer_filter %s, return_field %s " %(auth , peer_filter, return_fields_list)
+ all_records = dbsession.query(RegRecord).filter(RegRecord.type.like('%authority%')).all()
+ for record in all_records:
+ existing_records[(record.hrn,record.type)] = record
+ if record.type not in existing_hrns_by_types:
+ existing_hrns_by_types[record.type] = [record.hrn]
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers \t NOT IN existing_hrns_by_types %s " %( existing_hrns_by_types)
+ else:
+
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers \t INNN type %s hrn %s " %( record.type,record.hrn )
+ existing_hrns_by_types[record.type].append(record.hrn)
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers \t INNN existing_hrns_by_types %s " %( existing_hrns_by_types)
+ #existing_hrns_by_types.update({record.type:(existing_hrns_by_types[record.type].append(record.hrn))})
+
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers existing_hrns_by_types %s " %( existing_hrns_by_types)
+ records_list= []
+
+ try:
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers existing_hrns_by_types['authority+sa'] %s \t\t existing_records %s " %(existing_hrns_by_types['authority'],existing_records)
+ if peer_filter:
+ records_list.append(existing_records[(peer_filter,'authority')])
+ else :
+ for hrn in existing_hrns_by_types['authority']:
+ records_list.append(existing_records[(hrn,'authority')])
+
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers records_list %s " %(records_list)
+
+ except:
+ pass
+
+ return_records = records_list
+ if not peer_filter and not return_fields_list:
+ return records_list
+
+
+ print >>sys.stderr, "\r\n \r\n SLABDRIVER GetPeers return_records %s " %(return_records)
+ return return_records
+
+
+ #TODO : Handling OR request in make_ldap_filters_from_records instead of the for loop
+ #over the records' list
+ def GetPersons(self, person_filter=None, return_fields_list=None):
+ """
+ person_filter should be a list of dictionnaries when not set to None.
+ Returns a list of users found.
+
+ """
+ print>>sys.stderr, "\r\n \r\n \t\t\t GetPersons person_filter %s" %(person_filter)
+ person_list = []
+ if person_filter and isinstance(person_filter,list):
+ #If we are looking for a list of users (list of dict records)
+ #Usually the list contains only one user record
+ for f in person_filter:
+ person = self.ldap.LdapFindUser(f)
+ person_list.append(person)
+
+ else:
+ person_list = self.ldap.LdapFindUser()
+
+ return person_list
+
+
+ def GetTimezone(self):
+ server_timestamp,server_tz = self.oar.parser.SendRequest("GET_timezone")
+ return server_timestamp,server_tz
+
+
+ def DeleteJobs(self, job_id, slice_hrn):
+ if not job_id:
+ return
+ username = slice_hrn.split(".")[-1].rstrip("_slice")
+ reqdict = {}
+ reqdict['method'] = "delete"
+ reqdict['strval'] = str(job_id)
+ answer = self.oar.POSTRequestToOARRestAPI('DELETE_jobs_id',reqdict,username)
+ print>>sys.stderr, "\r\n \r\n jobid DeleteJobs %s " %(answer)
+
+
+ def GetJobs(self,job_id= None, resources=True,return_fields_list=None, username = None):
+ #job_resources=['reserved_resources', 'assigned_resources','job_id', 'job_uri', 'assigned_nodes',\
+ #'api_timestamp']
+ #assigned_res = ['resource_id', 'resource_uri']
+ #assigned_n = ['node', 'node_uri']
+
+ if job_id and resources is False:
+ req = "GET_jobs_id"
+ node_list_k = 'assigned_network_address'
+
+ if job_id and resources :
+ req = "GET_jobs_id_resources"
+ node_list_k = 'reserved_resources'
+
+ #Get job info from OAR
+ job_info = self.oar.parser.SendRequest(req, job_id, username)
+ print>>sys.stderr, "\r\n \r\n \t\t GetJobs %s " %(job_info)
+
+ if 'state' in job_info :
+ if job_info['state'] == 'Terminated':
+ print>>sys.stderr, "\r\n \r\n \t\t GetJobs TERMINELEBOUSIN "
+ return None
+ if job_info['state'] == 'Error':
+ print>>sys.stderr, "\r\n \r\n \t\t GetJobs ERROR message %s " %(job_info)
+ return None
+
+ #Get a dict of nodes . Key :hostname of the node
+ node_list = self.GetNodes()
+ node_hostname_list = []
+ for node in node_list:
+ node_hostname_list.append(node['hostname'])
+ node_dict = dict(zip(node_hostname_list,node_list))
+ try :
+ liste =job_info[node_list_k]
+ for k in range(len(liste)):
+ job_info[node_list_k][k] = node_dict[job_info[node_list_k][k]]['hostname']