Changeset 519 for trunk


Ignore:
Timestamp:
03/09/08 13:42:01 (16 years ago)
Author:
bastiaans
Message:

libtoga.php:

  • massive indentation code cleanup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/job_monarch/libtoga.php

    r518 r519  
    2525
    2626
    27 class HTTPVariables {
    28 
     27class HTTPVariables
     28{
    2929        var $clustername, $metricname;
    3030        var $restvars, $httpvars;
    3131
    32         function HTTPVariables( $httpvars, $getvars ) {
    33 
    34                 $this->restvars = array();
    35 
    36                 $this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"];
    37                 $this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"];
    38 
    39                 foreach( $httpvars as $httpvar => $httpval ) {
    40                        
    41                         if( $httpval ) {
     32        function HTTPVariables( $httpvars, $getvars )
     33        {
     34                $this->restvars         = array();
     35
     36                $this->clustername      = $httpvars["c"] ? $httpvars["c"] : $getvars["c"];
     37                $this->metricname       = $httpvars["m"] ? $httpvars["m"] : $getvars["m"];
     38
     39                foreach( $httpvars as $httpvar => $httpval )
     40                {
     41                        if( $httpval )
     42                        {
    4243                                $this->restvars[$httpvar] = $httpval;
    4344                        }
    4445                }
    4546
    46                 foreach( $getvars as $getvar => $getval ) {
    47 
    48                         if( $getval ) {
     47                foreach( $getvars as $getvar => $getval )
     48                {
     49                        if( $getval )
     50                        {
    4951                                $this->restvars[$getvar] = $getval;
    5052                        }
     
    5254        }
    5355
    54         function getClusterName() {
     56        function getClusterName()
     57        {
    5558                return $this->clustername;
    5659        }
    5760
    58         function getMetricName() {
     61        function getMetricName()
     62        {
    5963                return $this->metricname;
    6064        }
    6165
    62         function getHttpVar( $var ) {
     66        function getHttpVar( $var )
     67        {
    6368                if( isset( $this->restvars[$var] ) )
     69                {
    6470                        return $this->restvars[$var];
     71                }
    6572                else
     73                {
    6674                        return null;
     75                }
    6776        }
    6877}
     
    7079$CLUSTER_CONFS  = array();
    7180
    72 // Toga's conf
     81// Monarch's conf
    7382//
    7483include_once "./conf.php";
     
    7988global $JOB_ARCHIVE_DIR;
    8089global $JOB_ARCHIVE_DBASE;
    81 //global $SORTBY_HOSTNAME;
    82 //global $SORT_ORDER;
    8390global $skan_str;
    8491global $x_first, $y_first;
    85 //global $SORT_XLABEL, $SORT_YLABEL;
    8692global $CLUSTER_CONFS;
    8793
     
    95101include_once "./ganglia.php";
    96102include_once "./get_context.php";
    97 //unset( $start );
     103
    98104$context = 'cluster';
    99105include_once "./get_ganglia.php";
     
    110116global $context, $clustername, $reports;
    111117
    112 //$clustername = $httpvars->getClusterName();
    113 
    114118global $default_metric;
    115119
     
    121125global $DATETIME_FORMAT;
    122126
    123 function makeDate( $time ) {
     127function makeDate( $time )
     128{
    124129        global $DATETIME_FORMAT;
    125130        return strftime( $DATETIME_FORMAT, $time );
     
    127132
    128133
    129 class TarchDbase {
    130 
     134class TarchDbase
     135{
    131136        var $ip, $dbase, $conn;
    132137
    133         function TarchDbase( $ip = null, $dbase = null ) {
    134 
     138        function TarchDbase( $ip = null, $dbase = null )
     139        {
    135140                global $CLUSTER_CONFS, $clustername;
    136141                global $JOB_ARCHIVE_DBASE;
     
    153158        }
    154159
    155         function connect() {
    156 
     160        function connect()
     161        {
    157162                if( $this->ip == null )
    158163                        $this->conn = pg_connect( "dbname=".$this->dbase );
     
    161166        }
    162167
    163         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 ) {
    164 
     168        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 )
     169        {
    165170                global $SEARCH_RESULT_LIMIT;
    166171
    167                 if( $id ) {
     172                if( $id )
     173                {
    168174                        $select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'";
    169175                        $this->resultcount = 1;
    170                 } else {
     176                }
     177                else
     178                {
    171179                        $query_args = array();
    172180                       
    173181                        if( $queue )
     182                        {
    174183                                $query_args[] = "job_queue ='$queue'";
     184                        }
    175185                        if( $user )
     186                        {
    176187                                $query_args[] = "job_owner ='$user'";
     188                        }
    177189                        if( $name )
     190                        {
    178191                                $query_args[] = "job_name = '$name'";
     192                        }
    179193                        if( $start_from_time )
     194                        {
    180195                                $query_args[] = "job_start_timestamp >= $start_from_time";
     196                        }
    181197                        if( $start_to_time )
     198                        {
    182199                                $query_args[] = "job_start_timestamp <= $start_to_time";
     200                        }
    183201                        if( $end_from_time )
     202                        {
    184203                                $query_args[] = "job_stop_timestamp >= $end_from_time";
     204                        }
    185205                        if( $end_to_time )
     206                        {
    186207                                $query_args[] = "job_stop_timestamp <= $end_to_time";
     208                        }
    187209
    188210                        $query = "FROM jobs WHERE job_status = 'F' AND ";
    189211                        $extra_query_args = '';
    190212
    191                         foreach( $query_args as $myquery ) {
    192 
     213                        foreach( $query_args as $myquery )
     214                        {
    193215                                if( $extra_query_args == '' )
     216                                {
    194217                                        $extra_query_args = $myquery;
     218                                }
    195219                                else
     220                                {
    196221                                        $extra_query_args .= " AND ".$myquery;
     222                                }
    197223                        }
    198224                        $query .= $extra_query_args;
     
    214240
    215241                foreach( $ids as $crow)
     242                {
    216243                        $ret[] = $crow[job_id];
     244                }
    217245
    218246                return $ret;
    219247        }
    220248
    221         function getNodesForJob( $jobid ) {
    222 
     249        function getNodesForJob( $jobid )
     250        {
    223251                $result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" );
    224252
     
    226254
    227255                foreach( $result as $result_row )
    228 
     256                {
    229257                        $nodes[] = $this->getNodeArray( $result_row[node_id] );
     258                }
    230259
    231260                return $nodes;
    232261        }
    233262
    234         function getJobsForNode( $nodeid ) {
    235 
     263        function getJobsForNode( $nodeid )
     264        {
    236265                $result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" );
    237266
     
    239268
    240269                foreach( $result as $result_row )
    241 
     270                {
    242271                        $jobs[] = $this->getJobArray( $result_row[job_id] );
    243 
     272                }
    244273                return $jobs;
    245274        }
    246275
    247         function getJobArray( $id ) {
     276        function getJobArray( $id )
     277        {
    248278                $result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" );
    249279
     
    251281        }
    252282
    253         function getNodeArray( $id ) {
    254 
     283        function getNodeArray( $id )
     284        {
    255285                $result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" );
    256286
     
    258288        }
    259289
    260         function makeArray( $result_row ) {
    261 
     290        function makeArray( $result_row )
     291        {
    262292                $myar = array();
    263293
    264                 foreach( $result_row as $mykey => $myval ) {
    265 
     294                foreach( $result_row as $mykey => $myval )
     295                {
    266296                        $map_key = explode( '_', $mykey );
    267297
     
    278308        }
    279309
    280         function queryDbase( $query ) {
    281 
     310        function queryDbase( $query )
     311        {
    282312                $result_rows = array();
    283313       
    284314                if( !$this->conn )
     315                {
    285316                        $this->connect();
    286 
    287                 //printf( "query = [%s]\n", $query );
     317                }
     318
    288319                $result = pg_query( $this->conn, $query );
    289320
    290321                while ($row = pg_fetch_assoc($result))
     322                {
    291323                        $result_rows[] = $row;
     324                }
    292325
    293326                return $result_rows;
     
    295328}
    296329
    297 class TarchRrdGraph {
     330class TarchRrdGraph
     331{
    298332        var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics;
    299333
    300         function TarchRrdGraph( $clustername, $hostname ) {
    301 
     334        function TarchRrdGraph( $clustername, $hostname )
     335        {
    302336                global $RRDTOOL;
    303337                global $JOB_ARCHIVE_DIR;
    304338
    305                 $this->rrdbin = $RRDTOOL;
    306                 $this->rrdvalues = array();
    307                 $this->tarchdir = $JOB_ARCHIVE_DIR;
    308                 $this->clustername = $clustername;
    309                 $this->hostname = $hostname;
    310         }
    311 
    312         function doCmd( $command ) {
    313 
    314                 printf( "command = %s\n", $command );
     339                $this->rrdbin           = $RRDTOOL;
     340                $this->rrdvalues        = array();
     341                $this->tarchdir         = $JOB_ARCHIVE_DIR;
     342                $this->clustername      = $clustername;
     343                $this->hostname         = $hostname;
     344        }
     345
     346        function doCmd( $command )
     347        {
    315348                $pipe = popen( $command . ' 2>&1', 'r' );
    316349
    317                 if (!$pipe) {
     350                if (!$pipe)
     351                {
    318352                        print "pipe failed.";
    319353                        return "";
     
    321355
    322356                $output = '';
     357
    323358                while(!feof($pipe))
     359                {
    324360                        $output .= fread($pipe, 1024);
     361                }
    325362
    326363                pclose($pipe);
    327364
    328365                $output = explode( "\n", $output );
    329                 //print_r( $output );
     366
    330367                return $output;
    331368        }
    332369
    333         function dirList( $dir ) {
    334 
     370        function dirList( $dir )
     371        {
    335372                $dirlist = array();
    336373
    337                 if ($handle = opendir( $dir )) {
    338                         while (false !== ($file = readdir($handle))) {
    339                                 if ($file != "." && $file != "..") {
     374                if ($handle = opendir( $dir ))
     375                {
     376                        while (false !== ($file = readdir($handle)))
     377                        {
     378                                if ($file != "." && $file != "..")
     379                                {
    340380                                        $dirlist[] = $file;
    341381                                }
     
    347387        }
    348388
    349         function getTimePeriods( $start, $end ) {
    350 
    351                 //printf("start = %s end = %s\n", $start, $end );
     389        function getTimePeriods( $start, $end )
     390        {
    352391                $times = array();
    353392                $dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname );
    354393
    355                 //print_r( $dirlist );
    356 
    357394                $first = 0;
    358395                $last = 9999999999999;
    359396
    360                 foreach( $dirlist as $dir ) {
    361 
     397                foreach( $dirlist as $dir )
     398                {
    362399                        if( $dir > $first and $dir <= $start )
     400                        {
    363401                                $first = $dir;
     402                        }
    364403                        if( $dir < $last and $dir >= $end )
     404                        {
    365405                                $last = $dir;
    366                 }
    367 
    368                 //printf( "first = %s last = %s\n", $first, $last );
    369 
    370                 foreach( $dirlist as $dir ) {
    371 
    372                         //printf( "dir %s ", $dir );
    373 
    374                         if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) {
    375                        
     406                        }
     407                }
     408
     409                foreach( $dirlist as $dir )
     410                {
     411                        if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) )
     412                        {
    376413                                $times[] = $dir;
    377                                 //printf("newtime %s ", $dir );
    378 
    379                         }
    380                 }
    381 
    382                 //print_r( $times );
     414                        }
     415                }
    383416
    384417                sort( $times );
    385418
    386                 //print_r( $times );
    387 
    388419                return $times;
    389420        }
    390421
    391         function getRrdDirs( $start, $stop ) {
    392 
    393                 //printf( "tarchdir = %s\n", $this->tarchdir );
     422        function getRrdDirs( $start, $stop )
     423        {
    394424                $timess = $this->getTimePeriods( $start, $stop );
    395                 //print_r( $timess );
    396425
    397426                $rrd_files = array();
    398427
    399                 foreach( $timess as $time ) {
    400 
     428                foreach( $timess as $time )
     429                {
    401430                        $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time;
    402431                }
     
    405434        }
    406435
    407         function getRrdFiles( $metric, $start, $stop ) {
    408 
     436        function getRrdFiles( $metric, $start, $stop )
     437        {
    409438                $times = $this->getTimePeriods( $start, $stop );
    410439
    411440                $rrd_files = array();
    412441
    413                 foreach( $times as $time ) {
    414 
     442                foreach( $times as $time )
     443                {
    415444                        $rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd';
    416445                }
     
    418447                return $rrd_files;
    419448        }
    420 
    421         function graph( $descr ) {
    422 //      monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# rrdtool graph /var/www/ganglia/test1.png --start 1118683231 --end 1118750431 --width 300 --height 400 DEF:'1'='./1118647515/load_one.rrd':'sum':AVERAGE DEF:'2'='./1118690723/load_one.rrd':'sum':AVERAGE DEF:'3'='./1118733925/load_one.rrd':'sum':AVERAGE AREA:1#555555:"load_one" AREA:2#555555 AREA:3#555555
    423 //      380x461
    424 //      monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl#
    425                 //$command = $this->rrdbin . " graph - --start $start --end $end ".
    426                         "--width $width --height $height $upper_limit $lower_limit ".
    427                         "--title '$title' $vertical_label $extras $background ". $series;
    428 
    429                 //$graph = $this->doCmd( $command );
    430 
    431                 //return $graph;
    432                 return 0;
    433         }
    434449}
    435450
    436 class DataSource {
    437 
     451class DataSource
     452{
    438453        var $data, $ip, $port;
    439454
    440         //function DataSource( $ip = '127.0.0.1', $port = 8649 ) {
    441         function DataSource() {
    442 
     455        function DataSource()
     456        {
    443457                global $DATA_SOURCE;
    444458
     
    453467        }
    454468
    455         function getData() {
    456 
     469        function getData()
     470        {
    457471                $errstr;
    458472                $errno = 0;
     
    461475                $fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout );
    462476
    463                 if( !$fp ) {
     477                if( !$fp )
     478                {
    464479                        echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port );
    465480                        return;
     
    468483                stream_set_timeout( $fp, 30 );
    469484
    470                 while ( !feof( $fp ) ) {
    471                        
     485                while ( !feof( $fp ) )
     486                {
    472487                        $data .= fread( $fp, 16384 );
    473488                }
     
    479494}
    480495
    481 class DataGatherer {
    482 
     496class DataGatherer
     497{
    483498        var $xmlhandler, $data, $httpvars;
    484499
    485         function DataGatherer( $cluster ) {
    486 
    487                 //global $DATA_SOURCE;
    488        
    489                 //printf("dg cluster = %s\n", $cluster );
    490                 //$ds_fields = explode( ':', $DATA_SOURCE );
    491                 //$ds_ip = $ds_fields[0];
    492                 //$ds_port = $ds_fields[1];
    493 
    494                 //$this->source = new DataSource( $ds_ip, $ds_port );
    495 
     500        function DataGatherer( $cluster )
     501        {
    496502                $this->cluster  = $cluster;
    497503                $this->httpvars = $httpvars;
    498504        }
    499505
    500         function parseXML( $data ) {
    501 
    502                 //$src = &$this->source;
    503                 //$this->data = $src->getData();
    504 
     506        function parseXML( $data )
     507        {
    505508                $this->parser           = xml_parser_create();
    506509                $this->xmlhandler       = new TorqueXMLHandler( $this->cluster );
    507510
    508511                xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
    509                 //if ( !xml_parse( $this->parser, $this->data ) )
     512
    510513                if ( !xml_parse( $this->parser, $data ) )
     514                {
    511515                        $error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) );
    512         }
    513 
    514         function printInfo() {
     516                }
     517        }
     518
     519        function printInfo()
     520        {
    515521                $handler = $this->xmlhandler;
    516522                $handler->printInfo();
    517523        }
    518524
    519         function getUsingFQDN() {
     525        function getUsingFQDN()
     526        {
    520527                $handler = $this->xmlhandler;
    521528                return $handler->getUsingFQDN();
    522529        }
    523530
    524         function getNodes() {
     531        function getNodes()
     532        {
    525533                $handler = $this->xmlhandler;
    526534                return $handler->getNodes();
    527535        }
    528536
    529         function getNode( $node ) {
     537        function getNode( $node )
     538        {
    530539                $handler = $this->xmlhandler;
    531540                return $handler->getNode( $node );
    532541        }
    533542
    534         function getCpus() {
     543        function getCpus()
     544        {
    535545                $handler = $this->xmlhandler;
    536546                return $handler->getCpus();
    537547        }
    538548
    539         function getJobs() {
     549        function getJobs()
     550        {
    540551                $handler = $this->xmlhandler;
    541552                return $handler->getJobs();
    542553        }
    543554
    544         function getJob( $job ) {
     555        function getJob( $job )
     556        {
    545557                $handler = $this->xmlhandler;
    546558                return $handler->getJob( $job );
    547559        }
    548560
    549         function getHeartbeat() {
     561        function getHeartbeat()
     562        {
    550563                $handler = $this->xmlhandler;
    551564                return $handler->getHeartbeat();
    552565        }
    553566
    554         function isJobmonRunning() {
     567        function isJobmonRunning()
     568        {
    555569                $handler = $this->xmlhandler;
    556570                return $handler->isJobmonRunning();
     
    558572}
    559573
    560 class TorqueXMLHandler {
    561 
     574class TorqueXMLHandler
     575{
    562576        var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster;
    563577
    564         function TorqueXMLHandler( $clustername ) {
     578        function TorqueXMLHandler( $clustername )
     579        {
    565580                $jobs                   = array();
    566581                $clusters               = array();
     
    573588        }
    574589
    575         function getUsingFQDN() {
    576 
     590        function getUsingFQDN()
     591        {
    577592                return $this->fqdn;
    578        
    579        
    580         }
    581 
    582         function getCpus() {
    583 
     593        }
     594
     595        function getCpus()
     596        {
    584597                $cpus = 0;
    585598
    586                 if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) {
    587 
    588                         foreach( $this->jobs as $jobid=>$jobattrs ) {
    589 
    590                                 $nodes = count( $jobattrs[nodes] );
    591                                 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
    592                                 $mycpus = $nodes * $ppn;
    593 
    594                                 $cpus = $cpus + $mycpus;
    595                         }
    596                 }
    597         }
    598 
    599         function isJobmonRunning() {
    600 
     599                if( isset( $this->jobs ) && count( $this->jobs ) > 0 )
     600                {
     601                        foreach( $this->jobs as $jobid=>$jobattrs )
     602                        {
     603                                $nodes  = count( $jobattrs[nodes] );
     604                                $ppn    = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
     605                                $mycpus = $nodes * $ppn;
     606
     607                                $cpus   = $cpus + $mycpus;
     608                        }
     609                }
     610        }
     611
     612        function isJobmonRunning()
     613        {
    601614                if (isset( $this->heartbeat['time'] ))
     615                {
    602616                        return 1;
     617                }
    603618                else
     619                {
    604620                        return 0;
     621                }
    605622        }
    606623
     
    614631
    615632                //$tdomain = explode( '.', $thostname );
    616                 // TODO: domain van hostname afhalen: parameter weghalen
     633                //
     634                // TODO?: extract domain from hostname or something?
    617635
    618636                if( $tdomain )
     
    624642                        foreach( $nodes as $hostname => $nimage )
    625643                        {
    626        
    627644                                if( substr( $hostname, $domain_len ) != $tdomain )
    628645                                {
     
    651668        }
    652669
    653         function startElement( $parser, $name, $attrs ) {
    654 
     670        function startElement( $parser, $name, $attrs )
     671        {
    655672                $jobs = $this->jobs;
    656673                $nodes = $this->nodes;
    657674
    658                 if ( $attrs[TN] ) {
    659 
     675                if ( $attrs[TN] )
     676                {
    660677                        // Ignore dead metrics. Detect and mask failures.
    661678                        if ( $attrs[TN] > $attrs[TMAX] * 4 )
     679                        {
    662680                                return;
     681                        }
    663682                }
    664683
    665684                $jobid = null;
    666685
    667                 //printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
    668 
    669                 //printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster );
    670 
    671                 if( $name == 'CLUSTER' ) {
    672 
     686                if( $name == 'CLUSTER' )
     687                {
    673688                        $this->proc_cluster = $attrs[NAME];
    674                         //printf( "Found cluster %s\n", $attrs[NAME] );
    675                         //print_r( $attrs );
    676 
    677                         //if( !isset( $clusters[$clustername] ) )
    678                         //      $clusters[$clustername] = array();
    679 
    680                 } else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) {
    681 
     689                }
     690                else if( $name == 'HOST' and $this->proc_cluster == $this->clustername)
     691                {
    682692                        $hostname = $attrs[NAME];
    683693
    684 
    685694                        $location = $attrs[LOCATION];
    686                         //printf( "Found node %s\n", $hostname );
    687695
    688696                        if( !isset( $nodes[$hostname] ) )
     697                        {
    689698                                $nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname );
    690 
    691                 } else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) {
    692 
     699                        }
     700                }
     701                else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername )
     702                {
    693703                        if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) )
    694704                        {
     
    730740                                        }
    731741                                }
    732 
    733                         } else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) {
    734 
     742                        }
     743                        else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) )
     744                        {
    735745                                $fields         = explode( ' ', $attrs[VAL] );
    736746
     
    766776                                        }
    767777                                }
    768 
    769                         } else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) {
    770 
     778                        }
     779                        else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) )
     780                        {
    771781                                sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr );
    772782
    773783                                if( !isset( $jobs[$jobid] ) )
     784                                {
    774785                                        $jobs[$jobid] = array();
     786                                }
    775787
    776788                                $fields = explode( ' ', $attrs[VAL] );
    777789
    778                                 foreach( $fields as $f ) {
     790                                foreach( $fields as $f )
     791                                {
    779792                                        $togavalues = explode( '=', $f );
    780793
     
    782795                                        $togavalue = $togavalues[1];
    783796
    784                                         if( $toganame == 'nodes' ) {
    785 
    786                                                 if( $jobs[$jobid][status] == 'R' ) {
    787                                                
     797                                        if( $toganame == 'nodes' )
     798                                        {
     799                                                if( $jobs[$jobid][status] == 'R' )
     800                                                {
    788801                                                        if( !isset( $jobs[$jobid][$toganame] ) )
     802                                                        {
    789803                                                                $jobs[$jobid][$toganame] = array();
     804                                                        }
    790805
    791806                                                        $mynodes = explode( ';', $togavalue );
    792807
    793                                                         //print_r($mynodes);
    794 
    795                                                         foreach( $mynodes as $node ) {
    796 
    797                                                                 if( !in_array( $node, $jobs[$jobid][$toganame] ) ) {
     808                                                        foreach( $mynodes as $node )
     809                                                        {
     810                                                                if( !in_array( $node, $jobs[$jobid][$toganame] ) )
     811                                                                {
    798812                                                                        $jobs[$jobid][$toganame][] = $node;
    799813                                                                }
    800814                                                        }
    801815
    802                                                 } else if( $jobs[$jobid][status] == 'Q' ) {
    803 
     816                                                }
     817                                                else if( $jobs[$jobid][status] == 'Q' )
     818                                                {
    804819                                                        $jobs[$jobid][$toganame] = $togavalue;
    805820                                                }
    806                                                
    807                                         } else {
    808 
     821                                        }
     822                                        else
     823                                        {
    809824                                                $jobs[$jobid][$toganame] = $togavalue;
    810825                                        }
    811826                                }
    812827
    813                                 if( isset( $jobs[$jobid][nodes] ) ) {
    814                        
     828                                if( isset( $jobs[$jobid][nodes] ) )
     829                                {
    815830                                        $nr_nodes = count( $jobs[$jobid][nodes] );
    816831               
     
    860875
    861876                                                        if( !isset( $nodes[$host] ) )
     877                                                        {
    862878                                                                $my_node = new NodeImage( $this->proc_cluster, $host );
     879                                                        }
    863880                                                        else
     881                                                        {
    864882                                                                $my_node = $nodes[$host];
     883                                                        }
    865884
    866885                                                        if( !$my_node->hasJob( $jobid ) )
    867 
     886                                                        {
    868887                                                                if( isset( $jobs[$jobid][ppn] ) )
     888                                                                {
    869889                                                                        $my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) );
     890                                                                }
    870891                                                                else
     892                                                                {
    871893                                                                        $my_node->addJob( $jobid, 1 );
     894                                                                }
     895                                                        }
    872896
    873897                                                        $nodes[$host] = $my_node;
     
    877901                        }
    878902                }
    879                 $this->jobs = $jobs;
    880                 //print_r( $nodes );
    881                 $this->nodes = $nodes;
    882                 //print_r( $this->nodes );
    883         }
    884 
    885         function stopElement( $parser, $name ) {
    886 
     903                $this->jobs     = $jobs;
     904                $this->nodes    = $nodes;
     905        }
     906
     907        function stopElement( $parser, $name )
     908        {
    887909                $nodes  = $this->nodes;
    888910
     
    893915                                foreach( $this->down_nodes as $reported => $dnodes )
    894916                                {
    895 
    896917                                        if( $reported == $this->heartbeat['time'] )
    897918                                        {
     
    946967        }
    947968
    948         function printInfo() {
    949 
     969        function printInfo()
     970        {
    950971                $jobs = &$this->jobs;
    951972
    952973                printf( "---jobs---\n" );
    953974
    954                 foreach( $jobs as $jobid => $job ) {
    955 
     975                foreach( $jobs as $jobid => $job )
     976                {
    956977                        printf( "job %s\n", $jobid );
    957978
    958                         if( isset( $job[nodes] ) ) {
    959 
    960                                 foreach( $job[nodes] as $node ) {
    961 
     979                        if( isset( $job[nodes] ) )
     980                        {
     981                                foreach( $job[nodes] as $node )
     982                                {
    962983                                        $mynode = $this->nodes[$node];
    963984                                        $hostname = $mynode->getHostname();
     
    965986
    966987                                        printf( "\t- node %s\tlocation %s\n", $hostname, $location );
    967                                         //$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid );
    968988                                }
    969989                        }
     
    974994                $nodes = &$this->nodes;
    975995
    976                 foreach( $nodes as $node ) {
    977 
     996                foreach( $nodes as $node )
     997                {
    978998                        $hostname = $node->getHostname();
    979999                        $location = $node->getLocation();
     
    9831003        }
    9841004
    985         function getNodes() {
    986                 //print_r( $this->nodes );
     1005        function getNodes()
     1006        {
    9871007                return $this->nodes;
    9881008        }
    9891009
    990         function getNode( $node ) {
    991 
     1010        function getNode( $node )
     1011        {
    9921012                $nodes = &$this->nodes;
     1013
    9931014                if( isset( $nodes[$node] ) )
     1015                {
    9941016                        return $nodes[$node];
     1017                }
    9951018                else
     1019                {
    9961020                        return NULL;
    997         }
    998 
    999         function getJobs() {
     1021                }
     1022        }
     1023
     1024        function getJobs()
     1025        {
    10001026                return $this->jobs;
    10011027        }
    10021028
    1003         function getJob( $job ) {
    1004 
     1029        function getJob( $job )
     1030        {
    10051031                $jobs = &$this->jobs;
     1032
    10061033                if( isset( $jobs[$job] ) )
     1034                {
    10071035                        return $jobs[$job];
     1036                }
    10081037                else
     1038                {
    10091039                        return NULL;
    1010         }
    1011 
    1012         function getHeartbeat() {
     1040                }
     1041        }
     1042
     1043        function getHeartbeat()
     1044        {
    10131045                return $this->heartbeat['time'];
    10141046        }
    10151047}
    10161048
    1017 class NodeImage {
    1018 
     1049class NodeImage
     1050{
    10191051        var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo;
    10201052
    1021         function NodeImage( $cluster, $hostname ) {
    1022 
     1053        function NodeImage( $cluster, $hostname )
     1054        {
    10231055                global $SMALL_CLUSTERIMAGE_NODEWIDTH;
    10241056
    1025                 $this->jobs = array();
    1026                 //$this->image = $image;
    1027                 //$this->x = $x;
    1028                 //$this->y = $y;
    1029                 $this->tasks = 0;
    1030                 $this->hostname = $hostname;
    1031                 $this->cpus = $this->determineCpus();
    1032                 $this->clustername = $cluster;
    1033                 $this->showinfo = 1;
    1034                 $this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH;
    1035                 $this->down = 0;
    1036                 $this->offline = 0;
    1037         }
    1038 
    1039         function addJob( $jobid, $cpus ) {
    1040                 $jobs = &$this->jobs;
    1041 
    1042                 $jobs[] = $jobid;
    1043                 $this->jobs = $jobs;
     1057                $this->jobs             = array();
     1058                $this->tasks            = 0;
     1059                $this->hostname         = $hostname;
     1060                $this->cpus             = $this->determineCpus();
     1061                $this->clustername      = $cluster;
     1062                $this->showinfo         = 1;
     1063                $this->size             = $SMALL_CLUSTERIMAGE_NODEWIDTH;
     1064                $this->down             = 0;
     1065                $this->offline          = 0;
     1066        }
     1067
     1068        function addJob( $jobid, $cpus )
     1069        {
     1070                $jobs           = &$this->jobs;
     1071                $jobs[]         = $jobid;
     1072                $this->jobs     = $jobs;
    10441073
    10451074                $this->addTask( $cpus );
    10461075        }
    10471076
    1048         function hasJob( $jobid ) {
    1049 
     1077        function hasJob( $jobid )
     1078        {
    10501079                $jobfound = 0;
    10511080
    10521081                if( count( $this->jobs ) > 0 )
     1082                {
    10531083                        foreach( $this->jobs as $job )
    1054 
     1084                        {
    10551085                                if( $job == $jobid )
     1086                                {
    10561087                                        $jobfound = 1;
     1088                                }
     1089                        }
     1090                }
    10571091
    10581092                return $jobfound;
    10591093        }
    10601094
    1061         function addTask( $cpus ) {
    1062 
     1095        function addTask( $cpus )
     1096        {
    10631097                $this->tasks = $this->tasks + $cpus;
    10641098        }
    10651099
    1066         function setDown( $down ) {
    1067 
     1100        function setDown( $down )
     1101        {
    10681102                $this->down = $down;
    10691103        }
    10701104
    1071         function isDown() {
    1072 
     1105        function isDown()
     1106        {
    10731107                return $this->down;
    10741108        }
    1075         function setOffline( $offline ) {
    1076 
     1109        function setOffline( $offline )
     1110        {
    10771111                $this->offline = $offline;
    10781112        }
    10791113
    1080         function isOffline() {
    1081 
     1114        function isOffline()
     1115        {
    10821116                return $this->offline;
    10831117        }
    10841118
    1085         function setImage( $image ) {
    1086 
     1119        function setImage( $image )
     1120        {
    10871121                $this->image = $image;
    10881122        }
    10891123
    1090         function setCoords( $x, $y ) {
    1091 
     1124        function setCoords( $x, $y )
     1125        {
    10921126                $this->x = $x;
    10931127                $this->y = $y;
    10941128        }
    10951129
    1096         function getImagemapArea() {
    1097 
     1130        function getImagemapArea()
     1131        {
    10981132                $area_topleft           = $this->x . "," . $this->y;
    10991133                $area_bottomright       = ($this->x + $this->size) . "," . ($this->y + $this->size);
     
    11231157        }
    11241158
    1125         function colorHex( $color ) {
    1126        
     1159        function colorHex( $color )
     1160        {
    11271161                $my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) );
    11281162
     
    11301164        }
    11311165
    1132         function setLoad( $load ) {
     1166        function setLoad( $load )
     1167        {
    11331168                $this->load = $load;
    11341169        }
    11351170
    1136         function setHostname( $hostname ) {
     1171        function setHostname( $hostname )
     1172        {
    11371173                $this->hostname = $hostname;
    11381174        }
    11391175
    1140         function getHostname() {
     1176        function getHostname()
     1177        {
    11411178                return $this->hostname;
    11421179        }
    11431180
    1144         function getJobs() {
     1181        function getJobs()
     1182        {
    11451183                return $this->jobs;
    11461184        }
    11471185
    1148         function setShowinfo( $showinfo ) {
     1186        function setShowinfo( $showinfo )
     1187        {
    11491188                $this->showinfo = $showinfo;
    11501189        }
    11511190
    1152         function drawSmall() {
    1153 
     1191        function drawSmall()
     1192        {
    11541193                global $SMALL_CLUSTERIMAGE_NODEWIDTH;
    11551194
     
    11591198        }
    11601199
    1161         function drawBig() {
    1162 
     1200        function drawBig()
     1201        {
    11631202                global $BIG_CLUSTERIMAGE_NODEWIDTH;
    11641203
     
    11681207        }
    11691208
    1170         function draw() {
    1171 
     1209        function draw()
     1210        {
    11721211                global $JOB_NODE_MARKING, $NODE_DOWN_MARKING, $NODE_OFFLINE_MARKING;
    11731212
     
    11771216                imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color );
    11781217
    1179                 if( $this->showinfo) {
    1180                
     1218                if( $this->showinfo)
     1219                {
    11811220                        $this->load = $this->determineLoad();
    11821221
    1183                         if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) {
     1222                        if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) )
     1223                        {
    11841224                                printf( "aborting\n" );
    11851225                                printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
    11861226                                return;
    11871227                        }
    1188 
    11891228
    11901229                        // Convert Ganglias Hexadecimal load color to a Decimal one
     
    12051244                                imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color );
    12061245                        }
    1207 
    1208                 } else {
    1209 
     1246                }
     1247                else
     1248                {
    12101249                        // White
    12111250                        $usecolor = imageColorAllocate( $this->image, 255, 255, 255 );
    12121251                        imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor );
    12131252                }
    1214 
    1215 
    1216         }
    1217 
    1218         function determineCpus() {
    1219 
     1253        }
     1254
     1255        function determineCpus()
     1256        {
    12201257                global $metrics;
    12211258
    12221259                $cpus = $metrics[$this->hostname][cpu_num][VAL];
    1223                 if (!$cpus) $cpus=1;
     1260
     1261                if (!$cpus)
     1262                {
     1263                        $cpus=1;
     1264                }
    12241265
    12251266                return $cpus;
    12261267        }
    12271268
    1228         function determineLoad() {
    1229 
     1269        function determineLoad()
     1270        {
    12301271                global $metrics;
    12311272
    1232                 $load_one = $metrics[$this->hostname][load_one][VAL];
    1233                 $load = ((float) $load_one)/$this->cpus;
     1273                $load_one       = $metrics[$this->hostname][load_one][VAL];
     1274                $load           = ((float) $load_one)/$this->cpus;
    12341275
    12351276                return $load;
     
    12371278}
    12381279
    1239 class ClusterImage {
    1240 
     1280class ClusterImage
     1281{
    12411282        var $dataget, $image, $clustername;
    12421283        var $filtername, $filters;
    12431284
    1244         //function ClusterImage( $clustername ) {
    1245         function ClusterImage( $data, $clustername ) {
    1246 
    1247                 //$this->dataget                = $dataget;
     1285        function ClusterImage( $data, $clustername )
     1286        {
    12481287                $this->dataget          = new DataGatherer( $clustername );
    12491288                $this->data             = $data;
     
    12561295        }
    12571296
    1258         function getWidth() {
     1297        function getWidth()
     1298        {
    12591299                return $this->width;
    12601300        }
    1261         function getHeight() {
     1301        function getHeight()
     1302        {
    12621303                return $this->height;
    12631304        }
    1264 
    1265         function setSmall() {
     1305        function setSmall()
     1306        {
    12661307                $this->size     = 's';
    12671308        }
    1268 
    1269         function setBig() {
     1309        function setBig()
     1310        {
    12701311                $this->size     = 'b';
    12711312        }
    1272 
    1273         function setNoimage() {
     1313        function setNoimage()
     1314        {
    12741315                $this->output   = 0;
    12751316        }
    1276 
    1277         function isSmall() {
     1317        function isSmall()
     1318        {
    12781319                return ($this->size == 's');
    12791320        }
    1280 
    1281         function isBig() {
     1321        function isBig()
     1322        {
    12821323                return ($this->size == 'b');
    12831324        }
    1284 
    1285         function setFilter( $filtername, $filtervalue ) {
    1286 
     1325        function setFilter( $filtername, $filtervalue )
     1326        {
    12871327                $this->filters[$filtername] = $filtervalue;
    12881328        }
    12891329
    1290         function filterNodes( $jobs, $nodes ) {
    1291 
     1330        function filterNodes( $jobs, $nodes )
     1331        {
    12921332                $filtered_nodes = array();
    12931333
    1294                 foreach( $nodes as $node ) {
    1295 
     1334                foreach( $nodes as $node )
     1335                {
    12961336                        $hostname = $node->getHostname();
    12971337
    12981338                        $addhost = 1;
    12991339
    1300                         if( count( $this->filters ) > 0 ) {
    1301 
     1340                        if( count( $this->filters ) > 0 )
     1341                        {
    13021342                                $mynjobs = $node->getJobs();
    13031343
    1304                                 if( count( $mynjobs ) > 0 ) {
    1305 
    1306                                         foreach( $mynjobs as $myjob ) {
    1307 
    1308                                                 foreach( $this->filters as $filtername => $filtervalue ) {
    1309 
    1310                                                         if( $filtername!=null && $filtername!='' ) {
    1311 
    1312                                                                 if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) {
     1344                                if( count( $mynjobs ) > 0 )
     1345                                {
     1346                                        foreach( $mynjobs as $myjob )
     1347                                        {
     1348                                                foreach( $this->filters as $filtername => $filtervalue )
     1349                                                {
     1350                                                        if( $filtername!=null && $filtername!='' )
     1351                                                        {
     1352                                                                if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) )
     1353                                                                {
    13131354                                                                        $addhost = 0;
    1314                                                                 } else if( $filtername != 'jobid' ) {
    1315                                                                         if( $jobs[$myjob][$filtername] != $filtervalue ) {
     1355                                                                }
     1356                                                                else if( $filtername != 'jobid' )
     1357                                                                {
     1358                                                                        if( $jobs[$myjob][$filtername] != $filtervalue )
     1359                                                                        {
    13161360                                                                                $addhost = 0;
    13171361                                                                        }
     
    13201364                                                }
    13211365                                        }
    1322                                 } else
     1366                                }
     1367                                else
     1368                                {
    13231369                                        $addhost = 0;
     1370                                }
    13241371                        }
    13251372
    13261373                        if( $addhost )
     1374                        {
    13271375                                $filtered_nodes[] = $hostname;
     1376                        }
    13281377                }
    13291378
     
    13311380        }
    13321381
    1333         function draw() {
    1334 
     1382        function draw()
     1383        {
    13351384                global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH;
    13361385                global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH;
     
    13481397                }
    13491398
    1350                 //global $SORTBY_HOSTNAME, $SORT_ORDER;
    1351                 //global $SORT_XLABEL, $SORT_YLABEL;
    1352        
    1353                 //printf( "SORTBY_HOSTNAME %s SORT_YLABEL %s\n", $SORTBY_HOSTNAME, $SORT_YLABEL );
    1354 
    13551399                $mydatag = $this->dataget;
    13561400                $mydatag->parseXML( $this->data );
    13571401
    1358                 if( $this->isSmall() ) {
    1359                         $max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH;
    1360                         $node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH;
    1361                 } else if( $this->isBig() ) {
    1362                         $max_width = $BIG_CLUSTERIMAGE_MAXWIDTH;
    1363                         $node_width = $BIG_CLUSTERIMAGE_NODEWIDTH;
    1364                 }
    1365 
    1366                 $nodes = $mydatag->getNodes();
    1367                 $nodes_hosts = array_keys( $nodes );
    1368 
    1369                 $nodes_nr = count( $nodes );
    1370 
    1371                 $nodes_size = $nodes_nr*$node_width;
    1372                 $node_rows = 0;
    1373 
    1374                 if( $nodes_size > $max_width ) {
     1402                if( $this->isSmall() )
     1403                {
     1404                        $max_width      = $SMALL_CLUSTERIMAGE_MAXWIDTH;
     1405                        $node_width     = $SMALL_CLUSTERIMAGE_NODEWIDTH;
     1406                }
     1407                else if( $this->isBig() )
     1408                {
     1409                        $max_width      = $BIG_CLUSTERIMAGE_MAXWIDTH;
     1410                        $node_width     = $BIG_CLUSTERIMAGE_NODEWIDTH;
     1411                }
     1412
     1413                $nodes          = $mydatag->getNodes();
     1414                $nodes_hosts    = array_keys( $nodes );
     1415
     1416                $nodes_nr       = count( $nodes );
     1417
     1418                $nodes_size     = $nodes_nr*$node_width;
     1419                $node_rows      = 0;
     1420
     1421                if( $nodes_size > $max_width )
     1422                {
    13751423                        $nodes_per_row = ( (int) ($max_width/$node_width) );
    1376                 } else {
     1424                }
     1425                else
     1426                {
    13771427                        $nodes_per_row = $nodes_size;
    13781428                        $node_rows = 1;
    13791429                }
    13801430
    1381                 if( $nodes_per_row < $nodes_nr ) {
     1431                if( $nodes_per_row < $nodes_nr )
     1432                {
    13821433                        $node_rows = ( (int) ($nodes_nr/$nodes_per_row) );
    13831434                        $node_rest = fmod( $nodes_nr, $nodes_per_row );
    1384                         //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest );
    1385                         if( $node_rest > 0 ) {
     1435
     1436                        if( $node_rest > 0 )
     1437                        {
    13861438                                $node_rows++;
    1387                                 //printf( "noderows %d\n", $node_rows );
    13881439                        }
    13891440                }
     
    13991450                $this->height   = ($y_offset + (($node_rows*$node_width)+1) );
    14001451
    1401                 //$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) );
    1402                 //$colorwhite = imageColorAllocate( $image, 255, 255, 255 );
    1403                 //imageFill( $image, 0, 0, $colorwhite );
    1404 
    1405                 //if( $this->isSmall() ) {
    1406 
    1407                 //      $colorblue      = imageColorAllocate( $image, 0, 0, 255 );
    1408 
    1409                 //      imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue );
    1410                 //}
    1411 
    14121452                $jobs = $mydatag->getJobs();
    1413                 //printf("filtername = %s\n", $filtername );
    14141453                $filtered_nodes = $this->filterNodes( $jobs, $nodes );
    1415 
    1416                 //print_r($filtered_nodes);
    14171454
    14181455                if( $SORTBY_HOSTNAME != "" )
     
    16221659
    16231660                        }
    1624                         //$x_offset     = ($fontwidth * 3) + (5 * $fontspaceing);
    1625 
    1626                         //printf( "xmin %s xmax %s\n", $x_min, $x_max );
    1627                         //printf( "ymin %s ymax %s\n", $y_min, $y_max );
    1628 
    1629                         // werkt
    1630                         //print_r( $nodes );
    16311661
    16321662                        $image_width    = $x_offset + ($node_width * ($x_max-$x_min+2));
     
    16351665                        {
    16361666                                $image_width    = $max_width;
    1637                         } else if( $this->isBig() )
     1667                        }
     1668                        else if( $this->isBig() )
    16381669                        {
    16391670                                $image_width    = ($image_width < $max_width) ? $image_width : $max_width;
    16401671                        }
    1641                         //else if( $this->isSmall() )
    1642                         //{
    1643                         //      $image_width    = $this->width;
    1644                         //}
    16451672                        $image_height   = $y_offset + ($node_width * ($y_max-$y_min+2));
    16461673
     
    16531680                        imageFill( $image, 0, 0, $colorwhite );
    16541681
    1655                         if( $this->isSmall() ) {
    1656 
     1682                        if( $this->isSmall() )
     1683                        {
    16571684                                // Draw a fancy little header text to explain what it is
    16581685                                //
     
    17791806                                                $nodes[$cur_node]->setImage( $image );
    17801807
    1781                                                 //print_r( $nodes[$cur_node] );
    1782 
    17831808                                                if( $this->isSmall() )
     1809                                                {
    17841810                                                        $nodes[$cur_node]->drawSmall();
     1811                                                }
    17851812                                                else if( $this->isBig() )
     1813                                                {
    17861814                                                        $nodes[$cur_node]->drawBig();
     1815                                                }
    17871816
    17881817                                                $cur_node++;
     
    17941823                else
    17951824                {
    1796                         if( $this->isSmall() ) {
     1825                        if( $this->isSmall() )
     1826                        {
    17971827                                $image          = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) );
    1798                         } else if( $this->isBig() ) {
     1828                        }
     1829                        else if( $this->isBig() )
     1830                        {
    17991831                                $image_width    = ($node_width * $nodes_nr) + 2;
    18001832                                $image_width    = ($image_width < $max_width) ? $image_width : $max_width;
     
    18051837                        imageFill( $image, 0, 0, $colorwhite );
    18061838
    1807                         if( $this->isSmall() ) {
    1808 
     1839                        if( $this->isSmall() )
     1840                        {
    18091841                                $colorblue      = imageColorAllocate( $image, 0, 0, 255 );
    18101842
     
    18121844                        }
    18131845
    1814                         for( $n = 0; $n < $node_rows; $n++ ) {
    1815                        
    1816                                 for( $m = 0; $m < $nodes_per_row; $m++ ) {
    1817                        
     1846                        for( $n = 0; $n < $node_rows; $n++ )
     1847                        {
     1848                                for( $m = 0; $m < $nodes_per_row; $m++ )
     1849                                {
    18181850                                        $x = ($m * $node_width);
    18191851                                        $y = $y_offset + ($n * $node_width);
     
    18221854                                        $host = $nodes_hosts[$cur_node];
    18231855
    1824                                         if( isset( $nodes[$host] ) ) {
    1825 
     1856                                        if( isset( $nodes[$host] ) )
     1857                                        {
    18261858                                                $nodes[$host]->setCoords( $x, $y );
    18271859                                                $nodes[$host]->setImage( $image );
     
    18331865
    18341866                                                if( $this->isSmall() )
     1867                                                {
    18351868                                                        $nodes[$host]->drawSmall();
     1869                                                }
    18361870                                                else if( $this->isBig() )
     1871                                                {
    18371872                                                        $nodes[$host]->drawBig();
     1873                                                }
    18381874                                        }
    18391875                                }
     
    18431879                $this->nodes    = &$nodes;
    18441880
    1845                 if ($this->output) {
     1881                if ($this->output)
     1882                {
    18461883                        header( 'Content-type: image/png' );
    18471884                        imagePNG( $image );
     
    18501887        }
    18511888
    1852         function getImagemapArea() {
    1853 
     1889        function getImagemapArea()
     1890        {
    18541891                $clusterimage_map       = "";
    18551892
    1856                 foreach( $this->nodes as $hostname => $node ) {
    1857 
     1893                foreach( $this->nodes as $hostname => $node )
     1894                {
    18581895                        $node_map               = $node->getImagemapArea();
    18591896                        $clusterimage_map       .= $node_map;
     
    18641901}
    18651902
    1866 class EmptyImage {
    1867 
    1868         function draw() {
     1903class EmptyImage
     1904{
     1905        function draw()
     1906        {
    18691907                $image          = imageCreateTrueColor( 1, 1 );
    18701908                $colorwhite     = imageColorAllocate( $image, 255, 255, 255 );
     
    18771915}
    18781916
    1879 class HostImage {
    1880 
     1917class HostImage
     1918{
    18811919        var $data_gather, $cluster, $host, $node, $image;
    18821920        var $headerstrlen;
    18831921
    1884         function HostImage( $data_gather, $cluster, $host ) {
    1885 
     1922        function HostImage( $data_gather, $cluster, $host )
     1923        {
    18861924                $this->data_gather      = $data_gather;
    18871925                $this->cluster          = $cluster;
     
    19011939        }
    19021940
    1903         function drawJobs() {
    1904 
     1941        function drawJobs()
     1942        {
    19051943                $dg                     = &$this->data_gather;
    19061944                $colorblack             = imageColorAllocate( $this->image, 0, 0, 0 );
    19071945
    1908                 for( $n = 0; $n < count( $this->njobs ); $n++ ) {
    1909 
     1946                for( $n = 0; $n < count( $this->njobs ); $n++ )
     1947                {
    19101948                        $jobid                  = $this->njobs[$n];
    19111949                        $jobinfo                = $dg->getJob( $jobid );
     
    19141952                        imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack );
    19151953
    1916                         foreach( $this->headerstrlen as $headername => $headerlen ) {
    1917 
    1918                                 if( $headername == 'nodes' ) {
     1954                        foreach( $this->headerstrlen as $headername => $headerlen )
     1955                        {
     1956                                if( $headername == 'nodes' )
     1957                                {
    19191958                                        $attrval        = strval( count( $jobinfo[nodes] ) );
    1920                                 } else if( $headername == 'cpus' ) {
    1921 
     1959                                }
     1960                                else if( $headername == 'cpus' )
     1961                                {
    19221962                                        if( !isset( $jobinfo[ppn] ) )
     1963                                        {
    19231964                                                $jobinfo[ppn] = 1;
     1965                                        }
    19241966
    19251967                                        $attrval        = strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) );
    1926 
    1927                                 } else if( $headername == 'runningtime' ) {
     1968                                }
     1969                                else if( $headername == 'runningtime' )
     1970                                {
    19281971                                        $attrval        = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
    1929                                 } else {
     1972                                }
     1973                                else
     1974                                {
    19301975                                        $attrval        = strval( $jobinfo[$headername] );
    19311976                                }
     
    19341979               
    19351980                                $xoffset        = $xoffset + ($this->fontwidth * ( $headerlen + 1 ) );
    1936 
    19371981                        }
    19381982                       
     
    19411985        }
    19421986
    1943         function drawHeader() {
    1944 
     1987        function drawHeader()
     1988        {
    19451989                $dg                     = &$this->data_gather;
    19461990
    1947                 for( $n = 0; $n < count( $this->njobs ); $n++ ) {
    1948 
     1991                for( $n = 0; $n < count( $this->njobs ); $n++ )
     1992                {
    19491993                        $jobid                  = $this->njobs[$n];
    19501994                        $jobinfo                = $dg->getJob( $jobid );
    19511995
    19521996                        if( !isset( $this->headerstrlen[id] ) )
     1997                        {
    19531998                                $this->headerstrlen[id] = strlen( strval( $jobid ) );
    1954                         else
    1955                                 if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] )
    1956                                         $this->headerstrlen[id] = strlen( strval( $jobid ) );
     1999                        }
     2000                        else if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] )
     2001                        {
     2002                                $this->headerstrlen[id] = strlen( strval( $jobid ) );
     2003                        }
    19572004
    19582005                        if( !isset( $this->headerstrlen[owner] ) )
     2006                        {
    19592007                                $this->headerstrlen[owner]      = strlen( strval( $jobinfo[owner] ) );
    1960                         else
    1961                                 if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] )
    1962                                         $this->headerstrlen[owner]      = strlen( strval( $jobinfo[owner] ) );
     2008                        }
     2009                        else if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] )
     2010                        {
     2011                                $this->headerstrlen[owner]      = strlen( strval( $jobinfo[owner] ) );
     2012                        }
    19632013
    19642014                        if( !isset( $this->headerstrlen[queue] ) )
     2015                        {
    19652016                                $this->headerstrlen[queue]      = strlen( strval( $jobinfo[queue] ) );
    1966                         else
    1967                                 if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] )
    1968                                         $this->headerstrlen[queue]      = strlen( strval( $jobinfo[queue] ) );
     2017                        }
     2018                        else if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] )
     2019                        {
     2020                                $this->headerstrlen[queue]      = strlen( strval( $jobinfo[queue] ) );
     2021                        }
    19692022
    19702023                        if( !isset( $jobinfo[ppn] ) )
     2024                        {
    19712025                                $jobinfo[ppn] = 1;
     2026                        }
    19722027
    19732028                        $cpus                   = count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] );
    19742029
    19752030                        if( !isset( $this->headerstrlen[cpus] ) )
     2031                        {
    19762032                                $this->headerstrlen[cpus]       = strlen( strval( $cpus ) );
    1977                         else
    1978                                 if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] )
    1979                                         $this->headerstrlen[cpus]       = strlen( strval( $cpus ) );
     2033                        }
     2034                        else if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] )
     2035                        {
     2036                                $this->headerstrlen[cpus]       = strlen( strval( $cpus ) );
     2037                        }
    19802038
    19812039                        $nodes                  = count( $jobinfo[nodes] );
    19822040
    19832041                        if( !isset( $this->headerstrlen[nodes] ) )
     2042                        {
    19842043                                $this->headerstrlen[nodes]      = strlen( strval( $nodes ) );
    1985                         else
    1986                                 if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] )
    1987                                         $this->headerstrlen[nodes]      = strlen( strval( $nodes ) );
     2044                        }
     2045                        else if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] )
     2046                        {
     2047                                $this->headerstrlen[nodes]      = strlen( strval( $nodes ) );
     2048                        }
    19882049
    19892050                        $runningtime            = makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
    19902051
    19912052                        if( !isset( $this->headerstrlen[runningtime] ) )
     2053                        {
    19922054                                $this->headerstrlen[runningtime]        = strlen( strval( $runningtime) );
    1993                         else
    1994                                 if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] )
    1995                                         $this->headerstrlen[runningtime]        = strlen( strval( $runningtime) );
     2055                        }
     2056                        else if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] )
     2057                        {
     2058                                $this->headerstrlen[runningtime]        = strlen( strval( $runningtime) );
     2059                        }
    19962060
    19972061                        if( !isset( $this->headerstrlen[name] ) )
     2062                        {
    19982063                                $this->headerstrlen[name]       = strlen( strval( $jobinfo[name] ) );
    1999                         else
    2000                                 if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] )
    2001                                         $this->headerstrlen[name]       = strlen( strval( $jobinfo[name] ) );
    2002 
     2064                        }
     2065                        else if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] )
     2066                        {
     2067                                $this->headerstrlen[name]       = strlen( strval( $jobinfo[name] ) );
     2068                        }
    20032069                }
    20042070
    20052071                $xoffset        = 5;
    20062072
    2007                 foreach( $this->headerstrlen as $headername => $headerlen ) {
    2008 
     2073                foreach( $this->headerstrlen as $headername => $headerlen )
     2074                {
    20092075                        $colorgreen     = imageColorAllocate( $this->image, 0, 200, 0 );
    20102076
    20112077                        if( $headerlen < strlen( $headername ) )
     2078                        {
    20122079                                $this->headerstrlen[$headername]        = strlen( $headername );
     2080                        }
    20132081
    20142082                        imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen );
    20152083
    20162084                        $xoffset        = $xoffset + ($this->fontwidth * ( $this->headerstrlen[$headername] + 1 ) );
    2017 
    20182085                }
    20192086                $this->newLineOffset();
    20202087        }
    20212088
    2022         function newLineOffset() {
    2023 
     2089        function newLineOffset()
     2090        {
    20242091                $this->y_offset         = $this->y_offset + $this->fontheight + $this->fontspaceing;
    20252092        }
    20262093
    2027         function draw() {
    2028 
     2094        function draw()
     2095        {
    20292096                $xlen           = 450;
    20302097                $ylen           = ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight);
     
    20882155        global $x_present, $y_present;
    20892156
    2090         //printf("ppoep = %s\n", $skan_str);
    20912157        $a_node         = $a;
    20922158        $b_node         = $b;
     
    22282294        }
    22292295}
    2230 function makeTime( $time ) {
    2231 
     2296function makeTime( $time )
     2297{
    22322298        $days = intval( $time / 86400 );
    22332299        $time = ($days>0) ? $time % ($days * 86400) : $time;
    22342300
    2235         //printf( "time = %s, days = %s\n", $time, $days );
    2236 
    22372301        $date_str = '';
    22382302        $day_str = '';
    22392303
    2240         if( $days > 0 ) {
     2304        if( $days > 0 )
     2305        {
    22412306                if( $days > 1 )
     2307                {
    22422308                        $day_str .= $days . ' days';
     2309                }
    22432310                else
     2311                {
    22442312                        $day_str .= $days . ' day';
     2313                }
    22452314        }
    22462315
     
    22482317        $time = $hours ? $time % ($hours * 3600) : $time;
    22492318
    2250         //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
    2251         if( $hours > 0 ) {
     2319        if( $hours > 0 )
     2320        {
    22522321                $date_str .= $hours . ':';
    22532322                $date_unit = 'hours';
     
    22572326        $seconds = $minutes ? $time % ($minutes * 60) : $time;
    22582327
    2259         if( $minutes > 0 ) {
    2260 
     2328        if( $minutes > 0 )
     2329        {
    22612330                if( $minutes >= 10 )
     2331                {
    22622332                        $date_str .= $minutes . ':';
     2333                }
    22632334                else
     2335                {
    22642336                        $date_str .= '0' . $minutes . ':';
     2337                }
    22652338
    22662339                $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
    2267         } else {
    2268                 if($hours > 0 ) {
     2340        }
     2341        else
     2342        {
     2343                if($hours > 0 )
     2344                {
    22692345                        $date_str .= '00:';
    22702346                        $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
     
    22722348        }
    22732349
    2274 
    22752350        $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
    22762351
    2277         if( $seconds > 0 ) {
    2278 
     2352        if( $seconds > 0 )
     2353        {
    22792354                if( $seconds >= 10 )
     2355                {
    22802356                        $date_str .= $seconds . ' ' . $date_unit;
     2357                }
    22812358                else
     2359                {
    22822360                        $date_str .= '0' . $seconds . ' ' . $date_unit;
    2283 
    2284         } else if ( $hours > 0 or $minutes > 0 )
    2285 
     2361                }
     2362        }
     2363        else if ( $hours > 0 or $minutes > 0 )
     2364        {
    22862365                $date_str .= '00 ' . $date_unit;
    2287 
    2288         if( $days > 0) {
    2289 
     2366        }
     2367
     2368        if( $days > 0)
     2369        {
    22902370                if( $hours > 0 or $minutes > 0 or $seconds > 0 )
     2371                {
    22912372                        $date_str = $day_str . ' - ' . $date_str;
     2373                }
    22922374                else
     2375                {
    22932376                        $date_str = $day_str;
     2377                }
    22942378        }
    2295 
    22962379        return $date_str;
    22972380}
Note: See TracChangeset for help on using the changeset viewer.