Changeset 866 for trunk/Monitoring/smon
- Timestamp:
- 06/09/13 23:52:36 (11 years ago)
- Location:
- trunk/Monitoring/smon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/smon/local_repo.py
r865 r866 40 40 def create_tables(): 41 41 _conn.execute("create table simulation (id INTEGER PRIMARY KEY, name TEXT)") 42 _conn.execute("create table message (id INTEGER PRIMARY KEY, simulation_id INT)")42 _conn.execute("create table message (id INTEGER PRIMARY KEY, simulation_id TEXT)") # TODO: check how to use INT datatype for simulation_id column 43 43 44 44 def retrieve_simulation(name): … … 81 81 82 82 def create_message(message): 83 _conn.execute("insert into message (simulation_id) values (?)",(message.simu lation_id,))83 _conn.execute("insert into message (simulation_id) values (?)",(message.simuid,)) 84 84 85 85 def retrieve_last_message(simulation): -
trunk/Monitoring/smon/repo_io.py
r865 r866 28 28 29 29 30 31 32 33 # -- methods -- # 34 35 def init(): 36 if mode==CSTE_MODE_LOCAL_REPO: 37 repo.connect() 38 elif mode==CSTE_MODE_REMOTE_REPO: 39 _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" 40 prodiguer_shared.connect(_CONNECTION) 41 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 42 pass 43 else: 44 raise Exception("ERR004 - incorrect mode") 45 46 def free(): 47 if mode==CSTE_MODE_LOCAL_REPO: 48 repo.close() 49 elif mode==CSTE_MODE_REMOTE_REPO: 50 51 #prodiguer_shared.close() 52 pass 53 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 54 pass 55 else: 56 raise Exception("ERR009 - incorrect mode") 57 58 def test(): 59 repo.create_message("test2", 2, "bla2") 60 commit() 61 62 repo.update_simulation_status('1pctCO22', 'ERROR') 63 commit() 64 65 repo.create_message("test3", 3, "bla3") 66 rollback() 67 68 def commit(): 69 if mode==CSTE_MODE_LOCAL_REPO: 70 repo.commit() 71 elif mode==CSTE_MODE_REMOTE_REPO: 72 elixir.session.commit() 73 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 74 pass 75 else: 76 raise Exception("ERR002 - incorrect mode") 77 78 def rollback(): 79 if mode==CSTE_MODE_LOCAL_REPO: 80 repo.rollback() 81 elif mode==CSTE_MODE_REMOTE_REPO: 82 elixir.session.rollback() 83 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 84 pass 85 else: 86 raise Exception("ERR003 - incorrect mode") 87 88 def retrieve_simulation(name): 89 simulation=None 90 91 if mode==CSTE_MODE_LOCAL_REPO: 92 simulation=repo.retrieve_simulation(name) 93 elif mode==CSTE_MODE_REMOTE_REPO: 94 95 # prepare args 96 # .. 97 98 # execute 99 s=repo.retrieve_simulation(name) 100 101 # process return values 102 simulation=smon.types.Simulation(exec_start_date=s.ExecutionStartDate,exec_end_date=s.ExecutionEndDate,status=s.ExecutionState) # ExecutionState example: EXECUTION_STATE_RUNNING, EXECUTION_STATE_SET.. 103 104 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 105 pass 106 else: 107 raise Exception("ERR014 - incorrect mode") 108 109 return simulation 110 111 def delete_simulation(name): 112 if mode==CSTE_MODE_LOCAL_REPO: 113 repo.delete_simulation(name) 114 elif mode==CSTE_MODE_REMOTE_REPO: 115 116 # prepare args 117 # .. 118 119 # execute 120 repo.delete_simulation(name) 121 122 # process return values 123 # .. 124 125 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 126 pass 127 else: 128 raise Exception("ERR015 - incorrect mode") 129 130 def create_simulation(simulation): 131 if mode==CSTE_MODE_LOCAL_REPO: 132 repo.create_simulation(simulation) 133 elif mode==CSTE_MODE_REMOTE_REPO: 134 135 # prepare args 136 # .. 137 138 # execute 139 repo.create_simulation(activity) 140 141 # process return values 142 # .. 143 144 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 145 pass 146 else: 147 raise Exception("ERR016 - incorrect mode") 148 149 def update_simulation_status(simulation): 150 if mode==CSTE_MODE_LOCAL_REPO: 151 repo.update_simulation_status(simulation) 152 elif mode==CSTE_MODE_REMOTE_REPO: 153 154 # prepare args 155 # .. 156 157 # execute 158 repo.update_simulation_status(name) 159 160 # process return values 161 # .. 162 163 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 164 pass 165 else: 166 raise Exception("ERR017 - incorrect mode") 167 168 def retrieve_messages(simulation): 169 message=None 170 171 if mode==CSTE_MODE_LOCAL_REPO: 172 message=repo.retrieve_messages(simulation) 173 elif mode==CSTE_MODE_REMOTE_REPO: 174 175 # prepare args 176 # .. 177 178 # execute 179 repo.retrieve_messages(name) 180 181 # process return values 182 # .. 183 184 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 185 pass 186 else: 187 raise Exception("ERR018 - incorrect mode") 188 189 return message 190 191 def delete_messages(simulation): 192 if mode==CSTE_MODE_LOCAL_REPO: 193 repo.delete_messages(name) 194 elif mode==CSTE_MODE_REMOTE_REPO: 195 196 # prepare args 197 # .. 198 199 # execute 200 repo.delete_messages(name) 201 202 # process return values 203 # .. 204 205 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 206 pass 207 else: 208 raise Exception("ERR019 - incorrect mode") 209 210 def create_message(message): 211 if mode==CSTE_MODE_LOCAL_REPO: 212 repo.create_message(message) 213 elif mode==CSTE_MODE_REMOTE_REPO: 214 215 # prepare args 216 # .. 217 218 # execute 219 repo.create_message() 220 221 # process return values 222 # .. 223 224 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 225 pass 226 else: 227 raise Exception("ERR020 - incorrect mode") 228 229 def retrieve_last_message(simulation): 230 message=None 231 232 if mode==CSTE_MODE_LOCAL_REPO: 233 message=repo.retrieve_last_message(simulation) 234 elif mode==CSTE_MODE_REMOTE_REPO: 235 236 # prepare args 237 # .. 238 239 # execute 240 repo.retrieve_last_message(simulation) 241 242 # process return values 243 # .. 244 245 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 246 pass 247 else: 248 raise Exception("ERR021 - incorrect mode") 249 250 return message 251 252 253 # --- higher level methods --- # 254 255 def get_running_simulations(): 256 running_simulation=[] 257 258 for s in retrieve_simulation(): 259 if s.status=="running": 260 running_simulation.append(s) 261 262 return running_simulation 263 264 265 # --- module init --- # 266 30 267 CSTE_MODE_LOCAL_REPO="local_repo" 31 268 CSTE_MODE_REMOTE_REPO="remote_repo" … … 46 283 47 284 48 49 50 # -- methods -- # 51 52 def init(): 53 if mode==CSTE_MODE_LOCAL_REPO: 54 local_repo.connect() 55 elif mode==CSTE_MODE_REMOTE_REPO: 56 _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" 57 prodiguer_shared.connect(_CONNECTION) 58 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 59 pass 60 else: 61 raise Exception("ERR004 - incorrect mode") 62 63 def free(): 64 if mode==CSTE_MODE_LOCAL_REPO: 65 local_repo.close() 66 elif mode==CSTE_MODE_REMOTE_REPO: 67 68 #prodiguer_shared.close() 69 pass 70 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 71 pass 72 else: 73 raise Exception("ERR009 - incorrect mode") 74 75 def test(): 76 repo.create_message("test2", 2, "bla2") 77 commit() 78 79 repo.update_simulation_status('1pctCO22', 'ERROR') 80 commit() 81 82 repo.create_message("test3", 3, "bla3") 83 rollback() 84 85 def commit(): 86 if mode==CSTE_MODE_LOCAL_REPO: 87 local_repo.commit() 88 elif mode==CSTE_MODE_REMOTE_REPO: 89 elixir.session.commit() 90 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 91 pass 92 else: 93 raise Exception("ERR002 - incorrect mode") 94 95 def rollback(): 96 if mode==CSTE_MODE_LOCAL_REPO: 97 local_repo.rollback() 98 elif mode==CSTE_MODE_REMOTE_REPO: 99 elixir.session.rollback() 100 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 101 pass 102 else: 103 raise Exception("ERR003 - incorrect mode") 104 105 def retrieve_simulation(name): 106 simulation=None 107 108 if mode==CSTE_MODE_LOCAL_REPO: 109 simulation=repo.retrieve_simulation(name) 110 elif mode==CSTE_MODE_REMOTE_REPO: 111 112 # prepare args 113 # .. 114 115 # execute 116 s=repo.retrieve_simulation(name) 117 118 # process return values 119 simulation=smon.types.Simulation(exec_start_date=s.ExecutionStartDate,exec_end_date=s.ExecutionEndDate,status=s.ExecutionState) # ExecutionState example: EXECUTION_STATE_RUNNING, EXECUTION_STATE_SET.. 120 121 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 122 pass 123 else: 124 raise Exception("ERR014 - incorrect mode") 125 126 return simulation 127 128 def delete_simulation(name): 129 if mode==CSTE_MODE_LOCAL_REPO: 130 repo.delete_simulation(name) 131 elif mode==CSTE_MODE_REMOTE_REPO: 132 133 # prepare args 134 # .. 135 136 # execute 137 repo.delete_simulation(name) 138 139 # process return values 140 # .. 141 142 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 143 pass 144 else: 145 raise Exception("ERR015 - incorrect mode") 146 147 def create_simulation(simulation): 148 if mode==CSTE_MODE_LOCAL_REPO: 149 repo.create_simulation(simulation) 150 elif mode==CSTE_MODE_REMOTE_REPO: 151 152 # prepare args 153 # .. 154 155 # execute 156 repo.create_simulation(activity) 157 158 # process return values 159 # .. 160 161 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 162 pass 163 else: 164 raise Exception("ERR016 - incorrect mode") 165 166 def update_simulation_status(simulation): 167 if mode==CSTE_MODE_LOCAL_REPO: 168 repo.update_simulation_status(simulation) 169 elif mode==CSTE_MODE_REMOTE_REPO: 170 171 # prepare args 172 # .. 173 174 # execute 175 repo.update_simulation_status(name) 176 177 # process return values 178 # .. 179 180 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 181 pass 182 else: 183 raise Exception("ERR017 - incorrect mode") 184 185 def retrieve_messages(simulation): 186 message=None 187 188 if mode==CSTE_MODE_LOCAL_REPO: 189 message=repo.retrieve_messages(simulation) 190 elif mode==CSTE_MODE_REMOTE_REPO: 191 192 # prepare args 193 # .. 194 195 # execute 196 repo.retrieve_messages(name) 197 198 # process return values 199 # .. 200 201 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 202 pass 203 else: 204 raise Exception("ERR018 - incorrect mode") 205 206 return message 207 208 def delete_messages(simulation): 209 if mode==CSTE_MODE_LOCAL_REPO: 210 repo.delete_messages(name) 211 elif mode==CSTE_MODE_REMOTE_REPO: 212 213 # prepare args 214 # .. 215 216 # execute 217 repo.delete_messages(name) 218 219 # process return values 220 # .. 221 222 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 223 pass 224 else: 225 raise Exception("ERR019 - incorrect mode") 226 227 def create_message(message): 228 if mode==CSTE_MODE_LOCAL_REPO: 229 repo.create_message(message) 230 elif mode==CSTE_MODE_REMOTE_REPO: 231 232 # prepare args 233 # .. 234 235 # execute 236 repo.create_message() 237 238 # process return values 239 # .. 240 241 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 242 pass 243 else: 244 raise Exception("ERR020 - incorrect mode") 245 246 def retrieve_last_message(simulation): 247 message=None 248 249 if mode==CSTE_MODE_LOCAL_REPO: 250 message=repo.retrieve_last_message(simulation) 251 elif mode==CSTE_MODE_REMOTE_REPO: 252 253 # prepare args 254 # .. 255 256 # execute 257 repo.retrieve_last_message(simulation) 258 259 # process return values 260 # .. 261 262 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 263 pass 264 else: 265 raise Exception("ERR021 - incorrect mode") 266 267 return message 268 269 270 # --- higher level methods --- # 271 272 def get_running_simulations(): 273 running_simulation=[] 274 275 for s in retrieve_simulation(): 276 if s.status=="running": 277 running_simulation.append(s) 278 279 return running_simulation 285 # note that by putting init() call here, it will only be called when first imported by the first import statement 286 init() 287 -
trunk/Monitoring/smon/types.py
r865 r866 2 2 3 3 ################################## 4 # @program 4 # @program smon 5 5 # @description simulation monitor 6 # @copyright 7 # 8 # @svn_file 9 # @version 6 # @copyright Copyright â(c)2009 Centre National de la Recherche Scientifique CNRS. 7 # All Rights Reservedâ 8 # @svn_file $Id: types.py 2599 2013-03-24 19:01:23Z jripsl $ 9 # @version $Rev: 2599 $ 10 10 # @lastrevision $Date: 2013-03-24 20:01:23 +0100 (Sun, 24 Mar 2013) $ 11 # @license 11 # @license CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE) 12 12 ################################## 13 13 … … 25 25 self.msg=msg 26 26 27 28 27 def __str__(self): 28 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 29 29 30 30 class Tree(): 31 31 32 32 def __init__(self,**kw): 33 33 pass 34 34 35 36 35 def __str__(self): 36 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 37 37 38 38 class Simulation(): 39 39 40 40 def __init__(self,**kw): 41 41 self.exec_start_date=kw.get("exec_start_date") 42 42 self.exec_end_date=kw.get("exec_end_date") 43 43 self.status=kw.get("status") 44 self.name=kw.get("name") 44 45 45 def __str__(self): 46 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 46 def __str__(self): 47 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 48 49 class Message(): 50 51 def __init__(self,JSON_KW): 52 for key in JSON_KW: 53 setattr(self, key, JSON_KW[key]) 54 55 def __str__(self): 56 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 47 57 48 58 class SimulationTree(Tree): 49 59 50 60 def __init__(self,**kw): 51 61 dg = nx.DiGraph() 52 62 53 63 def update(cls): 54 64 dg.add_edge('a','b') 55 56 def print (cls):57 print dg.edges() 65 66 def print__TODO(cls): 67 print dg.edges() 58 68 59 69 def write(cls): … … 63 73 dg = pickle.load(open('/tmp/graph.txt')) 64 74 65 66 75 def __str__(self): 76 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 67 77 68 78 class SimulationTrees(): 69 79 70 71 80 def __init__(self,**kw): 81 self.sample=kw.get("sample",[]) 72 82 73 74 83 def __str__(self): 84 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()])
Note: See TracChangeset
for help on using the changeset viewer.