From 03dc21a0ac95b4fbe8c950c8dc052955d281cc44 Mon Sep 17 00:00:00 2001 From: Sandrine Avakian Date: Thu, 15 Dec 2011 11:28:27 +0100 Subject: [PATCH] Handle slice table update upon creation of a job. Bug fix in the update request in slabpostgres.py. Added other OAR get requests in OARrestapi. --- sfa/senslab/OARrestapi.py | 9 ++++++++- sfa/senslab/slabdriver.py | 13 ++++++++----- sfa/senslab/slabpostgres.py | 11 +++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/sfa/senslab/OARrestapi.py b/sfa/senslab/OARrestapi.py index 1769f1fc..a073b67a 100644 --- a/sfa/senslab/OARrestapi.py +++ b/sfa/senslab/OARrestapi.py @@ -21,6 +21,9 @@ OARrequests_uri_list = ['/oarapi/version.json','/oarapi/timezone.json', '/oarapi OARrequests_get_uri_dict = { 'GET_version': '/oarapi/version.json', 'GET_timezone':'/oarapi/timezone.json' , 'GET_jobs': '/oarapi/jobs.json', + 'GET_jobs': '/oarapi/jobs/id.json', + 'GET_jobs/resources': '/oarapi/jobs/id/resources.json', + 'GET_resources/': '/oarapi/resources/.json', 'GET_jobs_table': '/oarapi/jobs/table.json', 'GET_jobs_details': '/oarapi/jobs/details.json', 'GET_resources_full': '/oarapi/resources/full.json', @@ -44,8 +47,12 @@ class OARrestapi: self.oarserver['uri'] = None self.oarserver['postformat'] = 'json' - def GETRequestToOARRestAPI(self, request ): + def GETRequestToOARRestAPI(self, request, strval=None ): self.oarserver['uri'] = OARrequests_get_uri_dict[request] + if strval: + self.oarserver['uri'] = self.oarserver['uri'].replace("id",strval) + print>>sys.stderr, "\r\n \r\n GETRequestToOARRestAPI replace : self.oarserver['uri'] %s", self.oarserver['uri'] + try : conn = httplib.HTTPConnection(self.oarserver['ip'],self.oarserver['port']) conn.request("GET",self.oarserver['uri'] ) diff --git a/sfa/senslab/slabdriver.py b/sfa/senslab/slabdriver.py index bf62a989..47788c5f 100644 --- a/sfa/senslab/slabdriver.py +++ b/sfa/senslab/slabdriver.py @@ -51,6 +51,7 @@ class SlabDriver (): self.ldap = LDAPapi() self.users = SenslabImportUsers() self.time_format = "%Y-%m-%d %H:%M:%S" + self.db = SlabDB() #self.logger=sfa_logger() @@ -95,9 +96,9 @@ class SlabDriver (): return return_site_list def GetSlices(self,slice_filter = None, return_fields=None): - db = SlabDB() + return_slice_list =[] - sliceslist = db.find('slice',columns = ['slice_hrn', 'record_id_slice','record_id_user']) + sliceslist = self.db.find('slice',columns = ['slice_hrn', 'record_id_slice','record_id_user']) print >>sys.stderr, " \r\n \r\n SLABDRIVER.PY GetSlices slices %s" %(sliceslist) #slicesdict = sliceslist[0] if not (slice_filter or return_fields): @@ -270,7 +271,9 @@ class SlabDriver (): print>>sys.stderr, "\r\n \r\n AddSliceToNodes reqdict %s \r\n site_list %s" %(reqdict,site_list) OAR = OARrestapi() - OAR.POSTRequestToOARRestAPI('POST_job',reqdict,slice_user) + answer = OAR.POSTRequestToOARRestAPI('POST_job',reqdict,slice_user) + print>>sys.stderr, "\r\n \r\n AddSliceToNodes jobid %s " %(answer) + self.db.update('slice',['oar_job_id'], [answer['id']], 'slice_hrn', slice_name) return @@ -485,9 +488,9 @@ class SlabDriver (): if records['type'] == 'slice': - db = SlabDB() + sfatable = SfaTable() - recslice = db.find('slice',str(records['hrn'])) + recslice = self.db.find('slice',str(records['hrn'])) if isinstance(recslice,list) and len(recslice) == 1: recslice = recslice[0] recuser = sfatable.find( recslice['record_id_user'], ['hrn']) diff --git a/sfa/senslab/slabpostgres.py b/sfa/senslab/slabpostgres.py index f24d0b8a..ac9f9943 100644 --- a/sfa/senslab/slabpostgres.py +++ b/sfa/senslab/slabpostgres.py @@ -199,6 +199,7 @@ class SlabDB: """ #Creates the values string for the update SQL command + vclause = valueclause if len(column_names) is not len(values): return else: @@ -206,12 +207,14 @@ class SlabDB: valuesdict = dict(zip(column_names,values)) for k in valuesdict.keys(): valuesdict[k] = str(valuesdict[k]) - v = ' \''+ str(k) + '\''+ '='+' \''+ valuesdict[k]+'\'' + #v = ' \''+ str(k) + '\''+ '='+' \''+ valuesdict[k]+'\'' + v = str(k) + '=' + valuesdict[k] valueslist.append(v) - + if isinstance(vclause,str): + vclause = '\''+ vclause + '\'' statement = "UPDATE %s SET %s WHERE %s = %s" % \ - (table, ", ".join(valueslist), whereclause, valueclause) - + (table, ", ".join(valueslist), whereclause, vclause) + print>>sys.stderr,"\r\n \r\n SLABPOSTGRES.PY update statement %s valuesdict %s valueslist %s" %(statement,valuesdict,valueslist) mark = self.cursor() mark.execute(statement) self.connection.commit() -- 2.43.0