Merge Master in geni-v3 conflict resolution
[sfa.git] / sfa / senslab / slabpostgres.py
index 412d066..ca21776 100644 (file)
@@ -20,75 +20,62 @@ CASCADE ON UPDATE CASCADE','oar_job_id':'integer DEFAULT -1',  \
 'record_id_slice':'integer', 'slice_hrn':'text NOT NULL'}
 
 #Dict with all the specific senslab tables
-tablenames_dict = {'slice_senslab': slice_table}
+tablenames_dict = {'slab_xp': slice_table}
 
 
 SlabBase = declarative_base()
 
-class SliceSenslab (SlabBase):
+
+        
+class SenslabXP (SlabBase):
     """ SQL alchemy class to manipulate slice_senslab table in 
     slab_sfa database.
     
     """
-    __tablename__ = 'slice_senslab' 
-    #record_id_user = Column(Integer, primary_key=True)
+    __tablename__ = 'slab_xp' 
+
+
+    slice_hrn = Column(String)
+    job_id = Column(Integer, primary_key = True)
+    end_time = Column(Integer, nullable = False)
 
-    slice_hrn = Column(String, primary_key=True)
-    peer_authority = Column(String, nullable = True)
-    record_id_slice = Column(Integer)    
-    record_id_user = Column(Integer) 
 
     #oar_job_id = Column( Integer,default = -1)
     #node_list = Column(postgresql.ARRAY(String), nullable =True)
     
-    def __init__ (self, slice_hrn =None, record_id_slice=None, \
-                                    record_id_user= None,peer_authority=None):
+    def __init__ (self, slice_hrn =None, job_id=None,  end_time=None):
         """
         Defines a row of the slice_senslab table
         """
-        if record_id_slice: 
-            self.record_id_slice = record_id_slice
         if slice_hrn:
             self.slice_hrn = slice_hrn
-        if record_id_user: 
-            self.record_id_user = record_id_user
-        if peer_authority:
-            self.peer_authority = peer_authority
+        if job_id :
+            self.job_id = job_id
+        if end_time:
+            self.end_time = end_time
             
             
     def __repr__(self):
         """Prints the SQLAlchemy record to the format defined
         by the function.
         """
-        result="<Record id user =%s, slice hrn=%s, Record id slice =%s , \
-                peer_authority =%s"% (self.record_id_user, self.slice_hrn, \
-                self.record_id_slice, self.peer_authority)
+        result = "<slab_xp : slice_hrn = %s , job_id %s end_time = %s" \
+            %(self.slice_hrn, self.job_id, self.end_time)
         result += ">"
         return result
           
-    def dump_sqlalchemyobj_to_dict(self):
-        """Transforms a SQLalchemy record object to a python dictionary.
-        Returns the dictionary.
-        """
-        
-        dict = {'slice_hrn':self.slice_hrn,
-        'peer_authority':self.peer_authority,
-        'record_id':self.record_id_slice, 
-        'record_id_user':self.record_id_user,
-        'record_id_slice':self.record_id_slice, }
-        return dict 
-          
+   
           
 class SlabDB:
-    """ SQL Aclehmy connection class.
+    """ SQL Alchemy connection class.
     From alchemy.py
     """
-    def __init__(self,config, debug = False):
+    def __init__(self, config, debug = False):
         self.sl_base = SlabBase
         dbname = "slab_sfa"
         if debug == True :
             l_echo_pool = True
-            l_echo=True 
+            l_echo = True 
         else :
             l_echo_pool = False
             l_echo = False 
@@ -102,12 +89,12 @@ class SlabDB:
         # we indeed have /var/lib/pgsql/data/postgresql.conf where
         # this setting is unset, it might be an angle to tweak that if need be
         # try a unix socket first - omitting the hostname does the trick
-        unix_url = "postgresql+psycopg2://%s:%s@:%s/%s"%\
+        unix_url = "postgresql+psycopg2://%s:%s@:%s/%s"% \
             (config.SFA_DB_USER, config.SFA_DB_PASSWORD, \
                                     config.SFA_DB_PORT, dbname)
 
         # the TCP fallback method
-        tcp_url = "postgresql+psycopg2://%s:%s@%s:%s/%s"%\
+        tcp_url = "postgresql+psycopg2://%s:%s@%s:%s/%s"% \
             (config.SFA_DB_USER, config.SFA_DB_PASSWORD, config.SFA_DB_HOST, \
                                     config.SFA_DB_PORT, dbname)
         for url in [ unix_url, tcp_url ] :
@@ -144,16 +131,15 @@ class SlabDB:
             self.slab_session = Session(bind = self.slab_engine)
         return self.slab_session
         
-       
-    def close(self):
+    def close_session(self): 
         """
         Closes connection to database. 
         
         """
-        if self.connection is not None:
-            self.connection.close()
-            self.connection = None
-            
+        if self.slab_session is None: return
+        self.slab_session.close()
+        self.slab_session = None   
+        
 
     def exists(self, tablename):
         """
@@ -172,10 +158,10 @@ class SlabDB:
             return False
        
     
-    def createtable(self, tablename ):
+    def createtable(self):
         """
-        Creates the specifed table. Uses the global dictionnary holding the 
-        tablenames and the table schema.
+        Creates all the table sof the engine.  
+        Uses the global dictionnary holding the tablenames and the table schema.
     
         """
 
@@ -185,7 +171,6 @@ class SlabDB:
         return
     
 
-from sfa.util.config import Config
 
 slab_alchemy = SlabDB(Config())
 slab_engine = slab_alchemy.slab_engine