| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | # to treat aliases in bash-script correctly
|
|---|
| 4 | shopt -s expand_aliases
|
|---|
| 5 |
|
|---|
| 6 | # check if script has been started with absolute path
|
|---|
| 7 | if ! dirname $0 | grep -E '^/' >/dev/null 2>&1
|
|---|
| 8 | then
|
|---|
| 9 | echo "Please start your script with an absolute path."
|
|---|
| 10 | exit
|
|---|
| 11 | fi
|
|---|
| 12 |
|
|---|
| 13 | if [ "$AUTOMATIONSETUP" = "" ]
|
|---|
| 14 | then
|
|---|
| 15 | echo "Please set the environment variable \$AUTOMATIONSETUP."
|
|---|
| 16 | exit
|
|---|
| 17 | fi
|
|---|
| 18 |
|
|---|
| 19 | if [ "$SOURCEFILEPATH" = "" ]
|
|---|
| 20 | then
|
|---|
| 21 | export SOURCEFILEPATH=`dirname $0`
|
|---|
| 22 | fi
|
|---|
| 23 | if [ "$SCRIPTNAME" = "" ]
|
|---|
| 24 | then
|
|---|
| 25 | SCRIPTNAME=`basename $0`
|
|---|
| 26 | fi
|
|---|
| 27 |
|
|---|
| 28 | source $SOURCEFILEPATH/../Setup/setup.$AUTOMATIONSETUP
|
|---|
| 29 |
|
|---|
| 30 | if [ "$mars" = "" ]
|
|---|
| 31 | then
|
|---|
| 32 | echo "Please set the path for MARS."
|
|---|
| 33 | exit
|
|---|
| 34 | fi
|
|---|
| 35 |
|
|---|
| 36 | datetime=`date +%F-%H-%M-%S`
|
|---|
| 37 |
|
|---|
| 38 | if [ "$transferdelay" = "" ]
|
|---|
| 39 | then
|
|---|
| 40 | # setup where immediate report of problem is needed, i.e. mainly LP
|
|---|
| 41 | checknight=`date +%Y%m%d --date="-19HOUR"`
|
|---|
| 42 | else
|
|---|
| 43 | # any setup where transfer might cause a delay in arrival of files
|
|---|
| 44 | checknight=`date +%Y%m%d --date="-${transferdelay}day"`
|
|---|
| 45 | fi
|
|---|
| 46 |
|
|---|
| 47 | # function to make sure that a directory is made
|
|---|
| 48 | function makedir()
|
|---|
| 49 | {
|
|---|
| 50 | if [ ! -d $@ ]
|
|---|
| 51 | then
|
|---|
| 52 | if [ "$processlog" = "" ] || [ "$logfile" = "" ]
|
|---|
| 53 | then
|
|---|
| 54 | mkdir -p $@
|
|---|
| 55 | else
|
|---|
| 56 | mkdir -pv $@
|
|---|
| 57 | fi
|
|---|
| 58 | if [ ! -d $@ ]
|
|---|
| 59 | then
|
|---|
| 60 | if ! [ "$processlog" = "" ]
|
|---|
| 61 | then
|
|---|
| 62 | echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] ERROR could not make dir "$@ >> $processlog
|
|---|
| 63 | else
|
|---|
| 64 | echo "could not make dir "$@
|
|---|
| 65 | fi
|
|---|
| 66 | if ls $lockfile >/dev/null 2>&1
|
|---|
| 67 | then
|
|---|
| 68 | rm -v $lockfile
|
|---|
| 69 | fi
|
|---|
| 70 | exit
|
|---|
| 71 | fi
|
|---|
| 72 | fi
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | # logging paths for runlogs and processlog
|
|---|
| 76 | runlogpath=$logpath/run/`date +%Y/%m/%d`
|
|---|
| 77 | processlogpath=$logpath/processlog
|
|---|
| 78 | makedir $runlogpath
|
|---|
| 79 | makedir $processlogpath
|
|---|
| 80 | processlog=$processlogpath/process`date +%F`.log
|
|---|
| 81 |
|
|---|
| 82 | makedir $lockpath
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | # function to provide proper logging in a single logfile ($processlog)
|
|---|
| 86 | function printprocesslog
|
|---|
| 87 | {
|
|---|
| 88 | makedir $processlogpath
|
|---|
| 89 | echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] "$@ >> $processlog
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | # function to exit a script properly
|
|---|
| 93 | function finish()
|
|---|
| 94 | {
|
|---|
| 95 | if ! [ "$lockfile" = "" ] && ls $lockfile >/dev/null 2>&1
|
|---|
| 96 | then
|
|---|
| 97 | printprocesslog "DEBUG " `rm -v $lockfile`
|
|---|
| 98 | fi
|
|---|
| 99 | printprocesslog "DEBUG finished "$SOURCEFILEPATH"/"$SCRIPTNAME
|
|---|
| 100 | # fixme: handle different cases - sometimes exit of script is needed, sometimes only continue
|
|---|
| 101 | exit
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | # set checkvalue to ok at the beginning of the scripts
|
|---|
| 106 | check="ok"
|
|---|
| 107 |
|
|---|
| 108 | # setup for jobmanager:
|
|---|
| 109 | # log files (can't be defined in script itself, as script can run longer
|
|---|
| 110 | # than one day
|
|---|
| 111 | jmerrorlog=$runlogpath/jobmanager-`whoami`-$HOSTNAME-$AUTOMATIONSETUP-`date +%F`-error.log
|
|---|
| 112 | jmscriptlog=$runlogpath/jobmanager-`whoami`-$HOSTNAME-$AUTOMATIONSETUP-`date +%F`.log
|
|---|
| 113 |
|
|---|
| 114 | # check if rc-files are available
|
|---|
| 115 | if ! ls $steps >/dev/null
|
|---|
| 116 | then
|
|---|
| 117 | echo "Can't find steps.rc ($steps)"
|
|---|
| 118 | finish
|
|---|
| 119 | fi
|
|---|
| 120 | if ! ls $sqlrc >/dev/null 2>&1 || [ "$sqlrc" = "" ]
|
|---|
| 121 | then
|
|---|
| 122 | echo "Can't find sql.rc ($sqlrc)"
|
|---|
| 123 | finish
|
|---|
| 124 | fi
|
|---|
| 125 |
|
|---|
| 126 | # resetting values for jobmanager
|
|---|
| 127 | pno=0
|
|---|
| 128 | totalpno=0
|
|---|
| 129 | running=0
|
|---|
| 130 | queued=0
|
|---|
| 131 | runningscript=0
|
|---|
| 132 | queuedscript=0
|
|---|
| 133 | stillinqueue=0
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | # alias (we cannot check the beginning of the line due to
|
|---|
| 137 | # color codes in filldotraw.C)
|
|---|
| 138 | alias 'intgrep'='grep -E -o \\\("(int|Bool_t)"\\\)[0-9]+$ | grep -E -o [0-9]+'
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | # in the following the functions, which are needed by several scripts, are
|
|---|
| 142 | # defined
|
|---|
| 143 |
|
|---|
| 144 | # function to check if a process is already locked
|
|---|
| 145 | # command line option can be used to execute something, e.g. 'continue'
|
|---|
| 146 | function checklock()
|
|---|
| 147 | {
|
|---|
| 148 | if ! echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] "`uname -a` > $lockfile 2>/dev/null
|
|---|
| 149 | then
|
|---|
| 150 | if find $lockfile -amin -5
|
|---|
| 151 | then
|
|---|
| 152 | printprocesslog "INFO lockfile $lockfile exists"
|
|---|
| 153 | else
|
|---|
| 154 | printprocesslog "WARN lockfile $lockfile exists"
|
|---|
| 155 | fi
|
|---|
| 156 | $@
|
|---|
| 157 | exit
|
|---|
| 158 | else
|
|---|
| 159 | printprocesslog "DEBUG created lockfile $lockfile"
|
|---|
| 160 | fi
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | # print the current status values
|
|---|
| 164 | function printstatusvalues()
|
|---|
| 165 | {
|
|---|
| 166 | echo "the current values are:"
|
|---|
| 167 | echo " starttime=$starttime"
|
|---|
| 168 | echo " stoptime=$stoptime"
|
|---|
| 169 | echo " availtime=$availtime"
|
|---|
| 170 | echo " returncode=$returncode"
|
|---|
| 171 | echo "-- check: -$check-"
|
|---|
| 172 | echo ""
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | # function to send a mysql query
|
|---|
| 176 | function sendquery()
|
|---|
| 177 | {
|
|---|
| 178 | #getdbsetup
|
|---|
| 179 | printprocesslog "DEBUG sendquery QUERY: "$query
|
|---|
| 180 | val=`mysql --defaults-file=$sqlrc -s -e " $query " 2>&1`
|
|---|
| 181 | checkmysql=`echo $?`
|
|---|
| 182 | if [ $checkmysql -gt 0 ]
|
|---|
| 183 | then
|
|---|
| 184 | printprocesslog "ERROR could not query DB (program: $program, function sendquery, mysqlsetup $sqlrc) "
|
|---|
| 185 | printprocesslog "MYSQLERROR [returncode: "$checkmysql"] "$val
|
|---|
| 186 | error=`echo $val | grep -E -o 'ERROR [1-9]{1,4}' | grep -E -o '[1-9]{1,4}'`
|
|---|
| 187 | # here possible reaction to mysql error
|
|---|
| 188 | if [ $error -eq 1213 ] || [ $error -eq 1205 ]
|
|---|
| 189 | then
|
|---|
| 190 | #printprocesslog "WARN Deadlock found. Should resend query."
|
|---|
| 191 | printprocesslog "DEBUG sendquery QUERY: [2nd try] "$query
|
|---|
| 192 | val=`mysql --defaults-file=$sqlrc -s -e " $query " 2>&1`
|
|---|
| 193 | checkmysql2=`echo $?`
|
|---|
| 194 | if [ $checkmysql2 -gt 0 ]
|
|---|
| 195 | then
|
|---|
| 196 | printprocesslog "ERROR could not query DB (program: $program, function sendquery, mysqlsetup $sqlrc) [2nd try]"
|
|---|
| 197 | printprocesslog "MYSQLERROR [returncode: "$checkmysql"] "$val" [2nd try]"
|
|---|
| 198 | error2=`echo $val | grep -E -o 'ERROR [1-9]{1,4}' | grep -E -o '[1-9]{1,4}'`
|
|---|
| 199 | val=
|
|---|
| 200 | finish
|
|---|
| 201 | else
|
|---|
| 202 | if [ "$val" = "NULL" ]
|
|---|
| 203 | then
|
|---|
| 204 | val=
|
|---|
| 205 | fi
|
|---|
| 206 | echo $val
|
|---|
| 207 | return 0
|
|---|
| 208 | fi
|
|---|
| 209 | fi
|
|---|
| 210 | val=
|
|---|
| 211 | finish
|
|---|
| 212 | else
|
|---|
| 213 | warning=`echo $val | grep -o -E 'mysql: \[Warning\]'`
|
|---|
| 214 | if [ "$warning" != "" ]
|
|---|
| 215 | then
|
|---|
| 216 | printprocesslog "WARN possible problem to query DB (program: $program, function sendquery, mysqlsetup $sqlrc) "
|
|---|
| 217 | printprocesslog "MYSQLWARN [returncode: "$checkmysql"] "$val
|
|---|
| 218 | val=
|
|---|
| 219 | finish
|
|---|
| 220 | fi
|
|---|
| 221 | fi
|
|---|
| 222 | if [ "$val" = "NULL" ]
|
|---|
| 223 | then
|
|---|
| 224 | val=
|
|---|
| 225 | fi
|
|---|
| 226 | echo $val
|
|---|
| 227 | return 0
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | # function to get information from the setupfile $steps
|
|---|
| 231 | function getfromsetup()
|
|---|
| 232 | {
|
|---|
| 233 | grep $1"[.]"$2":" $steps | grep -v '#' | sed -e "s/$1[.]$2://"
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | # function to get the needed information from the dependencies-file steps.rc
|
|---|
| 237 | function getstepinfo()
|
|---|
| 238 | {
|
|---|
| 239 | #getdbsetup
|
|---|
| 240 | needs=( `getfromsetup $step "Needs"` )
|
|---|
| 241 | noderestricted=`getfromsetup $step "NodeRestricted"`
|
|---|
| 242 | prims=( `getfromsetup $step "Primaries"` )
|
|---|
| 243 | maintable=`getfromsetup $step "MainTable" | sed -e "s/\ //g"`
|
|---|
| 244 | sort=`getfromsetup $step "SortDirection" | sed -e "s/\ //g"`
|
|---|
| 245 | # echo " maintable: "$maintable
|
|---|
| 246 | # echo " needs: "${needs[@]}
|
|---|
| 247 | # echo " noderestricted: "$noderestricted
|
|---|
| 248 | # echo " prims: "${prims[@]}
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | # function to get the joins needed for the get/set status queries
|
|---|
| 252 | function getalljoins()
|
|---|
| 253 | {
|
|---|
| 254 | # add table
|
|---|
| 255 | query=$query" "$maintable"Status"
|
|---|
| 256 | # add special joins
|
|---|
| 257 | query=$query" "`getfromsetup $maintable "SpecialJoin"`
|
|---|
| 258 | if [ "$1" = "set" ]
|
|---|
| 259 | then
|
|---|
| 260 | query=$query" "`getfromsetup $maintable "SpecialJoinSet"`
|
|---|
| 261 | fi
|
|---|
| 262 | # add join for step unless step is the same as maintable
|
|---|
| 263 | if ! [ "$step" = "$maintable" ]
|
|---|
| 264 | then
|
|---|
| 265 | query=$query" LEFT JOIN "$step"Status USING("${prims[@]}") "
|
|---|
| 266 | fi
|
|---|
| 267 | # add joins for influences or needs
|
|---|
| 268 | for otherstep in ${othersteps[@]}
|
|---|
| 269 | do
|
|---|
| 270 | #printprocesslog "DEBUG "$otherstep
|
|---|
| 271 | if ! [ "$otherstep" = "$maintable" ]
|
|---|
| 272 | then
|
|---|
| 273 | # joins for needed steps
|
|---|
| 274 | if [ "$1" = "get" ]
|
|---|
| 275 | then
|
|---|
| 276 | query=$query" LEFT JOIN "$otherstep"Status USING("`getfromsetup $otherstep "Primaries"`") "
|
|---|
| 277 | fi
|
|---|
| 278 | # joins for influenced steps
|
|---|
| 279 | if [ "$1" = "set" ]
|
|---|
| 280 | then
|
|---|
| 281 | query=$query" "`getfromsetup $otherstep "SpecialJoinSet2"`
|
|---|
| 282 | query=$query" LEFT JOIN "$otherstep"Status USING("`getfromsetup $otherstep "Primaries"`") "
|
|---|
| 283 | fi
|
|---|
| 284 | fi
|
|---|
| 285 | done
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | # function to create the middle part of a query
|
|---|
| 289 | # which is identical for the functions getstatus() and gettodo()
|
|---|
| 290 | function getstatusquery()
|
|---|
| 291 | {
|
|---|
| 292 | # add from which table the information is queried
|
|---|
| 293 | query=$query" FROM "
|
|---|
| 294 | othersteps=${needs[@]}
|
|---|
| 295 | getalljoins "get"
|
|---|
| 296 | # add condition
|
|---|
| 297 | query=$query" WHERE "
|
|---|
| 298 | # add condition for step, i.e. step is not yet done
|
|---|
| 299 | query=$query" ISNULL("$step"Status.fStartTime) "
|
|---|
| 300 | query=$query" AND ISNULL("$step"Status.fStopTime) "
|
|---|
| 301 | query=$query" AND ISNULL("$step"Status.fAvailable) "
|
|---|
| 302 | query=$query" AND ISNULL("$step"Status.fReturnCode) "
|
|---|
| 303 | # add requirement for production host in case it is needed
|
|---|
| 304 | if [ "$1 " != " " ]
|
|---|
| 305 | then
|
|---|
| 306 | query=$query" AND fProductionHostKEY=$2 "
|
|---|
| 307 | fi
|
|---|
| 308 | query=$query`getfromsetup $step "SpecialWhere"`
|
|---|
| 309 | # add condition for needs, i.e. that step is done
|
|---|
| 310 | for (( k=0 ; k < ${#needs[@]} ; k++ ))
|
|---|
| 311 | do
|
|---|
| 312 | # if [ $k -eq 0 ]
|
|---|
| 313 | # then
|
|---|
| 314 | # query=$query" HAVING "
|
|---|
| 315 | # else
|
|---|
| 316 | query=$query" AND "
|
|---|
| 317 | # fi
|
|---|
| 318 | # query=$query" COUNT(*)=COUNT(IF("
|
|---|
| 319 | query=$query" NOT ISNULL("${needs[$k]}"Status.fStartTime) "
|
|---|
| 320 | query=$query" AND NOT ISNULL("${needs[$k]}"Status.fStopTime) "
|
|---|
| 321 | query=$query" AND NOT ISNULL("${needs[$k]}"Status.fAvailable) "
|
|---|
| 322 | query=$query" AND ISNULL("${needs[$k]}"Status.fReturnCode) "
|
|---|
| 323 | # query=$query" , 1, NULL)) "
|
|---|
| 324 | done
|
|---|
| 325 | # if ! echo $query | grep UPDATE >/dev/null 2>&1
|
|---|
| 326 | # then
|
|---|
| 327 | # query=$query" GROUP BY "${prims[@]}
|
|---|
| 328 | # fi
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | # function to get todolist
|
|---|
| 332 | # returns the next or the list of next steps
|
|---|
| 333 | function gettodo()
|
|---|
| 334 | {
|
|---|
| 335 | # reset the variable for the number of the next step
|
|---|
| 336 | process=
|
|---|
| 337 | printprocesslog "DEBUG getting todo for step $step..."
|
|---|
| 338 | getstepinfo
|
|---|
| 339 | # get query
|
|---|
| 340 | query=" SELECT "${prims[@]}
|
|---|
| 341 | getstatusquery $2
|
|---|
| 342 | # order by priority to the the number of the next step to be done
|
|---|
| 343 | query=$query" ORDER BY "$step"Status.fPriority "
|
|---|
| 344 | if [ "$sort" = "" ]
|
|---|
| 345 | then
|
|---|
| 346 | query=$query" ASC "
|
|---|
| 347 | else
|
|---|
| 348 | query=$query" "$sort
|
|---|
| 349 | fi
|
|---|
| 350 | # add limitation in case only one or a limited number of
|
|---|
| 351 | # processes should be executed
|
|---|
| 352 | if [ "$1 " != " " ]
|
|---|
| 353 | then
|
|---|
| 354 | query=$query" limit 0, $1 "
|
|---|
| 355 | fi
|
|---|
| 356 | # print query
|
|---|
| 357 | #printprocesslog "DEBUG gettodo for step $step QUERY: "$query
|
|---|
| 358 | # execute query
|
|---|
| 359 | process=`sendquery`
|
|---|
| 360 | #if ! process=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
|
|---|
| 361 | #then
|
|---|
| 362 | # printprocesslog "ERROR could not query processes from db (program: $program, function gettodo)"
|
|---|
| 363 | # finish
|
|---|
| 364 | #fi
|
|---|
| 365 | # get numbers of next step from mysql result
|
|---|
| 366 | if [ "$process" = "" ]
|
|---|
| 367 | then
|
|---|
| 368 | printprocesslog "DEBUG => nothing to do"
|
|---|
| 369 | finish
|
|---|
| 370 | else
|
|---|
| 371 | primaries=( $process )
|
|---|
| 372 | num=`expr ${#primaries[@]} / ${#prims[@]} `
|
|---|
| 373 | fi
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | # function to get the number of processes which still have to be done
|
|---|
| 377 | function getstatus()
|
|---|
| 378 | {
|
|---|
| 379 | printprocesslog "DEBUG getstatus for step "$step
|
|---|
| 380 | # reset the variable for the number of steps to be done
|
|---|
| 381 | numproc=0
|
|---|
| 382 | getstepinfo
|
|---|
| 383 | # get query
|
|---|
| 384 | query=" SELECT "${prims[@]}
|
|---|
| 385 | getstatusquery $1
|
|---|
| 386 | # print query
|
|---|
| 387 | #printprocesslog "DEBUG getstatus for step $step QUERY: "$query
|
|---|
| 388 | # execute query
|
|---|
| 389 | #numproc=`sendquery `#cannot be done with sendquery, because of row counting
|
|---|
| 390 | printprocesslog "DEBUG send query "$query
|
|---|
| 391 | printprocesslog "BLA "`which mysql`
|
|---|
| 392 | if ! numproc=`mysql --defaults-file=$sqlrc -s -e " $query " | wc -l`
|
|---|
| 393 | then
|
|---|
| 394 | printprocesslog "ERROR could not query number of processes from db (program: $program, function getstatus, mysqlsetup $sqlrc)"
|
|---|
| 395 | echo `date +%F\ %T`" ERROR could not query number of processes from db (program: $program, function getstatus, mysqlsetup $sqlrc)"
|
|---|
| 396 | continue
|
|---|
| 397 | fi
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | # function to set status of a process in the db
|
|---|
| 401 | function setstatus()
|
|---|
| 402 | {
|
|---|
| 403 | # remark:
|
|---|
| 404 | # this function does not include the 'Default' flag
|
|---|
| 405 | # for resetting steps
|
|---|
| 406 |
|
|---|
| 407 | # for dowebplots (there are steps which have no entry in the DB)
|
|---|
| 408 | if [ "$step" = "no" ]
|
|---|
| 409 | then
|
|---|
| 410 | return
|
|---|
| 411 | fi
|
|---|
| 412 |
|
|---|
| 413 | printprocesslog "DEBUG setstatus for step "$step
|
|---|
| 414 |
|
|---|
| 415 | # reset status values
|
|---|
| 416 | starttime=NULL
|
|---|
| 417 | stoptime=NULL
|
|---|
| 418 | availtime=NULL
|
|---|
| 419 | returncode=NULL
|
|---|
| 420 | # evaluate the status values
|
|---|
| 421 | case $@ in
|
|---|
| 422 | start) printprocesslog "DEBUG setstatus start"
|
|---|
| 423 | starttime="Now()"
|
|---|
| 424 | ;;
|
|---|
| 425 | startj) printprocesslog "DEBUG setstatus startj"
|
|---|
| 426 | starttime="'1971-01-01 01:01:01'" # special recognizable datetime, i.e. "reserved by JobManager for processing"
|
|---|
| 427 | ;;
|
|---|
| 428 | stop) case $check in
|
|---|
| 429 | ok) printprocesslog "DEBUG setstatus stop - ok"
|
|---|
| 430 | starttime=noreset
|
|---|
| 431 | stoptime="Now()"
|
|---|
| 432 | if [ "$processingsite" = "$storagesite" ]
|
|---|
| 433 | then
|
|---|
| 434 | availtime="Now()"
|
|---|
| 435 | fi
|
|---|
| 436 | ;;
|
|---|
| 437 | no) printprocesslog "DEBUG setstatus stop - nothing new"
|
|---|
| 438 | check="ok"
|
|---|
| 439 | ;;
|
|---|
| 440 | *) printprocesslog "DEBUG setstatus stop - failed"
|
|---|
| 441 | starttime=noreset
|
|---|
| 442 | stoptime="Now()"
|
|---|
| 443 | if [ "$processingsite" = "$storagesite" ]
|
|---|
| 444 | then
|
|---|
| 445 | availtime="Now()"
|
|---|
| 446 | fi
|
|---|
| 447 | if [ "$check" == "" ]
|
|---|
| 448 | then
|
|---|
| 449 | returncode=1
|
|---|
| 450 | else
|
|---|
| 451 | returncode=$check
|
|---|
| 452 | fi
|
|---|
| 453 | check="ok"
|
|---|
| 454 | ;;
|
|---|
| 455 | esac
|
|---|
| 456 | ;;
|
|---|
| 457 | *) printprocesslog "ERROR function setstatus got wrong variable"
|
|---|
| 458 | finish
|
|---|
| 459 | ;;
|
|---|
| 460 | esac
|
|---|
| 461 |
|
|---|
| 462 | # get
|
|---|
| 463 | getstepinfo
|
|---|
| 464 |
|
|---|
| 465 | # get the influences from the steps.rc by evaluating the needs of all steps
|
|---|
| 466 | othersteps=`grep $step $steps | grep -v '#' | grep "Needs" | grep -v "$step[.]Needs" | cut -d'.' -f1`
|
|---|
| 467 |
|
|---|
| 468 | # get query
|
|---|
| 469 | query=" UPDATE "
|
|---|
| 470 | getalljoins "set"
|
|---|
| 471 | # set the status values according to the new status of the step
|
|---|
| 472 | query=$query" SET "
|
|---|
| 473 | if ! [ "$starttime" = "noreset" ]
|
|---|
| 474 | then
|
|---|
| 475 | query=$query" "$step"Status.fStartTime=$starttime, "
|
|---|
| 476 | fi
|
|---|
| 477 | query=$query" "$step"Status.fStopTime=$stoptime, "$step"Status.fAvailable=$availtime"
|
|---|
| 478 | query=$query", "$step"Status.fReturnCode=$returncode , "$step"Status.fProcessingSiteKEY=$sitekey "
|
|---|
| 479 | # set also the status values of the influenced steps
|
|---|
| 480 | for otherstep in $othersteps
|
|---|
| 481 | do
|
|---|
| 482 | query=$query", "$otherstep"Status.fStartTime=IF("$otherstep"Status.fStartTime='1970-01-01 00:00:00', '1970-01-01 00:00:00', NULL) "
|
|---|
| 483 | query=$query", "$otherstep"Status.fStopTime=IF("$otherstep"Status.fStartTime='1970-01-01 00:00:00', '1970-01-01 00:00:00', NULL) "
|
|---|
| 484 | query=$query", "$otherstep"Status.fAvailable=NULL "
|
|---|
| 485 | query=$query", "$otherstep"Status.fReturnCode=NULL "
|
|---|
| 486 | query=$query", "$otherstep"Status.fProcessingSiteKEY=NULL "
|
|---|
| 487 | done
|
|---|
| 488 | # give the condition for which step the status values have to be set
|
|---|
| 489 | query=$query" WHERE "
|
|---|
| 490 | if [ "$s" = "" ]
|
|---|
| 491 | then
|
|---|
| 492 | s=0
|
|---|
| 493 | fi
|
|---|
| 494 | query=$query" "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}]}'"
|
|---|
| 495 | for (( j=1 ; j < ${#prims[@]} ; j++ ))
|
|---|
| 496 | do
|
|---|
| 497 | query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' "
|
|---|
| 498 | done
|
|---|
| 499 | # add additional query to allow for locking in db
|
|---|
| 500 | if [ "$1" = "start" ]
|
|---|
| 501 | then
|
|---|
| 502 | # process job only if it is not yet being processed
|
|---|
| 503 | # i.e. either StartTime NULL or '1971-01-01 01:01:01' (reserved by JobManager for processing)
|
|---|
| 504 | query=$query" AND (ISNULL("$step"Status.fStartTime) OR "$step"Status.fStartTime='1971-01-01 01:01:01')"
|
|---|
| 505 | fi
|
|---|
| 506 | # add row count to know how many rows have been changed
|
|---|
| 507 | query=$query"; SELECT ROW_COUNT();"
|
|---|
| 508 | # print query
|
|---|
| 509 | #printprocesslog "DEBUG setstatus for step $step QUERY: "$query
|
|---|
| 510 | #echo "DEBUG setstatus for step $step QUERY: "$query
|
|---|
| 511 | # execute query
|
|---|
| 512 | numchanged=`sendquery`
|
|---|
| 513 | # should not be needed anymore once finish does proper exit
|
|---|
| 514 | printprocesslog "DEBUG numchanged "$numchanged
|
|---|
| 515 | if [ "$numchanged" = "" ]
|
|---|
| 516 | then
|
|---|
| 517 | printprocesslog "DEBUG numchanged empty."
|
|---|
| 518 | finish
|
|---|
| 519 | fi
|
|---|
| 520 | if [ $numchanged -gt 0 ]
|
|---|
| 521 | then
|
|---|
| 522 | printprocesslog "INFO successful set of status in DB."
|
|---|
| 523 | #echo "INFO successful set of status in DB."
|
|---|
| 524 | else
|
|---|
| 525 | # action may be taken in script using $numchanged
|
|---|
| 526 | printprocesslog "DEBUG status in DB was already set by another process "
|
|---|
| 527 | #echo "ERROR status in DB was already set by another process "
|
|---|
| 528 | fi
|
|---|
| 529 | }
|
|---|
| 530 |
|
|---|
| 531 | function getdates()
|
|---|
| 532 | {
|
|---|
| 533 | case $1 in
|
|---|
| 534 | # all dates
|
|---|
| 535 | all)
|
|---|
| 536 | printprocesslog "DEBUG getdates case 'all'"
|
|---|
| 537 | dates=( `find $auxdata -mindepth 3 -type d | sort -r | sed "s/\${auxdata_for_sed}//g" | sed -e 's/^\///'` )
|
|---|
| 538 | ;;
|
|---|
| 539 | # certain date
|
|---|
| 540 | [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]/[0-9][0-9]-[0-9][0-9][0-9])
|
|---|
| 541 | d=`echo $1 | grep -o '[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]'`
|
|---|
| 542 | range=`echo $1 | grep -o '[0-9][0-9][0-9]$'`
|
|---|
| 543 | range=`echo $range | sed -e 's/^0//' -e 's/^0//'`
|
|---|
| 544 | printprocesslog "DEBUG getdates - certain date "$d"."
|
|---|
| 545 | dates=( $d )
|
|---|
| 546 | if [ "$range" != "" ]
|
|---|
| 547 | then
|
|---|
| 548 | printprocesslog "DEBUG getdates - add the last "$range" days."
|
|---|
| 549 | yy=`echo $d | cut -c 1-4`
|
|---|
| 550 | mm=`echo $d | cut -c 6-7`
|
|---|
| 551 | dd=`echo $d | cut -c 9-10`
|
|---|
| 552 | for (( numdates=1 ; numdates <= $range ; numdates++ ))
|
|---|
| 553 | do
|
|---|
| 554 | numhours=`echo " 12 + ( $numdates - 1 ) * 24 " | bc -l`
|
|---|
| 555 | dates=( ${dates[@]} `date +%Y/%m/%d --date=$yy/$mm/$dd"-"$numhours"hour"` )
|
|---|
| 556 | done
|
|---|
| 557 | fi
|
|---|
| 558 | ;;
|
|---|
| 559 | # certain number of dates (between 0 and 9999)
|
|---|
| 560 | [1-9][0-9][0-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9]|[1-9])
|
|---|
| 561 | # get last n nights
|
|---|
| 562 | printprocesslog "DEBUG getdates - get the last "$1" days."
|
|---|
| 563 | for (( numdates=1 ; numdates <= $1 ; numdates++ ))
|
|---|
| 564 | do
|
|---|
| 565 | numhours=`echo " 12 + ( $numdates - 1 ) * 24 " | bc -l`
|
|---|
| 566 | dates=( ${dates[@]} `date +%Y/%m/%d --date="-"$numhours"hour"` )
|
|---|
| 567 | done
|
|---|
| 568 | # hour-dependent number of dates
|
|---|
| 569 | if [ "$2" != "" ] && [ "$3" != "" ]
|
|---|
| 570 | then
|
|---|
| 571 | # get current hour
|
|---|
| 572 | hour=`date +%k`
|
|---|
| 573 | if [ $hour -le $2 ] || [ $hour -ge $3 ]
|
|---|
| 574 | then
|
|---|
| 575 | printprocesslog "DEBUG getdates - get the current night."
|
|---|
| 576 | dates=( `date +%Y/%m/%d --date="-19hour"` )
|
|---|
| 577 | fi
|
|---|
| 578 | fi
|
|---|
| 579 | ;;
|
|---|
| 580 | # certain number of dates in the future (between 0 and 9)
|
|---|
| 581 | +[1-9])
|
|---|
| 582 | # get next n nights
|
|---|
| 583 | printprocesslog "DEBUG getdates - get the next "$1" days (incl today)."
|
|---|
| 584 | for (( numdates=1 ; numdates <= $1 ; numdates++ ))
|
|---|
| 585 | do
|
|---|
| 586 | numhours=`echo " 0 + ( $numdates - 1 ) * 24 " | bc -l`
|
|---|
| 587 | dates=( ${dates[@]} `date +%Y/%m/%d --date="+"$numhours"hour"` )
|
|---|
| 588 | done
|
|---|
| 589 | # hour-dependent number of dates
|
|---|
| 590 | if [ "$2" != "" ] && [ "$3" != "" ]
|
|---|
| 591 | then
|
|---|
| 592 | # get current hour
|
|---|
| 593 | hour=`date +%k`
|
|---|
| 594 | if [ $hour -le $2 ] || [ $hour -ge $3 ]
|
|---|
| 595 | then
|
|---|
| 596 | printprocesslog "DEBUG getdates - get the current night."
|
|---|
| 597 | dates=( `date +%Y/%m/%d --date="-12hour"` )
|
|---|
| 598 | fi
|
|---|
| 599 | fi
|
|---|
| 600 | ;;
|
|---|
| 601 | *) # nothing valid given
|
|---|
| 602 | echo "Please give valid option (YYYY/MM/DD[-RRR] or 1-9999 or +0-9)"
|
|---|
| 603 | finish
|
|---|
| 604 | ;;
|
|---|
| 605 | esac
|
|---|
| 606 | }
|
|---|
| 607 |
|
|---|
| 608 | # missing: implement usage of this function in Fill*.sh
|
|---|
| 609 | function check_file_avail()
|
|---|
| 610 | {
|
|---|
| 611 | if [ "$1" = "" ]
|
|---|
| 612 | then
|
|---|
| 613 | echo "Please give file name as first argument."
|
|---|
| 614 | finish
|
|---|
| 615 | fi
|
|---|
| 616 |
|
|---|
| 617 | printprocesslog "INFO checking availability of "$1
|
|---|
| 618 | if ! [ -e $1 ]
|
|---|
| 619 | then
|
|---|
| 620 | filenight=`basename $1 | cut -c 1-8`
|
|---|
| 621 | # treat raw files differently than auxfiles
|
|---|
| 622 | checkraw=`echo $1 | grep -E -o raw`
|
|---|
| 623 | if [ "$checkraw" = "raw" ]
|
|---|
| 624 | then
|
|---|
| 625 | if [ $filenight -le $checknight ]
|
|---|
| 626 | then
|
|---|
| 627 | printprocesslog "WARN "$1" not found."
|
|---|
| 628 | else
|
|---|
| 629 | printprocesslog "INFO "$1" not found."
|
|---|
| 630 | fi
|
|---|
| 631 | return 1
|
|---|
| 632 | fi
|
|---|
| 633 | # only for aux files check of DB is needed
|
|---|
| 634 | # treat ratescan files
|
|---|
| 635 | checkratescan=`echo $1 | grep -E -o RATE_SCAN_DATA`
|
|---|
| 636 | if [ "$checkratescan" = "RATE_SCAN_DATA" ] && [ $filenight -gt 20130408 ]
|
|---|
| 637 | then
|
|---|
| 638 | #query="SELECT fMeasurementTypeKey from MeasurementType WHERE fMeasurementTypeName like 'Ratescan%'"
|
|---|
| 639 | #ratescantypes=`sendquery`
|
|---|
| 640 | query="SELECT COUNT(*) FROM Schedule WHERE fStart BETWEEN "$scheduletart" AND "$schedulestop" AND fMeasurementTypeKey IN (5,8) "
|
|---|
| 641 | numratescans=`sendquery`
|
|---|
| 642 | if [ $numratescans -gt 0 ]
|
|---|
| 643 | then
|
|---|
| 644 | printprocesslog "ERROR "$1" not found."
|
|---|
| 645 | else
|
|---|
| 646 | printprocesslog "INFO "$1" not found."
|
|---|
| 647 | fi
|
|---|
| 648 | return 1
|
|---|
| 649 | fi
|
|---|
| 650 | query="SELECT COUNT(*) FROM RunInfo WHERE fNight="$filenight" AND fRunTypeKey=1"
|
|---|
| 651 | numdatruns=`sendquery`
|
|---|
| 652 | # for some files it is more severe when they are missing
|
|---|
| 653 | checkfile=`echo $1 | grep -E -o 'DRIVE'\|'RATES'`
|
|---|
| 654 | # print INFO/WARN/ERROR depending on severity
|
|---|
| 655 | if [ $numdatruns -eq 0 ]
|
|---|
| 656 | then
|
|---|
| 657 | # in case no data runs are available from this night, it's not a problem if files are missing
|
|---|
| 658 | printprocesslog "INFO "$1" not found."
|
|---|
| 659 | else
|
|---|
| 660 | if [ "$checkfile" != "" ]
|
|---|
| 661 | then
|
|---|
| 662 | # drive and trigger-rates files are needed for analysis
|
|---|
| 663 | #printprocesslog "ERROR "$1" not found."
|
|---|
| 664 | if [ $filenight -le $checknight ]
|
|---|
| 665 | then
|
|---|
| 666 | printprocesslog "ERROR "$1" not found."
|
|---|
| 667 | else
|
|---|
| 668 | printprocesslog "WARN "$1" not found. ("$filenight" - "$checknight")"
|
|---|
| 669 | fi
|
|---|
| 670 | else
|
|---|
| 671 | # other aux-files would be good to have
|
|---|
| 672 | #printprocesslog "WARN "$1" not found."
|
|---|
| 673 | if [ $filenight -le $checknight ]
|
|---|
| 674 | then
|
|---|
| 675 | printprocesslog "WARN "$1" not found. ("$filenight" - "$checknight")"
|
|---|
| 676 | else
|
|---|
| 677 | printprocesslog "INFO "$1" not found."
|
|---|
| 678 | fi
|
|---|
| 679 | fi
|
|---|
| 680 | fi
|
|---|
| 681 | return 1
|
|---|
| 682 | fi
|
|---|
| 683 |
|
|---|
| 684 | # file available
|
|---|
| 685 | return 0
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|