- Timestamp:
- 05/13/05 16:51:31 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/toga-functions.php
r104 r105 66 66 class DataGatherer { 67 67 68 var $xmlhandler, $data ;68 var $xmlhandler, $data, $httpvars; 69 69 70 70 function DataGatherer() { … … 72 72 $this->parser = xml_parser_create(); 73 73 $this->source = new DataSource(); 74 $this->httpvars = new HTTPVariables(); 74 75 $this->xmlhandler = new TorqueXMLHandler(); 75 76 xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) ); … … 87 88 } 88 89 90 function printInfo() { 91 $handler = $this->xmlhandler; 92 $handler->printInfo(); 93 } 94 89 95 } 90 96 91 97 class TorqueXMLHandler { 92 98 93 var $clusters, $heartbeat ;99 var $clusters, $heartbeat, $nodes, $jobs; 94 100 95 101 function TorqueXMLHandler() { 102 $jobs = array(); 96 103 $clusters = array(); 104 $nodes = array(); 97 105 $heartbeat = array(); 98 106 } 99 107 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 100 133 function startElement( $parser, $name, $attrs ) { 134 135 $jobs = &$this->jobs; 101 136 102 137 if ( $attrs[TN] ) { … … 107 142 } 108 143 109 $jobs = array();110 144 $jobid = null; 111 145 112 146 // printf( '%s=%s', $attrs[NAME], $attrs[VAL] ); 113 114 147 115 148 if( $name == 'CLUSTER' ) { … … 120 153 $clusters[$clustername] = array(); 121 154 155 } else if( $name == 'HOST' ) { 156 157 $hostname = $attrs[NAME]; 158 $location = $attrs[LOCATION]; 159 160 $this->gotNode( $hostname, null,$location ); 161 122 162 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) { 123 163 … … 144 184 $togavalue = $togavalues[1]; 145 185 146 printf( " toganame %s, togavalue%s\n", $toganame, $togavalue );186 printf( "\t%s\t= %s\n", $toganame, $togavalue ); 147 187 148 188 if( $toganame == 'nodes' ) { 149 189 150 190 if( !isset( $jobs[$toganame] ) ) 151 $jobs[$ toganame] = array();191 $jobs[$jobid][$toganame] = array(); 152 192 153 193 $nodes = explode( ';', $togavalue ); … … 155 195 foreach( $nodes as $node ) { 156 196 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 ); 159 205 } 160 206 161 207 } else { 162 208 163 $jobs[$ toganame] = $togavalue;209 $jobs[$jobid][$toganame] = $togavalue; 164 210 165 211 } … … 171 217 function stopElement( $parser, $name ) { 172 218 } 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 } 173 256 } 174 257 175 258 class Node { 176 259 177 var $img, $hostname, $location ;260 var $img, $hostname, $location, $jobs; 178 261 179 262 function Node( $hostname ) { … … 181 264 $this->hostname = $hostname; 182 265 $this->img = new NodeImg(); 266 $this->jobs = array(); 267 } 268 269 function addJob( $jobid ) { 270 $jobs = &$this->jobs; 271 272 $jobs[] = $jobid; 183 273 } 184 274 … … 187 277 } 188 278 279 function setHostname( $hostname ) { 280 $this->hostname = $hostname; 281 } 282 189 283 function setCpus( $cpus ) { 190 284 $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; 191 301 } 192 302 } … … 247 357 $my_data = new DataGatherer(); 248 358 $my_data->parseXML(); 359 $my_data->printInfo(); 360 $my_data->printInfo(); 249 361 ?> 250 362 </PRE>
Note: See TracChangeset
for help on using the changeset viewer.