Ignore:
Timestamp:
11/12/09 17:08:03 (14 years ago)
Author:
ramonb
Message:

job_monarch/overview.php,
job_monarch/index.php:

  • old code cleanup

job_monarch/index.php,
job_monarch/image.php,
job_monarch/jobstore.php

  • rewrote session handling

job_monarch/image.php:

job_monarch/templates/header.tpl:

  • add session to clusterimage
  • (temp?) disabled pie chart

job_monarch/libtoga.php:

  • wrote new SessionHandler? class to handle all sessions
  • DataSource? now uses interactive port so can retrieve only relevant XML
  • disable XML_OPTION_CASE_FOLDING to speed up xml parsing
  • use jobmond poll interval to only reload XML when useful
  • use strpos instead of strstr, should be faster xml parsing
  • dont parse XML in ClusterImage? anymore, instead supply DataGather? object


job_monarch/conf.php:

  • use interactive gmetad port now
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/job_monarch/libtoga.php

    r602 r648  
    137137}
    138138
     139class 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}
    139223
    140224class TarchDbase
     
    459543        var $data, $ip, $port;
    460544
    461         function DataSource()
     545        function DataSource( $cluster )
    462546        {
    463547                global $DATA_SOURCE;
     
    470554                $this->ip       = $ds_ip;
    471555                $this->port     = $ds_port;
    472 
     556                $this->cluster  = $cluster;
    473557        }
    474558
     
    487571                }
    488572
     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
    489583                stream_set_timeout( $fp, 30 );
    490584
     
    515609                $this->xmlhandler       = new TorqueXMLHandler( $this->cluster );
    516610
     611                xml_parser_set_option( $this->parser, XML_OPTION_CASE_FOLDING, 0 );
    517612                xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
    518613
     
    521616                        $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) );
    522617                }
     618        }
     619
     620        function getPollInterval()
     621        {
     622                $handler = $this->xmlhandler;
     623                //printf("d i %s\n", $handler->getPollInterval() );
     624
     625                return $handler->getPollInterval();
    523626        }
    524627
     
    555658        function getJobs()
    556659        {
    557                 $handler = $this->xmlhandler;
    558                 return $handler->getJobs();
     660                $handler = &$this->xmlhandler;
     661                return ( $handler->getJobs() );
    559662        }
    560663
     
    593696                $this->fqdn             = 0;
    594697                $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 );
    595705        }
    596706
     
    621731                if (isset( $this->heartbeat['time'] ))
    622732                {
    623                         return 1;
     733                        return true;
    624734                }
    625735                else
    626736                {
    627                         return 0;
     737                        return false;
    628738                }
    629739        }
     
    633743                // Should hostname be FQDN or short w/o domain
    634744                //
    635                 $nodes = &$this->nodes;
     745                //$nodes = &$this->nodes;
    636746
    637747                $domain_len     = 0 - strlen( $tdomain );
     
    640750                {
    641751                        if( substr( $thostname, $domain_len ) != $tdomain )
     752                        //if( strpos( $thostname, $tdomain ) !== false )
    642753                        {
    643754                                $thostname = $thostname . '.'.$tdomain;
     
    650761        function startElement( $parser, $name, $attrs )
    651762        {
    652                 $jobs = $this->jobs;
    653                 $nodes = $this->nodes;
     763                $jobs   = $this->jobs;
     764                $nodes  = $this->nodes;
    654765
    655766                if ( $attrs['TN'] )
     
    664775                $jobid = null;
    665776
    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' )
    671783                {
    672784                        $hostname = $attrs['NAME'];
     
    698810                        }
    699811                }
    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 )
    703816                        {
    704817                                $this->heartbeat['time'] = $attrs['VAL'];
    705818                        }
    706                         else if( strstr( $attrs['NAME'], 'MONARCH-DOWN' ) )
     819                        else if( strpos( $attrs['NAME'], 'MONARCH-DOWN' ) !== false)
    707820                        {
    708821                                $fields         = explode( ' ', $attrs['VAL'] );
     
    717830                                        $toganame       = $togavalues[0];
    718831                                        $togavalue      = $togavalues[1];
     832
    719833
    720834                                        if( $toganame == 'nodes' )
     
    746860                                }
    747861                        }
    748                         else if( strstr( $attrs['NAME'], 'MONARCH-OFFLINE' ) )
     862                        else if( strpos( $attrs['NAME'], 'MONARCH-OFFLINE' ) !== false )
    749863                        {
    750864                                $fields         = explode( ' ', $attrs['VAL'] );
     
    788902                                }
    789903                        }
    790                         else if( strstr( $attrs['NAME'], 'MONARCH-JOB' ) )
     904                        else if( strpos( $attrs['NAME'], 'MONARCH-JOB' ) !== false )
    791905                        {
    792906                                sscanf( $attrs['NAME'], 'MONARCH-JOB-%d-%d', $jobid, $monincr );
     
    805919                                        $toganame = $togavalues[0];
    806920                                        $togavalue = $togavalues[1];
     921
     922                                        //printf( "tn %s\n", $toganame );
    807923
    808924                                        if( $toganame == 'nodes' )
     
    830946                                                        $jobs[$jobid][$toganame] = $togavalue;
    831947                                                }
     948                                        }
     949                                        else if( $toganame == 'poll_interval' )
     950                                        {
     951                                                $this->pollinterval     = $togavalue;
     952                                                //printf("u pi %s\n", $togavalue );
    832953                                        }
    833954                                        else
     
    13521473        var $filtername, $filters;
    13531474
    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;
    13581480                $this->clustername      = $clustername;
    13591481                $this->filters          = array();
     
    15031625                }
    15041626
    1505                 $mydatag = $this->dataget;
    1506                 $mydatag->parseXML( $this->data );
     1627                $mydatag                = &$this->dataget;
     1628                //$mydatag->parseXML( $this->data );
    15071629
    15081630                if( $this->isSmall() )
     
    15181640
    15191641                $nodes          = $mydatag->getNodes();
     1642                //print_r( $nodes);
    15201643                $nodes_hosts    = array_keys( $nodes );
    15211644
     
    15561679                $this->height   = ($y_offset + (($node_rows*$node_width)+1) );
    15571680
    1558                 $jobs = $mydatag->getJobs();
     1681                $jobs           = $mydatag->getJobs();
    15591682                $filtered_nodes = $this->filterNodes( $jobs, $nodes );
    15601683                $selected_host  = $this->selected;
Note: See TracChangeset for help on using the changeset viewer.