Changeset 105


Ignore:
Timestamp:
05/13/05 16:51:31 (19 years ago)
Author:
bastiaans
Message:

toga/toga-functions.php:

  • Job and Node relations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/toga-functions.php

    r104 r105  
    6666class DataGatherer {
    6767
    68         var $xmlhandler, $data;
     68        var $xmlhandler, $data, $httpvars;
    6969
    7070        function DataGatherer() {
     
    7272                $this->parser = xml_parser_create();
    7373                $this->source = new DataSource();
     74                $this->httpvars = new HTTPVariables();
    7475                $this->xmlhandler = new TorqueXMLHandler();
    7576                xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
     
    8788        }
    8889
     90        function printInfo() {
     91                $handler = $this->xmlhandler;
     92                $handler->printInfo();
     93        }
     94
    8995}
    9096
    9197class TorqueXMLHandler {
    9298
    93         var $clusters, $heartbeat;
     99        var $clusters, $heartbeat, $nodes, $jobs;
    94100
    95101        function TorqueXMLHandler() {
     102                $jobs = array();
    96103                $clusters = array();
     104                $nodes = array();
    97105                $heartbeat = array();
    98106        }
    99107
     108        function gotNode( $hostname, $jobid = null, $location = 'unspecified' ) {
     109
     110                $nodes = &$this->nodes;
     111
     112                if( !isset( $nodes[$hostname] ) ) {
     113
     114                        $nodes[$hostname] = new Node( $hostname );
     115                }
     116
     117                if( $location != 'unspecified' ) {
     118
     119                        $nodes[$hostname]->setLocation( $location );
     120                //} else {
     121
     122                        // Return pointer to this node if location was not set
     123                        // Which means that this is for a jobinfo
     124                        //$mynode = &$nodes[$hostname];
     125                        //return $mynode;
     126                }
     127
     128                if( $jobid ) {
     129                        $nodes[$hostname]->addJob( $jobid );
     130                }
     131        }
     132
    100133        function startElement( $parser, $name, $attrs ) {
     134
     135                $jobs = &$this->jobs;
    101136
    102137                if ( $attrs[TN] ) {
     
    107142                }
    108143
    109                 $jobs = array();
    110144                $jobid = null;
    111145
    112146                // printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
    113 
    114147
    115148                if( $name == 'CLUSTER' ) {
     
    120153                                $clusters[$clustername] = array();
    121154
     155                } else if( $name == 'HOST' ) {
     156
     157                        $hostname = $attrs[NAME];
     158                        $location = $attrs[LOCATION];
     159
     160                        $this->gotNode( $hostname, null,$location );
     161
    122162                } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
    123163
     
    144184                                        $togavalue = $togavalues[1];
    145185
    146                                         printf( "toganame %s, togavalue %s\n", $toganame, $togavalue );
     186                                        printf( "\t%s\t= %s\n", $toganame, $togavalue );
    147187
    148188                                        if( $toganame == 'nodes' ) {
    149189
    150190                                                if( !isset( $jobs[$toganame] ) )
    151                                                         $jobs[$toganame] = array();
     191                                                        $jobs[$jobid][$toganame] = array();
    152192
    153193                                                $nodes = explode( ';', $togavalue );
     
    155195                                                foreach( $nodes as $node ) {
    156196
    157                                                         printf( "node %s\n", $node );
    158                                                         $jobs[$toganame][] = new Node( $node );
     197                                                        // printf( "node %s\n", $node );
     198
     199                                                        $hostname = $node.'.'.$jobs[$jobid][domain];
     200                                                        $jobs[$jobid][$toganame][] = $hostname;
     201                                                        $this->gotNode( $hostname, $jobid );
     202
     203                                                        //$jobs[$jobid][$toganame][$hostname] = $this->gotNode( $hostname );
     204                                                        // $jobs[$toganame][$node] = new Node( $node );
    159205                                                }
    160206
    161207                                        } else {
    162208
    163                                                 $jobs[$toganame] = $togavalue;
     209                                                $jobs[$jobid][$toganame] = $togavalue;
    164210
    165211                                        }
     
    171217        function stopElement( $parser, $name ) {
    172218        }
     219
     220        function printInfo() {
     221
     222                $jobs = &$this->jobs;
     223
     224                printf( "---jobs---\n" );
     225
     226                foreach( $jobs as $jobid => $job ) {
     227
     228                        printf( "job %s\n", $jobid );
     229
     230                        if( isset( $job[nodes] ) ) {
     231
     232                                foreach( $job[nodes] as $node ) {
     233
     234                                        $mynode = $this->nodes[$node];
     235                                        $hostname = $mynode->getHostname();
     236                                        $location = $mynode->getLocation();
     237
     238                                        printf( "\t- node %s\tlocation %s\n", $hostname, $location );
     239                                        //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid );
     240                                }
     241                        }
     242                }
     243
     244                printf( "---nodes---\n" );
     245
     246                $nodes = &$this->nodes;
     247
     248                foreach( $nodes as $node ) {
     249
     250                        $hostname = $node->getHostname();
     251                        $location = $node->getLocation();
     252                        $jobs = implode( ' ', $node->getJobs() );
     253                        printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs );
     254                }
     255        }
    173256}
    174257
    175258class Node {
    176259
    177         var $img, $hostname, $location;
     260        var $img, $hostname, $location, $jobs;
    178261
    179262        function Node( $hostname ) {
     
    181264                $this->hostname = $hostname;
    182265                $this->img = new NodeImg();
     266                $this->jobs = array();
     267        }
     268
     269        function addJob( $jobid ) {
     270                $jobs = &$this->jobs;
     271
     272                $jobs[] = $jobid;
    183273        }
    184274
     
    187277        }
    188278
     279        function setHostname( $hostname ) {
     280                $this->hostname = $hostname;
     281        }
     282
    189283        function setCpus( $cpus ) {
    190284                $this->cpus = $cpus;
     285        }
     286
     287        function getHostname() {
     288                return $this->hostname;
     289        }
     290
     291        function getLocation() {
     292                return $this->location;
     293        }
     294
     295        function getCpus() {
     296                return $this->cpus;
     297        }
     298
     299        function getJobs() {
     300                return $this->jobs;
    191301        }
    192302}
     
    247357$my_data = new DataGatherer();
    248358$my_data->parseXML();
     359$my_data->printInfo();
     360$my_data->printInfo();
    249361?>
    250362</PRE>
Note: See TracChangeset for help on using the changeset viewer.