Changeset 874


Ignore:
Timestamp:
05/16/13 21:47:03 (11 years ago)
Author:
ramonb
Message:

libtoga.php:

  • modified XML processor to try and tackle DNS/hostname/FQDN inconsistency issue
  • each individual gangliahost can have different hostname style: short or FQDN
  • determine for each gangliahost if it is FQDN or short hostname during XML HOST processing
  • moved job/node/gangliahost association to finishUp(): first all ganglia hosts must be processed and FQDN detection completed
  • during job/node/gangliahost association use FQDN/short detected hostname as determined during XML processing

overview.php:

  • let XML processor (via data gatherer) decide if to use use FQDN or short hostname
Location:
branches/1.0/web/addons/job_monarch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/web/addons/job_monarch/libtoga.php

    r865 r874  
    598598    }
    599599
    600     function getUsingFQDN()
    601     {
    602         $handler = $this->xmlhandler;
    603         return $handler->getUsingFQDN();
    604     }
    605 
    606600    function getMetrics()
    607601    {
     
    649643        $handler = $this->xmlhandler;
    650644        return $handler->isJobmonRunning();
     645    }
     646
     647    function makeHostname( $ahost, $adomain )
     648    {
     649        $handler = $this->xmlhandler;
     650        return $handler->makeHostname( $ahost, $adomain );
    651651    }
    652652}
     
    658658    function TorqueXMLHandler( $clustername )
    659659    {
    660         $this->jobs        = array();
    661         $this->clusters     = array();
     660        $this->jobs          = array();
     661        $this->clusters      = array();
    662662        $this->nodes         = array();
    663         $this->metrics      = array();
     663        $this->metrics       = array();
    664664        $this->heartbeat     = array();
    665665        $this->down_nodes    = array();
    666         $this->offline_nodes    = array();
    667         $this->clustername    = $clustername;
    668         $this->proc_cluster = null;
     666        $this->offline_nodes = array();
     667        $this->clustername   = $clustername;
     668        $this->proc_cluster  = null;
    669669        $this->proc_hostname = null;
    670         $this->fqdn        = 1;
    671     }
    672 
    673     function getUsingFQDN()
    674     {
    675         return $this->fqdn;
     670        $this->fqdn          = array();
    676671    }
    677672
     
    705700    }
    706701
    707     function makeHostname( $thostname, $tdomain=null )
    708     {
    709         if( $this->fqdn && isset( $tdomain ) )
     702    function isFqdn( $somehost )
     703    {
     704        $chr_count = count_chars( $somehost );
     705        $dot_count = $chr_count[ ord('.') ];
     706
     707        if( $dot_count > 1 )
     708        {
     709            return true;
     710        }
     711        return false;
     712    }
     713
     714    function makeHostname( $thostname, $tdomain )
     715    {
     716        $mhost = $thostname;
     717
     718        if( ( $this->fqdn[ $thostname ] === true ) && isset( $tdomain ) && ( $tdomain !== '' ) )
    710719        {
    711720            if( strpos( $thostname, $tdomain ) === false )
     
    713722                $mhost = $thostname . '.' . $tdomain;
    714723            }
    715             else
    716             {
    717                 $mhost = $thostname;
    718             }
    719         }
    720         else
    721         {
    722             $mhost = $thostname;
    723724        }
    724725
     
    761762            $hostname = $attrs['NAME'];
    762763            $this->proc_hostname = $hostname;
     764
     765            if( $this->isFqdn( $hostname ) === true )
     766            {
     767                $host_fields = explode( '.', $hostname );
     768                $shorthost   = $host_fields[0];
     769
     770                $this->fqdn[ $shorthost ] = true;
     771            }
     772            else
     773            {
     774                $this->fqdn[ $hostname ] = false;
     775            }
    763776
    764777            # Pseudo metrics - add useful HOST attributes like gmond_started & last_reported to the metrics list:
     
    804817            {
    805818                $this->heartbeat['time'] = $attrs['VAL'];
    806                 return;
     819                return null;
    807820            }
    808821            else if( strpos( $attrs['NAME'], 'zplugin_monarch_down' ) !== false )
     
    811824
    812825                $nodes_down    = array();
    813                 $down_domain    = null;
     826                $down_domain   = null;
    814827
    815828                foreach( $fields as $f )
    816829                {
    817                     $togavalues    = explode( '=', $f );
     830                    $togavalues  = explode( '=', $f );
    818831
    819832                    $toganame    = $togavalues[0];
    820                     $togavalue    = $togavalues[1];
     833                    $togavalue   = $togavalues[1];
    821834
    822835                    if( $toganame == 'nodes' )
     
    837850                        if( !isset( $this->down_nodes['heartbeat'] ) )
    838851                        {
    839                             $this->down_nodes[$togavalue]    = array( $nodes_down, $down_domain );
     852                            $this->down_nodes[$togavalue] = array( $nodes_down, $down_domain );
    840853                        }
    841854                    }
     
    845858            else if( strpos( $attrs['NAME'], 'zplugin_monarch_offline' ) !== false )
    846859            {
    847                 $fields        = explode( ' ', $attrs['VAL'] );
    848 
    849                 $nodes_offline    = array();
    850                 $offline_domain    = null;
     860                $fields         = explode( ' ', $attrs['VAL'] );
     861
     862                $nodes_offline  = array();
     863                $offline_domain = null;
    851864
    852865                foreach( $fields as $f )
    853866                {
    854                     $togavalues    = explode( '=', $f );
    855 
    856                     $toganame    = $togavalues[0];
    857                     $togavalue    = $togavalues[1];
     867                    $togavalues = explode( '=', $f );
     868
     869                    $toganame   = $togavalues[0];
     870                    $togavalue  = $togavalues[1];
    858871
    859872                    if( $toganame == 'nodes' )
     
    895908                    $togavalues = explode( '=', $f );
    896909
    897                     $toganame = $togavalues[0];
    898                     $togavalue = $togavalues[1];
     910                    $toganame   = $togavalues[0];
     911                    $togavalue  = $togavalues[1];
    899912
    900913                    if( $toganame == 'nodes' )
     
    929942                }
    930943
    931                 if( isset( $this->jobs[$jobid]['nodes'] ) )
    932                 {
    933                     $nr_nodes = count( $this->jobs[$jobid]['nodes'] );
     944            }
     945            return;
     946        }
     947    }
     948
     949    function finishUp( )
     950    {
     951        $nodes    = $this->nodes;
     952
     953        foreach( $this->jobs as $jobid => &$jobattrs )
     954        {
     955            if( isset( $this->jobs[$jobid]['nodes'] ) )
     956            {
     957                $nr_nodes = count( $this->jobs[$jobid]['nodes'] );
    934958       
    935                     if( $this->jobs[$jobid]['status'] == 'R' )
     959                if( $this->jobs[$jobid]['status'] == 'R' )
     960                {
     961                    foreach( $this->jobs[$jobid]['nodes'] as $node )
    936962                    {
    937 
    938                         if( isset( $this->jobs[$jobid]['domain'] ) )
     963                        $domain = $this->jobs[$jobid]['domain'];
     964                        $host   = $this->makeHostname( $node, $domain );
     965
     966                        if( !isset( $nodes[$host] ) )
    939967                        {
    940                             $domain        = $this->jobs[$jobid]['domain'];
    941                             $domain_len    = 0 - strlen( $domain );
    942 
    943                             $first_host    = key( array_slice($this->nodes, 0, 1, true) );
    944 
    945                             // Let's see if Ganglia use's FQDN or short hostnames
    946                             //
    947                             if( strpos( $first_host, $domain ) === false )
    948                             {
    949                                 $this->fqdn    = 0;
    950                             }
     968                            $my_node = new NodeImage( $this->proc_cluster, $host );
    951969                        }
    952970                        else
    953971                        {
    954                             $this->fqdn    = 0;
     972                            $my_node = $nodes[$host];
    955973                        }
    956974
    957                         foreach( $this->jobs[$jobid]['nodes'] as $node )
     975                        if( !$my_node->hasJob( $jobid ) )
    958976                        {
    959 
    960                             // Only add domain name to the hostname if Ganglia is doing that too
    961                             //
    962                             if( $this->fqdn && isset( $this->jobs[$jobid]['domain'] ) )
     977                            if( isset( $this->jobs[$jobid]['ppn'] ) )
    963978                            {
    964                                 if( strpos( $node, $domain ) === false )
    965                                 {
    966                                     $host = $node. '.'.$domain;
    967                                 }
    968                                 else
    969                                 {
    970                                     $host = $node;
    971                                 }
     979                                $my_node->addJob( $jobid, ((int) $this->jobs[$jobid]['ppn']) );
    972980                            }
    973981                            else
    974982                            {
    975                                 $host    = $node;
     983                                $my_node->addJob( $jobid, 1 );
    976984                            }
    977 
    978                             if( !isset( $this->nodes[$host] ) )
    979                             {
    980                                 $my_node = new NodeImage( $this->proc_cluster, $host );
    981                             }
    982                             else
    983                             {
    984                                 $my_node = $this->nodes[$host];
    985                             }
    986 
    987                             if( !$my_node->hasJob( $jobid ) )
    988                             {
    989                                 if( isset( $jobs[$jobid]['ppn'] ) )
    990                                 {
    991                                     $my_node->addJob( $jobid, ((int) $jobs[$jobid]['ppn']) );
    992                                 }
    993                                 else
    994                                 {
    995                                     $my_node->addJob( $jobid, 1 );
    996                                 }
    997                             }
    998 
    999                             $this->nodes[$host] = $my_node;
    1000985                        }
     986
     987                        $nodes[$host] = $my_node;
    1001988                    }
    1002989                }
    1003990            }
    1004             return;
    1005         }
    1006     }
    1007 
    1008     function finishUp( )
    1009     {
    1010         $nodes    = $this->nodes;
     991        }
    1011992
    1012993        if( sizeof( $this->down_nodes ) > 0 )
     
    14901471    function getNodes()
    14911472    {
    1492         if( $this->nodes== null )
     1473        if( $this->nodes === null )
    14931474        {
    14941475            $this->checkParse();
  • branches/1.0/web/addons/job_monarch/overview.php

    r836 r874  
    5555$gnodes    = $data_gatherer->getNodes();
    5656$cpus      = $data_gatherer->getCpus();
    57 $use_fqdn  = $data_gatherer->getUsingFQDN();
    5857
    5958//print_r( $gnodes );
     
    467466                    $running_name_nodes[] = $tempnode;
    468467
     468                    $hostnode = $data_gatherer->makeHostname( $tempnode, $jobs[$jobid]['domain'] );
     469
    469470                    if( isset( $hostname ) && $hostname != '' )
    470471                    {
    471                         $domain_len     = 0 - strlen( $jobs[$jobid]['domain'] );
    472                         $hostnode     = $tempnode;
    473 
    474                         if( $use_fqdn == 1)
    475                         {
    476                             if( substr( $hostnode, $domain_len ) != $jobs[$jobid]['domain'] )
    477                             {
    478                                 $hostnode = $hostnode. '.'. $jobs[$jobid]['domain'];
    479                             }
    480                         }
    481 
    482472                        if( $hostname == $hostnode )
    483473                        {
     
    648638                        foreach( $jobs[$jobid]['nodes'] as $shortnode )
    649639                        {
    650                             if( $use_fqdn == 1)
    651                             {
    652                                 $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
    653                             }
     640                            $domain         = $jobs[$jobid]['domain'];
     641                            $mynode         = $data_gatherer->makeHostname( $shortnode, $domain );
    654642                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
    655643                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
     
    837825            foreach ( $hosts_up as $host )
    838826            {
    839                 $domain_len         = 0 - strlen( $domain );
    840 
    841                 if( $use_fqdn )
    842                 {
    843                     if( substr( $host, $domain_len ) != $domain )
    844                     {
    845                         $host         = $host . '.' . $domain;
    846                     }
    847                 }
     827                $host             = $data_gatherer->makeHostname( $host, $domain );
     828
    848829                $cpus             = 0;
    849830
Note: See TracChangeset for help on using the changeset viewer.