Changeset 592


Ignore:
Timestamp:
02/05/09 09:35:18 (15 years ago)
Author:
ramonb
Message:

job_monarch/index.php:

  • code cleanup
  • associative array WARNINGs fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web2/addons/job_monarch/index.php

    r555 r592  
    3333include_once "./libtoga.php";
    3434
    35 if ( !empty( $_GET ) ) {
     35if ( !empty( $_GET ) )
     36{
    3637        extract( $_GET );
    3738}
    38 
    39 //printf( "r2%s\n", $range );
    4039
    4140global $GANGLIA_PATH;
     
    5554if( !isset($sortby) ) $sortby = "id";
    5655
    57 if( isset( $filterorder ) && ($filterorder!='') ) {
     56if( isset( $filterorder ) && ($filterorder!='') )
     57{
    5858        $myfilter_fields = explode( ",", $filterorder );
    59 } else {
    60         if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
    61         if( isset($state) && ($state!='')) $filter[state]=$state;
    62         if( isset($user) && ($user!='')) $filter[user]=$user;
    63         if( isset($id) && ($id!='')) $filter[id]=$id;
     59}
     60else
     61{
     62        if( isset($queue) && ($queue!='')) $filter['queue']=$queue;
     63        if( isset($state) && ($state!='')) $filter['state']=$state;
     64        if( isset($user) && ($user!='')) $filter['user']=$user;
     65        if( isset($id) && ($id!='')) $filter['id']=$id;
    6466}
    6567
    6668// Fill filter array in order they were picked by user
    67 if( isset($myfilter_fields) ) {
    68 
    69         foreach( $myfilter_fields as $myfilter ) {
    70 
    71                 switch( $myfilter ) {
    72 
     69if( isset($myfilter_fields) )
     70{
     71        foreach( $myfilter_fields as $myfilter )
     72        {
     73                switch( $myfilter )
     74                {
    7375                        case "queue":
    74                                 $filter[queue]=$queue;
     76                                $filter['queue']=$queue;
    7577                                break;
    7678                        case "state":
    77                                 $filter[state]=$state;
     79                                $filter['state']=$state;
    7880                                break;
    7981                        case "user":
    80                                 $filter[user]=$user;
     82                                $filter['user']=$user;
    8183                                break;
    8284                        case "id":
    83                                 $filter[id]=$id;
     85                                $filter['id']=$id;
    8486                                break;
    8587                }
     
    8789}
    8890
    89 //if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
    90 //if( isset($state) && ($state!='')) $filter[state]=$state;
    91 //if( isset($user) && ($user!='')) $filter[user]=$user;
    92 //if( isset($id) && ($id!='')) $filter[id]=$id;
    93 
    94 function epochToDatetime( $epoch ) {
    95 
     91function epochToDatetime( $epoch )
     92{
    9693        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
    9794}
    9895
    99 function makeHeader( $page_call, $title, $longtitle ) {
    100 
     96function makeHeader( $page_call, $title, $longtitle )
     97{
    10198        global $tpl, $grid, $context, $initgrid;
    10299        global $jobrange, $jobstart;
     
    120117
    121118        # Maintain our path through the grid tree.
    122         $me = $self . "@" . $grid[$self][AUTHORITY];
     119        $me = $self . "@" . $grid[$self]['AUTHORITY'];
    123120
    124121        $gridstack = array();
    125122        $gridstack[] = $me;
    126123
    127         if ($gridwalk=="fwd") {
     124        if ($gridwalk=="fwd")
     125        {
    128126                # push our info on gridstack, format is "name@url>name2@url".
    129                 if (end($gridstack) != $me) {
     127                if (end($gridstack) != $me)
     128                {
    130129                        $gridstack[] = $me;
    131130                }
    132         } else if ($gridwalk=="back") {
     131        }
     132        else if ($gridwalk=="back")
     133        {
    133134                # pop a single grid off stack.
    134                 if (end($gridstack) != $me) {
     135                if (end($gridstack) != $me)
     136                {
    135137                        array_pop($gridstack);
    136138                }
     
    140142        $gridstack_url = rawurlencode($gridstack_str);
    141143
    142         if ($initgrid or $gridwalk) {
     144        if ($initgrid or $gridwalk)
     145        {
    143146                # Use cookie so we dont have to pass gridstack around within this site.
    144147                # Cookie values are automatically urlencoded. Expires in a day.
     
    152155        # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
    153156        # destination server that we're walking foward in the grid tree.
    154         if (strstr($clustername, "http://")) {
     157        if (strstr($clustername, "http://"))
     158        {
    155159                $tpl->assign("refresh", "0");
    156160                $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
     
    194198        $node_menu = "";
    195199
    196         if ($parentgrid) {
     200        if ($parentgrid)
     201        {
    197202                $node_menu .= "<B>$parentgrid $meta_designator</B> ";
    198203                $node_menu .= "<B>&gt;</B>\n";
     
    205210
    206211        if ($physical)
     212        {
    207213                $node_menu .= hiddenvar("p", $physical);
    208 
    209         if ( $clustername ) {
     214        }
     215
     216        if ( $clustername )
     217        {
    210218                $url = rawurlencode($clustername);
    211219                $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
     
    214222        }
    215223
    216         if (!count($metrics)) {
     224        if (!count($metrics))
     225        {
    217226                echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";
    218227                echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
     
    239248        $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
    240249
    241         if( isset( $hostname ) && ( $view != 'host' ) ) {
    242 
     250        if( isset( $hostname ) && ( $view != 'host' ) )
     251        {
    243252                $node_menu .= "<B>&gt;</B>\n";
    244253                $href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
     
    247256        }
    248257
    249         if( count( $filter ) > 0 && $view != "search" ) {
    250 
     258        if( count( $filter ) > 0 && $view != "search" )
     259        {
    251260                $my_ct = 1;
    252261                $filter_nr = count( $filter );
    253262
    254                 foreach( $filter as $filtername=>$filterval ) {
    255 
     263                foreach( $filter as $filtername=>$filterval )
     264                {
    256265                        $node_menu .= "<B>&gt;</B>\n";
    257266
     
    262271                        $my_filters = array_keys( $filter );
    263272
    264                         foreach( $n_filter as $n_filtername=>$n_filterval ) {
    265 
    266                                 if( $temp_ct < $my_ct ) {
     273                        foreach( $n_filter as $n_filtername=>$n_filterval )
     274                        {
     275                                if( $temp_ct < $my_ct )
     276                                {
    267277                                        $href .= "&". $n_filtername . "=" . $n_filterval;
    268278
     
    286296        }
    287297
    288         //$m = $metricname;
    289 
    290 
    291298        $tpl->gotoBlock( "_ROOT" );
    292299        $tpl->assignGlobal("view", $view);
    293300
    294 
    295         if( array_key_exists( "id", $filter ) or isset($hostname) ) {
    296 
     301        if( array_key_exists( "id", $filter ) or isset($hostname) )
     302        {
    297303                $range = "job";
    298304
    299                 //print_r( $context_metrics );
    300 
    301305                if( $page_call != "host_view" )
    302306                {
    303 
    304                         if (is_array($context_metrics) ) {
     307                        if (is_array($context_metrics) )
     308                        {
    305309                                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
    306310                                        ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
    307311
    308312                                sort($context_metrics);
    309                                 foreach( $context_metrics as $k ) {
     313                                foreach( $context_metrics as $k )
     314                                {
    310315                                        $url = rawurlencode($k);
    311316                                        $metric_menu .= "<OPTION VALUE=\"$url\" ";
     
    321326                $tpl->assign("metric_menu", $metric_menu );
    322327
    323                 if( $view == "search" or $view == "host" ) {
     328                if( $view == "search" or $view == "host" )
     329                {
    324330                        $tpl->newBlock("timeperiod");
    325                         if( is_numeric( $period_start ) ) {
     331                        if( is_numeric( $period_start ) )
     332                        {
    326333                                $period_start = epochToDatetime( $period_start );
    327334                        }
    328                         if( is_numeric( $period_stop ) ) {
     335                        if( is_numeric( $period_stop ) )
     336                        {
    329337                                $period_stop = epochToDatetime( $period_stop );
    330338                        }
     
    333341                        $tpl->assign("hostname", $hostname );
    334342
    335                         if( $view == "host" ) {
     343                        if( $view == "host" )
     344                        {
    336345                                $tpl->newBlock("hostview");
    337346                                $tpl->assign("job_start", $job_start );
     
    341350
    342351        }
    343 
    344         //$ex_fn = $tpl->getVarValue( "_ROOT", "form_name" );
    345352
    346353        if( $view != "search" )
     
    354361
    355362                $range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
    356                 foreach ($context_ranges as $v) {
     363                foreach ($context_ranges as $v)
     364                {
    357365                        $url=rawurlencode($v);
    358366                        $range_menu .= "<OPTION VALUE=\"$url\" ";
     
    367375        }
    368376
    369         if( $view == "search" or $view == "host" ) {
    370 
     377        if( $view == "search" or $view == "host" )
     378        {
    371379                $node_menu .= "<B>&gt;</B>\n";
    372380                $node_menu .= "<B>Jobarchive</B> ";
    373381                $form_name = "archive_search_form";
    374382                $tpl->assignGlobal("form_name", $form_name );
    375 
    376         } else {
     383        }
     384        else
     385        {
    377386                $form_name = "toga_form";
    378387                $tpl->assignGlobal("form_name", $form_name );
    379388        }
    380389
    381         if( $JOB_ARCHIVE && $page_call == 'overview' ) {
     390        if( $JOB_ARCHIVE && $page_call == 'overview' )
     391        {
    382392                $tpl->newBlock( "search" );
    383393                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
     
    395405}
    396406
    397 function makeFooter() {
     407function makeFooter()
     408{
    398409        global $tpl, $version, $parsetime, $monarchversion;
    399410
     
    402413        $tpl->assign("monarch-version", $monarchversion);
    403414
    404         if ($version["gmetad"]) {
     415        if ($version["gmetad"])
     416        {
    405417                $tpl->assign("webbackend-component", "gmetad");
    406418                $tpl->assign("webbackend-version",$version["gmetad"]);
    407         } else if ($version["gmond"]) {
     419        }
     420        else if ($version["gmond"])
     421        {
    408422                $tpl->assign("webbackend-component", "gmond");
    409423                $tpl->assign("webbackend-version", $version["gmond"]);
     
    413427}
    414428
    415 function includeSearchpage() {
     429function includeSearchpage()
     430{
    416431        global $tpl;
    417432
    418433        $tpl->assignInclude( "main", "templates/search.tpl" );
    419 
    420 }
    421 
    422 function includeOverview() {
     434}
     435
     436function includeOverview()
     437{
    423438        global $tpl;
    424439
     
    426441}
    427442
    428 function includeHostPage() {
    429 
     443function includeHostPage()
     444{
    430445        global $tpl;
    431446
     
    437452$tpl->assignInclude( "header", "templates/header.tpl" );
    438453
    439 if( isset( $h ) and $h != '' ) {
     454if( isset( $h ) and $h != '' )
     455{
    440456        $hostname = $h;
    441         //$view = "host";
    442 }
    443 
    444 switch( $view ) {
    445 
     457}
     458
     459switch( $view )
     460{
    446461        case "overview":
    447462
     
    470485$longtitle = "Batch Report :: Powered by Job Monarch!";
    471486$title = "Batch Report";
    472 //makeHeader( 'index' );
    473487$tpl->assign("cluster_url", rawurlencode($clustername) );
    474488$tpl->assign("cluster", $clustername );
    475489
    476 switch( $view ) {
    477 
     490switch( $view )
     491{
    478492        case "overview":
    479493
Note: See TracChangeset for help on using the changeset viewer.