[913] | 1 | #!/bin/ksh |
---|
[2] | 2 | |
---|
| 3 | #************************************************************** |
---|
| 4 | # Author: Patrick Brockmann, Martial Mancip |
---|
[373] | 5 | # Contact: Patrick.Brockmann__at__cea.fr Martial.Mancip__at__ipsl.jussieu.fr |
---|
| 6 | # $Revision:: $ Revision of last commit |
---|
| 7 | # $Author:: $ Author of last commit |
---|
| 8 | # $Date:: $ Date of last commit |
---|
[2] | 9 | # IPSL (2006) |
---|
| 10 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 11 | # |
---|
| 12 | #************************************************************** |
---|
| 13 | |
---|
| 14 | #================================================== |
---|
| 15 | # The documentation of this file can be automatically generated |
---|
[913] | 16 | # if you use the prefix #D- for comments to be extracted. |
---|
[2] | 17 | # Extract with command: cat lib* | grep "^#D-" | cut -c "4-" |
---|
| 18 | #================================================== |
---|
| 19 | |
---|
| 20 | #================================================== |
---|
| 21 | # Add high level verbosity |
---|
| 22 | typeset -i Verbosity=${Verbosity:=3} |
---|
| 23 | |
---|
| 24 | #================================================== |
---|
| 25 | # DEBUG_debug |
---|
| 26 | # Add low level verbosity |
---|
[1083] | 27 | DEBUG_debug=${DEBUG_debug:=false} |
---|
[2] | 28 | |
---|
[1290] | 29 | #D- postProcessingStopLevel (0,1,2,3) |
---|
| 30 | #D- 3 stop if any post-processing went wrong |
---|
| 31 | #D- 2 dont stop if atlas, monitoring or metrics failed |
---|
| 32 | #D- 1 dont stop if atlas, monitoring, metrics, create_ts or create_se failed |
---|
| 33 | #D- 0 dont stop if atlas, monitoring, metrics, create_ts, create_se, rebuild or pack_* failed |
---|
| 34 | postProcessingStopLevel=${postProcessingStopLevel:=0} |
---|
| 35 | |
---|
[872] | 36 | #================================================== |
---|
| 37 | # GENERATE RANDOM ERROR ; only apply if ( ${DEBUG_debug} ) |
---|
[1244] | 38 | typeset -r RandomError=false |
---|
[872] | 39 | |
---|
[2] | 40 | #================================================== |
---|
| 41 | # NULL_STR |
---|
| 42 | # Default null string |
---|
[913] | 43 | typeset -r NULL_STR="_0_" |
---|
[2] | 44 | |
---|
| 45 | #================================================== |
---|
| 46 | # libIGCM_CurrentTag |
---|
| 47 | # Current libIGCM tag, check compatibilty with *.card |
---|
[1325] | 48 | typeset -r libIGCMVersion="2.8.1" |
---|
[2] | 49 | |
---|
| 50 | #================================================== |
---|
| 51 | # Exit Flag (internal debug) |
---|
| 52 | # When true, end the master loop AFTER SAVES FILES |
---|
| 53 | ExitFlag=false |
---|
| 54 | |
---|
| 55 | #================================================== |
---|
[1243] | 56 | # When we start to run the simulation is not finished |
---|
| 57 | simulationIsOver=false |
---|
| 58 | |
---|
| 59 | #================================================== |
---|
[1268] | 60 | # When we start to run we dont flush AMQP messages |
---|
| 61 | FlushAMQP=false |
---|
| 62 | |
---|
| 63 | #================================================== |
---|
[2] | 64 | # Declare a stack of functions calls |
---|
[59] | 65 | unset IGCM_debug_Stack |
---|
| 66 | unset IGCM_debug_StackArgs |
---|
[913] | 67 | unset IGCM_debug_StackTiming |
---|
[54] | 68 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 69 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[913] | 70 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
[2] | 71 | IGCM_debug_LenStack=0 |
---|
| 72 | |
---|
| 73 | #D-#================================================================== |
---|
[913] | 74 | #D-function IGCM_debug_getDate_ms |
---|
| 75 | #D- * Purpose: Give number of milliseconds since 01-jan-1970 |
---|
| 76 | function IGCM_debug_getDate_ms |
---|
| 77 | { |
---|
[926] | 78 | typeset nanosecs ms |
---|
[913] | 79 | # nano secondes since 01-jan-1970 |
---|
| 80 | nanosecs=$( date +%s%N ) |
---|
| 81 | |
---|
| 82 | # truncate the last 6 digits to get milliseconds since 01-jan-1970 |
---|
| 83 | ms=${nanosecs:0:${#nanosecs}-6} |
---|
| 84 | |
---|
| 85 | echo "$ms" |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | #D-#================================================================== |
---|
| 89 | #D-function IGCM_debug_sizeOfTabContent |
---|
| 90 | #D- * Purpose: Give sumed size of a list of files |
---|
[924] | 91 | #D- * Usage: IGCM_debug_sizeOfTabContent entityList destination |
---|
| 92 | #D- * where entityList is a list of files or directory |
---|
| 93 | #D- * where dest is either a directory or a file name |
---|
[913] | 94 | function IGCM_debug_sizeOfTabContent |
---|
| 95 | { |
---|
[924] | 96 | typeset entityListe destination iEntity sizeKo sumSizeKo sumSizeMo |
---|
| 97 | |
---|
| 98 | eval set +A entityListe \${${1}} |
---|
[941] | 99 | destination=${2} |
---|
[924] | 100 | sumSizeKo=0 |
---|
| 101 | |
---|
| 102 | # Here we will try to compute size (file or directory size) from local path and not from archive. |
---|
[941] | 103 | for ((i = 0; i < ${#entityListe[*]}; i += 1)) ; do |
---|
| 104 | if [ -f ${entityListe[$i]} ] ; then |
---|
| 105 | # One file or a bunch of files has been copied without renaming from a visible filesystem |
---|
| 106 | iEntity=${entityListe[$i]} |
---|
| 107 | elif [ -f ${entityListe[$i]##/*/} ] ; then |
---|
| 108 | # One file or a bunch of files has been copied without renaming from an non visible filesystem |
---|
[924] | 109 | # remove path /home/login/../ from entityListe elements |
---|
| 110 | iEntity=${entityListe[$i]##/*/} |
---|
| 111 | elif [ -f ${destination} ] ; then |
---|
[941] | 112 | # a file has been copied and renamed |
---|
[924] | 113 | iEntity=${destination} |
---|
| 114 | elif [ -f ${destination}/${entityListe[$i]##/*/} ] ; then |
---|
| 115 | # a copy in a directory but not in ${PWD} |
---|
| 116 | iEntity=${destination}/${entityListe[$i]##/*/} |
---|
| 117 | elif [ -d ${entityListe[$i]} ] ; then |
---|
[941] | 118 | # a directory has been copied from a non remote place |
---|
[924] | 119 | iEntity=${entityListe[$i]} |
---|
| 120 | elif [ -d ${destination}/${entityListe[$i]##/*/} ] ; then |
---|
[941] | 121 | # a directory has been copied from a remote archive and not renamed |
---|
[924] | 122 | iEntity=${destination}/${entityListe[$i]##/*/} |
---|
| 123 | elif [ -d ${destination} ] ; then |
---|
[941] | 124 | # a directory has been copied from a remote archive and renamed |
---|
[924] | 125 | iEntity=${destination} |
---|
[917] | 126 | fi |
---|
[1083] | 127 | sizeKo=$( du --apparent-size -skL ${iEntity} | gawk '{print $1}' ) |
---|
[924] | 128 | sumSizeKo=$(( $sumSizeKo + $sizeKo )) |
---|
[913] | 129 | done |
---|
[924] | 130 | sumSizeMo=$( echo "scale=6;${sumSizeKo}/1024" | bc ) |
---|
| 131 | echo "${sumSizeKo}|${sumSizeMo}" |
---|
[913] | 132 | } |
---|
| 133 | |
---|
| 134 | #D-#================================================================== |
---|
[983] | 135 | #D-function IGCM_debug_send_AMQP_msg__MAILTUNNEL |
---|
| 136 | #D- * Purpose: Take over AMQP C client using mail as a message recipient |
---|
| 137 | #D- * One argument : base64 encoded message |
---|
[1051] | 138 | #D- * Attach encoded config.card when starting the simulation |
---|
| 139 | |
---|
[983] | 140 | function IGCM_debug_send_AMQP_msg__MAILTUNNEL { |
---|
| 141 | |
---|
[987] | 142 | typeset b64_encoded_msg mail_recipient |
---|
[1076] | 143 | typeset buffer send_messages mail_frequency |
---|
[987] | 144 | typeset last_mail_date__file |
---|
[1234] | 145 | typeset secondsBetweenRefAndLastMail secondsSinceLastMail |
---|
[987] | 146 | |
---|
[983] | 147 | b64_encoded_msg=$1 |
---|
| 148 | |
---|
[1072] | 149 | mail_recipient="superviseur@ipsl.jussieu.fr" |
---|
[983] | 150 | send_messages=0 |
---|
| 151 | mail_frequency=3600 # in seconds |
---|
| 152 | # use to keep track when was last mail sent (maybe to be replaced with global variable) |
---|
[1150] | 153 | last_mail_date__file=${R_BUF}/.stamp.${config_UserChoices_TagName}.${config_UserChoices_JobName} |
---|
| 154 | # use to accumulate messages before sending them |
---|
| 155 | buffer=${R_BUF}/.buffer.${config_UserChoices_TagName}.${config_UserChoices_JobName} |
---|
[983] | 156 | |
---|
| 157 | # init |
---|
| 158 | if [ ! -f "${buffer}" ]; then |
---|
[1150] | 159 | touch ${buffer} |
---|
[983] | 160 | fi |
---|
| 161 | |
---|
| 162 | if [ ! -f "${last_mail_date__file}" ]; then |
---|
[1150] | 163 | touch ${last_mail_date__file} |
---|
[983] | 164 | else |
---|
[1150] | 165 | # compute last time the file was changed (in seconds) |
---|
[1234] | 166 | secondsBetweenRefAndLastMail=$(stat -c %Y ${last_mail_date__file}) |
---|
| 167 | status=$? |
---|
| 168 | # |
---|
[1275] | 169 | # Only execute this block when the stat command succeeded. |
---|
| 170 | # The stat command might fail in some circumstance but we consider it is ok to continue anyway. |
---|
| 171 | if [ ${status} -eq 0 ] ; then |
---|
| 172 | secondsSinceLastMail=$(( $(date +%s) - ${secondsBetweenRefAndLastMail} )) |
---|
| 173 | # send message when exceeding threshold |
---|
| 174 | [ ${secondsSinceLastMail} -gt ${mail_frequency} ] && send_messages=1 |
---|
[1234] | 175 | fi |
---|
[983] | 176 | fi |
---|
| 177 | |
---|
[997] | 178 | # queue messages in the buffer |
---|
| 179 | echo ${b64_encoded_msg} >> ${buffer} |
---|
| 180 | |
---|
| 181 | # send mail |
---|
[1051] | 182 | |
---|
[1053] | 183 | if [ X${initBigBro} = Xtrue ] ; then |
---|
[1087] | 184 | #echo $(date +"%Y-%m-%dT%H:%M:%S.%N%z") > ${SUBMIT_DIR}/mail.txt |
---|
[1051] | 185 | mailx -s "[TEMPORARY AMQP CHANNEL]" -a ${SUBMIT_DIR}/config.card.base64 ${mail_recipient} < ${buffer} # send buffer |
---|
| 186 | rm -f $buffer ; touch ${buffer} # clear buffer |
---|
| 187 | touch ${last_mail_date__file} # memorize last mail date |
---|
[1293] | 188 | rm -f ${SUBMIT_DIR}/config.card.base64 # remove temporary file |
---|
[1051] | 189 | initBigBro=false |
---|
[1150] | 190 | elif [ ${send_messages} -eq 1 ] ; then |
---|
[1087] | 191 | #echo $(date +"%Y-%m-%dT%H:%M:%S.%N%z") >> ${SUBMIT_DIR}/mail.txt |
---|
[1051] | 192 | mailx -s "[TEMPORARY AMQP CHANNEL]" ${mail_recipient} < ${buffer} # send buffer |
---|
[1150] | 193 | rm -f ${buffer} ; touch ${buffer} # flush the buffer |
---|
[1051] | 194 | touch ${last_mail_date__file} # memorize last mail date |
---|
[983] | 195 | fi |
---|
[987] | 196 | |
---|
[1189] | 197 | if ( ${FlushAMQP} ) ; then |
---|
[1150] | 198 | mailx -s "[TEMPORARY AMQP CHANNEL]" ${mail_recipient} < ${buffer} # send buffer |
---|
| 199 | rm -f ${buffer} # cleaning behind us |
---|
| 200 | rm -f ${last_mail_date__file} # cleaning behind us |
---|
| 201 | fi |
---|
| 202 | |
---|
[983] | 203 | # Allways all good for now. |
---|
| 204 | return 0 |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | #D-#================================================================== |
---|
[1162] | 208 | #D-function IGCM_debug_sendAMQP_Metrics |
---|
| 209 | #D- * Purpose: Take over AMQP C client using mail as a message recipient |
---|
[1202] | 210 | #D- * Two arguments : - Directory where metrics.json files can be found |
---|
| 211 | #D- * - Metrics Group Name. metrics will be added to this group |
---|
[1162] | 212 | #D- * Attach encoded metrics.json files. |
---|
| 213 | |
---|
| 214 | function IGCM_debug_sendAMQP_Metrics { |
---|
| 215 | |
---|
| 216 | typeset mail_recipient encodedBody |
---|
| 217 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 218 | mail_recipient="superviseur@ipsl.jussieu.fr" |
---|
| 219 | # Metrics tag on server side |
---|
| 220 | code=7100 |
---|
| 221 | # Usual AMQP message to route messages on server side |
---|
[1202] | 222 | encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"metricsGroupName\":\"${2}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" | base64 -w 0 ) |
---|
[1162] | 223 | # send mail |
---|
| 224 | attachmentsOptions="" |
---|
| 225 | for metricsFile in $( ls $1/*json ) ; do |
---|
| 226 | attachmentsOptions="-a ${metricsFile} ${attachmentsOptions}" |
---|
| 227 | done |
---|
[1204] | 228 | IGCM_debug_Print 2 "IGCM_debug_sendAMQP_Metrics " |
---|
[1162] | 229 | echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient} |
---|
| 230 | fi |
---|
| 231 | |
---|
| 232 | # Allways all good for now. |
---|
| 233 | return 0 |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | #D-#================================================================== |
---|
[1285] | 237 | #D-function IGCM_debug_sendAMQP_projectAccounting |
---|
| 238 | #D- * Purpose: Take over AMQP C client using mail as a message recipient |
---|
| 239 | #D- * One argument : - File name where project accounting details are stored |
---|
| 240 | #D- * Attach encoded accounting file. |
---|
| 241 | |
---|
| 242 | function IGCM_debug_sendAMQP_projectAccounting { |
---|
| 243 | |
---|
| 244 | typeset mail_recipient encodedBody |
---|
| 245 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 246 | mail_recipient="superviseur@ipsl.jussieu.fr" |
---|
| 247 | # Metrics tag on server side |
---|
| 248 | code=7010 |
---|
| 249 | # Usual AMQP message to route messages on server side |
---|
| 250 | encodedBody=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"accountingProject\":\"${PROJECT}\",\"centre\":\"${CENTER}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" | base64 -w 0 ) |
---|
| 251 | # send mail |
---|
| 252 | attachmentsOptions="-a ${1}" |
---|
| 253 | IGCM_debug_Print 2 "IGCM_debug_sendAMQP_projectAccounting" |
---|
| 254 | echo ${encodedBody}|mailx -s "[TEMPORARY AMQP CHANNEL]" ${attachmentsOptions} ${mail_recipient} |
---|
[1290] | 255 | # clean behind |
---|
| 256 | rm -f $1 |
---|
[1285] | 257 | fi |
---|
| 258 | |
---|
| 259 | # Allways all good for now. |
---|
| 260 | return 0 |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | #D-#================================================================== |
---|
[913] | 264 | #D-function IGCM_debug_SendAMQP |
---|
| 265 | #D- * Purpose: Send body; encoded body and config.card to rabbitMQ |
---|
[1053] | 266 | function IGCM_debug_sendAMQP { |
---|
| 267 | |
---|
[913] | 268 | typeset decal first additionnalOption encodedBody |
---|
| 269 | |
---|
| 270 | # Encode message Body |
---|
| 271 | encodedBody=$( echo "${Body}" | base64 -w 0 ) |
---|
| 272 | |
---|
| 273 | # Send config.card ? |
---|
| 274 | if [ X${1} = Xactivate ] ; then |
---|
| 275 | # Encode config.card |
---|
| 276 | cat ${SUBMIT_DIR}/config.card | base64 -w 0 > ${SUBMIT_DIR}/config.card.base64 |
---|
| 277 | # Prepare additionnal option |
---|
| 278 | additionnalOption="-f ${SUBMIT_DIR}/config.card.base64" |
---|
[1076] | 279 | # |
---|
[1051] | 280 | initBigBro=true |
---|
[913] | 281 | else |
---|
| 282 | additionnalOption= |
---|
[1051] | 283 | # |
---|
| 284 | initBigBro=false |
---|
[913] | 285 | fi |
---|
| 286 | |
---|
| 287 | # Only cosmetics : stack file |
---|
[1115] | 288 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 289 | decal=0 |
---|
| 290 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 291 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
| 292 | (( decal = decal + 1 )) |
---|
| 293 | done |
---|
| 294 | # Log to stack file using human readable format |
---|
| 295 | echo "${Body}" >> ${StackFileLocation}/${StackFileName} |
---|
| 296 | fi |
---|
[913] | 297 | |
---|
[983] | 298 | # Log separately encoded AMQP message command for reuse in a mock up |
---|
[1120] | 299 | #echo sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody} >> ${RUN_DIR_PATH}/send.AMQP.${config_UserChoices_JobName}.${config_UserChoices_ExperimentName}.${config_UserChoices_SpaceName}.${config_UserChoices_TagName}.${CumulPeriod}.history.txt |
---|
[913] | 300 | |
---|
| 301 | # Send the message |
---|
[983] | 302 | if [ X${BigBrotherChannel} = XMAIL ] ; then |
---|
| 303 | IGCM_debug_send_AMQP_msg__MAILTUNNEL "${encodedBody}" |
---|
| 304 | status=$? |
---|
| 305 | else |
---|
| 306 | sendAMQPMsg -h localhost -p 5672 ${additionnalOption} -b ${encodedBody} |
---|
| 307 | status=$? |
---|
| 308 | fi |
---|
| 309 | |
---|
[913] | 310 | if [ ${status} -gt 0 ] ; then |
---|
| 311 | IGCM_debug_Print 2 "IGCM_debug_Push/PopStack/ActivateBigBro : command sendAMQPMsg failed error code ${status}" |
---|
[1051] | 312 | echo sendAMQPMsg -h localhost -p 5672 -b "${Body}" |
---|
[1090] | 313 | exit 1 |
---|
[913] | 314 | fi |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | #D-#================================================================== |
---|
[2] | 318 | #D-function IGCM_debug_CallStack |
---|
[913] | 319 | #D-* Purpose: Print the call stack tree from the oldest to the youngest (opposite of the display standard) |
---|
[2] | 320 | #D- |
---|
| 321 | function IGCM_debug_CallStack { |
---|
[544] | 322 | if ( $DEBUG_debug ) ; then |
---|
[913] | 323 | # Cosmetics |
---|
[544] | 324 | typeset i decal |
---|
[823] | 325 | i=0 |
---|
[544] | 326 | until [ $i -eq ${IGCM_debug_LenStack} ]; do |
---|
| 327 | decal=0 |
---|
| 328 | until [ $decal -eq ${i} ]; do |
---|
[869] | 329 | printf -- ' ' |
---|
[823] | 330 | (( decal = decal + 1 )) |
---|
[544] | 331 | done |
---|
[869] | 332 | echo "$i - ${IGCM_debug_Stack[$(( $IGCM_debug_LenStack-$i-1 ))]}" "(${IGCM_debug_StackArgs[$(( $IGCM_debug_LenStack-$i-1 ))]})" |
---|
[823] | 333 | ((i = i + 1)) |
---|
[544] | 334 | done |
---|
| 335 | fi |
---|
[2] | 336 | } |
---|
| 337 | |
---|
| 338 | #D-#================================================================== |
---|
| 339 | #D-function IGCM_debug_PushStack |
---|
| 340 | #D-* Purpose: Push a function name in the stack |
---|
| 341 | #D- |
---|
| 342 | function IGCM_debug_PushStack { |
---|
[544] | 343 | if ( $DEBUG_debug ) ; then |
---|
[913] | 344 | typeset decal inputs startTime_ms |
---|
| 345 | |
---|
| 346 | # Only cosmetics : stack file |
---|
[1115] | 347 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 348 | echo >> ${StackFileLocation}/${StackFileName} |
---|
| 349 | decal=0 |
---|
| 350 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 351 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
| 352 | (( decal = decal + 1 )) |
---|
| 353 | done |
---|
[2] | 354 | |
---|
[1115] | 355 | # Fill the stack file |
---|
| 356 | echo "> ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName} |
---|
| 357 | fi |
---|
[926] | 358 | |
---|
[913] | 359 | # Save input list in an indexed array |
---|
[823] | 360 | INPUTS=( $@ ) |
---|
[913] | 361 | |
---|
| 362 | # Get timing information |
---|
| 363 | startTime_ms=$( IGCM_debug_getDate_ms ) |
---|
| 364 | |
---|
[544] | 365 | # We add function call name on beginning of the stack |
---|
| 366 | set +A IGCM_debug_Stack -- ${1} ${IGCM_debug_Stack[*]} |
---|
[2] | 367 | |
---|
[913] | 368 | # Save timing in milliseconds in an indexed array |
---|
| 369 | set +A IGCM_debug_StackTiming -- ${startTime_ms} ${IGCM_debug_StackTiming[*]} |
---|
| 370 | |
---|
[544] | 371 | # We include the "null" Args in the beginning of the StackArgs |
---|
[913] | 372 | set +A IGCM_debug_StackArgs ${NULL_STR} ${IGCM_debug_StackArgs[*]} |
---|
| 373 | |
---|
[544] | 374 | # Then, we shift StackArgs tabular |
---|
[1065] | 375 | # Replacing blank separated list by comma separated list of quoted elements (except the first and last element) |
---|
[913] | 376 | if [ $# -gt 1 ]; then |
---|
[1065] | 377 | IGCM_debug_StackArgs[0]=$(echo ${INPUTS[*]:1} | sed -e "s/\ /\",\"/g" ) |
---|
[544] | 378 | fi |
---|
[855] | 379 | |
---|
| 380 | # Increment LenStack |
---|
[544] | 381 | (( IGCM_debug_LenStack = IGCM_debug_LenStack + 1 )) |
---|
[2] | 382 | |
---|
[869] | 383 | #IGCM_debug_CallStack |
---|
[544] | 384 | fi |
---|
[2] | 385 | } |
---|
| 386 | |
---|
| 387 | #D-#================================================================== |
---|
| 388 | #D-function IGCM_debug_PopStack |
---|
| 389 | #D-* Purpose: Pop a function name in the stack |
---|
| 390 | #D- |
---|
| 391 | function IGCM_debug_PopStack { |
---|
[544] | 392 | if ( $DEBUG_debug ) ; then |
---|
[926] | 393 | typeset i decal command arguments startTime_ms endTime_ms |
---|
[941] | 394 | typeset instrumentation dest prefix |
---|
[926] | 395 | # they are not typeset because they are send "by adress" to son functions |
---|
| 396 | # we unset them to avoid "memory effect" |
---|
| 397 | unset fileList source |
---|
[913] | 398 | |
---|
| 399 | # INTRODUCE SIMPLE ERROR GENERATOR TO TEST SUPERVISOR |
---|
| 400 | # PROBABILITY ERROR IS 0.0001 PER COMMAND OR FUNCTION CALL |
---|
| 401 | # THERE ARE ~500 COMMAND OR FUNCTION CALL PER PERIOD |
---|
[1277] | 402 | # ONLY WHEN TaskType is "computing". |
---|
| 403 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 404 | if [ X${TaskType} = Xcomputing ]; then |
---|
| 405 | if ( ${RandomError} ) ; then |
---|
| 406 | if [ $((RANDOM%10000)) -le 10 ] ; then |
---|
| 407 | IGCM_debug_Print 1 "Random error has been triggered" |
---|
| 408 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 409 | echo "RANDOM ERROR" >> ${StackFileLocation}/${StackFileName} |
---|
| 410 | fi |
---|
| 411 | ExitFlag=true |
---|
| 412 | fi |
---|
[1115] | 413 | fi |
---|
[913] | 414 | fi |
---|
| 415 | fi |
---|
| 416 | |
---|
[544] | 417 | if [ "${IGCM_debug_Stack[0]}" = "${1}" ]; then |
---|
[913] | 418 | # Everything is cool |
---|
| 419 | |
---|
| 420 | # Get timing information |
---|
| 421 | endTime_ms=$( IGCM_debug_getDate_ms ) |
---|
| 422 | |
---|
| 423 | # Save Stack information before poping the stack |
---|
| 424 | command=${IGCM_debug_Stack[0]} |
---|
| 425 | |
---|
[1084] | 426 | # Go from comma separated list of quoted elements (except the first and the last element) |
---|
| 427 | # to unquoted space separated elements in an array |
---|
[1083] | 428 | set -A arguments -- $( echo ${IGCM_debug_StackArgs[0]} | sed -e "s/\",\"/\ /g" ) |
---|
[913] | 429 | |
---|
| 430 | # Save Stack information before poping the stack |
---|
| 431 | startTime_ms=${IGCM_debug_StackTiming[0]} |
---|
| 432 | |
---|
| 433 | # Pop the stack |
---|
[823] | 434 | (( IGCM_debug_LenStack = IGCM_debug_LenStack - 1 )) |
---|
| 435 | set -A IGCM_debug_Stack -- ${IGCM_debug_Stack[*]:1} |
---|
| 436 | set -A IGCM_debug_StackArgs -- ${IGCM_debug_StackArgs[*]:1} |
---|
[913] | 437 | set -A IGCM_debug_StackTiming -- ${IGCM_debug_StackTiming[*]:1} |
---|
[544] | 438 | else |
---|
| 439 | echo 'IGCM_debug_Exit : stack is corrupted ! LenStack =' ${IGCM_debug_LenStack} |
---|
| 440 | IGCM_debug_Exit $@ |
---|
| 441 | fi |
---|
[913] | 442 | |
---|
[914] | 443 | # Special actions depending on command to prepare IGCM_debug_PrintInfosActions call |
---|
[913] | 444 | # We are interested in: |
---|
| 445 | # 0. Which command performs the work |
---|
| 446 | # 1. Size of entity we are working with |
---|
| 447 | # 2. Where are we reading |
---|
| 448 | # 3. Where are we writing |
---|
| 449 | # 4. How long it took |
---|
| 450 | |
---|
[915] | 451 | instrumentation=false |
---|
| 452 | |
---|
[913] | 453 | case ${command} in |
---|
[925] | 454 | # Classical copy (only files are given to IGCM_sys_Cp as options) |
---|
| 455 | IGCM_sys_Cp) |
---|
| 456 | instrumentation=true |
---|
| 457 | # All but the latest |
---|
| 458 | fileList=${arguments[*]:0:${#arguments[*]}-1} |
---|
| 459 | # just need the first file to get the directory |
---|
| 460 | source=${arguments[0]} |
---|
| 461 | # Nothing but the latest |
---|
| 462 | dest=${arguments[${#arguments[*]}-1]} |
---|
| 463 | # Size of file whose name are stored in a list |
---|
| 464 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
| 465 | ;; |
---|
| 466 | |
---|
[913] | 467 | # Copy from archive machine or from buffer |
---|
| 468 | IGCM_sys_Get|IGCM_sys_GetBuffer) |
---|
[915] | 469 | instrumentation=true |
---|
[913] | 470 | if [ ${#arguments[*]} -eq 2 ] ; then |
---|
| 471 | source=${arguments[0]} |
---|
| 472 | dest=${arguments[1]} |
---|
| 473 | # Size of file whose name are stored in a variable |
---|
[917] | 474 | entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} ) |
---|
[913] | 475 | elif ( [ ${#arguments[*]} -eq 3 ] && [ ${arguments[0]} = '/l' ] ) ; then |
---|
[936] | 476 | # IGCM_sys_Get /l liste_file[*] /ccc/scratch/cont003/dsm/p86denv/RUN_DIR/985998_14754/ |
---|
[913] | 477 | # Keep the array name hosting the all list |
---|
[936] | 478 | eval set +A fileList \${${arguments[1]}} |
---|
[913] | 479 | # just need the first file to get the directory |
---|
[936] | 480 | source=${fileList[0]} |
---|
[931] | 481 | dest=${arguments[2]} |
---|
[934] | 482 | # Size of file whose name are stored in a list |
---|
[936] | 483 | entitySize=$( IGCM_debug_sizeOfTabContent fileList[*] ${dest} ) |
---|
[913] | 484 | elif [ [ ${#arguments[*]} -ge 3 ] ; then |
---|
| 485 | # All but the latest |
---|
[916] | 486 | fileList=${arguments[*]:0:${#arguments[*]}-1} |
---|
[913] | 487 | # just need the first file to get the directory |
---|
| 488 | source=${arguments[0]} |
---|
| 489 | # Nothing but the latest |
---|
| 490 | dest=${arguments[${#arguments[*]}-1]} |
---|
| 491 | # Size of file whose name are stored in a list |
---|
[917] | 492 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
[913] | 493 | fi |
---|
| 494 | ;; |
---|
| 495 | |
---|
[925] | 496 | # Copy from compute node or copy to archive/buffer |
---|
| 497 | IGCM_sys_Get_Master|IGCM_sys_Get_Dir|IGCM_sys_Put_Out|IGCM_sys_PutBuffer_Out) |
---|
[924] | 498 | instrumentation=true |
---|
[916] | 499 | source=${arguments[0]} |
---|
[924] | 500 | dest=${arguments[1]} |
---|
| 501 | # Size of file whose name are stored in a variable |
---|
| 502 | entitySize=$( IGCM_debug_sizeOfTabContent source ${dest} ) |
---|
[913] | 503 | ;; |
---|
| 504 | |
---|
| 505 | # Rebuild command |
---|
| 506 | IGCM_sys_rebuild|IGCM_sys_rebuild_station) |
---|
[915] | 507 | instrumentation=true |
---|
[913] | 508 | # All but the first |
---|
| 509 | fileList=${arguments[*]:1:${#arguments[*]}-1} |
---|
| 510 | # just need a file to get the directory |
---|
| 511 | source=${arguments[1]} |
---|
| 512 | # Nothing but the first |
---|
| 513 | dest=${arguments[0]} |
---|
| 514 | # Size of file whose name are stored in a list |
---|
[917] | 515 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
[913] | 516 | ;; |
---|
[941] | 517 | |
---|
[926] | 518 | # NCO commands |
---|
| 519 | IGCM_sys_ncrcat|IGCM_sys_ncecat|IGCM_sys_ncra|IGCM_sys_ncks|IGCM_sys_cdo) |
---|
| 520 | # Example of what we want to catch : only filenames in those command lines |
---|
| 521 | # IGCM_sys_ncrcat -O -v ${list_var_final_ncrcat} ${OUT_SE[*]} ${RESULT_SE} |
---|
| 522 | # IGCM_sys_ncrcat --hst -v ${liste_coord}${var} ${file1} ${liste_file_tmp[*]} ${file_out} |
---|
| 523 | # IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output} |
---|
| 524 | # IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output} |
---|
| 525 | instrumentation=true |
---|
[941] | 526 | keepGoing=true |
---|
| 527 | prefix=. |
---|
[926] | 528 | i=0 |
---|
| 529 | while ( ${keepGoing} ) ; do |
---|
[941] | 530 | # the last one is not interesting |
---|
| 531 | if [ ${i} -eq ${#arguments[*]}-1 ] ; then |
---|
| 532 | keepGoing=false |
---|
| 533 | # look after "-p" option. Path prefix is the following arguments |
---|
| 534 | elif [ ${arguments[${i}]} = "-p" ] ; then |
---|
[926] | 535 | ((i = i + 1)) |
---|
[941] | 536 | prefix=${arguments[${i}]} |
---|
| 537 | ((i = i + 1)) |
---|
| 538 | elif [ ${i} -eq ${#arguments[*]}-1 ] ; then |
---|
[926] | 539 | keepGoing=false |
---|
[941] | 540 | # looking for files |
---|
| 541 | elif [ -f ${prefix}/${arguments[${i}]} ] ; then |
---|
| 542 | fileList="${fileList} ${prefix}/${arguments[${i}]}" |
---|
| 543 | ((i = i + 1)) |
---|
| 544 | # other options are not interesting |
---|
[926] | 545 | else |
---|
| 546 | ((i = i + 1)) |
---|
| 547 | fi |
---|
| 548 | done |
---|
[941] | 549 | |
---|
[926] | 550 | # i value is at least 1 |
---|
| 551 | # just need one file to get the directory |
---|
[941] | 552 | source=$( echo ${fileList} | gawk '{print $1}' ) |
---|
[926] | 553 | # Nothing but the latest |
---|
| 554 | dest=${arguments[${#arguments[*]}-1]} |
---|
| 555 | # Size of file whose name are stored in a list |
---|
| 556 | entitySize=$( IGCM_debug_sizeOfTabContent fileList ${dest} ) |
---|
| 557 | ;; |
---|
[913] | 558 | esac |
---|
| 559 | |
---|
| 560 | # Print information related to instrumentation |
---|
[915] | 561 | ( ${instrumentation} ) && IGCM_debug_PrintInfosActions ${command} ${entitySize} ${startTime_ms} ${endTime_ms} ${dest} ${source} |
---|
[913] | 562 | |
---|
| 563 | # Only cosmetics : stack file |
---|
[1115] | 564 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 565 | decal=0 |
---|
| 566 | while [ ${decal} -lt ${IGCM_debug_LenStack} ]; do |
---|
| 567 | printf ' ' >> ${StackFileLocation}/${StackFileName} |
---|
| 568 | (( decal = decal + 1 )) |
---|
| 569 | done |
---|
| 570 | fi |
---|
[2] | 571 | |
---|
[855] | 572 | if ( ${ExitFlag} ) ; then |
---|
| 573 | # Inform the stack file |
---|
[1115] | 574 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 575 | echo '!!! ExitFlag has been activated !!!' >> ${StackFileLocation}/${StackFileName} |
---|
| 576 | fi |
---|
[874] | 577 | |
---|
[1216] | 578 | # Unplugged message 4900 handling for now. To ease downstream treatment. |
---|
[1244] | 579 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 580 | if [ X${TaskType} = Xcomputing ]; then |
---|
| 581 | # RabbitMQ message code "COMPUTING JOBs COMMAND FAILURE" |
---|
| 582 | code=1900 |
---|
| 583 | elif [ X${TaskType} = Xpost-processing ]; then |
---|
| 584 | # RabbitMQ message code "POST-PROCESSING JOBs COMMAND FAILURE" |
---|
| 585 | code=2900 |
---|
| 586 | elif [ X${TaskType} = Xchecking ]; then |
---|
| 587 | # RabbitMQ message code "POST-PROCESSING FROM CHECKER JOBs COMMAND FAILURE" |
---|
| 588 | code=3900 |
---|
| 589 | fi |
---|
| 590 | # RabbitMQ message body |
---|
| 591 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"command\":\"${command}\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
| 592 | |
---|
| 593 | # Fill the rabbitMQ queue |
---|
| 594 | IGCM_debug_sendAMQP |
---|
| 595 | fi |
---|
[855] | 596 | else |
---|
| 597 | # Inform the stack file |
---|
[1115] | 598 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 599 | echo "< ${IGCM_debug_LenStack} : ${@}" >> ${StackFileLocation}/${StackFileName} |
---|
| 600 | fi |
---|
[855] | 601 | fi |
---|
| 602 | |
---|
[913] | 603 | # Reset array if necessary |
---|
[544] | 604 | if [ ${IGCM_debug_LenStack} = 0 ]; then |
---|
| 605 | #echo |
---|
| 606 | #IGCM_debug_Print 3 "Clean stack array" |
---|
| 607 | #echo |
---|
| 608 | unset IGCM_debug_Stack |
---|
| 609 | unset IGCM_debug_StackArgs |
---|
[913] | 610 | unset IGCM_debug_StackTiming |
---|
[544] | 611 | IGCM_debug_Stack[0]=${NULL_STR} |
---|
| 612 | IGCM_debug_StackArgs[0]=${NULL_STR} |
---|
[913] | 613 | IGCM_debug_StackTiming[0]=${NULL_STR} |
---|
[2] | 614 | fi |
---|
[544] | 615 | fi |
---|
[869] | 616 | #IGCM_debug_CallStack |
---|
[2] | 617 | } |
---|
| 618 | |
---|
| 619 | #D-#================================================================== |
---|
[1189] | 620 | #D-function IGCM_debug_BigBro_Initialize |
---|
[855] | 621 | #D-* Purpose: switch rabbitMQ on |
---|
| 622 | #D- |
---|
[1189] | 623 | function IGCM_debug_BigBro_Initialize { |
---|
| 624 | IGCM_debug_PushStack "IGCM_debug_BigBro_Initialize" |
---|
[855] | 625 | |
---|
[1347] | 626 | typeset postProcessingIDLength postProcessingName postProcessingDate postProcessingDimn postProcessingComp postProcessingFile accountingFile |
---|
[1229] | 627 | |
---|
[1051] | 628 | # Message type standard fields: |
---|
| 629 | # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields |
---|
| 630 | |
---|
| 631 | # Message type dictionnary and custom fields: |
---|
| 632 | # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary |
---|
| 633 | |
---|
[868] | 634 | if [ X${BigBrother} = Xtrue ] ; then |
---|
[1051] | 635 | # create a unique ID for this specific job |
---|
| 636 | jobuid=$(uuidgen) |
---|
[913] | 637 | |
---|
[1244] | 638 | # get the assigned id by the scheduler for that job |
---|
| 639 | IGCM_sys_getJobSchedulerID jobSchedulerID |
---|
| 640 | |
---|
[1189] | 641 | if [ X${TaskType} = Xcomputing ]; then |
---|
| 642 | if ( ${FirstInitialize} ) ; then |
---|
| 643 | # RabbitMQ message code "BEGIN A SIMULATION" |
---|
| 644 | code=0000 |
---|
| 645 | # create and persist a unique id for this simulation |
---|
| 646 | simuid=$(uuidgen) |
---|
| 647 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration simuid ${simuid} |
---|
| 648 | # Standard fields for the first message |
---|
[1244] | 649 | genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"activity\":\"IPSL\",\"name\":\"${config_UserChoices_JobName}\",\"experiment\":\"${config_UserChoices_ExperimentName}\",\"space\":\"${config_UserChoices_SpaceName}\",\"model\":\"${config_UserChoices_TagName}\",\"startDate\":\"${config_UserChoices_DateBegin}\",\"endDate\":\"${config_UserChoices_DateEnd}\",\"login\":\"${LOGIN}\",\"centre\":\"${CENTER}\",\"machine\":\"${MASTER}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" ) |
---|
[1189] | 650 | # RabbitMQ message body with specific fields associated message codes treated here |
---|
[1277] | 651 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
[1189] | 652 | # Fill the rabbitMQ queue (the config.card in use will be sent) |
---|
| 653 | IGCM_debug_sendAMQP activate |
---|
| 654 | else |
---|
| 655 | # RabbitMQ message code "A NEW COMPUTING JOB IS RUNNING PART OF A SIMULATION" |
---|
| 656 | code=1000 |
---|
| 657 | # retrieve this simulation's unique id |
---|
| 658 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid |
---|
| 659 | simuid=${run_Configuration_simuid} |
---|
| 660 | # Using standard fields for message others than the first one. Still subject to change |
---|
[1244] | 661 | genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" ) |
---|
[1189] | 662 | # RabbitMQ message body with specific fields associated message codes treated here |
---|
[1244] | 663 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
[1189] | 664 | # Fill the rabbitMQ queue |
---|
| 665 | IGCM_debug_sendAMQP |
---|
| 666 | fi |
---|
| 667 | |
---|
| 668 | # NOT VERY NICE BUT ... IT WORKS |
---|
| 669 | # Be sure that the genericSimulationID will be small from now on |
---|
| 670 | # Using standard fields for messages others than the first one. Still subject to change |
---|
[1244] | 671 | genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" ) |
---|
[1189] | 672 | |
---|
| 673 | elif [ X${TaskType} = Xpost-processing ]; then |
---|
| 674 | # RabbitMQ message code "A NEW POST-PROCESSING JOB IS RUNNING PART OF A SIMULATION" |
---|
| 675 | code=2000 |
---|
[1076] | 676 | # retrieve this simulation's unique id |
---|
[1051] | 677 | IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration simuid |
---|
[1086] | 678 | simuid=${run_Configuration_simuid} |
---|
[1076] | 679 | # Using standard fields for message others than the first one. Still subject to change |
---|
[1244] | 680 | genericSimulationID=$( echo "\"msgApplication\":\"monitoring\",\"msgProducer\":\"libigcm\",\"msgProducerVersion\":\"${libIGCMVersion}\",\"simuid\":\"${simuid}\",\"jobuid\":\"${jobuid}\"" ) |
---|
[1229] | 681 | |
---|
| 682 | # Specify the post-processing task we are dealing with |
---|
[1244] | 683 | postProcessingIDLength=$( echo "${Script_Post_Output}" | tr -d -c "\." | wc -c ) |
---|
[1229] | 684 | postProcessingName=$( echo "${Script_Post_Output}" | gawk -F. '{print $1}' ) |
---|
| 685 | postProcessingDate=$( echo "${Script_Post_Output}" | gawk -F. '{print $2}' ) |
---|
[1231] | 686 | postProcessingDimn="null" |
---|
| 687 | postProcessingComp="null" |
---|
| 688 | postProcessingFile="null" |
---|
[1254] | 689 | if [ ${postProcessingIDLength} -eq 2 ] ; then |
---|
[1231] | 690 | postProcessingDimn=$( echo "${Script_Post_Output}" | gawk -F. '{print $3}' ) |
---|
[1254] | 691 | elif [ ${postProcessingIDLength} -eq 4 ] ; then |
---|
[1229] | 692 | postProcessingComp=$( echo "${Script_Post_Output}" | gawk -F. '{print $4}' ) |
---|
| 693 | postProcessingFile=$( echo "${Script_Post_Output}" | gawk -F. '{print $5}' ) |
---|
| 694 | fi |
---|
| 695 | |
---|
[1087] | 696 | # RabbitMQ message body with specific fields associated message codes treated here |
---|
[1244] | 697 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"accountingProject\":\"${PROJECT}\",\"jobWarningDelay\":\"${jobWarningDelay}\",\"jobSchedulerID\":\"${jobSchedulerID}\",\"jobSubmissionPath\":\"${SUBMIT_DIR}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\",\"postProcessingName\":\"${postProcessingName}\",\"postProcessingDate\":\"${postProcessingDate}\",\"postProcessingDimn\":\"${postProcessingDimn}\",\"postProcessingComp\":\"${postProcessingComp}\",\"postProcessingFile\":\"${postProcessingFile}\"}" ) |
---|
[1087] | 698 | # Fill the rabbitMQ queue |
---|
| 699 | IGCM_debug_sendAMQP |
---|
[855] | 700 | fi |
---|
[1285] | 701 | |
---|
[1295] | 702 | # Turn the flag on |
---|
| 703 | ActivateBigBro=true |
---|
| 704 | |
---|
[1285] | 705 | # Save project accounting details in a file |
---|
[1347] | 706 | accountingFile=cpt_${CENTER}_${PROJECT}_$( date +"%Y%m%d_%H%M" ).dat |
---|
| 707 | IGCM_sys_projectAccounting ${accountingFile} |
---|
[1285] | 708 | |
---|
| 709 | # And send it |
---|
[1347] | 710 | IGCM_debug_sendAMQP_projectAccounting ${accountingFile} |
---|
[1285] | 711 | |
---|
[855] | 712 | fi |
---|
[1189] | 713 | IGCM_debug_PopStack "IGCM_debug_BigBro_Initialize" |
---|
[855] | 714 | } |
---|
| 715 | |
---|
| 716 | #D-#================================================================== |
---|
[1332] | 717 | #D-function IGCM_debug_BigBro_Update |
---|
| 718 | #D-* Purpose: Update rabbitMQ messages exchanges during the run |
---|
| 719 | #D- |
---|
| 720 | function IGCM_debug_BigBro_Update { |
---|
| 721 | IGCM_debug_PushStack "IGCM_debug_BigBro_Update" |
---|
| 722 | |
---|
| 723 | # Message type standard fields: |
---|
| 724 | # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields |
---|
| 725 | |
---|
| 726 | # Message type dictionnary and custom fields: |
---|
| 727 | # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary |
---|
| 728 | |
---|
| 729 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 730 | if [ X${TaskType} = Xcomputing ]; then |
---|
| 731 | # Send ${PeriodDateBegin}, ${PeriodDateEnd} and ${CumulPeriod} |
---|
| 732 | # RabbitMQ message body |
---|
[1348] | 733 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"1001\",\"PeriodDateBegin\":\"${PeriodDateBegin}\",\"PeriodDateEnd\":\"${PeriodDateEnd}\",\"CumulPeriod\":\"${CumulPeriod}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
[1332] | 734 | # Fill the rabbitMQ queue |
---|
| 735 | IGCM_debug_sendAMQP |
---|
| 736 | fi |
---|
| 737 | fi |
---|
| 738 | IGCM_debug_PopStack "IGCM_debug_BigBro_Update" |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | #D-#================================================================== |
---|
[1189] | 742 | #D-function IGCM_debug_BigBro_Finalize |
---|
| 743 | #D-* Purpose: Finalize rabbitMQ messages exchanges |
---|
| 744 | #D- |
---|
| 745 | function IGCM_debug_BigBro_Finalize { |
---|
| 746 | IGCM_debug_PushStack "IGCM_debug_BigBro_Finalize" |
---|
| 747 | |
---|
| 748 | # Message type standard fields: |
---|
| 749 | # https://github.com/Prodiguer/prodiguer-docs/wiki/MQ-Standard-Message-Fields |
---|
| 750 | |
---|
| 751 | # Message type dictionnary and custom fields: |
---|
| 752 | # https://github.com/Prodiguer/prodiguer-docs/wiki/Monitoring-Message-Dictionary |
---|
| 753 | |
---|
| 754 | if ( $DEBUG_debug ) ; then |
---|
| 755 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 756 | if [ X${TaskType} = Xcomputing ]; then |
---|
| 757 | if ( ${simulationIsOver} ) ; then |
---|
| 758 | # RabbitMQ message code "SIMULATION ENDS" |
---|
| 759 | code=0100 |
---|
| 760 | FlushAMQP=true |
---|
[1207] | 761 | elif ( ${ExitFlag} ) ; then |
---|
| 762 | # RabbitMQ message code "EXIT THE JOBS BECAUSE ERROR(S) HAS BEEN TRIGGERED" |
---|
[1244] | 763 | code=1999 |
---|
[1207] | 764 | FlushAMQP=true |
---|
[1189] | 765 | else |
---|
| 766 | # RabbitMQ message code "COMPUTING JOB ENDS" |
---|
| 767 | code=1100 |
---|
| 768 | fi |
---|
| 769 | elif [ X${TaskType} = Xpost-processing ]; then |
---|
[1207] | 770 | if ( ${ExitFlag} ) ; then |
---|
| 771 | # RabbitMQ message code "POST-PROCESSING JOB FAILS" |
---|
[1244] | 772 | code=2999 |
---|
[1207] | 773 | FlushAMQP=true |
---|
[1244] | 774 | else |
---|
[1207] | 775 | # RabbitMQ message code "POST-PROCESSING JOB ENDS" |
---|
| 776 | code=2100 |
---|
| 777 | FlushAMQP=true |
---|
| 778 | fi |
---|
[1244] | 779 | elif [ X${TaskType} = Xchecking ]; then |
---|
| 780 | if ( ${ExitFlag} ) ; then |
---|
| 781 | # RabbitMQ message code "POST-PROCESSING JOB FAILS" |
---|
| 782 | code=3999 |
---|
| 783 | FlushAMQP=true |
---|
| 784 | else |
---|
| 785 | # RabbitMQ message code "POST-PROCESSING JOB ENDS" |
---|
| 786 | code=3100 |
---|
| 787 | FlushAMQP=true |
---|
| 788 | fi |
---|
[1189] | 789 | fi |
---|
| 790 | # RabbitMQ message body |
---|
| 791 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
| 792 | # Fill the rabbitMQ queue |
---|
| 793 | IGCM_debug_sendAMQP |
---|
| 794 | fi |
---|
| 795 | fi |
---|
| 796 | |
---|
| 797 | IGCM_debug_PopStack "IGCM_debug_BigBro_Finalize" |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | #D-#================================================================== |
---|
[2] | 801 | #D-function IGCM_debug_Exit |
---|
| 802 | #D-* Purpose: Print Call Stack and set ExitFlag to true |
---|
| 803 | #D- |
---|
| 804 | function IGCM_debug_Exit { |
---|
[544] | 805 | IGCM_debug_PushStack "IGCM_debug_Exit" |
---|
| 806 | echo "IGCM_debug_Exit : " "${@}" |
---|
[913] | 807 | echo |
---|
[894] | 808 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!" |
---|
[913] | 809 | echo "!! ERROR TRIGGERED !!" |
---|
| 810 | echo "!! EXIT FLAG SET !!" |
---|
| 811 | echo "!------------------------!" |
---|
| 812 | echo |
---|
[894] | 813 | IGCM_debug_CallStack |
---|
[544] | 814 | ExitFlag=true |
---|
| 815 | IGCM_debug_PopStack "IGCM_debug_Exit" |
---|
[2] | 816 | } |
---|
| 817 | |
---|
| 818 | #D-#================================================== |
---|
| 819 | #D-function IGCM_debug_Verif_Exit |
---|
| 820 | #D-* Purpose: exit with number 1 if ExitFlag is true |
---|
| 821 | #D- |
---|
| 822 | function IGCM_debug_Verif_Exit { |
---|
[544] | 823 | if ( ${ExitFlag} ) ; then |
---|
[1206] | 824 | echo "IGCM_debug_Verif_Exit : Something wrong happened previously." |
---|
[1207] | 825 | echo "IGCM_debug_Verif_Exit : ERROR and EXIT keyword will help find out where." |
---|
[1206] | 826 | # Only computing TaskType stops the job for now. |
---|
| 827 | if [ X${TaskType} = Xcomputing ] ; then |
---|
[775] | 828 | IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal" |
---|
| 829 | echo " EXIT THE JOB." |
---|
| 830 | echo |
---|
[869] | 831 | IGCM_debug_CallStack |
---|
[874] | 832 | |
---|
[1206] | 833 | # Mail notification |
---|
| 834 | IGCM_sys_SendMail |
---|
[913] | 835 | |
---|
[1207] | 836 | # Inform the rabbitMQ queue |
---|
| 837 | IGCM_debug_BigBro_Finalize |
---|
| 838 | |
---|
[544] | 839 | # And Good Bye |
---|
| 840 | date |
---|
| 841 | exit 1 |
---|
[1206] | 842 | |
---|
| 843 | elif [ X${TaskType} = Xpost-processing ] ; then |
---|
[1302] | 844 | StopAll=false |
---|
[1282] | 845 | # Test if we need to stop the computing job |
---|
| 846 | case ${postProcessingName} in |
---|
| 847 | atlas*|monitoring*|metrics*) |
---|
| 848 | [ ${postProcessingStopLevel} -gt 2 ] && StopAll=true ;; |
---|
| 849 | create_*) |
---|
| 850 | [ ${postProcessingStopLevel} -gt 1 ] && StopAll=true ;; |
---|
| 851 | rebuild*|pack_*) |
---|
| 852 | [ ${postProcessingStopLevel} -gt 0 ] && StopAll=true ;; |
---|
| 853 | esac |
---|
| 854 | # Notify the computing job that something wrong happened and stop it. |
---|
[1302] | 855 | ( ${StopAll} ) && IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Fatal.${Script_Post_Output}" |
---|
[1282] | 856 | |
---|
| 857 | # If SpaceName is PROD we stop when post_processing failed |
---|
[1206] | 858 | if [ X${config_UserChoices_SpaceName} = XPROD ] ; then |
---|
[1220] | 859 | echo " EXIT THE POST-PROCESSING JOB." |
---|
[1206] | 860 | echo |
---|
[1207] | 861 | IGCM_debug_CallStack |
---|
| 862 | |
---|
| 863 | # Inform the rabbitMQ queue |
---|
| 864 | IGCM_debug_BigBro_Finalize |
---|
| 865 | |
---|
[1206] | 866 | # And Good Bye |
---|
| 867 | date |
---|
| 868 | exit 1 |
---|
| 869 | else |
---|
[1207] | 870 | echo "In config.card the variable SpaceName is not in PROD" |
---|
[1206] | 871 | echo " SO WE DO NOT EXIT THE JOB." |
---|
| 872 | echo |
---|
| 873 | date |
---|
| 874 | fi |
---|
| 875 | elif [ X${TaskType} = Xchecking ] ; then |
---|
[1207] | 876 | echo "Nothing will happen for now" |
---|
[2] | 877 | fi |
---|
[544] | 878 | fi |
---|
[2] | 879 | } |
---|
| 880 | |
---|
| 881 | #D-#================================================================== |
---|
| 882 | #D-function IGCM_debug_Print |
---|
| 883 | #D-* Purpose: Print arguments according to a level of verbosity. |
---|
| 884 | #D- |
---|
| 885 | function IGCM_debug_Print |
---|
| 886 | { |
---|
[544] | 887 | typeset level=$1 |
---|
| 888 | shift |
---|
| 889 | |
---|
| 890 | if [ X"${1}" = X"-e" ]; then |
---|
| 891 | typeset cmd_echo="echo -e" |
---|
[2] | 892 | shift |
---|
[544] | 893 | else |
---|
| 894 | typeset cmd_echo="echo" |
---|
| 895 | fi |
---|
[2] | 896 | |
---|
[544] | 897 | if [ ${level} -le ${Verbosity} ] ; then |
---|
| 898 | typeset i |
---|
| 899 | case "${level}" in |
---|
| 900 | 1) for i in "$@" ; do |
---|
[734] | 901 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--Debug1-->" ${i} |
---|
[913] | 902 | done ;; |
---|
[544] | 903 | 2) for i in "$@" ; do |
---|
[734] | 904 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------Debug2-->" ${i} |
---|
[913] | 905 | done ;; |
---|
[544] | 906 | 3) for i in "$@" ; do |
---|
[734] | 907 | ${cmd_echo} $(date +"%Y-%m-%d %T") "--------------Debug3-->" ${i} |
---|
[913] | 908 | done ;; |
---|
[544] | 909 | esac |
---|
| 910 | fi |
---|
[2] | 911 | } |
---|
| 912 | |
---|
| 913 | #D-#================================================================== |
---|
| 914 | #D-function IGCM_debug_PrintVariables |
---|
| 915 | #D-* Purpose: Print arguments when match a pattern |
---|
| 916 | #D- according to a level of verbosity. |
---|
| 917 | function IGCM_debug_PrintVariables |
---|
| 918 | { |
---|
[544] | 919 | typeset level=$1 |
---|
| 920 | shift |
---|
[2] | 921 | |
---|
[830] | 922 | list=$( set | grep ^$1 | sed -e "s/'//g" ) |
---|
[54] | 923 | |
---|
[544] | 924 | if [ "X${list}" != X ] ; then |
---|
| 925 | IGCM_debug_Print ${level} ${list} |
---|
| 926 | fi |
---|
[2] | 927 | } |
---|
| 928 | |
---|
| 929 | #D-#================================================================== |
---|
[914] | 930 | #D-function IGCM_debug_PrintInfosActions |
---|
[913] | 931 | #D-* Purpose: Print information related to instrumentation |
---|
| 932 | function IGCM_debug_PrintInfosActions |
---|
| 933 | { |
---|
| 934 | typeset actionType=$1 |
---|
| 935 | typeset entitySize=$2 |
---|
| 936 | typeset start_ms=$3 |
---|
| 937 | typeset end_ms=$4 |
---|
| 938 | |
---|
| 939 | typeset dest=$5 |
---|
| 940 | typeset source=$6 |
---|
| 941 | |
---|
| 942 | typeset diff_ms entitySizeKo entitySizeMo flux_Ko_ms flux_Ko_s flux_Mo_s |
---|
[1090] | 943 | typeset dirFrom dirTo |
---|
[913] | 944 | |
---|
| 945 | diff_ms=$(( $end_ms - $start_ms )) |
---|
| 946 | # echo "diff_ms=$diff_ms" |
---|
| 947 | |
---|
| 948 | entitySizeKo=$( echo ${entitySize} | gawk -F"|" '{print $1}' ) |
---|
| 949 | # echo "entitySizeKo=$entitySizeKo" |
---|
| 950 | entitySizeMo=$( echo ${entitySize} | gawk -F"|" '{print $2}' ) |
---|
| 951 | |
---|
| 952 | # flux en Ko / ms |
---|
| 953 | flux_Ko_ms=$( echo "scale=6;${entitySizeKo}/${diff_ms}" | bc ) |
---|
| 954 | # echo "flux_Ko_ms=$flux_Ko_ms" |
---|
| 955 | |
---|
| 956 | # flux en Ko / s |
---|
| 957 | flux_Ko_s=$(( $flux_Ko_ms * 1000 )) |
---|
| 958 | # echo "flux_Ko_s=$flux_Ko_s" |
---|
| 959 | |
---|
| 960 | # flux en Mo / s |
---|
| 961 | flux_Mo_s=$( echo "scale=6;${flux_Ko_s}/1024" | bc ) |
---|
| 962 | # echo "flux_Mo_s=$flux_Mo_s" |
---|
| 963 | |
---|
| 964 | if [ -d $dest ] ; then |
---|
[1090] | 965 | dirTo=$( readlink -f ${dest} ) |
---|
[913] | 966 | else |
---|
[1090] | 967 | dirTo=$( readlink -f $( dirname ${dest} ) ) |
---|
[913] | 968 | fi |
---|
| 969 | |
---|
| 970 | if [ -d $source ] ; then |
---|
[1090] | 971 | dirFrom=$( readlink -f ${source} ) |
---|
[913] | 972 | else |
---|
[1090] | 973 | dirFrom=$( readlink -f $( dirname ${source} ) ) |
---|
[913] | 974 | fi |
---|
| 975 | |
---|
[1094] | 976 | instrumentationContent=$( echo "\"actionName\":\"${actionType}\",\"size_Mo\":\"${entitySizeMo}\",\"duration_ms\":\"${diff_ms}\",\"throughput_Mo_s\":\"${flux_Mo_s}\",\"dirFrom\":\"${dirFrom}\",\"dirTo\":\"${dirTo}\"" ) |
---|
[1050] | 977 | |
---|
[1115] | 978 | if [ X${ActivateStackFilling} = Xtrue ] ; then |
---|
| 979 | echo "{${instrumentationContent}}" >> ${StackFileLocation}/${StackFileName} |
---|
| 980 | fi |
---|
[1050] | 981 | |
---|
| 982 | # Inform the rabbitMQ queue |
---|
| 983 | if [ X${ActivateBigBro} = Xtrue ] ; then |
---|
| 984 | # RabbitMQ message body |
---|
[1065] | 985 | Body=$( echo "{${genericSimulationID},\"msgCode\":\"7000\",\"msgUID\":\"$(uuidgen)\",${instrumentationContent},\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" ) |
---|
[1050] | 986 | # Fill the rabbitMQ queue |
---|
| 987 | IGCM_debug_sendAMQP |
---|
| 988 | fi |
---|
[913] | 989 | } |
---|
| 990 | |
---|
| 991 | #D-#================================================================== |
---|
[2] | 992 | #D-function IGCM_debug_Check |
---|
| 993 | #D- * Purpose: Check the present file by comparison with a reference file |
---|
| 994 | function IGCM_debug_Check |
---|
| 995 | { |
---|
[544] | 996 | #--------------------- |
---|
| 997 | if [ ! -n "${libIGCM}" ] ; then |
---|
| 998 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 999 | echo "--Error--> libIGCM variable is not defined" |
---|
| 1000 | exit 2 |
---|
| 1001 | fi |
---|
[2] | 1002 | |
---|
[544] | 1003 | #--------------------- |
---|
| 1004 | if [ ! -n "${Verbosity}" ] ; then |
---|
| 1005 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 1006 | echo "--Error--> Verbosity variable is not defined" |
---|
| 1007 | exit 3 |
---|
| 1008 | fi |
---|
[2] | 1009 | |
---|
[544] | 1010 | #--------------------- |
---|
[1118] | 1011 | # Need to remove timestamps here |
---|
| 1012 | diff ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref <(${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh | sed -e "s:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]\:[0-9][0-9]\:[0-9][0-9] ::g") > /dev/null 2>&1 |
---|
[1106] | 1013 | status=$? |
---|
[2] | 1014 | |
---|
[1118] | 1015 | if [ ${status} -eq 0 ] ; then |
---|
[544] | 1016 | echo "Check libIGCM_debug ..............................................[ OK ]" |
---|
| 1017 | else |
---|
| 1018 | echo "Check libIGCM_debug ..........................................[ FAILED ]" |
---|
| 1019 | echo "--Error--> Execution of ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh" |
---|
| 1020 | echo " has produced the file IGCM_debug_Test.ref.failed" |
---|
| 1021 | echo " Please analyse differences with the reference file by typing:" |
---|
| 1022 | echo " diff IGCM_debug_Test.ref.failed ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref" |
---|
| 1023 | echo " Report errors to the author: Patrick.Brockmann@cea.fr" |
---|
[1118] | 1024 | diff ${libIGCM}/libIGCM_debug/IGCM_debug_Test.ref <(${libIGCM}/libIGCM_debug/IGCM_debug_Test.ksh | sed -e "s:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]\:[0-9][0-9]\:[0-9][0-9] ::g") |
---|
[544] | 1025 | exit 4 |
---|
| 1026 | fi |
---|
| 1027 | #--------------------- |
---|
[2] | 1028 | } |
---|