Changeset 879 for trunk/Monitoring/smon/repo_io.py
- Timestamp:
- 06/13/13 07:08:13 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/smon/repo_io.py
r877 r879 17 17 18 18 import sys 19 import datetime 19 20 20 21 # line below is to include Prodiguer database I/O library in the search path 21 sys.path.append("/home/jripsl/snapshot/src") 22 23 # import Prodiguer database I/O library 24 import elixir 25 import prodiguer_shared 26 27 28 29 30 22 sys.path.append("/home/jripsl/snapshot/src/prodiguer_shared/src") 23 24 25 import types 31 26 32 27 … … 37 32 CSTE_MODE_REMOTE_REPO_STUB="remote_repo_stub" 38 33 34 35 # HACK 36 import prodiguer_shared.repo.session as repo_session 37 import prodiguer_shared.models as models 38 39 40 # Test constants. 41 _SIM_ACTIVITY = 'IPSL' 42 _SIM_COMPUTE_NODE = 'TGCC' 43 _SIM_COMPUTE_NODE_LOGIN = 'p86denv' 44 _SIM_COMPUTE_NODE_MACHINE = 'TGCC - Curie' 45 _SIM_EXECUTION_START_DATE = datetime.datetime.now() 46 _SIM_EXECUTION_STATE = models.EXECUTION_STATE_RUNNING 47 _SIM_EXPERIMENT = '1pctCO2' 48 _SIM_MODEL_ENGINE = 'IPSL-CM5A-LR' 49 _SIM_SPACE = models.SIMULATION_SPACE_TEST 50 _MSG_TYPE = "0000" 51 _MSG_CONTENT1 = "12345690" 52 _MSG_CONTENT2 = "12345690" 53 54 55 56 57 58 59 39 60 # set mode 40 mode=CSTE_MODE_LOCAL_REPO # CSTE_MODE_LOCAL_REPO, CSTE_MODE_REMOTE_REPO, CSTE_MODE_REMOTE_REPO_STUB 61 mode=CSTE_MODE_REMOTE_REPO 62 #mode=CSTE_MODE_LOCAL_REPO 41 63 42 64 # set repository driver 43 65 if mode==CSTE_MODE_REMOTE_REPO_STUB: 44 import prodiguer_shared.repo.mq.hooks_stub as repo 66 raise Exception() 67 45 68 elif mode==CSTE_MODE_REMOTE_REPO: 46 import prodiguer_shared.repo.mq.hooks as repo 69 70 # import Prodiguer database I/O library 71 import prodiguer_shared.mq.hooks as repo 72 73 47 74 elif mode==CSTE_MODE_LOCAL_REPO: 48 75 import local_repo as repo … … 61 88 repo.connect() 62 89 elif mode==CSTE_MODE_REMOTE_REPO: 63 _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" 64 prodiguer_shared.connect(_CONNECTION) 90 _CONNECTION = "postgresql://postgres:Silence107!@ib-pp-db-dev.ipslnet:5432/pdgr_1_0b5" 91 repo_session.start(_CONNECTION) 92 65 93 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 66 94 pass … … 72 100 repo.free() 73 101 elif mode==CSTE_MODE_REMOTE_REPO: 74 75 #prodiguer_shared.close() 76 pass 102 repo_session.end() 77 103 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 78 104 pass … … 91 117 used by get_running_simulations 92 118 """ 93 return repo.retrieve_simulations() 119 simulations=None 120 121 # debug 122 #print "bla" 123 124 125 if mode==CSTE_MODE_LOCAL_REPO: 126 simulations=repo.retrieve_simulations() 127 elif mode==CSTE_MODE_REMOTE_REPO: 128 129 # prepare 130 simulations=[] 131 132 # execute 133 sims=repo.retrieve_simulations() 134 135 # process return values 136 137 for s in sims: 138 139 status=get_repo_execution_state(s.ExecutionState_ID) 140 141 # HACK 142 if status=="queued": 143 status="waiting" 144 145 146 147 simulations.append(types.Simulation(id=s.ID,name=s.Name,status=status.lower())) 148 149 150 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 151 pass 152 else: 153 raise Exception("ERR115 - incorrect mode") 154 155 156 # debug 157 """ 158 if len(simulations)<1: 159 raise Exception("ERR915 - debug") 160 else: 161 print "%d"%len(simulations) 162 """ 163 164 165 return simulations 94 166 95 167 def test(): … … 111 183 repo.cleanup() 112 184 elif mode==CSTE_MODE_REMOTE_REPO: 113 raise Exception("ERR707") 185 186 187 simulations_to_delete=["BIGBRO.clim.TEST.LMDZOR.p86denv.TGCC.CURIE", 188 "BIGBRO.clim.TEST.LMDZOR.p86denv.TGCC.CURIE", 189 "v5cf.amipMR1.amip.PROD.LMDZOR.p86denv.TGCC.CURIE", 190 "v5cf.amipMR2.amip.PROD.LMDZOR.p86denv.TGCC.CURIE", 191 "v5cf.amipMR3.amip.PROD.LMDZOR.p86denv.TGCC.CURIE"] 192 193 194 for s in simulations_to_delete: 195 repo.delete_messages(s) 196 repo.delete_simulation(s) 197 198 commit() 199 200 201 114 202 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 115 203 pass … … 121 209 repo.commit() 122 210 elif mode==CSTE_MODE_REMOTE_REPO: 123 elixir.session.commit()211 repo_session.commit() 124 212 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 125 213 pass … … 131 219 repo.rollback() 132 220 elif mode==CSTE_MODE_REMOTE_REPO: 133 elixir.session.rollback()221 repo_session.commit() 134 222 elif mode==CSTE_MODE_REMOTE_REPO_STUB: 135 223 pass 136 224 else: 137 225 raise Exception("ERR003 - incorrect mode") 226 227 def get_repo_execution_state(state_id): 228 for key, value in models.EXECUTION_STATE_ID_SET.items(): 229 if value == state_id: 230 return key 231 return None 138 232 139 233 def retrieve_simulation(name): … … 141 235 142 236 if mode==CSTE_MODE_LOCAL_REPO: 143 simulation=repo.retrieve_simulation(name) 237 238 try: 239 simulation=repo.retrieve_simulation(name) 240 except: 241 traceback.print_exc() 242 144 243 elif mode==CSTE_MODE_REMOTE_REPO: 145 244 … … 150 249 s=repo.retrieve_simulation(name) 151 250 152 # process return values 153 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.. 251 if s is None: 252 raise Exception("RG543534") 253 254 255 256 # process return values 257 258 status=get_repo_execution_state(s.ExecutionState_ID) 259 260 # HACK 261 if status=="queued": 262 status="waiting" 263 264 simulation=types.Simulation(id=s.ID,name=s.Name,status=status) 265 266 154 267 155 268 elif mode==CSTE_MODE_REMOTE_REPO_STUB: … … 185 298 186 299 # prepare args 187 # .. 188 189 # execute 190 repo.create_simulation(activity) 300 model_engine=None 301 space=None 302 exp=None 303 304 if "BIGBRO" in simulation.name: 305 306 model_engine="IPSL-CM5A-LR" 307 space="TEST" 308 exp="sstClim" 309 310 elif "v5cf.amipMR" in simulation.name: 311 312 model_engine="IPSL-CM5A-MR" 313 space="PROD" 314 exp="amip" 315 316 else: 317 318 model_engine=_SIM_MODEL_ENGINE 319 space=_SIM_SPACE 320 exp=_SIM_EXPERIMENT 321 322 323 # execute 324 repo.create_simulation(_SIM_ACTIVITY, 325 _SIM_COMPUTE_NODE, 326 _SIM_COMPUTE_NODE_LOGIN, 327 _SIM_COMPUTE_NODE_MACHINE, 328 _SIM_EXECUTION_START_DATE, 329 _SIM_EXECUTION_STATE, 330 exp, 331 model_engine, 332 simulation.name, 333 space, 334 parent_simulation_name=None) 335 191 336 192 337 # process return values … … 200 345 def update_simulation_status(simulation): 201 346 if mode==CSTE_MODE_LOCAL_REPO: 202 repo.update_simulation_status(simulation) 203 elif mode==CSTE_MODE_REMOTE_REPO: 204 205 # prepare args 206 # .. 207 208 # execute 209 repo.update_simulation_status(name) 210 211 # process return values 212 # .. 347 348 try: 349 repo.update_simulation_status(simulation) 350 except: 351 traceback.print_exc() 352 353 elif mode==CSTE_MODE_REMOTE_REPO: 354 355 # prepare args 356 # .. 357 358 359 # HACK 360 prodiguer_status=simulation.status 361 if simulation.status == "waiting": 362 prodiguer_status="queued" 363 364 365 # execute 366 repo.update_simulation_status(simulation.name, prodiguer_status.upper()) 367 368 # process return values 369 # .. 370 371 commit() 213 372 214 373 elif mode==CSTE_MODE_REMOTE_REPO_STUB: … … 267 426 # .. 268 427 269 # execute 270 repo.create_message() 428 print "%s %s %s"%(simulation.name,message.code,"message.body") 429 430 # execute 431 try: 432 repo.create_message(simulation.name,message.code,"message.body") 433 except ValueError as i: 434 print "bla (%s)"%str(i) 435 436 commit() 437 271 438 272 439 # process return values … … 277 444 else: 278 445 raise Exception("ERR020 - incorrect mode") 446 447 commit() 448 279 449 280 450 def retrieve_last_message(simulation): … … 285 455 elif mode==CSTE_MODE_REMOTE_REPO: 286 456 287 # prepare args 288 # .. 289 290 # execute 291 repo.retrieve_last_message(simulation) 292 293 # process return values 294 # .. 457 # execute 458 message=repo.retrieve_last_message(simulation.name) 459 460 if message is None: 461 raise Exception("ERR221 - null value") 462 463 # process return values 464 di={} 465 di["crea_date"]=message.CreateDate 466 message=types.Message(di) 295 467 296 468 elif mode==CSTE_MODE_REMOTE_REPO_STUB: … … 308 480 309 481 for s in retrieve_simulations(): 482 310 483 if s.status=="running": 311 484 running_simulation.append(s)
Note: See TracChangeset
for help on using the changeset viewer.