Changeset 866 for trunk/Monitoring


Ignore:
Timestamp:
06/09/13 23:52:36 (11 years ago)
Author:
jripsl
Message:

Add demo scenarios.

Location:
trunk/Monitoring
Files:
8 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Monitoring/Broker/README

    r854 r866  
    4545                - cd /opt/rabbitmq-server-3.0.2/sbin 
    4646                - ./rabbitmq-server -detached 
    47         - to stop the daemon, use this 
     47        - to stop the daemon, use one of those 
    4848                - kill -TERM $(pidof epmd) 
     49                - rabbitmqctl stop 
    4950- operation 
    5051        - to print RabbitMQ status, use 
  • trunk/Monitoring/CNClient/README

    r854 r866  
    1 - This program uses rabbitmq-c library (v0.3.0) 
     1- this program uses rabbitmq-c library (v0.3.0) 
    22        - https://github.com/alanxz/rabbitmq-c 
    3 - Compilation (static) 
    4         - Library installation 
    5                 - using system package 
    6                         - install using commands below 
    7                                 - aptitude install librabbitmq0 
    8                                 - aptitude install librabbitmq-dev 
    9                         - note that it is likely that system packages versions are out of date (we need v0.3.0) 
    10                           so better use installation from source 
    11                 - from source 
    12                         - retrieve source 
    13                                 - wget https://github.com/alanxz/rabbitmq-c/archive/rabbitmq-c-v0.3.0.zip -O rabbitmq-c-v0.3.0.zip 
    14                                 - unzip rabbitmq-c-v0.3.0.zip 
    15                                 - cd rabbitmq-c-v0.3.0 
    16                         - compilation using autoconf (automake v1.9+, and libtool v2.2+) 
    17                                 - autoreconf -i 
    18                                         - if error occurs at this step, check requirement below 
    19                                                 - we require autotools v2.63 or better to build. I think RHEL5 ships with v2.59 which lacks the AC_PROC_CC_C99 macro. 
    20                                                         - You can do one of two things; 
    21                                                                 - Install a newer version of autotools 
    22                                                                 - Build using cmake (v2.6 or better). 
    23                                 - ./configure --enable-static 
    24                                 - make 
    25                                 - make install 
    26                         - compilation using cmake (CMake v2.6+) 
    27                                 - mkdir build && cd build 
    28                                 - cmake -DBUILD_STATIC_LIBS=True -DBUILD_SHARED_LIBS=True .. 
    29                                 - cmake --build . 
    30                                 - make 
    31                                         - you got error AAA below, it's normal 
    32                                                 make[2]: *** Pas de rÚgle pour fabriquer la cible « librabbitmq/librabbitmq.so.1.0.1 », nécessaire pour « examples/amqp_bind ». Arrêt. 
    33                                                 make[1]: *** [examples/CMakeFiles/amqp_bind.dir/all] Erreur 2 
    34                                                 make: *** [all] Erreur 2 
    35                                 - make 
    36                                   (because of the above error (AAA), you need to run make twice) 
    37                                 - make install 
     3- library installation 
     4        - using system package 
     5                - install using commands below 
     6                        - aptitude install librabbitmq0 
     7                        - aptitude install librabbitmq-dev 
     8                - note that it is likely that system packages versions are out of date (we need v0.3.0) 
     9                  so better use installation from source 
     10        - from source 
     11                - retrieve source 
     12                        - wget https://github.com/alanxz/rabbitmq-c/archive/rabbitmq-c-v0.3.0.zip -O rabbitmq-c-v0.3.0.zip 
     13                        - unzip rabbitmq-c-v0.3.0.zip 
     14                        - cd rabbitmq-c-v0.3.0 
     15                - compilation using autoconf (automake v1.9+, and libtool v2.2+) 
     16                        - autoreconf -i 
     17                                - if error occurs at this step, check requirement below 
     18                                        - we require autotools v2.63 or better to build. I think RHEL5 ships with v2.59 which lacks the AC_PROC_CC_C99 macro. 
     19                                                - You can do one of two things; 
     20                                                        - Install a newer version of autotools 
     21                                                        - Build using cmake (v2.6 or better). 
     22                        - ./configure --enable-static 
     23                        - make 
     24                        - make install 
     25                - compilation using cmake (CMake v2.6+) 
     26                        - mkdir build && cd build 
     27                        - cmake -DBUILD_STATIC_LIBS=True -DBUILD_SHARED_LIBS=True .. 
     28                        - cmake --build . 
     29                        - make 
     30                                - you got error AAA below, it's normal 
     31                                        make[2]: *** Pas de rÚgle pour fabriquer la cible « librabbitmq/librabbitmq.so.1.0.1 », nécessaire pour « examples/amqp_bind ». Arrêt. 
     32                                        make[1]: *** [examples/CMakeFiles/amqp_bind.dir/all] Erreur 2 
     33                                        make: *** [all] Erreur 2 
     34                        - make 
     35                          (because of the above error (AAA), you need to run make twice) 
     36                        - make install 
     37- compilation (static) 
    3838        - gcc -static -I/usr/local/include -L/usr/local/lib -Wall -o sendAMQPMsg send_AMQP_msg.c -lrabbitmq 
    3939                - we get warning below during compilation 
  • trunk/Monitoring/CNClient/send_AMQP_msg.c

    r857 r866  
    259259        break; 
    260260      case 'e': 
    261         fprintf(stderr, "Usage: amqp_producer host port rate_limit message_count\n"); 
    262  
    263         fprintf(stderr, "Example 1: ./sendAMQPMsg -h localhost -p 5672 -b 'eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg=='\n"); 
    264  
    265         // obsolete (from now all sent data must be B64 encoded) 
    266         fprintf(stderr, "Example 2: ./sendAMQPMsg -h localhost -p 5672 -f /home/foobar/config.card -b '{\"jobid\":\"toto\"}'\n"); 
    267  
    268         fprintf(stderr, "Example 3: ./sendAMQPMsg -h localhost -p 5672 -b 'am9iaWQ6dG90byBjb2RlOjAwMDAK' -f ../sample/config.card.base64\n"); 
     261 
     262        fprintf(stderr, "Usage: amqp_producer host port\n"); 
     263 
     264 
     265        // --- example without config card --- 
     266 
     267        // eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg => '{"jobid":"toto","code":"0000"}' 
     268        fprintf(stderr, "./sendAMQPMsg -h localhost -p 5672 -b 'eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg=='\n"); 
     269 
     270 
     271        // --- example with config card --- 
     272 
     273        // eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg => '{"jobid":"toto","code":"0000","file":"<base64 encoded file here>"}' 
     274        fprintf(stderr, "./sendAMQPMsg -h localhost -p 5672 -b 'eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg==' -f /home/jripsl/snapshot/Monitoring/sample/config.card.base64\n"); 
     275 
     276        // eyJzaW11aWQiOiJmb29iYXIiLCJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg== => '{"simuid":"foobar","jobid":"toto","code":"0000","file":"<base64 encoded file here>"}' 
     277        fprintf(stderr, "./sendAMQPMsg -h localhost -p 5672 -b 'eyJzaW11aWQiOiJmb29iYXIiLCJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg==' -f /home/jripsl/snapshot/Monitoring/sample/config.card.base64\n"); 
     278 
     279 
    269280        exit(0); 
    270281      case 'f': 
     
    316327    } 
    317328 
    318     body_final=malloc(strlen(body_tmp) + 6 + strlen(buf) + 1); 
     329    body_final=malloc(5 + strlen(body_tmp) + 6 + strlen(buf) + 1); 
    319330    //strcpy(body_final,"\0"); 
     331    strcat(body_final,"body:"); 
    320332    strcat(body_final,body_tmp); 
    321     strcat(body_final,",file="); 
     333    strcat(body_final,",file:"); 
    322334    strcat(body_final,buf); 
    323335 
     
    330342    // retrieve msg body from argument 
    331343 
    332     body=body_tmp; 
    333  
     344    body_final=malloc(5 + strlen(body_tmp) + 1); 
     345 
     346    strcat(body_final,"body:"); 
     347    strcat(body_final,body_tmp); 
     348 
     349    body=body_final; 
    334350  } 
    335351 
     
    368384    free(buf); 
    369385 
     386  free(body_final); 
    370387 
    371388  //this is to prevent overwhelming rabbitMQ server (and to prevent triggering rabbitMQ defensive behaviours (e.g. connection blocking)) 
    372   usleep( 200 000 ); // O.2 second 
     389  //usleep( 200000 ); // O.2 second 
    373390 
    374391 
  • trunk/Monitoring/Watch/watch

    r865 r866  
    2626sys.path.append("/home/jripsl/snapshot/Monitoring") 
    2727 
    28 import smon.repo_io 
    29  
     28import smon.repo_io as repo_io 
     29import smon.types 
    3030 
    3131""" 
     
    6666 
    6767        @classmethod 
    68         def store_msg(cls): 
    69                 repo_io.store_messages(name) 
    70  
    71         @classmethod 
    72         def set_sim_status_to_error(cls): 
     68        def store_msg(cls,message): 
     69                repo_io.create_message(message) 
     70 
     71        @classmethod 
     72        def set_sim_status_to_error(cls,message): 
    7373                repo_io.update_simulation_status() 
    7474 
    7575        @classmethod 
    76         def crea_sim(cls): 
     76        def crea_sim(cls,message): 
     77 
    7778                #repo_io.retrieve_simulation(name) 
    7879                #repo_io.delete_simulation(name) 
    79                 repo_io.create_simulation() 
     80 
     81                simulation=smon.types.Simulation(name=message.simuid) 
     82 
     83                repo_io.create_simulation(simulation) 
    8084 
    8185        @classmethod 
     
    8892 
    8993                if "file" in message: 
    90                         print "%s %s %s\n"%(message["code"],message["jobid"],message["file"]) 
     94                        print "%s %s %s\n"%(message.code,message.jobid,message.file) 
    9195                else: 
    92                         print "%s %s\n"%(message["code"],message["jobid"]) 
     96                        print "%s %s\n"%(message.code,message.jobid) 
    9397 
    9498        @classmethod 
    9599        def log(cls,message): 
    96100                with open("/home/jripsl/supervisor/log/supervisor.log", "a") as log_file: 
    97                         log_file.write("%s %s %s\n"%(datetime.now().strftime('%Y%m%d_%H%M%S'), message["code"],message["jobid"])) 
     101                        log_file.write("%s %s %s\n"%(datetime.now().strftime('%Y%m%d_%H%M%S'), message.code,message.jobid)) 
    98102 
    99103        @classmethod 
    100104        def execActions(cls,message): 
    101105 
    102                 message_code=message["code"] 
     106                message_code=message.code 
    103107 
    104108                for action in MessageActionsMapping.mapping[message_code]: 
     
    155159 
    156160                def callback(ch, method, properties, raw_msg): 
    157                         # 
    158                         #return 
    159  
    160                         base64_decoded_msg=base64.b64decode(raw_msg) 
     161 
     162                        # msg fmt: body:base64,file:base64 (no JSON here !!!) 
     163 
     164 
     165 
     166 
     167                        # first deserialization (no JSON here !!!) 
     168 
     169                        fields=raw_msg.split(",") 
     170 
     171                        l__tmp_dic={} 
     172 
     173                        for field in fields: 
     174 
     175                                # debug 
     176                                print " [x] Received %s" % field 
     177 
     178                                splitted_field=field.split(":") 
     179 
     180                                key=splitted_field[0] 
     181                                val=splitted_field[1] 
     182 
     183                                l__tmp_dic[key]=val 
     184 
     185 
     186                        # debug 
     187                        print " [x] Received %s (encoded)" % l__tmp_dic["body"] 
     188 
     189                         
     190                        # base64 decode body 
     191                        base64_decoded_msg=base64.b64decode(l__tmp_dic["body"]) 
     192 
    161193 
    162194                        # debug 
    163195                        #print " [x] Received %s" % raw_msg 
     196                        print " [x] Received %s (uudecoded)" % base64_decoded_msg  
    164197                        #print " [x] Received %s (uudecoded)" % base64_decoded_msg  
     198 
    165199 
    166200                        message=None 
    167201                        try: 
    168                                 message=json.loads(base64_decoded_msg) 
     202                                # body deserialization  
     203                                JSON_msg=json.loads(base64_decoded_msg) 
     204                                message=smon.types.Message(JSON_msg)      # all JSON object members will be available in smon.types.Message object 
     205 
     206                                if "file" in l__tmp_dic: 
     207 
     208                                        # base64 decode file 
     209                                        base64_decoded_file=base64.b64decode(l__tmp_dic["file"]) 
     210 
     211                                        # add into msg 
     212                                        message.file=base64_decoded_file 
    169213 
    170214                                # message code based action 
    171                                 Watcher.execActions(message) 
     215                                Actions.execActions(message) 
     216 
    172217                        except Exception,e: 
    173218                                print "Exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg) 
     219 
     220                                #traceback.print_exc() 
     221 
     222                                raise 
    174223 
    175224                self.channel.basic_consume(callback, queue='myqueue', no_ack=True) 
     
    198247        except Exception, e: 
    199248 
    200                 traceback.print_exc() 
     249                #traceback.print_exc() 
    201250 
    202251                sys.exit(1) 
  • trunk/Monitoring/doc/README

    r859 r866  
    66        - Supervisor installation 
    77                - Python installation 
    8                         - TODO: add python install instructions here 
     8                        - yum install python26 
     9                        - yum install python26-devel 
     10                        - yum install sqlite 
     11                        - yum install sqlite-devel 
     12                        - yum install python-sqlite 
    913                - Virtualenv installation 
    10                         - TODO: add virtual env install instructions here 
     14                        - cd /opt/src/ 
     15                        - wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.6.1.tar.gz 
     16                        - tar xzvf virtualenv-1.6.1.tar.gz 
     17                        - rm virtualenv-1.6.1.tar.gz 
     18                        - cd /opt/src/virtualenv-1.6.1 
     19                        - /usr/bin/python26 virtualenv.py --distribute --unzip-setuptools /opt/python2.6_ve 
     20                        - source /opt/python2.6_ve/bin/activate 
    1121                - Python PYPI libraries installation 
    1222                        - procedure (as root) 
     
    1727                                - pip install <package name> 
    1828                        - packages list 
    19                                 - packages below are needed by SMON 
    20                                         - pip install pika # RabbitMQ client library 
    21                                 - packages below are needed by Prodiguer library 
    22                                         - 
    23                                                 - pip install psycopg2 
    24                                                         - doesn't work (Error: pg_config executable not found) 
    25                                                                 - solution is 
    26                                                                         - yum install python-psycopg2.x86_64 
    27                                                                         - yum install libpqxx-devel 
    28                                                                         - yum install python-devel 
    29                                                                         - pip install psycopg2 
    30                                                                                 - works 
    31                                                 - pip install Sqlalchemy 
    32                                                 - pip install elixir 
    33                                                 - pip install simplejson 
    34                                         - note: some Elixir/SQLAlchemy versions are not compatible. 
    35                                           to be sure, you can use version below which are compatible 
    36                                                 - Elixir-0.7.1-py2.6.egg-info 
    37                                                 - SQLAlchemy-0.7.8-py2.6.egg-info 
     29                                - pika     # RabbitMQ client library 
     30                                - networkx # graph library 
     31                                - #pip amqplib # not used for now 
    3832                - Prodiguer library installation 
    39                         - svn co svn+ssh://<login here>@forge.ipsl.jussieu.fr/ipsl/forge/projets/prodiguer/svn/sw/src/python/trunk/prodiguer_shared/src 
    40                         - edit "watch" script and edit line below accordingly 
    41                                 - sys.path.append("/home/jripsl/snapshot/src")  
     33                        - dependencies (PYPI packages) 
     34                                - 
     35                                        - pip install psycopg2 
     36                                                - doesn't work (Error: pg_config executable not found) 
     37                                                        - solution is 
     38                                                                - yum install python-psycopg2.x86_64 
     39                                                                - yum install libpqxx-devel 
     40                                                                - yum install python-devel 
     41                                                                - pip install psycopg2 
     42                                                                        - works 
     43                                        - pip install Sqlalchemy 
     44                                        - pip install elixir 
     45                                        - pip install simplejson 
     46                                - notes 
     47                                        - some Elixir/SQLAlchemy versions are not compatible. 
     48                                                - to be sure, you can use version below which are compatible 
     49                                                        - Elixir-0.7.1-py2.6.egg-info 
     50                                                        - SQLAlchemy-0.7.8-py2.6.egg-info 
     51                                                - to install specific version with pip, do 
     52                                                        - pip install SQLAlchemy==0.7.8 
     53                        - Prodiguer package 
     54                                - svn co svn+ssh://<login here>@forge.ipsl.jussieu.fr/ipsl/forge/projets/prodiguer/svn/sw/src/python/trunk/prodiguer_shared/src 
     55                                - edit "watch" script and edit line below accordingly 
     56                                        - sys.path.append("/home/jripsl/snapshot/src")  
  • trunk/Monitoring/script/libIGCM_mock.sh

    r854 r866  
    1212################################## 
    1313 
     14# Notes 
     15#   - bash required version: 3+ 
     16#   - "=" and " " are used as delimiter in scenario file (be sure note to use it in fields data) 
     17 
     18# init 
     19 
    1420stack_file=$1 
    15 send_msg="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 
     21send_msg_cmd="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 
     22scenario_dir=scenario 
     23g__mode="scenario" 
     24g__stackfile= 
     25g__scenario_file= 
    1626 
    17 if [ $# -lt 1 ]; then 
    18         echo "Usage $0 ../sample/stack_light" 
     27# func 
     28 
     29curdate () 
     30{ 
     31    date '+%F %T' 
     32} 
     33 
     34msg () 
     35{ 
     36    l__code="$1" 
     37    l__msg="$2" 
     38 
     39    echo "$(curdate) - $l__code - $l__msg" 
     40} 
     41 
     42usage () 
     43{ 
     44        cat >&1 << EOF 
     45 
     46USAGE: $(basename $0) [-m mode] [-s scenario] [-l] [-t file] 
     47 
     48OPTIONS: 
     49   -f              set stack file 
     50   -l              print scenarios list  
     51   -m              set mode (if missing, "scenario" mode is used) 
     52   -s              set scenario 
     53 
     54EXAMPLES: 
     55 
     56   To parse a stack file and send corressponding messages, do: 
     57 
     58   $0 -m stackfile -f ../sample/stack_light 
     59 
     60   To list scenarios, do: 
     61 
     62   $0 -l 
     63 
     64   To run scenario <scenario>, do: 
     65 
     66   $0 -s <scenario> 
     67EOF 
     68        exit 2 
     69} 
     70 
     71list_scenarios () 
     72{ 
     73        echo "" 
     74        echo "Scenarios list:" 
     75        echo "" 
     76        ls -1 $scenario_dir 
     77        echo "" 
     78        exit 2 
     79} 
     80 
     81# check 
     82 
     83if [ $# -eq 0 ]; then 
     84        usage 
     85fi 
     86 
     87# parse args 
     88 
     89while getopts 'f:hlm:s:' OPTION 
     90do 
     91  case $OPTION in 
     92  f)    g__stackfile="$OPTARG" 
     93        ;; 
     94  h)    usage 
     95        ;; 
     96  l)    list_scenarios 
     97        ;; 
     98  m)    g__mode="$OPTARG" 
     99        ;; 
     100  s)    l__scenario_file="$OPTARG" 
     101 
     102                if [[ "$l__scenario_file" =~ "*/*" ]]; then 
     103                        # full/relative path was given with the filename 
     104 
     105                        g__scenario_file="$l__scenario_file" 
     106                else 
     107                        # only the filename was given 
     108 
     109                        g__scenario_file="$scenario_dir/$l__scenario_file" 
     110                fi 
     111 
     112                ;; 
     113  ?)    exit 1 # we come here when a required option argument is missing (bash getopts mecanism) 
     114        ;; 
     115  esac 
     116done 
     117 
     118# mode switch 
     119if [ "$g__mode" = "scenario" ]; then 
     120 
     121        # check 
     122        if [ ! -f "$g__scenario_file" ]; then 
     123                msg "LIBIGCM-MOCK-ERR003" "scenario file not found" 
     124                exit 1 
     125        fi 
     126 
     127        N=0 
     128        while read LINE ; do 
     129 
     130                N=$((N+1)) 
     131 
     132                l__JSON_msg_buf= 
     133 
     134                # process fields (split on " " delimiter) 
     135                for field in "$LINE"; do 
     136                        arr=(${LINE//=/ }) # process key/value (split on "=" delimiter) 
     137                        key=${arr[0]} 
     138                        val=${arr[1]} 
     139 
     140                        # base64 encoding 
     141 
     142                        # append to JSON message buffer 
     143                        l__JSON_msg_buf=$l__JSON_msg_buf 
     144 
     145                done 
     146 
     147                # message base64 encoding 
     148 
     149 
     150                #callname=$(echo $line | awk -F" " '{print $4}' ) 
     151 
     152                # send AMQP message 
     153                #$send_msg_cmd localhost 5672 string "$callname" 
     154                echo 
     155 
     156        done < $g__scenario_file 
     157 
     158elif [ "$g__mode" = "stackfile" ]; then 
     159 
     160        # check 
     161        if [ ! -f $stack_file ]; then 
     162                msg "LIBIGCM-MOCK-ERR001" "file not found" 
     163                exit 1 
     164        fi 
     165 
     166        IFS=$'\n' 
     167        for line in $(cat $stack_file); do 
     168                #echo $line | awk -F" " '{print $4}' 
     169                callname=$(echo $line | awk -F" " '{print $4}' ) 
     170                $send_msg_cmd localhost 5672 string "$callname" 
     171        done 
     172else 
     173        msg "LIBIGCM-MOCK-ERR002" "incorrect mode" 
    19174        exit 1 
    20175fi 
    21176 
    22 IFS=$'\n' 
    23 for line in $(cat $stack_file); do 
    24         #echo $line | awk -F" " '{print $4}' 
    25         callname=$(echo $line | awk -F" " '{print $4}' ) 
    26         $send_msg localhost 5672 string "$callname" 
    27 done 
     177exit 0 
  • trunk/Monitoring/smon/local_repo.py

    r865 r866  
    4040def create_tables(): 
    4141        _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 
    4343 
    4444def retrieve_simulation(name): 
     
    8181 
    8282def create_message(message): 
    83         _conn.execute("insert into message (simulation_id) values (?)",(message.simulation_id,)) 
     83        _conn.execute("insert into message (simulation_id) values (?)",(message.simuid,)) 
    8484 
    8585def retrieve_last_message(simulation): 
  • trunk/Monitoring/smon/repo_io.py

    r865 r866  
    2828 
    2929 
     30 
     31 
     32 
     33# -- methods -- # 
     34 
     35def 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 
     46def 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 
     58def 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 
     68def 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 
     78def 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 
     88def 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 
     111def 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 
     130def 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 
     149def 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 
     168def 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 
     191def 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 
     210def 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 
     229def 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 
     255def 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 
    30267CSTE_MODE_LOCAL_REPO="local_repo" 
    31268CSTE_MODE_REMOTE_REPO="remote_repo" 
     
    46283 
    47284 
    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 
     286init() 
     287 
  • trunk/Monitoring/smon/types.py

    r865 r866  
    22 
    33################################## 
    4 #  @program        smon 
     4#  @program                smon 
    55#  @description    simulation monitor 
    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 $ 
     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 $ 
    1010#  @lastrevision   $Date: 2013-03-24 20:01:23 +0100 (Sun, 24 Mar 2013) $ 
    11 #  @license        CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE) 
     11#  @license                CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE) 
    1212################################## 
    1313 
     
    2525                self.msg=msg 
    2626 
    27     def __str__(self): 
    28         return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
     27        def __str__(self): 
     28                return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
    2929 
    3030class Tree(): 
    3131 
    32     def __init__(self,**kw): 
     32        def __init__(self,**kw): 
    3333                pass 
    3434 
    35     def __str__(self): 
    36         return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
     35        def __str__(self): 
     36                return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
    3737 
    3838class Simulation(): 
    3939 
    40     def __init__(self,**kw): 
     40        def __init__(self,**kw): 
    4141                self.exec_start_date=kw.get("exec_start_date") 
    4242                self.exec_end_date=kw.get("exec_end_date") 
    4343                self.status=kw.get("status") 
     44                self.name=kw.get("name") 
    4445 
    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 
     49class 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()]) 
    4757 
    4858class SimulationTree(Tree): 
    4959 
    50     def __init__(self,**kw): 
     60        def __init__(self,**kw): 
    5161                dg = nx.DiGraph() 
    5262 
    5363        def update(cls): 
    5464                dg.add_edge('a','b') 
    55  
    56         def print(cls): 
    57                 print dg.edges() 
     65         
     66        def print__TODO(cls): 
     67                print dg.edges()  
    5868 
    5969        def write(cls): 
     
    6373                dg = pickle.load(open('/tmp/graph.txt')) 
    6474 
    65     def __str__(self): 
    66         return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
     75        def __str__(self): 
     76                return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
    6777 
    6878class SimulationTrees(): 
    6979 
    70     def __init__(self,**kw): 
    71         self.sample=kw.get("sample",[]) 
     80        def __init__(self,**kw): 
     81                self.sample=kw.get("sample",[]) 
    7282 
    73     def __str__(self): 
    74         return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 
     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.