X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fiotlab%2Fiotlabpostgres.py;h=d454cbf71eab017737b49513400add6dfae071ef;hb=0a4f0ce95a763b227ed4b7c553804a1c072867d5;hp=3c65278b2c413510d4bed8552fb1f89c3da971d0;hpb=8f8fa64f4144bfc02a925dd08e23467342528e58;p=sfa.git diff --git a/sfa/iotlab/iotlabpostgres.py b/sfa/iotlab/iotlabpostgres.py index 3c65278b..d454cbf7 100644 --- a/sfa/iotlab/iotlabpostgres.py +++ b/sfa/iotlab/iotlabpostgres.py @@ -23,32 +23,32 @@ slice_table = {'record_id_user': 'integer PRIMARY KEY references X ON DELETE \ 'record_id_slice': 'integer', 'slice_hrn': 'text NOT NULL'} #Dict with all the specific iotlab tables -tablenames_dict = {'iotlab_xp': slice_table} +# tablenames_dict = {'testbed_xp': slice_table} -IotlabBase = declarative_base() +TestbedBase = declarative_base() -class IotlabXP (IotlabBase): +class TestbedXP (TestbedBase): """ SQL alchemy class to manipulate the rows of the slice_iotlab table in - iotlab_sfa database. Handles the records representation and creates the + lease_table database. Handles the records representation and creates the table if it does not exist yet. """ - __tablename__ = 'iotlab_xp' + __tablename__ = 'testbed_xp' slice_hrn = Column(String) - job_id = Column(Integer, primary_key=True) + experiment_id = Column(Integer, primary_key=True) end_time = Column(Integer, nullable=False) - def __init__(self, slice_hrn=None, job_id=None, end_time=None): + def __init__(self, slice_hrn=None, experiment_id=None, end_time=None): """ Defines a row of the slice_iotlab table """ if slice_hrn: self.slice_hrn = slice_hrn - if job_id: - self.job_id = job_id + if experiment_id: + self.experiment_id = experiment_id if end_time: self.end_time = end_time @@ -56,20 +56,20 @@ class IotlabXP (IotlabBase): """Prints the SQLAlchemy record to the format defined by the function. """ - result = " 0: - self.iotlab_session.query(IotlabXP).filter(IotlabXP.job_id.in_(deleted_jobs)).delete(synchronize_session='fetch') - self.iotlab_session.commit() + set_experiment_list_in_db = set(experiment_list_in_db) + + kept_experiments = set(experiment_list_from_testbed).intersection(set_experiment_list_in_db) + logger.debug("\r\n \t update_experiments_in_additional_sfa_db \ + experiment_list_in_db %s \r\n \ + experiment_list_from_testbed %s \ + kept_experiments %s " + % (set_experiment_list_in_db, + experiment_list_from_testbed, kept_experiments)) + deleted_experiments = set_experiment_list_in_db.difference( + kept_experiments) + deleted_experiments = list(deleted_experiments) + if len(deleted_experiments) > 0: + self.testbed_session.query(TestbedXP).filter(TestbedXP.job_id.in_(deleted_experiments)).delete(synchronize_session='fetch') + self.testbed_session.commit() return def __init__(self, config, debug=False): - self.sl_base = IotlabBase + self.sl_base = TestbedBase # Check whether we already have an instance - if IotlabDB._connection_singleton is None: - IotlabDB._connection_singleton = IotlabDB.Singleton(config, debug) + if TestbedAdditionalSfaDB._connection_singleton is None: + TestbedAdditionalSfaDB._connection_singleton = \ + TestbedAdditionalSfaDB.Singleton(config, debug) # Store instance reference as the only member in the handle - self._EventHandler_singleton = IotlabDB._connection_singleton + self._EventHandler_singleton = \ + TestbedAdditionalSfaDB._connection_singleton def __getattr__(self, aAttr): """ @@ -240,7 +249,7 @@ class IotlabDB(object): :rtype: bool """ - metadata = MetaData(bind=self.iotlab_engine) + metadata = MetaData(bind=self.testbed_engine) try: table = Table(tablename, metadata, autoload=True) return True @@ -257,8 +266,8 @@ class IotlabDB(object): """ - logger.debug("SLABPOSTGRES createtable \ - IotlabBase.metadata.sorted_tables %s \r\n engine %s" - % (IotlabBase.metadata.sorted_tables, self.iotlab_engine)) - IotlabBase.metadata.create_all(self.iotlab_engine) + logger.debug("IOTLABPOSTGRES createtable \ + TestbedBase.metadata.sorted_tables %s \r\n engine %s" + % (TestbedBase.metadata.sorted_tables, self.testbed_engine)) + TestbedBase.metadata.create_all(self.testbed_engine) return