source: trunk/Monitoring/smon/repo_io.py @ 859

Last change on this file since 859 was 859, checked in by jripsl, 11 years ago
  • add killed/segfault detection.
  • database communication implementation (suite).
  • trap BREAK signal to stop consumer before exiting.
File size: 2.9 KB
Line 
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"""
15This module contains repository I/O code
16"""
17
18import sys
19
20# line below is to include Prodiguer database I/O library in the search path
21sys.path.append("/home/jripsl/snapshot/src")
22
23# import Prodiguer database I/O library
24import elixir
25import prodiguer_shared
26
27# set mode
28mode="local_repo" # local_repo, remote_repo, remote_repo__stub
29
30# set repository driver
31if mode=="remote_repo__stub":
32        import prodiguer_shared.repo.mq.hooks_stub as mq_hooks
33elif mode=="remote_repo":
34        import prodiguer_shared.repo.mq.hooks as mq_hooks
35elif mode=="local_repo":
36        import local_repo_hooks as mq_hooks
37else:
38        raise Exception("ERR001 - incorrect mode")
39
40
41
42
43
44_CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer"
45
46def 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
56def 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
66def 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
76def 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
86def retrieve_simulation(name):
87        mq_hooks.retrieve_simulation(name)
88
89def delete_simulation(name):
90        mq_hooks.delete_simulation(name)
91
92def create_simulation(simulation):
93        mq_hooks.create_simulation(activity,
94
95def update_simulation_status(name):
96        mq_hooks.update_simulation_status(name,
97
98def retrieve_messages(name):
99        mq_hooks.retrieve_messages(name)
100
101def delete_messages(name):
102        mq_hooks.delete_messages(name)
103
104def create_message(name):
105        mq_hooks.create_message()
106
107def retrieve_last_messages(simulation):
108        mq_hooks.retrieve_last_messages(simulation)
109
110"""
111from 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
123def 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
Note: See TracBrowser for help on using the repository browser.