Added DeleteJobs in SlabDriver.
authorSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 23 Feb 2012 16:06:30 +0000 (17:06 +0100)
committerSandrine Avakian <sandrine.avakian@inria.fr>
Thu, 23 Feb 2012 16:06:30 +0000 (17:06 +0100)
Fixed the OAR/EH/Hibernate/java lib  problem by using dirty
hardcoded username in the code.(original senslab account savakian
behaves really weird and cannot be deleted entirely
from the rpod senslab platform. Using new account avakian
but sfa BD is not synchronized with senslab prod LDAP:
avakian not existing in sfa.Using savakian slice and avakian for
oar etc...)

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

index da10b0e..69f1721 100644 (file)
@@ -27,15 +27,18 @@ OARrequests_get_uri_dict = { 'GET_version': '/oarapi/version.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_resources_id': '/oarapi/resources/id.json',
                        'GET_jobs_table': '/oarapi/jobs/table.json',
                        'GET_jobs_details': '/oarapi/jobs/details.json',
                        'GET_resources_full': '/oarapi/resources/full.json',
                        'GET_resources':'/oarapi/resources.json',
                         
+                        
 }
 
-OARrequest_post_uri_dict = { 'POST_job': '/oarapi/jobs.json'}
+OARrequest_post_uri_dict = { 
+                            'POST_job':{'uri': '/oarapi/jobs.json'},
+                            'DELETE_jobs_id':{'uri':'/oarapi/jobs/id.json'},}
 
 POSTformat = {  #'yaml': {'content':"text/yaml", 'object':yaml}
 'json' : {'content':"application/json",'object':json}, 
@@ -59,16 +62,14 @@ class OARrestapi:
             
     def GETRequestToOARRestAPI(self, request, strval=None  ): 
         self.oarserver['uri'] = OARrequests_get_uri_dict[request] 
-        #if request is "GET_jobs_details":
-            #data = json.dumps([])
-        #else:
+
         data = json.dumps({})
         if strval:
           self.oarserver['uri'] = self.oarserver['uri'].replace("id",str(strval))
           print>>sys.stderr, "\r\n \r\n   GETRequestToOARRestAPI replace :  self.oarserver['uri'] %s",  self.oarserver['uri']
         
         try :  
-            headers = {'X-REMOTE_IDENT':'savakian',\
+            headers = {'X-REMOTE_IDENT':'avakian',\
             'content-length':'0'}
             #conn = httplib.HTTPConnection(self.oarserver['ip'],self.oarserver['port'])
             #conn.putheader(headers)
@@ -91,21 +92,32 @@ class OARrestapi:
         except ValueError:
             raise ServerError("Failed to parse Server Response:" + js)
 
-   
                
     def POSTRequestToOARRestAPI(self, request, datadict, username=None):
         #first check that all params for are OK 
-      
+        
         print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI username",username
         try:
-            self.oarserver['uri'] = OARrequest_post_uri_dict[request] 
+            self.oarserver['uri'] = OARrequest_post_uri_dict[request]['uri']
+            print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI rq %s datadict %s  " % ( self.oarserver['uri'] ,datadict)
+
         except:
             print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI request not in OARrequest_post_uri_dict"
             return
+        try:
+            print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI  %s " %( 'strval' in datadict)
+            if datadict and 'strval' in datadict:
+                self.oarserver['uri'] = self.oarserver['uri'].replace("id",str(datadict['strval']))
+                print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI REPLACE OK %s"%(self.oarserver['uri'])
+                del datadict['strval']
+                print>>sys.stderr, " \r\n \r\n \t POSTRequestToOARRestAPI datadict %s  rq %s" %(datadict, self.oarserver['uri'] )
+        except:
+            print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI ERRRRRORRRRRR "
+            return
         #if format in POSTformat:
             #if format is 'json':
         data = json.dumps(datadict)
-        headers = {'X-REMOTE_IDENT':username,\
+        headers = {'X-REMOTE_IDENT':'avakian',\
                 'content-type':POSTformat['json']['content'],\
                 'content-length':str(len(data))}     
         try :
@@ -251,7 +263,8 @@ class OARGETParser:
         self.ParseNodes()
        
         
-            
+    def ParseDeleteJobs(self):
+        return  
             
     def ParseResourcesFull(self ) :
         print>>sys.stderr, " \r\n \t\t\t  ParseResourcesFull_____________________________ "
@@ -350,6 +363,7 @@ class OARGETParser:
         'GET_jobs_details': {'uri':'/oarapi/jobs/details.json','parse_func': ParseJobsDetails},
         'GET_resources_full': {'uri':'/oarapi/resources/full.json','parse_func': ParseResourcesFull},
         'GET_resources':{'uri':'/oarapi/resources.json' ,'parse_func': ParseResources},
+        'DELETE_jobs_id':{'uri':'/oarapi/jobs/id.json' ,'parse_func': ParseDeleteJobs}
         }
 
     
index 7154c01..21f57a2 100644 (file)
@@ -376,7 +376,16 @@ class SlabDriver(Driver):
         return time
     
 
-            
+    def DeleteJobs(self, job_id):
+        if not job_id:
+            return
+        reqdict = {}
+        reqdict['method'] = "delete"
+        reqdict['strval'] = str(job_id)
+        answer = self.oar.POSTRequestToOARRestAPI('DELETE_jobs_id',reqdict,'avakian')
+        print>>sys.stderr, "\r\n \r\n  jobid  DeleteJobs %s "  %(answer)
+        
+                
     def GetJobs(self,job_id= None, resources=True,return_fields=None):
         #job_resources=['reserved_resources', 'assigned_resources','job_id', 'job_uri', 'assigned_nodes',\
         #'api_timestamp']
@@ -586,14 +595,14 @@ class SlabDriver(Driver):
             #site_list.append( l[0] )
         reqdict['property'] =  reqdict['property'][0: len( reqdict['property'])-2] +")"
         reqdict['resource'] ="network_address="+ str(len(nodeid_list))
-        reqdict['resource']+= ",walltime=" + str(00) + ":" + str(05) + ":" + str(00)
-        reqdict['script_path'] = "/bin/sleep 400"
+        reqdict['resource']+= ",walltime=" + str(00) + ":" + str(10) + ":" + str(00)
+        reqdict['script_path'] = "/bin/sleep 600"
         reqdict['type'] = "deploy" 
         timestamp = self.GetTimezone()
 
         readable_time = strftime(self.time_format, gmtime(float(timestamp))) 
         print >>sys.stderr," \r\n \r\n \t\t\t\t AVANT ParseTimezone readable_time %s timestanp %s " %(readable_time, timestamp )
-        timestamp =  timestamp+ 3780 #Add 3 min to server time
+        timestamp =  timestamp+ 3645 #Add 3 min to server time
         readable_time = strftime(self.time_format, gmtime(float(timestamp))) 
 
         print >>sys.stderr,"  \r\n \r\n \t\t\t\tAPRES ParseTimezone readable_time %s timestanp %s  " %(readable_time , timestamp)
@@ -601,8 +610,8 @@ class SlabDriver(Driver):
          
         # first step : start the OAR job
         print>>sys.stderr, "\r\n \r\n AddSliceToNodes reqdict   %s \r\n site_list   %s"  %(reqdict,site_list)   
-        OAR = OARrestapi()
-        answer = OAR.POSTRequestToOARRestAPI('POST_job',reqdict,slice_user)
+        #OAR = OARrestapi()
+        answer = self.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)
         
@@ -624,7 +633,7 @@ class SlabDriver(Driver):
         javacmdline="/usr/bin/java"
         jarname="/opt/senslabexperimentwrapper/sfa-1.0-jar-with-dependencies.jar"
         #ret=subprocess.check_output(["/usr/bin/java", "-jar", ", str(jobid), slice_user])
-        output = subprocess.Popen([javacmdline, "-jar", jarname, str(jobid), slice_user],stdout=subprocess.PIPE).communicate()[0]
+        output = subprocess.Popen([javacmdline, "-jar", jarname, str(jobid), "avakian"],stdout=subprocess.PIPE).communicate()[0]
 
         print>>sys.stderr, "\r\n \r\n AddSliceToNodes wrapper returns   %s "  %(output)
         return