Handle slice table update upon creation of a job.
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 15 Dec 2011 10:28:27 +0000 (11:28 +0100)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 15 Dec 2011 10:28:27 +0000 (11:28 +0100)
Bug fix in the update request in slabpostgres.py.
Added other OAR get requests in OARrestapi.

sfa/senslab/OARrestapi.py
sfa/senslab/slabdriver.py
sfa/senslab/slabpostgres.py

index 1769f1f..a073b67 100644 (file)
@@ -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<id>': '/oarapi/jobs/id.json',
+                        'GET_jobs<id>/resources': '/oarapi/jobs/id/resources.json',
+                        'GET_resources/<id>': '/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'] )
index bf62a98..47788c5 100644 (file)
@@ -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'])
index f24d0b8..ac9f994 100644 (file)
@@ -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()