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

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

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

  • Setup for search results template

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

  • Misc testing stuff for remembering filter order

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

  • Template for search

web/addons/toga/index.php:

  • Testing stuff from remembering filter order
  • Do not add filters in a search window

web/addons/toga/overview.php:

  • Extra test field for filterorder

web/addons/toga/search.php:

  • First good setup for search page

web/addons/toga/libtoga.php:

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