Changeset 6 for trunk/gridctl.php
- Timestamp:
- Apr 22, 2015, 10:27:05 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gridctl.php
r3 r6 1 1 <?php 2 2 3 include_once "/home/us3/bin/listen-config.php"; 4 include "/home/us3/bin/cleanup.php"; 3 $us3bin = exec( "ls -d ~us3/bin" ); 4 include_once "$us3bin/listen-config.php"; 5 include "$us3bin/cleanup_aira.php"; 6 include "$us3bin/cleanup_gfac.php"; 5 7 6 8 // Global variables … … 10 12 $cluster = ''; 11 13 14 //global $self; 15 12 16 // Produce some output temporarily, so cron will send me message 13 17 $now = time(); 14 //echo "Time started: " . date( 'Y-m-d H:i:s', $now ) . "\n";18 echo "Time started: " . date( 'Y-m-d H:i:s', $now ) . "\n"; 15 19 16 20 // Get data from global GFAC DB … … 36 40 37 41 if ( mysql_num_rows( $result ) == 0 ) 42 { 43 //write_log( "$self: analysis read got numrows==0" ); 38 44 exit(); // Nothing to do 45 } 39 46 40 47 while ( list( $gfacID, $us3_db, $cluster, $status, $queue_msg, $time, $updateTime ) … … 42 49 { 43 50 // Checking we need to do for each entry 51 echo "us3db=$us3_db gfid=$gfacID\n"; 52 switch ( $us3_db ) 53 { 54 case 'Xuslims3_cauma3' : 55 case 'Xuslims3_cauma3d' : 56 case 'Xuslims3_HHU' : 57 case 'Xuslims3_Uni_KN' : 58 $serviceURL = "http://gridfarm005.ucs.indiana.edu:9090/ogce-rest/job"; 59 break; 60 61 default : 62 // $serviceURL = "http://gridfarm005.ucs.indiana.edu:8080/ogce-rest/job"; 63 break; 64 } 65 66 $awork = array(); 67 $awork = explode( "-", $gfacID ); 68 $gfacLabl = $awork[0] . "-" . $awork[1] . "-" . $awork[2]; 69 $loghdr = $self . ":" . $gfacLabl . "...:"; 70 71 // If entry is for Airvata/Thrift, get the true current status 72 73 if ( is_aira_job( $gfacID ) ) 74 { 75 $status_in = $status; 76 //write_log( "$loghdr status_in=$status_in" ); 77 $status = aira_status( $gfacID, $status_in ); 78 if($status != $status_in ) 79 write_log( "$loghdr Set to $status from $status_in" ); 80 } 81 else 82 { 83 $status_gw = $status; 84 $status = get_gfac_status( $gfacID ); 85 //if ( $status == 'FINISHED' ) 86 if ( $status_gw == 'COMPLETE' ) 87 $status = $status_gw; 88 write_log( "$loghdr non-AThrift status=$status status_gw=$status_gw" ); 89 } 44 90 45 91 // Sometimes during testing, the us3_db entry is not set … … 47 93 if ( strlen( $us3_db ) == 0 && $status != 'ERROR' ) 48 94 { 49 write_log( "$ self:GFAC DB is NULL - $gfacID" );95 write_log( "$loghdr GFAC DB is NULL - $gfacID" ); 50 96 mail_to_admin( "fail", "GFAC DB is NULL\n$gfacID" ); 51 97 … … 55 101 56 102 if ( ! $result2 ) 57 write_log( "$self: Query failed $query2 - " . mysql_error( $gLink ) ); 58 59 } 60 103 write_log( "$loghdr Query failed $query2 - " . mysql_error( $gLink ) ); 104 105 } 106 107 //echo " st=$status\n"; 61 108 switch ( $status ) 62 109 { … … 76 123 77 124 case "RUNNING": 125 case "STARTED": 126 case "STAGING": 127 case "ACTIVE": 78 128 running( $time ); 79 129 break; … … 84 134 85 135 case "DATA": 136 case "RESULTS_GEN": 86 137 wait_data( $time ); 87 138 break; … … 91 142 break; 92 143 144 case "COMPLETED": 93 145 case "COMPLETE": 94 146 complete(); … … 101 153 break; 102 154 155 case "FINISHED": 156 case "DONE": 157 if ( is_aira_job( $gfacID ) ) 158 { 159 complete(); 160 } 161 case "PROCESSING": 103 162 default: 104 163 break; … … 113 172 global $gLink; 114 173 global $gfacID; 174 global $loghdr; 115 175 116 176 $now = time(); … … 127 187 128 188 if ( ! in_array( $job_status, array( 'SUBMITTED', 'INITIALIZED', 'PENDING' ) ) ) 189 { 190 write_log( "$loghdr submitted:job_status=$job_status" ); 129 191 update_job_status( $job_status, $gfacID ); 192 } 130 193 131 194 return; … … 150 213 global $gLink; 151 214 global $gfacID; 215 global $loghdr; 152 216 153 217 if ( ( $job_status = get_gfac_status( $gfacID ) ) === false ) … … 185 249 global $gLink; 186 250 global $gfacID; 251 global $loghdr; 187 252 188 253 $now = time(); … … 200 265 return; 201 266 202 if ( $job_status != 'ACTIVE')267 if ( ! in_array( $job_status, array( 'ACTIVE', 'RUNNING', 'STARTED' ) ) ) 203 268 update_job_status( $job_status, $gfacID ); 204 269 … … 224 289 global $gLink; 225 290 global $gfacID; 291 global $loghdr; 226 292 227 293 if ( ( $job_status = get_gfac_status( $gfacID ) ) === false ) … … 231 297 return; 232 298 233 if ( $job_status != 'ACTIVE')299 if ( ! in_array( $job_status, array( 'ACTIVE', 'RUNNING', 'STARTED' ) ) ) 234 300 { 235 301 update_job_status( $job_status, $gfacID ); … … 261 327 global $gLink; 262 328 global $gfacID; 329 global $loghdr; 263 330 264 331 $now = time(); … … 308 375 global $gLink; 309 376 global $gfacID; 377 global $loghdr; 310 378 311 379 if ( ( $job_status = get_gfac_status( $gfacID ) ) === false ) … … 368 436 global $gfacID; 369 437 global $us3_db; 438 global $loghdr; 370 439 371 440 // Double check that the gfacID exists … … 382 451 list( $count ) = mysql_fetch_array( $result ); 383 452 453 if ($count==0) 454 write_log( "$loghdr count = $count gfacID = $gfacID" ); 384 455 if ( $count == 0 ) return; 385 456 386 457 // Now check the us3 instance 387 458 $requestID = get_us3_data(); 459 //write_log( "$loghdr requestID = $requestID gfacID = $gfacID" ); 388 460 if ( $requestID == 0 ) return; 389 461 390 gfac_cleanup( $us3_db, $requestID, $gLink ); 462 if ( preg_match( "/US3-AIRA/i", $gfacID ) ) 463 { 464 //write_log( "$loghdr CALLING aira_cleanup()" ); 465 aira_cleanup( $us3_db, $requestID, $gLink ); 466 //write_log( "$loghdr RTN FR aira_cleanup()" ); 467 } 468 else 469 { 470 //write_log( "$loghdr CALLING gfac_cleanup()" ); 471 gfac_cleanup( $us3_db, $requestID, $gLink ); 472 } 391 473 } 392 474 … … 395 477 { 396 478 global $gLink; 479 global $query; 480 global $self; 481 global $loghdr; 397 482 398 483 switch ( $job_status ) … … 401 486 case 'SUBMITED' : 402 487 case 'INITIALIZED' : 488 case 'UPDATING' : 403 489 case 'PENDING' : 404 490 $query = "UPDATE analysis SET status='SUBMITTED' WHERE gfacID='$gfacID'"; … … 406 492 break; 407 493 494 case 'STARTED' : 495 case 'RUNNING' : 408 496 case 'ACTIVE' : 409 497 $query = "UPDATE analysis SET status='RUNNING' WHERE gfacID='$gfacID'"; … … 411 499 break; 412 500 501 case 'FINISHED' : 502 $query = "UPDATE analysis SET status='FINISHED' WHERE gfacID='$gfacID'"; 503 $message = "NONE"; 504 break; 505 506 case 'DONE' : 507 $query = "UPDATE analysis SET status='DONE' WHERE gfacID='$gfacID'"; 508 $message = "NONE"; 509 break; 510 413 511 case 'COMPLETED' : 414 case ' DONE' :512 case 'COMPLETE' : 415 513 $query = "UPDATE analysis SET status='COMPLETE' WHERE gfacID='$gfacID'"; 416 $message = "Job status request reports job is COMPLETE ";514 $message = "Job status request reports job is COMPLETED"; 417 515 break; 418 516 419 case 'DATA' :517 case 'DATA' : 420 518 $query = "UPDATE analysis SET status='DATA' WHERE gfacID='$gfacID'"; 421 519 $message = "Job status request reports job is COMPLETE, waiting for data"; … … 423 521 424 522 case 'CANCELED' : 425 case 'CANCELLED' 523 case 'CANCELLED' : 426 524 $query = "UPDATE analysis SET status='CANCELED' WHERE gfacID='$gfacID'"; 427 525 $message = "Job status request reports job is CANCELED"; … … 434 532 435 533 case 'UNKNOWN' : 436 // $query = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'"; 534 write_log( "$loghdr job_status='UNKNOWN', reset to 'ERROR' " ); 535 $query = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'"; 437 536 $message = "Job status request reports job is not in the queue"; 438 537 break; … … 440 539 default : 441 540 // We shouldn't ever get here 442 $query = " ";541 $query = "UPDATE analysis SET status='ERROR' WHERE gfacID='$gfacID'"; 443 542 $message = "Job status was not recognized - $job_status"; 444 write_log( "$ self -update_job_status: " .543 write_log( "$loghdr update_job_status: " . 445 544 "Job status was not recognized - $job_status\n" . 446 545 "gfacID = $gfacID\n" ); … … 451 550 $result = mysql_query( $query, $gLink ); 452 551 if ( ! $result ) 453 write_log( "$self: Query failed $query - " . mysql_error( $gLink ) ); 454 455 update_queue_messages( $message ); 456 update_db( $message ); 552 write_log( "$loghdr Query failed $query - " . mysql_error( $gLink ) ); 553 554 if ( $message != 'NONE' ) 555 { 556 update_queue_messages( $message ); 557 update_db( $message ); 558 } 457 559 } 458 560 … … 466 568 global $us3_db; 467 569 global $updateTime; 570 global $loghdr; 468 571 469 572 $us3_link = mysql_connect( $dbhost, $user, $passwd ); … … 471 574 if ( ! $us3_link ) 472 575 { 473 write_log( "$ self:could not connect: $dbhost, $user, $passwd" );576 write_log( "$loghdr could not connect: $dbhost, $user, $passwd" ); 474 577 mail_to_admin( "fail", "Could not connect to $dbhost" ); 475 578 return 0; … … 481 584 if ( ! $result ) 482 585 { 483 write_log( "$ self:could not select DB $us3_db" );586 write_log( "$loghdr could not select DB $us3_db" ); 484 587 mail_to_admin( "fail", "Could not select DB $us3_db, $dbhost, $user, $passwd" ); 485 588 return 0; … … 503 606 } 504 607 505 // Function to determine if this is a gfac job or a local job608 // Function to determine if this is a gfac job or not 506 609 function is_gfac_job( $gfacID ) 507 610 { … … 517 620 } 518 621 622 // Function to determine if this is an airavata/thrift job or not 623 function is_aira_job( $gfacID ) 624 { 625 global $cluster; 626 627 if ( preg_match( "/US3-AIRA/i", $gfacID ) && 628 ! preg_match( "/juropa/i", $cluster ) ) 629 { 630 // Then it's an Airavata/Thrift job 631 return true; 632 } 633 634 return false; 635 } 636 519 637 // Function to get the current job status from GFAC 520 638 function get_gfac_status( $gfacID ) 521 639 { 522 640 global $serviceURL; 523 524 if ( ! is_gfac_job( $gfacID ) ) 641 global $self; 642 global $loghdr; 643 global $cluster; 644 645 if ( is_aira_job( $gfacID ) ) 646 { 647 $status_ex = getExperimentStatus( $gfacID ); 648 $gfac_status = standard_status( $status_ex ); 649 return $gfac_status; 650 } 651 652 else if ( ! is_gfac_job( $gfacID ) ) 525 653 return false; 526 654 … … 534 662 catch ( HttpException $e ) 535 663 { 536 write_log( "$ self:Status not available - marking failed - $gfacID" );664 write_log( "$loghdr Status not available - marking failed - $gfacID" ); 537 665 return 'GFAC_STATUS_UNAVAILABLE'; 538 666 } … … 547 675 'INITIALIZED', 548 676 'PENDING', 677 'RUNNING', 549 678 'ACTIVE', 679 'STARTED', 550 680 'COMPLETED', 681 'FINISHED', 551 682 'DONE', 552 683 'DATA', 684 'RESULTS_GEN', 553 685 'CANCELED', 554 686 'CANCELLED', 555 687 'FAILED', 688 'STAGING', 556 689 'UNKNOWN'); 557 690 if ( ! in_array( $gfac_status, $status_types ) ) … … 560 693 "Status: /$gfac_status/\n" ); 561 694 695 if ( in_array( $gfac_status, array( 'DONE', 'DATA', 'RESULTS_GEN' ) ) ) 696 $gfac_status = 'DATA'; 697 562 698 return $gfac_status; 563 699 } … … 567 703 { 568 704 global $serviceURL; 705 global $self; 569 706 570 707 // Make sure it's a GFAC job and status is appropriate for this call … … 575 712 } 576 713 577 if ( ! in_array( $job_status, array( 'DONE', 'FAILED', 'COMPLETE' ) ) )714 if ( ! in_array( $job_status, array( 'DONE', 'FAILED', 'COMPLETE', 'FINISHED' ) ) ) 578 715 { 579 716 // Then it's not appropriate to request data … … 637 774 { 638 775 global $cluster; 776 global $self; 639 777 640 778 $system = "$cluster.uthscsa.edu"; … … 697 835 // Insert message into queue_message table 698 836 $query = "INSERT INTO queue_messages SET " . 699 "message = '" . mysql_real_escape_string( $message, $gLink ) . "', " .700 "analysisID = $analysisID";837 "message = '" . mysql_real_escape_string( $message, $gLink ) . "', " . 838 "analysisID = '$analysisID' "; 701 839 $result = mysql_query( $query, $gLink ); 702 840 if ( ! $result ) … … 755 893 $headers = "From: $org_name Admin<$admin_email>" . "\n"; 756 894 $headers .= "Cc: $org_name Admin<$admin_email>" . "\n"; 757 $headers .= "Bcc: Dan Zollars<dzollars@gmail.com>" . "\n"; // make sure895 $headers .= "Bcc: Gary Gorbet<gegorbet@gmail.com>" . "\n"; // make sure 758 896 759 897 // Set the reply address … … 781 919 mail( $admin_email, $subject, $message, $headers ); 782 920 } 921 922 // Convert a status string to one of the standard DB status strings 923 function standard_status( $status_in ) 924 { 925 switch ( $status_in ) 926 { // Map variations to standard gateway status values 927 case 'QUEUED' : 928 case 'LAUNCHED' : 929 case 'CREATED' : 930 case 'VALIDATED' : 931 case 'SCHEDULED' : 932 case 'submitted' : 933 case '' : 934 $status = 'SUBMITTED'; 935 break; 936 937 case 'EXECUTING' : 938 case 'ACTIVE' : 939 case 'running' : 940 case 'executing' : 941 $status = 'RUNNING'; 942 break; 943 944 case 'PENDING' : 945 case 'CANCELING' : 946 $status = 'UPDATING'; 947 break; 948 949 case 'CANCELLED' : 950 case 'canceled' : 951 $status = 'CANCELED'; 952 break; 953 954 $status = 'DATA'; 955 break; 956 957 case 'COMPLETED' : 958 case 'completed' : 959 $status = 'COMPLETE'; 960 break; 961 962 case 'FAILED_DATA' : 963 case 'SUBMIT_TIMEOUT' : 964 case 'RUN_TIMEOUT' : 965 case 'DATA_TIMEOUT' : 966 $status = 'FAILED'; 967 break; 968 969 case 'COMPLETE' : 970 $status = 'DONE'; 971 break; 972 973 case 'UNKNOWN' : 974 $status = 'ERROR'; 975 break; 976 977 // Where already standard value, retain value 978 case 'ERROR' : 979 case 'RUNNING' : 980 case 'SUBMITTED' : 981 case 'UPDATING' : 982 case 'CANCELED' : 983 case 'DATA' : 984 case 'FAILED' : 985 case 'DONE' : 986 case 'FINISHED' : 987 default : 988 $status = $status_in; 989 break; 990 } 991 992 return $status; 993 } 994 995 function aira_status( $gfacID, $status_in ) 996 { 997 global $self; 998 global $loghdr; 999 //echo "a_st: st_in$status_in : $gfacID\n"; 1000 //$status_gw = standard_status( $status_in ); 1001 $status_gw = $status_in; 1002 //echo "a_st: st_db=$status_gw\n"; 1003 $status = $status_gw; 1004 1005 if ( preg_match( "/US3-AIRA/i", $gfacID ) ) 1006 { 1007 $status_ex = getExperimentStatus( $gfacID ); 1008 1009 if ( $status_ex == 'COMPLETED' ) 1010 { // Experiment is COMPLETED: check for 'FINISHED' or 'DONE' 1011 if ( $status_gw == 'FINISHED' || $status_gw == 'DONE' ) 1012 { // COMPLETED + FINISHED/DONE : gateway status is now COMPLETE 1013 $status = 'COMPLETE'; 1014 } 1015 1016 else 1017 { // COMPLETED + NOT-FINISHED/DONE: gw status now DONE 1018 $status = 'DONE'; 1019 } 1020 } 1021 1022 else if ( $status_gw == 'FINISHED' || $status_gw == 'DONE' ) 1023 { // Gfac status == FINISHED/DONE: leave as is (unless FAILED) 1024 $status = $status_gw; 1025 if ( $status_ex == 'FAILED' ) 1026 { 1027 sleep( 10 ); 1028 $status_ex = getExperimentStatus( $gfacID ); 1029 if ( $status_ex == 'FAILED' ) 1030 { 1031 write_log( "$loghdr status still 'FAILED' after 10-second delay" ); 1032 sleep( 10 ); 1033 $status_ex = getExperimentStatus( $gfacID ); 1034 if ( $status_ex == 'FAILED' ) 1035 write_log( "$loghdr status still 'FAILED' after 20-second delay" ); 1036 else 1037 write_log( "$loghdr status is $status_ex after 20-second delayed retry" ); 1038 } 1039 write_log( "$loghdr status reset to 'COMPLETE'" ); 1040 $status = 'COMPLETE'; 1041 } 1042 } 1043 1044 else 1045 { // Experiment not COMPLETED/FINISHED/DONE: use experiment status 1046 $status = standard_status( $status_ex ); 1047 } 1048 1049 write_log( "$loghdr status/_in/_gw/_ex=$status/$status_in/$status_gw/$status_ex" ); 1050 if ( $status != $status_gw ) 1051 { 1052 update_job_status( $status, $gfacID ); 1053 } 1054 } 1055 1056 return $status; 1057 } 1058 783 1059 ?>
Note:
See TracChangeset
for help on using the changeset viewer.