1 | # -*- coding: ISO-8859-1 -*- |
---|
2 | |
---|
3 | ################################## |
---|
4 | # @program smon |
---|
5 | # @description simulation monitor |
---|
6 | # @copyright Copyright â(c)2009 Centre National de la Recherche Scientifique CNRS. |
---|
7 | # All Rights Reservedâ |
---|
8 | # @svn_file $Id: repo_io.py 2599 2013-03-24 19:01:23Z jripsl $ |
---|
9 | # @version $Rev: 2599 $ |
---|
10 | # @lastrevision $Date: 2013-03-24 20:01:23 +0100 (Sun, 24 Mar 2013) $ |
---|
11 | # @license CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE) |
---|
12 | ################################## |
---|
13 | |
---|
14 | """ |
---|
15 | This module contains repository I/O code |
---|
16 | """ |
---|
17 | |
---|
18 | import sys |
---|
19 | |
---|
20 | # 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 | # set mode |
---|
28 | mode="local_repo" # local_repo, remote_repo, remote_repo__stub |
---|
29 | |
---|
30 | # set repository driver |
---|
31 | if mode=="remote_repo__stub": |
---|
32 | import prodiguer_shared.repo.mq.hooks_stub as mq_hooks |
---|
33 | elif mode=="remote_repo": |
---|
34 | import prodiguer_shared.repo.mq.hooks as mq_hooks |
---|
35 | elif mode=="local_repo": |
---|
36 | import local_repo_hooks as mq_hooks |
---|
37 | else: |
---|
38 | raise Exception("ERR001 - incorrect mode") |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" |
---|
45 | |
---|
46 | def init(): |
---|
47 | if mode=="local_repo": |
---|
48 | pass |
---|
49 | elif mode=="remote_repo": |
---|
50 | prodiguer_shared.connect(_CONNECTION) |
---|
51 | elif mode=="remote_repo__stub": |
---|
52 | pass |
---|
53 | else: |
---|
54 | raise Exception("ERR004 - incorrect mode") |
---|
55 | |
---|
56 | def test(): |
---|
57 | mq_hooks.create_message("test2", 2, "bla2") |
---|
58 | commit() |
---|
59 | |
---|
60 | mq_hooks.update_simulation_status('1pctCO22', 'ERROR') |
---|
61 | commit() |
---|
62 | |
---|
63 | mq_hooks.create_message("test3", 3, "bla3") |
---|
64 | rollback() |
---|
65 | |
---|
66 | def commit(): |
---|
67 | if mode=="local_repo": |
---|
68 | pass |
---|
69 | elif mode=="remote_repo": |
---|
70 | elixir.session.commit() |
---|
71 | elif mode=="remote_repo__stub": |
---|
72 | pass |
---|
73 | else: |
---|
74 | raise Exception("ERR002 - incorrect mode") |
---|
75 | |
---|
76 | def rollback(): |
---|
77 | if mode=="local_repo": |
---|
78 | pass |
---|
79 | elif mode=="remote_repo": |
---|
80 | elixir.session.rollback() |
---|
81 | elif mode=="remote_repo__stub": |
---|
82 | pass |
---|
83 | else: |
---|
84 | raise Exception("ERR003 - incorrect mode") |
---|
85 | |
---|
86 | def retrieve_simulation(name): |
---|
87 | mq_hooks.retrieve_simulation(name) |
---|
88 | |
---|
89 | def delete_simulation(name): |
---|
90 | mq_hooks.delete_simulation(name) |
---|
91 | |
---|
92 | 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 | """ |
---|
120 | |
---|
121 | # --- higher level methods --- # |
---|
122 | |
---|
123 | def get_running_simulations(): |
---|
124 | running_simulation=[] |
---|
125 | |
---|
126 | for s in retrieve_simulation(): |
---|
127 | if s.status=="running": |
---|
128 | running_simulation.append(s) |
---|
129 | |
---|
130 | return running_simulation |
---|