Changeset 866 for trunk/Monitoring
- Timestamp:
- 06/09/13 23:52:36 (11 years ago)
- Location:
- trunk/Monitoring
- Files:
-
- 8 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/Broker/README
r854 r866 45 45 - cd /opt/rabbitmq-server-3.0.2/sbin 46 46 - ./rabbitmq-server -detached 47 - to stop the daemon, use this47 - to stop the daemon, use one of those 48 48 - kill -TERM $(pidof epmd) 49 - rabbitmqctl stop 49 50 - operation 50 51 - 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) 2 2 - https://github.com/alanxz/rabbitmq-c 3 - Compilation (static)4 - Library installation5 - using system package6 - install using commands below7 - aptitude install librabbitmq08 - aptitude install librabbitmq-dev9 - note that it is likely that system packages versions are out of date (we need v0.3.0)10 so better use installationfrom source11 - fromsource12 - retrieve source13 - wget https://github.com/alanxz/rabbitmq-c/archive/rabbitmq-c-v0.3.0.zip -Orabbitmq-c-v0.3.0.zip14 - unzip rabbitmq-c-v0.3.0.zip15 - cd rabbitmq-c-v0.3.016 - compilation using autoconf (automake v1.9+, and libtool v2.2+)17 - autoreconf -i18 - if error occurs at this step, check requirement below19 - 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 autotools22 - Build using cmake (v2.6 or better).23 - ./configure --enable-static24 - make25 - make install26 - compilation using cmake (CMake v2.6+)27 - mkdir build && cd build28 - cmake -DBUILD_STATIC_LIBS=True -DBUILD_SHARED_LIBS=True ..29 - cmake --build .30 - make31 - you got error AAA below, it's normal32 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 234 make: *** [all] Erreur 235 - make36 (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) 38 38 - gcc -static -I/usr/local/include -L/usr/local/lib -Wall -o sendAMQPMsg send_AMQP_msg.c -lrabbitmq 39 39 - we get warning below during compilation -
trunk/Monitoring/CNClient/send_AMQP_msg.c
r857 r866 259 259 break; 260 260 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 269 280 exit(0); 270 281 case 'f': … … 316 327 } 317 328 318 body_final=malloc( strlen(body_tmp) + 6 + strlen(buf) + 1);329 body_final=malloc(5 + strlen(body_tmp) + 6 + strlen(buf) + 1); 319 330 //strcpy(body_final,"\0"); 331 strcat(body_final,"body:"); 320 332 strcat(body_final,body_tmp); 321 strcat(body_final,",file =");333 strcat(body_final,",file:"); 322 334 strcat(body_final,buf); 323 335 … … 330 342 // retrieve msg body from argument 331 343 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; 334 350 } 335 351 … … 368 384 free(buf); 369 385 386 free(body_final); 370 387 371 388 //this is to prevent overwhelming rabbitMQ server (and to prevent triggering rabbitMQ defensive behaviours (e.g. connection blocking)) 372 usleep( 200000 ); // O.2 second389 //usleep( 200000 ); // O.2 second 373 390 374 391 -
trunk/Monitoring/Watch/watch
r865 r866 26 26 sys.path.append("/home/jripsl/snapshot/Monitoring") 27 27 28 import smon.repo_io 29 28 import smon.repo_io as repo_io 29 import smon.types 30 30 31 31 """ … … 66 66 67 67 @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): 73 73 repo_io.update_simulation_status() 74 74 75 75 @classmethod 76 def crea_sim(cls): 76 def crea_sim(cls,message): 77 77 78 #repo_io.retrieve_simulation(name) 78 79 #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) 80 84 81 85 @classmethod … … 88 92 89 93 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) 91 95 else: 92 print "%s %s\n"%(message ["code"],message["jobid"])96 print "%s %s\n"%(message.code,message.jobid) 93 97 94 98 @classmethod 95 99 def log(cls,message): 96 100 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)) 98 102 99 103 @classmethod 100 104 def execActions(cls,message): 101 105 102 message_code=message ["code"]106 message_code=message.code 103 107 104 108 for action in MessageActionsMapping.mapping[message_code]: … … 155 159 156 160 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 161 193 162 194 # debug 163 195 #print " [x] Received %s" % raw_msg 196 print " [x] Received %s (uudecoded)" % base64_decoded_msg 164 197 #print " [x] Received %s (uudecoded)" % base64_decoded_msg 198 165 199 166 200 message=None 167 201 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 169 213 170 214 # message code based action 171 Watcher.execActions(message) 215 Actions.execActions(message) 216 172 217 except Exception,e: 173 218 print "Exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg) 219 220 #traceback.print_exc() 221 222 raise 174 223 175 224 self.channel.basic_consume(callback, queue='myqueue', no_ack=True) … … 198 247 except Exception, e: 199 248 200 traceback.print_exc()249 #traceback.print_exc() 201 250 202 251 sys.exit(1) -
trunk/Monitoring/doc/README
r859 r866 6 6 - Supervisor installation 7 7 - 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 9 13 - 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 11 21 - Python PYPI libraries installation 12 22 - procedure (as root) … … 17 27 - pip install <package name> 18 28 - 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 38 32 - 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 12 12 ################################## 13 13 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 14 20 stack_file=$1 15 send_msg="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 21 send_msg_cmd="/home/jripsl/snapshot/Monitoring/CNClient/sendAMQPMsg" 22 scenario_dir=scenario 23 g__mode="scenario" 24 g__stackfile= 25 g__scenario_file= 16 26 17 if [ $# -lt 1 ]; then 18 echo "Usage $0 ../sample/stack_light" 27 # func 28 29 curdate () 30 { 31 date '+%F %T' 32 } 33 34 msg () 35 { 36 l__code="$1" 37 l__msg="$2" 38 39 echo "$(curdate) - $l__code - $l__msg" 40 } 41 42 usage () 43 { 44 cat >&1 << EOF 45 46 USAGE: $(basename $0) [-m mode] [-s scenario] [-l] [-t file] 47 48 OPTIONS: 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 54 EXAMPLES: 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> 67 EOF 68 exit 2 69 } 70 71 list_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 83 if [ $# -eq 0 ]; then 84 usage 85 fi 86 87 # parse args 88 89 while getopts 'f:hlm:s:' OPTION 90 do 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 116 done 117 118 # mode switch 119 if [ "$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 158 elif [ "$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 172 else 173 msg "LIBIGCM-MOCK-ERR002" "incorrect mode" 19 174 exit 1 20 175 fi 21 176 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 177 exit 0 -
trunk/Monitoring/smon/local_repo.py
r865 r866 40 40 def create_tables(): 41 41 _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 43 43 44 44 def retrieve_simulation(name): … … 81 81 82 82 def create_message(message): 83 _conn.execute("insert into message (simulation_id) values (?)",(message.simu lation_id,))83 _conn.execute("insert into message (simulation_id) values (?)",(message.simuid,)) 84 84 85 85 def retrieve_last_message(simulation): -
trunk/Monitoring/smon/repo_io.py
r865 r866 28 28 29 29 30 31 32 33 # -- methods -- # 34 35 def 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 46 def 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 58 def 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 68 def 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 78 def 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 88 def 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 111 def 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 130 def 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 149 def 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 168 def 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 191 def 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 210 def 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 229 def 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 255 def 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 30 267 CSTE_MODE_LOCAL_REPO="local_repo" 31 268 CSTE_MODE_REMOTE_REPO="remote_repo" … … 46 283 47 284 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 286 init() 287 -
trunk/Monitoring/smon/types.py
r865 r866 2 2 3 3 ################################## 4 # @program 4 # @program smon 5 5 # @description simulation monitor 6 # @copyright 7 # 8 # @svn_file 9 # @version 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 $ 10 10 # @lastrevision $Date: 2013-03-24 20:01:23 +0100 (Sun, 24 Mar 2013) $ 11 # @license 11 # @license CeCILL (http://dods.ipsl.jussieu.fr/jripsl/smon/LICENSE) 12 12 ################################## 13 13 … … 25 25 self.msg=msg 26 26 27 28 27 def __str__(self): 28 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 29 29 30 30 class Tree(): 31 31 32 32 def __init__(self,**kw): 33 33 pass 34 34 35 36 35 def __str__(self): 36 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 37 37 38 38 class Simulation(): 39 39 40 40 def __init__(self,**kw): 41 41 self.exec_start_date=kw.get("exec_start_date") 42 42 self.exec_end_date=kw.get("exec_end_date") 43 43 self.status=kw.get("status") 44 self.name=kw.get("name") 44 45 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 49 class 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()]) 47 57 48 58 class SimulationTree(Tree): 49 59 50 60 def __init__(self,**kw): 51 61 dg = nx.DiGraph() 52 62 53 63 def update(cls): 54 64 dg.add_edge('a','b') 55 56 def print (cls):57 print dg.edges() 65 66 def print__TODO(cls): 67 print dg.edges() 58 68 59 69 def write(cls): … … 63 73 dg = pickle.load(open('/tmp/graph.txt')) 64 74 65 66 75 def __str__(self): 76 return ",".join(['%s=%s'%(k,str(v)) for (k,v) in self.__dict__.iteritems()]) 67 77 68 78 class SimulationTrees(): 69 79 70 71 80 def __init__(self,**kw): 81 self.sample=kw.get("sample",[]) 72 82 73 74 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.