Changeset 865
- Timestamp:
- 06/03/13 08:57:32 (11 years ago)
- Location:
- trunk/Monitoring
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/Watch/watch
r859 r865 23 23 from datetime import datetime 24 24 25 26 from smon import repo_io 25 # line below is to include "smon" package in the search path 26 sys.path.append("/home/jripsl/snapshot/Monitoring") 27 28 import smon.repo_io 27 29 28 30 -
trunk/Monitoring/smon/repo_io.py
r859 r865 25 25 import prodiguer_shared 26 26 27 28 29 30 CSTE_MODE_LOCAL_REPO="local_repo" 31 CSTE_MODE_REMOTE_REPO="remote_repo" 32 CSTE_MODE_REMOTE_REPO_STUB="remote_repo_stub" 33 27 34 # set mode 28 mode= "local_repo" # local_repo, remote_repo, remote_repo__stub35 mode=CSTE_MODE_LOCAL_REPO # CSTE_MODE_LOCAL_REPO, CSTE_MODE_REMOTE_REPO, CSTE_MODE_REMOTE_REPO_STUB 29 36 30 37 # set repository driver 31 if mode== "remote_repo__stub":32 import prodiguer_shared.repo.mq.hooks_stub as mq_hooks33 elif mode== "remote_repo":34 import prodiguer_shared.repo.mq.hooks as mq_hooks35 elif mode== "local_repo":36 import local_repo _hooks as mq_hooks38 if mode==CSTE_MODE_REMOTE_REPO_STUB: 39 import prodiguer_shared.repo.mq.hooks_stub as repo 40 elif mode==CSTE_MODE_REMOTE_REPO: 41 import prodiguer_shared.repo.mq.hooks as repo 42 elif mode==CSTE_MODE_LOCAL_REPO: 43 import local_repo as repo 37 44 else: 38 45 raise Exception("ERR001 - incorrect mode") … … 41 48 42 49 43 44 _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" 50 # -- methods -- # 45 51 46 52 def init(): 47 if mode=="local_repo": 48 pass 49 elif mode=="remote_repo": 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" 50 57 prodiguer_shared.connect(_CONNECTION) 51 elif mode== "remote_repo__stub":58 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 52 59 pass 53 60 else: 54 61 raise Exception("ERR004 - incorrect mode") 55 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 56 75 def test(): 57 mq_hooks.create_message("test2", 2, "bla2")76 repo.create_message("test2", 2, "bla2") 58 77 commit() 59 78 60 mq_hooks.update_simulation_status('1pctCO22', 'ERROR')79 repo.update_simulation_status('1pctCO22', 'ERROR') 61 80 commit() 62 81 63 mq_hooks.create_message("test3", 3, "bla3")82 repo.create_message("test3", 3, "bla3") 64 83 rollback() 65 84 66 85 def commit(): 67 if mode== "local_repo":68 pass69 elif mode== "remote_repo":86 if mode==CSTE_MODE_LOCAL_REPO: 87 local_repo.commit() 88 elif mode==CSTE_MODE_REMOTE_REPO: 70 89 elixir.session.commit() 71 elif mode== "remote_repo__stub":90 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 72 91 pass 73 92 else: … … 75 94 76 95 def rollback(): 77 if mode== "local_repo":78 pass79 elif mode== "remote_repo":96 if mode==CSTE_MODE_LOCAL_REPO: 97 local_repo.rollback() 98 elif mode==CSTE_MODE_REMOTE_REPO: 80 99 elixir.session.rollback() 81 elif mode== "remote_repo__stub":100 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 82 101 pass 83 102 else: … … 85 104 86 105 def retrieve_simulation(name): 87 mq_hooks.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 88 127 89 128 def delete_simulation(name): 90 mq_hooks.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") 91 146 92 147 def create_simulation(simulation): 93 mq_hooks.create_simulation(activity, 94 95 def update_simulation_status(name): 96 mq_hooks.update_simulation_status(name, 97 98 def retrieve_messages(name): 99 mq_hooks.retrieve_messages(name) 100 101 def delete_messages(name): 102 mq_hooks.delete_messages(name) 103 104 def create_message(name): 105 mq_hooks.create_message() 106 107 def retrieve_last_messages(simulation): 108 mq_hooks.retrieve_last_messages(simulation) 109 110 """ 111 from prodiguer_shared.models import ( 112 ExecutionState, 113 EXECUTION_STATE_RUNNING, 114 EXECUTION_STATE_SET, 115 Message, 116 Simulation, 117 SIMULATION_SPACE_TEST 118 ) 119 """ 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 120 269 121 270 # --- higher level methods --- # -
trunk/Monitoring/smon/types.py
r842 r865 36 36 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 37 37 38 class Simulation(): 39 40 def __init__(self,**kw): 41 self.exec_start_date=kw.get("exec_start_date") 42 self.exec_end_date=kw.get("exec_end_date") 43 self.status=kw.get("status") 44 45 def __str__(self): 46 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 47 38 48 class SimulationTree(Tree): 39 49
Note: See TracChangeset
for help on using the changeset viewer.