source: trunk/web/addons/toga/libtoga.php @ 140

Last change on this file since 140 was 140, checked in by bastiaans, 19 years ago

web/addons/toga/templates/header.tpl:

  • Use block to include link to archive search

web/addons/toga/templates/overview.tpl:

  • Cleanup
  • Javascript moved to seperate .js file

web/addons/toga/templates/search.tpl:

  • Added search results and future showhosts block section

web/addons/toga/index.php:

  • Use block instead of include for archive search link

web/addons/toga/search.php:

  • Setup of working search style

web/addons/toga/libtoga.php:

  • searchDbase() will return a list of jobids matching the criteria
File size: 18.4 KB
Line 
1<?php
2// If php is compiled without globals
3//
4if ( !empty( $_GET ) ) {
5        extract( $_GET );
6}
7
8class HTTPVariables {
9
10        var $clustername, $metricname;
11        var $restvars, $httpvars;
12
13        function HTTPVariables( $httpvars, $getvars ) {
14
15                $this->restvars = array();
16
17                $this->clustername = $httpvars["c"] ? $httpvars["c"] : null;
18                $this->metricname = $httpvars["m"] ? $httpvars["m"] : null;
19
20                foreach( $httpvars as $httpvar => $httpval ) {
21                       
22                        if( $httpval ) {
23                                $this->restvars[$httpvar] = $httpval;
24                        }
25                }
26
27                foreach( $getvars as $getvar => $getval ) {
28
29                        if( $getval ) {
30                                $this->restvars[$getvar] = $getval;
31                        }
32                }
33        }
34
35        function getClusterName() {
36                return $this->clustername;
37        }
38
39        function getMetricName() {
40                return $this->metricname;
41        }
42
43        function getHttpVar( $var ) {
44                if( isset( $this->restvars[$var] ) )
45                        return $this->restvars[$var];
46                else
47                        return null;
48        }
49}
50
51// Toga's conf
52//
53include_once "./conf.php";
54
55global $GANGLIA_PATH;
56
57$my_dir = getcwd();
58
59// Load Ganglia's PHP
60chdir( $GANGLIA_PATH );
61
62$context = 'cluster';
63
64include_once "./conf.php";
65include_once "./functions.php";
66include_once "./ganglia.php";
67//include_once "./get_context.php";
68include_once "./get_ganglia.php";
69
70// Back to our PHP
71chdir( $my_dir );
72
73global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET;
74$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
75
76// Set cluster context so that Ganglia will
77// provide us with the correct metrics array
78//
79global $context, $clustername, $reports;
80
81//$clustername = $httpvars->getClusterName();
82
83global $default_metric;
84
85// Ganglia's array of host metrics
86//
87global $metrics, $hosts_up;
88
89class TarchDbase {
90
91        var $ip, $dbase, $conn;
92
93        function TarchDbase( $ip = null, $dbase = 'toga' ) {
94                $this->ip = $ip;
95                $this->dbase = $dbase;
96                $this->conn = null;
97        }
98
99        function connect() {
100
101                if( $this->ip == null and $this->dbase == 'toga' )
102                        $this->conn = pg_connect( "dbname=".$this->dbase );
103                else
104                        $this->conn = pg_connect( "host=".$this->ip." dbase=".$this->dbase );
105        }
106
107        function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) {
108
109                if( $id ) 
110                        $query = "SELECT job_id FROM jobs WHERE job_id = '$id'";
111                else {
112                        $query_args = array();
113                       
114                        if( $queue )
115                                $query_args[] = "job_queue ='$queue'";
116                        if( $user )
117                                $query_args[] = "job_owner ='$user'";
118                        if( $name )
119                                $query_args[] = "job_name = '$name'";
120                        if( $start_from_time )
121                                $query_args[] = "job_start_timestamp >= $start_from_time";
122                        if( $start_end_time )
123                                $query_args[] = "job_start_timestamp <= $start_to_time";
124                        if( $end_from_time )
125                                $query_args[] = "job_stop_timestamp >= $end_from_time";
126                        if( $end_to_time )
127                                $query_args[] = "job_stop_timestamp <= $end_to_time";
128
129                        $query = "SELECT job_id FROM jobs WHERE ";
130                        $extra_query_args = '';
131
132                        foreach( $query_args as $myquery ) {
133
134                                if( $extra_query_args == '' )
135                                        $extra_query_args = $myquery;
136                                else
137                                        $extra_query_args .= " AND ".$myquery;
138                        }
139                        $query .= $extra_query_args;
140                }
141
142                $ids = $this->queryDbase( $query );
143
144                $ret = array();
145
146                foreach( $ids as $crow)
147                        $ret[] = $crow[job_id];
148
149                return $ret;
150        }
151
152        function getNodesForJob( $jobid ) {
153
154                $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" );
155
156                $nodes = array();
157
158                foreach( $result as $result_row ) 
159
160                        $nodes[] = $this->getNodeArray( $result_row['id'] );
161
162                return $nodes;
163        }
164
165        function getJobsForNode( $nodeid ) {
166
167                $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" );
168
169                $jobs = array();
170
171                foreach( $result as $result_row )
172
173                        $jobs[] = $this->getJobArray( $result_row['id'] );
174
175                return $jobs;
176        }
177
178        function getJobArray( $id ) {
179                $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" );
180
181                return ( $this->makeArray( $result[0] ) );
182        }
183
184        function getNodeArray( $id ) {
185
186                $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" );
187
188                return ( $this->makeArray( $result[0] ) );
189        }
190
191        function makeArray( $result_row ) {
192
193                $myar = array();
194
195                foreach( $result_row as $mykey => $myval ) {
196
197                        $map_key = explode( '_', $mykey );
198
199                        $newkey = $map_key[1];
200                       
201                        $myar[$newkey] = $result_row[$mykey];
202                }
203
204                return $myar;
205        }
206
207        function queryDbase( $query ) {
208
209                $result_rows = array();
210       
211                if( !$this->conn )
212                        $this->connect();
213
214                $result = pg_query( $this->conn, $query );
215
216                while ($row = pg_fetch_assoc($result))
217                        $result_rows[] = $row;
218
219                return $result_rows;
220        }
221}
222
223class TarchRrdGraph {
224        var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics;
225
226        function TarchRrd( $clustername, $rrdbin = '/usr/bin/rrdtool', $tarchdir = '/data/toga/rrds' ) {
227                $this->rrdbin = $rrdbin;
228                $this->rrdvalues = array();
229                $this->tarchdir = $tarchdir;
230        }
231
232        function doCmd( $command ) {
233
234                printf( "command = %s\n", $command );
235                $pipe = popen( $command . ' 2>&1', 'r' );
236
237                if (!$pipe) {
238                        print "pipe failed.";
239                        return "";
240                }
241
242                $output = '';
243                while(!feof($pipe))
244                        $output .= fread($pipe, 1024);
245
246                pclose($pipe);
247
248                $output = explode( "\n", $output );
249                //print_r( $output );
250                return $output;
251        }
252
253        function dirList( $dir ) {
254
255                $dirlist = array();
256
257                if ($handle = opendir( $dir )) {
258                        while (false !== ($file = readdir($handle))) {
259                                if ($file != "." && $file != "..") {
260                                        $dirlist[] = $file;
261                                }
262                        }
263                        closedir($handle);
264                }
265
266                return $dirlist;
267        }
268
269        function getTimePeriods( $start, $end ) {
270
271                $times = array();
272                $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname );
273                $first = 0;
274                $last = 9999999999999;
275
276                foreach( $dirlist as $dir ) {
277
278                        if( $dir > $first and $dir <= $start )
279                                $first = $dir;
280                        if( $dir < $last and $dir >= $end )
281                                $last = $dir;
282                }
283
284                foreach( $dirlist as $dir ) {
285
286                        if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) )
287                                $times[] = $dir;
288                }
289
290                sort( $times );
291
292                return $times;
293        }
294
295        function graph( $descr ) {
296                //$command = $this->rrdbin . " graph - --start $start --end $end ".
297                        "--width $width --height $height $upper_limit $lower_limit ".
298                        "--title '$title' $vertical_label $extras $background ". $series;
299
300                //$graph = $this->doCmd( $command );
301
302                //return $graph;
303        }
304}
305
306class DataSource {
307
308        var $data, $ip, $port;
309
310        function DataSource( $ip = '127.0.0.1', $port = 8649 ) {
311                $this->ip = $ip;
312                $this->port = $port;
313        }
314
315        function getData() {
316
317                $errstr;
318                $errno = 0;
319                $timeout = 3;
320
321                $fp = fsockopen( $this->ip, $this->port, &$errno, &$errstr, $timeout );
322
323                if( !$fp ) {
324                        echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port );
325                        return;
326                }
327
328                while ( !feof( $fp ) ) {
329                       
330                        $data .= fread( $fp, 16384 );
331                }
332
333                fclose( $fp );
334
335                return $data;
336        }
337}
338
339class DataGatherer {
340
341        var $xmlhandler, $data, $httpvars;
342
343        function DataGatherer() {
344
345                global $DATA_SOURCE;
346               
347                $ds_fields = explode( ':', $DATA_SOURCE );
348                $ds_ip = $ds_fields[0];
349                $ds_port = $ds_fields[1];
350
351                $this->source = new DataSource( $ds_ip, $ds_port );
352
353                $this->parser = xml_parser_create();
354                $this->httpvars = $httpvars;
355                $this->xmlhandler = new TorqueXMLHandler();
356                xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
357        }
358
359        function parseXML() {
360
361                $src = &$this->source;
362                $this->data = $src->getData();
363
364                if ( !xml_parse( &$this->parser, $this->data ) )
365                        $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( &$this->parser ) ), xml_get_current_line_number( &$this->parser ) );
366        }
367
368        function printInfo() {
369                $handler = $this->xmlhandler;
370                $handler->printInfo();
371        }
372
373        function getNodes() {
374                $handler = $this->xmlhandler;
375                return $handler->getNodes();
376        }
377
378        function getCpus() {
379                $handler = $this->xmlhandler;
380                return $handler->getCpus();
381        }
382
383        function getJobs() {
384                $handler = $this->xmlhandler;
385                return $handler->getJobs();
386        }
387
388        function getHeartbeat() {
389                $handler = $this->xmlhandler;
390                return $handler->getHeartbeat();
391        }
392}
393
394class TorqueXMLHandler {
395
396        var $clusters, $heartbeat, $nodes, $jobs;
397
398        function TorqueXMLHandler() {
399                $jobs = array();
400                $clusters = array();
401                $nodes = array();
402                $heartbeat = array();
403        }
404
405        function getCpus() {
406
407                $cpus = 0;
408
409                foreach( $this->jobs as $jobid=>$jobattrs ) {
410
411                        $nodes = count( $jobattrs[nodes] );
412                        $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
413                        $mycpus = $nodes * $ppn;
414
415                        $cpus = $cpus + $mycpus;
416                }
417        }
418
419        function startElement( $parser, $name, $attrs ) {
420
421                $jobs = &$this->jobs;
422                $nodes = &$this->nodes;
423
424                if ( $attrs[TN] ) {
425
426                        // Ignore dead metrics. Detect and mask failures.
427                        if ( $attrs[TN] > $attrs[TMAX] * 4 )
428                                return;
429                }
430
431                $jobid = null;
432
433                // printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
434
435                if( $name == 'CLUSTER' ) {
436
437                        $clustername = $attrs[VAL];
438
439                        if( !isset( $clusters[$clustername] ) )
440                                $clusters[$clustername] = array();
441
442                } else if( $name == 'HOST' ) {
443
444                        $hostname = $attrs[NAME];
445                        $location = $attrs[LOCATION];
446
447                        if( !isset( $this->nodes[$hostname] ) )
448                                $this->nodes[$hostname] = new NodeImage( $hostname );
449
450                } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
451
452                        if( strstr( $attrs[NAME], 'TOGA-HEARTBEAT' ) ) {
453
454                                $this->heartbeat['time'] = $attrs[VAL];
455                                //printf( "heartbeat %s\n", $heartbeat['time'] );
456
457                        } else if( strstr( $attrs[NAME], 'TOGA-JOB' ) ) {
458
459                                sscanf( $attrs[NAME], 'TOGA-JOB-%d', $jobid );
460
461                                //printf( "jobid %s\n", $jobid );
462
463                                if( !isset( $jobs[$jobid] ) )
464                                        $jobs[$jobid] = array();
465
466                                $fields = explode( ' ', $attrs[VAL] );
467
468                                foreach( $fields as $f ) {
469                                        $togavalues = explode( '=', $f );
470
471                                        $toganame = $togavalues[0];
472                                        $togavalue = $togavalues[1];
473
474                                        //printf( "\t%s\t= %s\n", $toganame, $togavalue );
475
476                                        if( $toganame == 'nodes' ) {
477
478                                                if( $jobs[$jobid][status] == 'R' ) {
479                                               
480                                                        if( !isset( $jobs[$jobid][$toganame] ) )
481                                                                $jobs[$jobid][$toganame] = array();
482
483                                                        $mynodes = explode( ';', $togavalue );
484
485                                                        foreach( $mynodes as $node )
486
487                                                                $jobs[$jobid][$toganame][] = $node;
488
489                                                } else if( $jobs[$jobid][status] == 'Q' ) {
490
491                                                        $jobs[$jobid][$toganame] = $togavalue;
492                                                }
493                                               
494                                        } else {
495
496                                                $jobs[$jobid][$toganame] = $togavalue;
497                                        }
498                                }
499
500                                if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) {
501                       
502                                        $nr_nodes = count( $jobs[$jobid][nodes] );
503                       
504                                        foreach( $jobs[$jobid][nodes] as $node ) {
505
506                                                $host = $node.'.'.$jobs[$jobid][domain];
507                               
508                                                if( !isset( $this->nodes[$host] ) )
509                                                        $my_node = new NodeImage( $host );
510                                                else
511                                                        $my_node = $this->nodes[$host];
512
513                                                if( !$my_node->hasJob( $jobid ) )
514
515                                                        if( isset( $jobs[$jobid][ppn] ) )
516                                                                $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) );
517                                                        else
518                                                                $my_node->addJob( $jobid, 1 );
519
520                                                $this->nodes[$host] = $my_node;
521                                        }
522                                }
523                        }
524                }
525                $this->jobs = $jobs;
526        }
527
528        function stopElement( $parser, $name ) {
529        }
530
531        function printInfo() {
532
533                $jobs = &$this->jobs;
534
535                printf( "---jobs---\n" );
536
537                foreach( $jobs as $jobid => $job ) {
538
539                        printf( "job %s\n", $jobid );
540
541                        if( isset( $job[nodes] ) ) {
542
543                                foreach( $job[nodes] as $node ) {
544
545                                        $mynode = $this->nodes[$node];
546                                        $hostname = $mynode->getHostname();
547                                        $location = $mynode->getLocation();
548
549                                        printf( "\t- node %s\tlocation %s\n", $hostname, $location );
550                                        //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid );
551                                }
552                        }
553                }
554
555                printf( "---nodes---\n" );
556
557                $nodes = &$this->nodes;
558
559                foreach( $nodes as $node ) {
560
561                        $hostname = $node->getHostname();
562                        $location = $node->getLocation();
563                        $jobs = implode( ' ', $node->getJobs() );
564                        printf( "* node %s\tlocation %s\tjobs %s\n", $hostname, $location, $jobs );
565                }
566        }
567
568        function getNodes() {
569                return $this->nodes;
570        }
571
572        function getJobs() {
573                return $this->jobs;
574        }
575
576        function getHeartbeat() {
577                return $this->heartbeat['time'];
578        }
579}
580
581class NodeImage {
582
583        var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo;
584
585        function NodeImage( $hostname ) {
586
587                $this->jobs = array();
588                //$this->image = $image;
589                //$this->x = $x;
590                //$this->y = $y;
591                $this->tasks = 0;
592                $this->hostname = $hostname;
593                $this->cpus = $this->determineCpus();
594                $this->showinfo = 1;
595        }
596
597        function addJob( $jobid, $cpus ) {
598                $jobs = &$this->jobs;
599
600                $jobs[] = $jobid;
601                $this->jobs = $jobs;
602
603                $this->addTask( $cpus );
604        }
605
606        function hasJob( $jobid ) {
607
608                $jobfound = 0;
609
610                if( count( $this->jobs ) > 0 )
611                        foreach( $this->jobs as $job )
612
613                                if( $job == $jobid )
614                                        $jobfound = 1;
615
616                return $jobfound;
617        }
618
619        function addTask( $cpus ) {
620
621                $this->tasks = $this->tasks + $cpus;
622        }
623
624        function setImage( $image ) {
625
626                $this->image = $image;
627        }
628
629        function setCoords( $x, $y ) {
630
631                $this->x = $x;
632                $this->y = $y;
633        }
634
635        function colorHex( $color ) {
636       
637                $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) );
638
639                return $my_color;
640        }
641
642        function setLoad( $load ) {
643                $this->load = $load;
644        }
645
646        function setHostname( $hostname ) {
647                $this->hostname = $hostname;
648        }
649
650        function getHostname() {
651                return $this->hostname;
652        }
653
654        function getJobs() {
655                return $this->jobs;
656        }
657
658        function setShowinfo( $showinfo ) {
659                $this->showinfo = $showinfo;
660        }
661
662        function draw() {
663
664                $this->drawSmall();
665        }
666
667        function drawBig() {
668
669        }
670
671        function drawSmall() {
672
673                global $SMALL_CLUSTERIMAGE_NODEWIDTH;
674                global $JOB_NODE_MARKING;
675
676                $black_color = imageColorAllocate( $this->image, 0, 0, 0 );
677                $size = $SMALL_CLUSTERIMAGE_NODEWIDTH;
678
679                imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color );
680
681                if( $this->showinfo) {
682               
683                        $this->load = $this->determineLoad();
684
685                        if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) {
686                                printf( "aborting\n" );
687                                printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
688                                return;
689                        }
690
691
692                        // Convert Ganglias Hexadecimal load color to a Decimal one
693                        //
694                        $load = $this->determineLoad(); 
695                        $usecolor = $this->colorHex( load_color($load) );
696                        imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor );
697                        if( count( $this->jobs ) > 0 )
698                                imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), $JOB_NODE_MARKING, $black_color );
699
700                } else {
701
702                        // White
703                        $usecolor = imageColorAllocate( $this->image, 255, 255, 255 );
704                        imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor );
705                }
706
707
708        }
709
710        function determineCpus() {
711
712                global $metrics;
713
714                $cpus = $metrics[$this->hostname][cpu_num][VAL];
715                if (!$cpus) $cpus=1;
716
717                return $cpus;
718        }
719
720        function determineLoad() {
721
722                global $metrics;
723
724                $load_one = $metrics[$this->hostname][load_one][VAL];
725                $load = ((float) $load_one)/$this->cpus;
726
727                return $load;
728        }
729}
730
731class ClusterImage {
732
733        var $dataget, $image, $clustername;
734        var $filtername, $filters;
735
736        function ClusterImage( $clustername ) {
737
738                $this->dataget = new DataGatherer();
739                $this->clustername = $clustername;
740                $this->filters = array();
741        }
742
743        function setFilter( $filtername, $filtervalue ) {
744
745                //printf("filter %s = %s\n", $filtername, $filtervalue );
746                //printf( "filter set to %s = %s\n", $filtername, $filtervalue );
747                $this->filters[$filtername] = $filtervalue;
748                //print_r($this->filters);
749        }
750
751        function filterNodes( $jobs, $nodes ) {
752
753                $filtered_nodes = array();
754
755                foreach( $nodes as $node ) {
756
757                        $hostname = $node->getHostname();
758
759                        $addhost = 1;
760
761                        if( count( $this->filters ) > 0 ) {
762
763                                $mynjobs = $node->getJobs();
764
765                                if( count( $mynjobs ) > 0 ) {
766
767                                        foreach( $mynjobs as $myjob ) {
768
769                                                foreach( $this->filters as $filtername => $filtervalue ) {
770
771                                                        //printf("filter bla %s = %s\n", $filtername,$filtervalue );
772
773                                                        if( $filtername!=null && $filtername!='' ) {
774
775                                                                if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) {
776                                                                        $addhost = 0;
777                                                                        //printf("host %s has no job %s\n", $hostname, $filtervalue);
778                                                                } else if( $filtername != 'jobid' ) {
779                                                                        //printf("myjob is %s\n", $myjob );
780                                                                        if( $jobs[$myjob][$filtername] != $filtervalue ) {
781                                                                                //printf("host %s has no job with %s=%s\n", $hostname, $filtername, $filtervalue);
782                                                                                $addhost = 0;
783                                                                        }
784                                                                }
785                                                        }
786                                                }
787                                        }
788                                } else
789                                        $addhost = 0;
790                        }
791
792                        if( $addhost )
793                                $filtered_nodes[] = $hostname;
794                }
795
796                return $filtered_nodes;
797        }
798
799        function draw() {
800
801                //printf("stopt met uitvoer");
802                //return;
803
804                global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH;
805       
806                $mydatag = $this->dataget;
807                $mydatag->parseXML();
808
809                //$max_width = 250;
810                //$node_width = 11;
811
812                $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH;
813                $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH;
814
815                //printf( "cmaxw %s nmaxw %s", $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH );
816
817                $nodes = $mydatag->getNodes();
818                $nodes_hosts = array_keys( $nodes );
819
820                $nodes_nr = count( $nodes );
821
822                $nodes_size = $nodes_nr*$node_width;
823                $node_rows = 0;
824
825                if( $nodes_size > $max_width ) {
826                        $nodes_per_row = ( (int) ($max_width/$node_width) );
827                } else {
828                        $nodes_per_row = $nodes_size;
829                        $node_rows = 1;
830                }
831
832                if( $nodes_per_row < $nodes_nr ) {
833                        $node_rows = ( (int) ($nodes_nr/$nodes_per_row) );
834                        $node_rest = fmod( $nodes_nr, $nodes_per_row );
835                        //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest );
836                        if( $node_rest > 0 ) {
837                                $node_rows++;
838                                //printf( "noderows %d\n", $node_rows );
839                        }
840                }
841
842                //printf( "imagecreate: %dx%d", ($nodes_per_row*$node_width), ($node_rows*$node_width) );
843                $image = imageCreateTrueColor( ($nodes_per_row*$node_width)+1, ($node_rows*$node_width)+1 );
844                $colorwhite = imageColorAllocate( $image, 255, 255, 255 );
845                imageFill( $image, 0, 0, $colorwhite );
846
847                $jobs = $mydatag->getJobs();
848                //printf("filtername = %s\n", $filtername );
849                $filtered_nodes = $this->filterNodes( $jobs, $nodes );
850
851                //print_r($filtered_nodes);
852
853                for( $n = 0; $n < $node_rows; $n++ ) {
854                       
855                        for( $m = 0; $m < $nodes_per_row; $m++ ) {
856                       
857                                $x = ($m * $node_width);
858                                $y = ($n * $node_width);
859
860                                $cur_node = ($n * $nodes_per_row) + ($m);
861                                $host = $nodes_hosts[$cur_node];
862
863
864                                if( isset( $nodes[$host] ) ) {
865
866                                        $nodes[$host]->setCoords( $x, $y );
867                                        $nodes[$host]->setImage( $image );
868
869                                        if( !in_array( $host, $filtered_nodes ) )
870                                                $nodes[$host]->setShowinfo( 0 );
871
872                                        $nodes[$host]->draw();
873                                }
874                        }
875                }
876               
877                header( 'Content-type: image/png' );
878                imagePNG( $image );
879                imageDestroy( $image );
880        }
881}
882
883//$my_data = new DataGatherer();
884//$my_data->parseXML();
885//$my_data->printInfo();
886
887//$ic = new ClusterImage( "LISA Cluster" );
888//$ic->draw();
889?>
Note: See TracBrowser for help on using the repository browser.