Changeset 111 for trunk


Ignore:
Timestamp:
05/24/05 11:26:41 (19 years ago)
Author:
bastiaans
Message:

toga/conf.php:

  • How nodes will be marked with a job is now configurable

toga/image.php:

  • Really use clustername for image

toga/libtoga.php:

Location:
trunk/web/addons/toga
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/conf.php

    r110 r111  
    1414$SMALL_CLUSTERIMAGE_NODEWIDTH = 11;
    1515
     16// How to mark nodes with a job in clusterimage
     17// allcpus when all cpu's are in use
     18// singlecpu when less than all cpus are in use
     19//
     20$JOB_NODE_MARKING_ALLCPUS = "J";
     21$JOB_NODE_MARKING_SINGLECPU = "j";
     22
    1623// XML Datasource for Toga
    1724// by default localhost's gmetad
  • trunk/web/addons/toga/image.php

    r110 r111  
    66
    77$view = $httpvars->getHttpVar( "view" );
     8$clustername = $httpvars->getClusterName();
    89
    910function drawSmallClusterImage() {
    1011
    11         $ic = new ClusterImage();
     12        $ic = new ClusterImage( $clustername );
    1213        $ic->draw();
    1314}
  • trunk/web/addons/toga/libtoga.php

    r110 r111  
    187187
    188188                $jobs = &$this->jobs;
     189                $nodes = &$this->nodes;
    189190
    190191                if ( $attrs[TN] ) {
     
    211212                        $location = $attrs[LOCATION];
    212213
    213                         $this->gotNode( $hostname, $location, null );
     214                        if( !isset( $this->nodes[$hostname] ) )
     215                                $this->nodes[$hostname] = new NodeImage( $hostname );
     216
     217                        //$this->gotNode( $hostname, $location, null );
    214218
    215219                } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
     
    244248                                                        $jobs[$jobid][$toganame] = array();
    245249
    246                                                 $nodes = explode( ';', $togavalue );
    247 
    248                                                 foreach( $nodes as $node ) {
    249 
    250                                                         $hostname = $node.'.'.$jobs[$jobid][domain];
    251                                                         $jobs[$jobid][$toganame][] = $hostname;
    252                                                         $this->gotNode( $hostname, null, $jobid );
    253                                                         //printf( "got job %s on node %s", $jobid, $hostname );
     250                                                $mynodes = explode( ';', $togavalue );
     251
     252                                                foreach( $mynodes as $node ) {
     253
     254                                                        //$hostname = $node.'.'.$jobs[$jobid][domain];
     255                                                        $jobs[$jobid][$toganame][] = $node;
     256
     257                                                        //if( !isset( $this->nodes[$hostname] ) )
     258                                                                //$mynode = new NodeImage( $hostname );
     259
     260                                                        //$the_node = $this->nodes[$hostname];
     261                                                        //$the_node->addJob( $jobid,
     262                                                        //$this->gotNode( $hostname, null, $jobid );
     263                                                        //printf( "got node %s\n", $node );
    254264                                                }
    255265
     
    258268                                                $jobs[$jobid][$toganame] = $togavalue;
    259269                                        }
     270                                }
     271
     272                                if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) {
     273                               
     274                                        foreach( $jobs[$jobid][nodes] as $node ) {
     275
     276                                                $host = $node.'.'.$jobs[$jobid][domain];
     277                               
     278                                                if( !isset( $this->nodes[$host] ) )
     279                                                        $my_node = new NodeImage( $host );
     280                                                else
     281                                                        $my_node = $this->nodes[$host];
     282
     283                                                if( !$my_node->hasJob( $jobid ) )
     284
     285                                                        if( isset( $jobs[$jobid][ppn] ) )
     286                                                                $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) );
     287                                                        else
     288                                                                $my_node->addJob( $jobid, 1 );
     289
     290                                                $this->nodes[$host] = $my_node;
     291                                        }
     292                                } else {
     293
     294                                        printf( "no domain or nodes set for %s\n", $jobid );
    260295                                }
    261296                        }
     
    332367        }
    333368
     369
    334370        function setLocation( $location ) {
    335371                $this->location = $location;
     
    361397        }
    362398
    363         function setCoords( $x, $y ) {
    364                 $myimg = $this->img;
    365                 $myimg->setCoords( $x, $y );
    366         }
     399        //function setCoords( $x, $y ) {
     400                //$myimg = $this->img;
     401                //$myimg->setCoords( $x, $y );
     402        //}
    367403
    368404        function setImage( $image ) {
     
    388424class NodeImage {
    389425
    390         var $image, $x, $y, $hostname, $jobs;
    391 
    392         function NodeImage( $image, $x, $y, $hostname, $multiproc_job ) {
     426        var $image, $x, $y, $hostname, $jobs, $tasks;
     427
     428        function NodeImage( $hostname ) {
     429
     430                $this->jobs = array();
     431                //$this->image = $image;
     432                //$this->x = $x;
     433                //$this->y = $y;
     434                $this->tasks = 0;
     435                $this->hostname = $hostname;
     436                $this->cpus = $this->determineCpus();
     437        }
     438
     439        function addJob( $jobid, $cpus ) {
     440                $jobs = &$this->jobs;
     441
     442                $jobs[] = $jobid;
     443                $this->jobs = $jobs;
     444
     445                $this->addTask( $cpus );
     446        }
     447
     448        function hasJob( $jobid ) {
     449
     450                $jobfound = 0;
     451
     452                if( count( $this->jobs ) > 0 )
     453                        foreach( $this->jobs as $job )
     454
     455                                if( $job == $jobid )
     456                                        $jobfound = 1;
     457
     458                return $jobfound;
     459        }
     460
     461        function addTask( $cpus ) {
     462
     463                $this->tasks = $this->tasks + $cpus;
     464        }
     465
     466        function setImage( $image ) {
    393467
    394468                $this->image = $image;
    395                 $this->x = $x;
    396                 $this->y = $y;
    397                 $this->hostname = $hostname;
    398                 $this->multiproc_job = $multiproc_job;
    399469        }
    400470
     
    412482        }
    413483
    414         function setImage( $image ) {
    415                 $this->image = $image;
    416         }
    417 
    418484        function setLoad( $load ) {
    419485                $this->load = $load;
     
    424490        }
    425491
    426         function drawNode( $load ) {
    427 
    428                 global $SMALL_CLUSTERIMAGE_NODEWIDTH;
    429 
    430                 if( !isset( $this->x ) or !isset( $this->y ) or !isset( $load ) ) {
     492        function draw() {
     493
     494                global $SMALL_CLUSTERIMAGE_NODEWIDTH, $JOB_NODE_MARKING_ALLCPUS, $JOB_NODE_MARKING_SINGLECPU;
     495
     496                $this->load = $this->determineLoad();
     497
     498                if( !isset( $this->x ) or !isset( $this->y ) or !isset( $this->load ) ) {
    431499                        printf( "aborting\n" );
    432500                        printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
     
    434502                }
    435503
    436                 $black_color = imageColorAllocate( &$this->image, 0, 0, 0 );
     504                $black_color = imageColorAllocate( $this->image, 0, 0, 0 );
    437505
    438506                // Convert Ganglias Hexadecimal load color to a Decimal one
     507                //
     508                $load = $this->determineLoad();
    439509                $my_loadcolor = $this->colorHex( load_color($load) );
    440510
     
    443513                imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color );
    444514                imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $my_loadcolor );
    445                 if( $this->multiproc_job == 2 )
    446                         imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), "J", $black_color );
    447                 else if( $this->multiproc_job == 1 )
    448                         imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), "j", $black_color );
    449 
    450                 // Een job markering?
    451                 //imageFilledEllipse( $this->image, ($this->x+9)/2, ($this->y+9)/2, 6, 6, $jobcolor );
    452         }
    453 
    454         function draw() {
     515
     516                $nr_jobs = count( $this->jobs );
     517
     518                $node_mark = null;
     519
     520                if( count( $this->jobs ) > 0 )
     521
     522                        if( $this->tasks < $this->cpus )
     523                                $node_mark = $JOB_NODE_MARKING_SINGLECPU;
     524
     525                        else if( $this->tasks == $this->cpus )
     526                                $node_mark = $JOB_NODE_MARKING_ALLCPUS;
     527
     528                if( $node_mark )
     529                        imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), $node_mark, $black_color );
     530        }
     531
     532        function determineCpus() {
    455533
    456534                global $metrics;
     
    458536                $cpus = $metrics[$this->hostname][cpu_num][VAL];
    459537                if (!$cpus) $cpus=1;
     538
     539                return $cpus;
     540        }
     541
     542        function determineLoad() {
     543
     544                global $metrics;
     545
    460546                $load_one = $metrics[$this->hostname][load_one][VAL];
    461                 $load = ((float) $load_one)/$cpus;
    462                 //printf( "hostname %s cpus %s load_one %s load %f\n", $this->hostname, $cpus, $load_one, $load );
    463 
    464                 $this->drawNode( $load );
     547                $load = ((float) $load_one)/$this->cpus;
     548
     549                return $load;
    465550        }
    466551}
     
    468553class ClusterImage {
    469554
    470         var $dataget, $image;
    471 
    472         function ClusterImage() {
     555        var $dataget, $image, $clustername;
     556
     557        function ClusterImage( $clustername ) {
    473558                $this->dataget = new DataGatherer();
     559                $this->clustername = $clustername;
    474560        }
    475561
     
    490576
    491577                $nodes = $mydatag->getNodes();
     578                $nodes_hosts = array_keys( $nodes );
    492579
    493580                $nodes_nr = count( $nodes );
    494                 $node_keys = array_keys( $nodes );
     581                //printf( "%d nodes\n", $nodes_nr );
    495582
    496583                $nodes_size = $nodes_nr*$node_width;
     
    527614
    528615                                $cur_node = ($n * $nodes_per_row) + ($m);
    529                                 $host = $node_keys[$cur_node];
     616                                $host = $nodes_hosts[$cur_node];
     617
     618                                if( isset( $nodes[$host] ) ) {
     619
     620                                        $nodes[$host]->setCoords( $x, $y );
     621                                        $nodes[$host]->setImage( $image );
     622                                        $nodes[$host]->draw();
     623                                }
     624                               
    530625
    531626                                //printf( "host %s curnode %s ", $host, $cur_node );
    532627
    533                                 if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {
    534                                         //printf( "image %s\n", $host );
    535                                         $nodejobs = $nodes[$host]->getJobs();
    536                                         $jobs = $mydatag->getJobs();
    537 
    538                                         $multiproc_job = 0;
    539 
    540                                         if( count( $nodejobs ) > 0 ) {
    541                                                 $multiproc_job = 1;
    542 
    543                                                 foreach( $nodejobs as $myjob ){
    544                                                         if( isset($jobs[$myjob]['ppn']) and $jobs[$myjob]['ppn'] > 1 )
    545                                                                 $multiproc_job = 2;
    546                                                                 break;
    547                                                 }
    548                                         }
     628                        //      if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {
     629                        //              //printf( "image %s\n", $host );
     630                        //              $nodejobs = $nodes[$host]->getJobs();
     631                        //              $jobs = $mydatag->getJobs();
     632
     633                        //              $multiproc_job = 0;
     634
     635                        //              if( count( $nodejobs ) > 0 ) {
     636                        //                      $multiproc_job = 1;
     637
     638                        //                      foreach( $nodejobs as $myjob ){
     639                        //                              if( isset($jobs[$myjob]['ppn']) and $jobs[$myjob]['ppn'] > 1 )
     640                        //                                      $multiproc_job = 2;
     641                        //                                      break;
     642                        //                      }
     643                        //              }
    549644
    550645                                        //printf( "jobs %s node %s", $nrjobs, $host );
    551                                         $node = new NodeImage( $image, $x, $y, $host, $multiproc_job );
     646                        //              $node = new NodeImage( $image, $x, $y, $host, $multiproc_job );
    552647                                        //$node->setHostname( $host );
    553                                         $node->draw();
     648                        //              $node->draw();
    554649                                        //$nodes[$host]->setCoords( $x, $y );
    555650                                        //$nodes[$host]->setImage( &$image );
    556651                                        //$nodes[$host]->draw();
    557652                                        //$cur_node++;
    558                                 }
     653                        //      }
    559654                        }
    560655                }
     
    570665//$my_data->printInfo();
    571666
    572 $ic = new ClusterImage();
     667$ic = new ClusterImage( "LISA Cluster" );
    573668$ic->draw();
    574669?>
Note: See TracChangeset for help on using the changeset viewer.