source: branches/0.4/web/addons/job_monarch/index.php @ 722

Last change on this file since 722 was 722, checked in by ramonb, 11 years ago
  • decided to sort job id descending by default instead
  • Property svn:keywords set to Id
File size: 13.6 KB
RevLine 
[113]1<?php
[225]2/*
3 *
4 * This file is part of Jobmonarch
5 *
6 * Copyright (C) 2006  Ramon Bastiaans
7 *
8 * Jobmonarch is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * Jobmonarch is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 *
[231]22 * SVN $Id: index.php 722 2013-03-21 21:27:26Z ramonb $
[225]23 */
[113]24
[686]25ini_set("memory_limit","500M");
[398]26set_time_limit(0);
27
[409]28
29$my_dir = getcwd();
30
31global $r, $range;
32
33include_once "./libtoga.php";
34
[715]35if ( !empty( $_GET ) ) 
36{
37    extract( $_GET );
[117]38}
39
[113]40
[117]41global $GANGLIA_PATH;
[113]42
43include_once "./class.TemplatePower.inc.php";
44
[117]45$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
46$clustername = $httpvars->getClusterName();
[708]47$view = $httpvars->getHttpVar( "j_view" );
[113]48
[119]49$filter = array();
50
[117]51if( !isset($view) ) $view = "overview";
[722]52if( !isset($sortorder) ) $sortorder = "desc";
[117]53if( !isset($sortby) ) $sortby = "id";
54
[715]55if( isset( $filterorder ) && ($filterorder!='') ) 
56{
57    $myfilter_fields = explode( ",", $filterorder );
58} 
59else 
60{
61    if( isset($queue) && ($queue!='')) $filter['queue']=$queue;
62    if( isset($state) && ($state!='')) $filter['state']=$state;
63    if( isset($owner) && ($owner!='')) $filter['owner']=$owner;
64    if( isset($id) && ($id!='')) $filter['id']=$id;
[178]65}
[158]66
67// Fill filter array in order they were picked by user
[715]68if( isset($myfilter_fields) ) 
69{
[158]70
[715]71    foreach( $myfilter_fields as $myfilter ) 
72    {
[158]73
[715]74        switch( $myfilter ) 
75        {
[300]76
[715]77            case "queue":
78                $filter['queue']=$queue;
79                break;
80            case "state":
81                $filter['state']=$state;
82                break;
83            case "owner":
84                $filter['owner']=$owner;
85                break;
86            case "id":
87                $filter['id']=$id;
88                break;
89        }
90    }
[158]91}
92
[715]93function epochToDatetime( $epoch ) 
94{
[189]95
96        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
97}
98
[715]99function makeHeader( $page_call, $title, $longtitle ) 
100{
[117]101
[715]102    global $tpl, $grid, $context, $initgrid;
103    global $jobrange, $jobstart;
104    global $page, $gridwalk, $clustername;
105    global $parentgrid, $physical, $hostname;
106    global $self, $filter, $cluster_url, $get_metric_string;
107    global $metrics, $reports, $m, $default_metric;
108    global $default_refresh, $filterorder, $view;
109    global $JOB_ARCHIVE, $period_start, $period_stop, $h, $id;
110    global $job_start, $job_stop, $range, $r, $metricname;
111   
112    if( isset($default_metric) and !isset($m) )
113        $metricname = $default_metric;
114    else
115        if( isset( $m ) )
116            $metricname = $m;
117        else
118            $metricname = "load_one";
[126]119
[715]120    $header = "header";
[117]121
[715]122    # Maintain our path through the grid tree.
123    $me = $self . "@" . $grid[$self][AUTHORITY];
[117]124
[715]125    $gridstack = array();
126    $gridstack[] = $me;
[129]127
[715]128    if ($gridwalk=="fwd") 
129    {
130        # push our info on gridstack, format is "name@url>name2@url".
131        if (end($gridstack) != $me) 
132        {
133            $gridstack[] = $me;
134        }
135    } 
136    else if ($gridwalk=="back") 
137    {
138        # pop a single grid off stack.
139        if (end($gridstack) != $me) 
140        {
141            array_pop($gridstack);
142        }
143    }
[117]144
[715]145    $gridstack_str = join(">", $gridstack);
146    $gridstack_url = rawurlencode($gridstack_str);
[117]147
[715]148    if ($initgrid or $gridwalk) 
149    {
150        # Use cookie so we dont have to pass gridstack around within this site.
151        # Cookie values are automatically urlencoded. Expires in a day.
152        setcookie("gs", $gridstack_str, time() + 86400);
153    }
[117]154
[715]155    # Invariant: back pointer is second-to-last element of gridstack. Grid stack never
156    # has duplicate entries.
157    list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
[117]158
[715]159    # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
160    # destination server that we're walking foward in the grid tree.
161    if (strstr($clustername, "http://")) 
162    {
163        $tpl->assign("refresh", "0");
164        $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
165        echo "<h2>Redirecting, please wait...</h2>";
166        $tpl->printToScreen();
167        exit;
168    }
169    $tpl->gotoBlock( "_ROOT" );
[117]170
[715]171    if( $view != "search" )
172    {
173        $tpl->assign( "refresh", $default_refresh );
174    }
[160]175
[715]176    $tpl->assign( "date", date("r") );
177    $tpl->assign( "longpage_title", $longtitle );
178    $tpl->assign( "page_title", $title );
[117]179
[715]180    # The page to go to when "Get Fresh Data" is pressed.
181    $tpl->assign("page","./");
[117]182
[715]183    # Templated Logo image
184    $tpl->assign("images","./templates/$template_name/images");
[117]185
[715]186    #
187    # Used when making graphs via graph.php. Included in most URLs
188    #
189    $sort_url=rawurlencode($sort);
190    $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
[117]191
[715]192    if ($jobrange and $jobstart)
193        $get_metric_string .= "&jr=$jobrange&js=$jobstart";
[117]194
[715]195    # Set the Alternate view link.
196    $cluster_url=rawurlencode($clustername);
197    $node_url=rawurlencode($hostname);
[117]198
[715]199    # Make some information available to templates.
200    $tpl->assign("cluster_url", $cluster_url);
201    # Build the node_menu
202    $node_menu = "";
[117]203
[715]204    if ($parentgrid) 
205    {
206        $node_menu .= "<B>$parentgrid $meta_designator</B> ";
207        $node_menu .= "<B>&gt;</B>\n";
208    }
[117]209
[715]210    # Show grid.
211    $mygrid =  ($self == "unspecified") ? "" : $self;
212    $node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> ";
213    $node_menu .= "<B>&gt;</B>\n";
[117]214
[715]215    if ($physical)
216    {
217        $node_menu .= hiddenvar("p", $physical);
218    }
[117]219
[715]220    if ( $clustername ) 
221    {
222        $url = rawurlencode($clustername);
223        $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
224        $node_menu .= "<B>&gt;</B>\n";
225        $node_menu .= hiddenvar("c", $clustername);
226    }
[117]227
[715]228    if (!count($metrics)) 
229    {
230        echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";
231        echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
232        exit;
233    }
234    reset($metrics);
235    $firsthost = key($metrics);
[145]236
[715]237    $mmfh    = array();
[126]238
[715]239    $mmfh    = $metrics[$firsthost];
[406]240
[715]241    $context_metrics    = array();
[406]242
[715]243    foreach( $mmfh as $mm => $bla )
244    {
245        $context_metrics[] = $mm;
246    }
[406]247
[715]248    foreach ($reports as $mr => $mfoo)
249        $context_metrics[] = $mr;
[406]250
[715]251    $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
[122]252
[715]253    if( isset( $hostname ) && ( $view != 'host' ) ) 
254    {
[267]255
[715]256        $node_menu .= "<B>&gt;</B>\n";
257        $href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
258        $node_menu .= "<B>$href";
259        $node_menu .= "host: $hostname</A></B> ";
260    }
[267]261
[715]262    if( count( $filter ) > 0 && $view != "search" ) 
263    {
[119]264
[715]265        $my_ct = 1;
266        $filter_nr = count( $filter );
[119]267
[715]268        foreach( $filter as $filtername=>$filterval ) 
269        {
[138]270
[715]271            $node_menu .= "<B>&gt;</B>\n";
[153]272
[715]273            $href = "<A HREF=\"./?c=".rawurlencode($clustername);
274            $temp_ct = 0;
275            $n_filter = $filter;
276            $my_filterorder = "";
277            $my_filters = array_keys( $filter );
[153]278
[715]279            foreach( $n_filter as $n_filtername=>$n_filterval ) 
280            {
[153]281
[715]282                if( $temp_ct < $my_ct ) 
283                {
284                    $href .= "&". $n_filtername . "=" . $n_filterval;
[153]285
[715]286                    if( $my_filterorder == "" )
287                        $my_filterorder = $my_filters[$temp_ct];
288                    else
289                        $my_filterorder .= "," . $my_filters[$temp_ct];
290                }
[158]291
[715]292                $temp_ct++;
293            }
294            $href .= "&filterorder=$my_filterorder\">";
[138]295
[715]296            if( $my_ct < $filter_nr )
297                $node_menu .= "<B>$href$filtername: $filterval</A></B> ";
298            else
299                $node_menu .= "<B>$filtername: $filterval</B> ";
[153]300
[715]301            $my_ct++;
302        }
303    }
[119]304
[715]305    $tpl->gotoBlock( "_ROOT" );
306    $tpl->assignGlobal("view", $view);
[143]307
[409]308
[715]309    if( array_key_exists( "id", $filter ) or isset($hostname) )
310    {
[117]311
[715]312        $range = "job";
[409]313
[715]314        if( $page_call != "host_view" )
315        {
[126]316
[715]317            if (is_array($context_metrics) )
318            {
319                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
320                    ."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
[413]321
[715]322                sort($context_metrics);
323                foreach( $context_metrics as $k ) 
324                {
325                    $url = rawurlencode($k);
326                    $metric_menu .= "<OPTION VALUE=\"$url\" ";
327                    if ($k == $metricname )
328                        $metric_menu .= "SELECTED";
329                    $metric_menu .= ">$k\n";
330                }
331                $metric_menu .= "</SELECT>\n";
332            }
[189]333
[715]334        }
[149]335
[715]336        $tpl->assign("metric_menu", $metric_menu );
[189]337
[715]338        if( $view == "search" or $view == "host" )
339        {
340            $tpl->newBlock("timeperiod");
341            if( is_numeric( $period_start ) )
342            {
343                $period_start = epochToDatetime( $period_start );
344            }
345            if( is_numeric( $period_stop ) )
346            {
347                $period_stop = epochToDatetime( $period_stop );
348            }
349            $tpl->assign("period_start", $period_start );
350            $tpl->assign("period_stop", $period_stop );
351            $tpl->assign("hostname", $hostname );
[189]352
[715]353            if( $view == "host" )
354            {
355                $tpl->newBlock("hostview");
356                $tpl->assign("job_start", $job_start );
357                $tpl->assign("job_stop", $job_stop );
358            }
359        }
[189]360
[715]361    }
[126]362
[715]363    if( $view != "search" )
364    {
365        $context_ranges[]="hour";
366        $context_ranges[]="day";
367        $context_ranges[]="week";
368        $context_ranges[]="month";
369        $context_ranges[]="year";
370        $context_ranges[]="job";
[409]371
[715]372        $range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
373        foreach ($context_ranges as $v) 
374        {
375            $url=rawurlencode($v);
376            $range_menu .= "<OPTION VALUE=\"$url\" ";
377            if ($v == $range)
378                $range_menu .= "SELECTED";
379            $range_menu .= ">$v\n";
380        }
381        $range_menu .= "</SELECT>\n";
[410]382
[715]383        $tpl->assign("range_menu", $range_menu);
[410]384
[715]385    }
[409]386
[715]387    if( $view == "search" or $view == "host" )
388    {
[189]389
[715]390        $node_menu .= "<B>&gt;</B>\n";
391        $node_menu .= "<B>Jobarchive</B> ";
392        $form_name = "archive_search_form";
393        $tpl->assignGlobal("form_name", $form_name );
[189]394
[715]395    }
396    else
397    {
398        $form_name = "toga_form";
399        $tpl->assignGlobal("form_name", $form_name );
400    }
[189]401
[715]402    if( $JOB_ARCHIVE && $page_call == 'overview' )
403    {
404        $tpl->newBlock( "search" );
405        $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
406        $tpl->assignGlobal( "cluster", $clustername );
407    }
408    $tpl->gotoBlock( "_ROOT" );
409    $tpl->assignGlobal( "cluster", $clustername );
410    $tpl->assign("node_menu", $node_menu);
[140]411
[715]412    # Make sure that no data is cached..
413    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
414    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
415    header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
416    header ("Pragma: no-cache");                          # HTTP/1.0
[117]417}
418
[715]419function makeFooter()
420{
421    global $tpl, $version, $parsetime, $monarchversion;
[117]422
[715]423    $tpl->gotoBlock( "_ROOT" );
424    $tpl->assign("webfrontend-version",$version["webfrontend"]);
425    $tpl->assign("monarch-version", $monarchversion);
[117]426
[715]427    if ($version["gmetad"])
428    {
429        $tpl->assign("webbackend-component", "gmetad");
430        $tpl->assign("webbackend-version",$version["gmetad"]);
431    }
432    else if ($version["gmond"])
433    {
434        $tpl->assign("webbackend-component", "gmond");
435        $tpl->assign("webbackend-version", $version["gmond"]);
436    }
[117]437
[715]438    $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
[117]439}
440
[715]441function includeSearchpage()
442{
443    global $tpl;
[117]444
[715]445    $tpl->assignInclude( "main", "templates/search.tpl" );
[129]446
[117]447}
448
[715]449function includeOverview()
450{
451    global $tpl;
[117]452
[715]453    $tpl->assignInclude( "main", "templates/overview.tpl" );
[117]454}
455
[715]456function includeHostPage()
457{
[149]458
[715]459    global $tpl;
[149]460
[715]461    $tpl->assignInclude( "main", "templates/host_view.tpl" );
[149]462}
463
[117]464$tpl = new TemplatePower( "templates/index.tpl" );
465
466$tpl->assignInclude( "header", "templates/header.tpl" );
467
[715]468if( isset( $h ) and $h != '' )
469{
470    $hostname = $h;
[149]471}
472
[715]473switch( $view )
474{
[117]475
[715]476    case "overview":
[117]477
[715]478        includeOverview();
479        break;
[117]480
[715]481    case "search":
[117]482
[715]483        includeSearchPage();
484        break;
[117]485
[715]486    case "host":
[149]487
[715]488        includeHostPage();
489        break;
[149]490
[715]491    default:
[117]492
[715]493        includeOverview();
494        break;
[117]495}
496
497$tpl->assignInclude( "footer", "templates/footer.tpl" );
498$tpl->prepare();
499
[334]500$longtitle = "Batch Report :: Powered by Job Monarch!";
[323]501$title = "Batch Report";
[129]502$tpl->assign("cluster_url", rawurlencode($clustername) );
503$tpl->assign("cluster", $clustername );
[117]504
[715]505switch( $view )
506{
[117]507
[715]508    case "overview":
[117]509
[715]510        include "./overview.php";
511        makeOverview();
512        break;
[117]513
[715]514    case "search":
[117]515
[715]516        include "./search.php";
517        makeSearchPage();
518        break;
[117]519
[715]520    case "host":
[149]521
[715]522        include "./host_view.php";
523        makeHostView();
524        break;
[149]525
[715]526    default:
[117]527
[715]528        makeOverview();
529        break;
[117]530}
531
532makeFooter();
533$tpl->printToScreen();
[113]534?>
Note: See TracBrowser for help on using the repository browser.