Changeset 104


Ignore:
Timestamp:
05/13/05 12:07:07 (19 years ago)
Author:
bastiaans
Message:

toga/toga-functions.php:

  • XML parsing actually working
  • More attributes for Node class


File:
1 edited

Legend:

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

    r103 r104  
     1<PRE>
    12<?php
    23$GANGLIA_PATH = "/var/www/ganglia";
     
    9091class TorqueXMLHandler {
    9192
     93        var $clusters, $heartbeat;
     94
    9295        function TorqueXMLHandler() {
     96                $clusters = array();
     97                $heartbeat = array();
    9398        }
    9499
     
    105110                $jobid = null;
    106111
    107                 printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
    108 
    109                 sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid );
    110 
    111                 if( $jobid ) {
    112 
    113                         if( !isset( $jobs[$jobid] ) )
    114                                 $jobs[$jobid] = array();
    115 
    116                         $fields = explode( ' ', $attrs[VAL] );
    117 
    118                         foreach( $fields as $f ) {
    119                                 $togavalues = explode( '=', $f );
    120 
    121                                 foreach( $togavalues as $toganame => $togavalue ) {
     112                // printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
     113
     114
     115                if( $name == 'CLUSTER' ) {
     116
     117                        $clustername = $attrs[VAL];
     118
     119                        if( !isset( $clusters[$clustername] ) )
     120                                $clusters[$clustername] = array();
     121
     122                } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
     123
     124                        if( strstr( $attrs[NAME], 'TOGA-HEARTBEAT' ) ) {
     125
     126                                $heartbeat['time'] = $attrs[VAL];
     127                                printf( "heartbeat %s\n", $heartbeat['time'] );
     128
     129                        } else if( strstr( $attrs[NAME], 'TOGA-JOB' ) ) {
     130
     131                                sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid );
     132
     133                                printf( "jobid %s\n", $jobid );
     134
     135                                if( !isset( $jobs[$jobid] ) )
     136                                        $jobs[$jobid] = array();
     137
     138                                $fields = explode( ' ', $attrs[VAL] );
     139
     140                                foreach( $fields as $f ) {
     141                                        $togavalues = explode( '=', $f );
     142
     143                                        $toganame = $togavalues[0];
     144                                        $togavalue = $togavalues[1];
     145
     146                                        printf( "toganame %s, togavalue %s\n", $toganame, $togavalue );
    122147
    123148                                        if( $toganame == 'nodes' ) {
    124149
     150                                                if( !isset( $jobs[$toganame] ) )
     151                                                        $jobs[$toganame] = array();
     152
    125153                                                $nodes = explode( ';', $togavalue );
    126154
    127155                                                foreach( $nodes as $node ) {
    128156
    129                                                         // Doe iets koels met $node
     157                                                        printf( "node %s\n", $node );
     158                                                        $jobs[$toganame][] = new Node( $node );
    130159                                                }
    131160
     161                                        } else {
     162
     163                                                $jobs[$toganame] = $togavalue;
     164
    132165                                        }
    133 
    134                                         $jobs[$toganame] = $togavalue;
    135 
    136166                                }
    137167                        }
    138 
    139168                }
    140169        }
     
    146175class Node {
    147176
    148         var $img;
    149 
    150         function Node() {
    151 
     177        var $img, $hostname, $location;
     178
     179        function Node( $hostname ) {
     180
     181                $this->hostname = $hostname;
    152182                $this->img = new NodeImg();
     183        }
     184
     185        function setLocation( $location ) {
     186                $this->location = $location;
     187        }
     188
     189        function setCpus( $cpus ) {
     190                $this->cpus = $cpus;
    153191        }
    154192}
     
    210248$my_data->parseXML();
    211249?>
     250</PRE>
Note: See TracChangeset for help on using the changeset viewer.