Changeset 648 for trunk/web/addons/job_monarch/libtoga.php
- Timestamp:
- 11/12/09 17:08:03 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/job_monarch/libtoga.php
r602 r648 137 137 } 138 138 139 class SessionHandler 140 { 141 var $cluster, $poll_stored; 142 143 function SessionHandler( $cluster ) 144 { 145 $this->cluster = $cluster; 146 $this->ds = new DataSource( $this->cluster ); 147 148 //ob_start(); 149 session_start(); 150 } 151 152 function refreshSession() 153 { 154 $ds = &$this->ds; 155 $myxml_data = $ds->getData(); 156 157 $_SESSION['data'] = &$myxml_data; 158 $_SESSION['gather_time'] = time(); 159 } 160 161 function hasSession() 162 { 163 return ( $this->have_session ); 164 } 165 166 function getSession() 167 { 168 return $_SESSION; 169 170 } 171 172 function endSession() 173 { 174 session_write_close(); 175 //ob_end_flush(); 176 //session_unlock(); 177 //session_destroy(); 178 } 179 180 function updatePollInterval( $poll_interval ) 181 { 182 //if( ! isset( $_SESSION['poll_interval'] ) ) 183 //{ 184 $_SESSION['poll_interval'] = $poll_interval; 185 //} 186 } 187 188 function checkSession() 189 { 190 // I got nothing; create session 191 // 192 //if( ! $this->have_session ) 193 //{ 194 // $this->refreshSession(); 195 // 196 // return 0; 197 //} 198 199 //if( $this->poll_stored ) 200 //{ 201 // session_start(); 202 203 if( isset( $_SESSION['gather_time'] ) && isset( $_SESSION['poll_interval'] ) ) 204 { 205 206 $gather_time = $_SESSION['gather_time']; 207 $poll_interval = $_SESSION['poll_interval']; 208 209 // If poll_interval time elapsed since last update; recreate session 210 // 211 if( (time() - $gather_time) >= $poll_interval ) 212 { 213 $this->refreshSession(); 214 } 215 } 216 else 217 { 218 $this->refreshSession(); 219 } 220 //} 221 } 222 } 139 223 140 224 class TarchDbase … … 459 543 var $data, $ip, $port; 460 544 461 function DataSource( )545 function DataSource( $cluster ) 462 546 { 463 547 global $DATA_SOURCE; … … 470 554 $this->ip = $ds_ip; 471 555 $this->port = $ds_port; 472 556 $this->cluster = $cluster; 473 557 } 474 558 … … 487 571 } 488 572 573 $clustername = $this->cluster; 574 575 $rc = fputs($fp, "/$clustername"."\n" ); 576 577 if (!$rc) 578 { 579 echo "Could not sent request to gmetad: $errstr"; 580 return; 581 } 582 489 583 stream_set_timeout( $fp, 30 ); 490 584 … … 515 609 $this->xmlhandler = new TorqueXMLHandler( $this->cluster ); 516 610 611 xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 ); 517 612 xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); 518 613 … … 521 616 $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) ); 522 617 } 618 } 619 620 function getPollInterval() 621 { 622 $handler = $this->xmlhandler; 623 //printf("d i %s\n", $handler->getPollInterval() ); 624 625 return $handler->getPollInterval(); 523 626 } 524 627 … … 555 658 function getJobs() 556 659 { 557 $handler = $this->xmlhandler;558 return $handler->getJobs();660 $handler = &$this->xmlhandler; 661 return ( $handler->getJobs() ); 559 662 } 560 663 … … 593 696 $this->fqdn = 0; 594 697 $this->fqdnFound = 0; 698 $this->pollinterval = 0; 699 } 700 701 function getPollInterval() 702 { 703 //printf( "t pi %s\n", $this->pollinterval ); 704 return ( $this->pollinterval ); 595 705 } 596 706 … … 621 731 if (isset( $this->heartbeat['time'] )) 622 732 { 623 return 1;733 return true; 624 734 } 625 735 else 626 736 { 627 return 0;737 return false; 628 738 } 629 739 } … … 633 743 // Should hostname be FQDN or short w/o domain 634 744 // 635 $nodes = &$this->nodes;745 //$nodes = &$this->nodes; 636 746 637 747 $domain_len = 0 - strlen( $tdomain ); … … 640 750 { 641 751 if( substr( $thostname, $domain_len ) != $tdomain ) 752 //if( strpos( $thostname, $tdomain ) !== false ) 642 753 { 643 754 $thostname = $thostname . '.'.$tdomain; … … 650 761 function startElement( $parser, $name, $attrs ) 651 762 { 652 $jobs 653 $nodes 763 $jobs = $this->jobs; 764 $nodes = $this->nodes; 654 765 655 766 if ( $attrs['TN'] ) … … 664 775 $jobid = null; 665 776 666 if( $name == 'CLUSTER' ) 667 { 668 $this->proc_cluster = $attrs['NAME']; 669 } 670 else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) 777 //if( $name == 'CLUSTER' ) 778 //{ 779 // $this->proc_cluster = $attrs['NAME']; 780 //} 781 //else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) 782 if( $name == 'HOST' ) 671 783 { 672 784 $hostname = $attrs['NAME']; … … 698 810 } 699 811 } 700 else if( $name == 'METRIC' and strstr( $attrs['NAME'], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) 701 { 702 if( strstr( $attrs['NAME'], 'MONARCH-HEARTBEAT' ) ) 812 //else if( $name == 'METRIC' and strstr( $attrs['NAME'], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) 813 else if( ($name == 'METRIC') && (strpos( $attrs['NAME'], 'MONARCH' ) !== false) ) 814 { 815 if( strpos( $attrs['NAME'], 'MONARCH-HEARTBEAT' ) !== false ) 703 816 { 704 817 $this->heartbeat['time'] = $attrs['VAL']; 705 818 } 706 else if( str str( $attrs['NAME'], 'MONARCH-DOWN' ))819 else if( strpos( $attrs['NAME'], 'MONARCH-DOWN' ) !== false) 707 820 { 708 821 $fields = explode( ' ', $attrs['VAL'] ); … … 717 830 $toganame = $togavalues[0]; 718 831 $togavalue = $togavalues[1]; 832 719 833 720 834 if( $toganame == 'nodes' ) … … 746 860 } 747 861 } 748 else if( str str( $attrs['NAME'], 'MONARCH-OFFLINE' ))862 else if( strpos( $attrs['NAME'], 'MONARCH-OFFLINE' ) !== false ) 749 863 { 750 864 $fields = explode( ' ', $attrs['VAL'] ); … … 788 902 } 789 903 } 790 else if( str str( $attrs['NAME'], 'MONARCH-JOB' ))904 else if( strpos( $attrs['NAME'], 'MONARCH-JOB' ) !== false ) 791 905 { 792 906 sscanf( $attrs['NAME'], 'MONARCH-JOB-%d-%d', $jobid, $monincr ); … … 805 919 $toganame = $togavalues[0]; 806 920 $togavalue = $togavalues[1]; 921 922 //printf( "tn %s\n", $toganame ); 807 923 808 924 if( $toganame == 'nodes' ) … … 830 946 $jobs[$jobid][$toganame] = $togavalue; 831 947 } 948 } 949 else if( $toganame == 'poll_interval' ) 950 { 951 $this->pollinterval = $togavalue; 952 //printf("u pi %s\n", $togavalue ); 832 953 } 833 954 else … … 1352 1473 var $filtername, $filters; 1353 1474 1354 function ClusterImage( $data, $clustername ) 1355 { 1356 $this->dataget = new DataGatherer( $clustername ); 1357 $this->data = $data; 1475 function ClusterImage( $datag, $clustername ) 1476 { 1477 //$this->dataget = new DataGatherer( $clustername ); 1478 $this->dataget = $datag; 1479 //$this->data = $data; 1358 1480 $this->clustername = $clustername; 1359 1481 $this->filters = array(); … … 1503 1625 } 1504 1626 1505 $mydatag =$this->dataget;1506 $mydatag->parseXML( $this->data );1627 $mydatag = &$this->dataget; 1628 //$mydatag->parseXML( $this->data ); 1507 1629 1508 1630 if( $this->isSmall() ) … … 1518 1640 1519 1641 $nodes = $mydatag->getNodes(); 1642 //print_r( $nodes); 1520 1643 $nodes_hosts = array_keys( $nodes ); 1521 1644 … … 1556 1679 $this->height = ($y_offset + (($node_rows*$node_width)+1) ); 1557 1680 1558 $jobs 1681 $jobs = $mydatag->getJobs(); 1559 1682 $filtered_nodes = $this->filterNodes( $jobs, $nodes ); 1560 1683 $selected_host = $this->selected;
Note: See TracChangeset
for help on using the changeset viewer.