Changeset 9585 for trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
- Timestamp:
- 06/11/10 17:36:11 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
r9543 r9585 20 20 # Author(s): Daniela Dorner 05/2005 <mailto:dorner@astro.uni-wuerzburg.de> 21 21 # 22 # Copyright: MAGIC Software Development, 2000-20 0722 # Copyright: MAGIC Software Development, 2000-2010 23 23 # 24 24 # … … 209 209 } 210 210 211 function resetstatusvalues() 212 { 213 statustime=NULL 214 starttime=NULL 215 returncode=NULL 216 programid=NULL 217 failedtime=NULL 218 } 219 211 # print the current status values 220 212 function printstatusvalues() 221 213 { 222 214 echo "the current values are:" 223 echo " statustime=$statustime"224 215 echo " starttime=$starttime" 216 echo " stoptime=$stoptime" 225 217 echo " returncode=$returncode" 226 echo " programid=$programid"227 echo " failedtime=$failedtime"228 218 echo "-- check: -$check-" 229 219 echo "" 230 220 } 231 221 232 # function evaluating the statusvalues 233 function evalstatus() 234 { 235 case $@ in 236 start) printprocesslog "INFO setstatus start" 237 starttime="Now()" 238 ;; 239 stop) case $check in 240 ok) printprocesslog "INFO setstatus stop - ok" 241 statustime="Now()" 242 ;; 243 no) printprocesslog "INFO setstatus stop - nothing new" 244 check="ok" 245 ;; 246 *) printprocesslog "INFO setstatus stop - failed" 247 starttime=noreset 248 if [ "$check" == "" ] 249 then 250 returncode=1 251 else 252 returncode=$check 253 fi 254 programid=$com 255 failedtime="Now()" 256 check="ok" 257 ;; 258 esac 259 ;; 260 *) printprocesslog "ERROR function evalstatus got wrong variable" 261 finish 262 ;; 263 esac 264 } 265 222 # get the db-setup from the sql.rc 266 223 function getdbsetup() 267 224 { … … 277 234 } 278 235 236 # function to get the needed information from the dependencies-file steps.rc 279 237 function getstepinfo() 280 238 { 281 239 getdbsetup 282 table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'` 283 coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'` 284 needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"` 285 noderestricted=`grep "$coltab[.]NodeRestricted:" $steps | sed -e "s/$coltab[.]NodeRestricted://" -e 's/ //g'` 286 influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"` 287 prims=( `grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"` ) 288 # echo " column $column - table $table - coltab $coltab" 240 needs=`grep "$step[.]Needs:" $steps | sed -e "s/$step[.]Needs://"` 241 noderestricted=`grep "$step[.]NodeRestricted:" $steps | sed -e "s/$step[.]NodeRestricted://" -e 's/ //g'` 242 prims=( `grep "$step[.]Primaries:" $steps | sed -e "s/$step[.]Primaries://"` ) 289 243 # echo " needs: $needs" 290 # echo " influences: $influences"291 244 # echo " noderestricted: $noderestricted" 292 245 # echo " prims: ${prims[@]}" 293 246 } 294 247 248 # function to get the primaries of a step from the dependencies-file steps.rc 249 function getprimary() 250 { 251 getdbsetup 252 grep $@"[.]Primaries:" $steps | sed -e "s/$@[.]Primaries://" 253 } 254 255 # function to get the join of a step from the dependencies-file steps.rc 256 function getjoin() 257 { 258 getdbsetup 259 grep $@"[.]Join:" $steps | sed -e "s/$@[.]Join://" 260 } 261 262 # function to create the middle part of a query 263 # which is identical for the functions getstatus() and gettodo() 264 function middlepartofquery() 265 { 266 # add from which table the information is queried 267 query=$query" FROM "$step"Status " 268 # add the joins to the tables in which the status of the preceding steps is stored 269 for need in $needs 270 do 271 needprims=( `getprimary $need` ) 272 if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ] 273 then 274 query=$query" LEFT JOIN "$need"Status USING (${prims[@]}) " 275 fi 276 done 277 # add condition 278 query=$query" WHERE " 279 # add condition for the status of the peceding steps 280 counter=0 281 for need in $needs 282 do 283 if [ $counter -gt 0 ] 284 then 285 query=$query" AND " 286 fi 287 needprims=( `getprimary $need` ) 288 # in case the primaries of the tables agree 289 # only the condition is given 290 # for tables with differing primaries a special query 291 # is needed 292 if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ] 293 then 294 query=$query" NOT ISNULL("$need"Status.fStartTime) AND " 295 query=$query" NOT ISNULL("$need"Status.fStopTime) AND " 296 query=$query" ISNULL("$need"Status.fReturnCode) " 297 else 298 query=$query" (SELECT COUNT(*) FROM "$need"Status " 299 query=$query" "`getjoin $need`" " 300 query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'` 301 for (( j=1 ; j < ${#prims[@]} ; j++ )) 302 do 303 query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'` 304 done 305 query=$query") = (SELECT COUNT(*) FROM "$need"Status " 306 query=$query" "`getjoin $need`" " 307 query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'` 308 for (( j=1 ; j < ${#prims[@]} ; j++ )) 309 do 310 query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'` 311 done 312 query=$query" AND NOT ISNULL(fStartTime) " 313 query=$query" AND NOT ISNULL(fStopTime) " 314 query=$query" AND ISNULL(fReturnCode)) " 315 fi 316 counter=`echo $counter + 1 | bc -l` 317 done 318 # add condition for the status of the step itself 319 query=$query" AND ISNULL("$step"Status.fStartTime) " 320 query=$query" AND ISNULL("$step"Status.fStopTime) " 321 query=$query" AND ISNULL("$step"Status.fReturnCode) " 322 } 323 295 324 # function to get todolist 325 # returns the next or the list of next steps 296 326 function gettodo() 297 327 { 328 # reset the variable for the number of the next step 298 329 process= 299 330 printprocesslog "INFO getting todo..." 300 331 getstepinfo 301 332 # get query 302 query=" SELECT " ${prims[0]}303 for (( i=1 ; i < ${#prims[@]} ; i++ ))333 query=" SELECT "`echo ${prims[0]} | sed -e 's/,//g'` 334 for (( j=1 ; j < ${#prims[@]} ; j++ )) 304 335 do 305 query=$query", ${prims[$i]}"336 query=$query", "`echo ${prims[$j]} | sed -e 's/,//g'` 306 337 done 307 query=$query" FROM $table WHERE " 308 if ! echo $needs | grep '#' > /dev/null 309 then 310 for need in $needs 311 do 312 query=$query" NOT ISNULL($need) AND" 313 done 314 fi 315 query=$query" ISNULL($column) " 338 # get middle par of query 339 middlepartofquery 340 # add requirement for production host in case it is needed 316 341 if [ "$2 " != " " ] 317 342 then 318 343 query=$query" AND fProductionHostKEY=$2 " 319 344 fi 320 query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) " 321 query=$query" ORDER BY fPriority desc " 345 # order by priority to the the number of the next step to be done 346 query=$query" ORDER BY "$step"Status.fPriority desc " 347 # add limitation in case only one or a limited number of 348 # processes should be executed 322 349 if [ "$1 " != " " ] 323 350 then 324 351 query=$query" limit 0, $1 " 325 352 fi 326 # echo " QUERY: "$query 353 # print query 354 echo " gettodo QUERY: "$query 327 355 printprocesslog "INFO gettodo QUERY: "$query 356 # execute query 328 357 if ! process=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "` 329 358 then … … 331 360 finish 332 361 fi 333 362 # get numbers of next step from mysql result 334 363 if [ "$process" = "" ] 335 364 then … … 342 371 } 343 372 344 345 373 # function to get the number of processes which still have to be done 346 374 function getstatus() 347 375 { 376 # reset the variable for the number of steps to be done 348 377 numproc= 349 378 getstepinfo 350 379 # get query 351 query=" SELECT COUNT(*) FROM $table WHERE " 352 if ! echo $needs | grep '#' > /dev/null 353 then 354 for need in $needs 355 do 356 query=$query" NOT ISNULL($need) AND" 357 done 358 fi 359 query=$query" ISNULL($column) " 380 query=" SELECT COUNT(*), 1 " # the 1 is just for grouping 381 # get middle part of query 382 middlepartofquery 383 # add requirement for production host in case it is needed 360 384 if [ "$1 " != " " ] 361 385 then 362 386 query=$query" AND fProductionHostKEY=$1 " 363 387 fi 364 query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) " 365 query=$query" GROUP BY $column " 366 # echo "QUERY: "$query 388 # group by an 'artifical' column to get the number of lines 389 query=$query" GROUP BY 2 " 390 # printing query 391 echo " getstatus QUERY: "$query 367 392 printprocesslog "INFO getstatus QUERY: "$query 368 if ! numproc=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "` 393 # execute query 394 if ! numprocs=( `mysql -s -u $us --password=$pw --host=$ho $db -e " $query "` ) 369 395 then 370 396 printprocesslog "ERROR could not query number of processes from db (program: $program, function getstatus)" … … 372 398 continue 373 399 fi 374 if [ "$numproc" = "" ] 400 # get number of processes from mysql result 401 if [ "${numprocs[1]}" = "" ] 375 402 then 376 403 numproc=0 404 else 405 numproc=${numprocs[0]} 377 406 fi 378 407 } … … 381 410 function setstatus() 382 411 { 383 if [ "$column" = "no" ] 412 # remark: 413 # this function does not include the 'Default' flag 414 # for resetting steps 415 416 # for dowebplots (there are steps which have no entry in the DB) 417 if [ "$step" = "no" ] 384 418 then 385 419 return 386 420 fi 387 resetstatusvalues 388 evalstatus $@ 421 422 # reset status values 423 starttime=NULL 424 stoptime=NULL 425 returncode=NULL 426 # evaluate the status values 427 case $@ in 428 start) printprocesslog "INFO setstatus start" 429 starttime="Now()" 430 ;; 431 stop) case $check in 432 ok) printprocesslog "INFO setstatus stop - ok" 433 starttime=noreset 434 stoptime="Now()" 435 ;; 436 no) printprocesslog "INFO setstatus stop - nothing new" 437 check="ok" 438 ;; 439 *) printprocesslog "INFO setstatus stop - failed" 440 starttime=noreset 441 stoptime="Now()" 442 if [ "$check" == "" ] 443 then 444 returncode=1 445 else 446 returncode=$check 447 fi 448 check="ok" 449 ;; 450 esac 451 ;; 452 *) printprocesslog "ERROR function setstatus got wrong variable" 453 finish 454 ;; 455 esac 456 # get 389 457 getstepinfo 458 459 # get the influences from the steps.rc by evaluating the needs of all steps 460 influences=`grep $step $rc | grep "Needs" | grep -v "$step[.]Needs" | cut -d'.' -f1` 461 390 462 # get query 391 reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'` 392 if [ "$reset" = "no" ] 393 then 394 printprocesslog "ERROR You cannot reset $column for ${primaries[$s+$s]}" 395 finish 396 fi 397 query=" update $table set $column=$statustime" 398 if ! echo $influences | grep '#' > /dev/null 399 then 400 for influence in $influences 401 do 402 query=$query", $influence=NULL" 403 done 404 fi 463 query=" UPDATE "$step"Status " 464 # add joins to the influenced tables 465 for influence in $influences 466 do 467 query=$query" LEFT JOIN $influence USING("`getprimary $influence`") " 468 specialjoin=`getjoin $influence` 469 if ! [ "$specialjoin" = "" ] 470 then 471 query=$query$specialjoin 472 fi 473 done 474 # set the status values according to the new status of the step 475 query=$query" SET " 405 476 if ! [ "$starttime" = "noreset" ] 406 477 then 407 query=$query", fStartTime=$starttime" 408 fi 409 query=$query", fFailedTime=$failedtime, fProgramId=$programid, fReturnCode=$returncode " 410 query=$query" where " 478 query=$query" "$step"Status.fStartTime=$starttime, " 479 fi 480 query=$query" "$step"Status.fStopTime=$stoptime, "$step"Status.fReturnCode=$returncode " 481 # set also the status values of the influenced steps 482 for influence in $influences 483 do 484 query=$query", "$influence"Status.fStartTime=NULL " 485 query=$query", "$influence"Status.fStopTime=NULL " 486 query=$query", "$influence"Status.fReturnCode=NULL " 487 done 488 # give the condition for which step the status values have to be set 489 query=$query" WHERE " 411 490 if [ "$s" = "" ] 412 491 then 413 492 s=0 414 493 fi 415 query=$query" ${prims[0]}='${primaries[$s*${#prims[@]}]}'"416 for (( i=1 ; i < ${#prims[@]} ; i++ ))494 query=$query" "`echo ${prims[0]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}]}'" 495 for (( j=1 ; j < ${#prims[@]} ; j++ )) 417 496 do 418 query=$query" AND ${prims[$i]}='${primaries[$s*${#prims[@]}+$i]}' "497 query=$query" AND "`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' " 419 498 done 420 # echo " QUERY: "$query 499 # print query 500 echo " setstatus QUERY: "$query 421 501 printprocesslog "INFO setstatus QUERY: "$query 502 # execute query 422 503 if ! mysql -s -u $us --password=$pw --host=$ho $db -e " $query " 423 504 then … … 425 506 finish 426 507 fi 427 428 508 } 429 509
Note:
See TracChangeset
for help on using the changeset viewer.