Changeset 875 for trunk/Monitoring/smon
- Timestamp:
- 06/11/13 15:05:18 (11 years ago)
- Location:
- trunk/Monitoring/smon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/smon/local_repo.py
r871 r875 26 26 raise Exception() 27 27 28 _conn=sqlite3.connect(":memory:",timeout) 28 db_file="/home/jripsl/supervisor/local_db/local_repo.db" 29 #db_file=":memory:" 30 31 _conn=sqlite3.connect(db_file,timeout) 29 32 30 33 create_tables() … … 40 43 _conn=None 41 44 45 def commit(): 46 """ 47 public method 48 49 not used for now 50 """ 51 _conn.commit() 52 53 def rollback(): 54 _conn.rollback() 55 42 56 def create_tables(): 43 57 44 _conn.execute("create table simulation (id INTEGER PRIMARY KEY, nameTEXT)")45 _conn.execute("create unique index i dx_simulationon simulation (name)")58 _conn.execute("create table if not exists simulation (id INTEGER PRIMARY KEY, name TEXT, status TEXT)") 59 _conn.execute("create unique index if not exists idx_simulation_1 on simulation (name)") 46 60 47 _conn.execute("create table message (id INTEGER PRIMARY KEY, simulation_id TEXT)") # TODO: check how to use INT datatype for simulation_id column 61 _conn.execute("create table if not exists message (id INTEGER PRIMARY KEY, simulation_id TEXT)") # TODO: check how to use INT datatype for simulation_id column 62 63 def cleanup(): 64 _conn.execute("delete from simulation") 65 _conn.execute("delete from message") 66 _conn.commit() 48 67 49 68 def populate_tables_with_sample(): 50 69 51 rows = [('SIMU-001',), 52 ('SIMU-002',), 53 ('SIMU-003',),] 54 _conn.executemany('INSERT INTO simulation (name) VALUES (?)', rows) 70 rows = [('SIMU-001','running'), 71 ('SIMU-002','running'), 72 ('SIMU-003','running'),] 73 74 _conn.executemany('INSERT INTO simulation (name,status) VALUES (?,?)', rows) 75 76 _conn.commit() 55 77 56 78 def retrieve_simulations(): … … 58 80 c=_conn.cursor() 59 81 60 c.execute("select name,id from simulation")82 c.execute("select name,id,status from simulation") 61 83 62 84 rs=c.fetchone() 63 85 while rs is not None: 64 li.append(types.Simulation(name=rs[0],id=rs[1] ))86 li.append(types.Simulation(name=rs[0],id=rs[1],status=rs[2])) 65 87 rs=c.fetchone() 66 88 … … 70 92 c=_conn.cursor() 71 93 72 c.execute("select name,id from simulation where name = ?",(name,))94 c.execute("select name,id,status from simulation where name = ?",(name,)) 73 95 74 96 rs=c.fetchone() … … 77 99 raise Exception() 78 100 79 return types.Simulation( id=rs[1])101 return types.Simulation(name=rs[0],id=rs[1],status=rs[2]) 80 102 81 103 def delete_simulation(simulation): 82 104 _conn.execute("delete from simulation where name = ?",(simulation.name,)) 83 105 106 _conn.commit() 107 84 108 def create_simulation(simulation): 85 _conn.execute("insert into simulation (name) values (?)",(simulation.name,)) 109 _conn.execute("insert into simulation (name,status) values (?,?)",(simulation.name,simulation.status)) 110 111 _conn.commit() 86 112 87 113 def update_simulation_status(simulation): 88 114 _conn.execute("update simulation set status=? where name = ?",(simulation.status,simulation.name)) 115 116 _conn.commit() 89 117 90 118 def retrieve_messages(simulation): … … 105 133 _conn.execute("delete from message where simulation_id = ?",(simulation.id,)) 106 134 135 _conn.commit() 136 107 137 def create_message(message): 108 138 _conn.execute("insert into message (simulation_id) values (?)",(message.simuid,)) 139 140 _conn.commit() 109 141 110 142 def retrieve_last_message(simulation): -
trunk/Monitoring/smon/repo_io.py
r871 r875 87 87 88 88 def test(): 89 """ 90 not used 91 """ 92 89 93 repo.create_message("test2", 2, "bla2") 90 94 commit() … … 95 99 repo.create_message("test3", 3, "bla3") 96 100 rollback() 101 102 def cleanup(): 103 if mode==CSTE_MODE_LOCAL_REPO: 104 repo.cleanup() 105 elif mode==CSTE_MODE_REMOTE_REPO: 106 raise Exception("ERR707") 107 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 108 pass 109 else: 110 raise Exception("ERR007 - incorrect mode") 97 111 98 112 def commit(): -
trunk/Monitoring/smon/types.py
r866 r875 48 48 49 49 class Message(): 50 file=None 50 51 51 52 def __init__(self,JSON_KW):
Note: See TracChangeset
for help on using the changeset viewer.