source: trunk/web/addons/job_monarch/index.php @ 323

Last change on this file since 323 was 323, checked in by bastiaans, 17 years ago

web/addons/job_monarch/index.php:

  • It's now: Batch Report instead of Torque
  • Property svn:keywords set to Id
File size: 11.1 KB
Line 
1<?php
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 *
22 * SVN $Id: index.php 323 2007-04-19 10:38:45Z bastiaans $
23 */
24
25if ( !empty( $_GET ) ) {
26        extract( $_GET );
27}
28
29$my_dir = getcwd();
30
31include_once "./libtoga.php";
32
33global $GANGLIA_PATH;
34chdir( $GANGLIA_PATH );
35
36include_once "./class.TemplatePower.inc.php";
37chdir( $my_dir );
38
39$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
40$clustername = $httpvars->getClusterName();
41$view = $httpvars->getHttpVar( "view" );
42
43$filter = array();
44
45if( !isset($view) ) $view = "overview";
46if( !isset($sortorder) ) $sortorder = "asc";
47if( !isset($sortby) ) $sortby = "id";
48
49if( isset( $filterorder ) && ($filterorder!='') ) {
50        $myfilter_fields = explode( ",", $filterorder );
51} else {
52        if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
53        if( isset($state) && ($state!='')) $filter[state]=$state;
54        if( isset($user) && ($user!='')) $filter[user]=$user;
55        if( isset($id) && ($id!='')) $filter[id]=$id;
56}
57
58// Fill filter array in order they were picked by user
59if( isset($myfilter_fields) ) {
60
61        foreach( $myfilter_fields as $myfilter ) {
62
63                switch( $myfilter ) {
64
65                        case "queue":
66                                $filter[queue]=$queue;
67                                break;
68                        case "state":
69                                $filter[state]=$state;
70                                break;
71                        case "user":
72                                $filter[user]=$user;
73                                break;
74                        case "id":
75                                $filter[id]=$id;
76                                break;
77                }
78        }
79}
80
81//if( isset($queue) && ($queue!='')) $filter[queue]=$queue;
82//if( isset($state) && ($state!='')) $filter[state]=$state;
83//if( isset($user) && ($user!='')) $filter[user]=$user;
84//if( isset($id) && ($id!='')) $filter[id]=$id;
85
86function epochToDatetime( $epoch ) {
87
88        return strftime( "%d-%m-%Y %H:%M:%S", $epoch );
89}
90
91function makeHeader( $page_call ) {
92
93        global $tpl, $grid, $context, $initgrid;
94        global $jobrange, $jobstart, $title;
95        global $page, $gridwalk, $clustername;
96        global $parentgrid, $physical, $hostname;
97        global $self, $filter, $cluster_url, $get_metric_string;
98        global $metrics, $reports, $m, $default_metric;
99        global $default_refresh, $filterorder, $view;
100        global $JOB_ARCHIVE, $period_start, $period_stop, $h, $id;
101        global $job_start, $job_stop;
102       
103        if( isset($default_metric) and !isset($m) )
104                $metricname = $default_metric;
105        else
106                if( isset( $m ) )
107                        $metricname = $m;
108                else
109                        $metricname = "load_one";
110
111        $header = "header";
112
113        # Maintain our path through the grid tree.
114        $me = $self . "@" . $grid[$self][AUTHORITY];
115
116        $gridstack = array();
117        $gridstack[] = $me;
118
119        if ($gridwalk=="fwd") {
120                # push our info on gridstack, format is "name@url>name2@url".
121                if (end($gridstack) != $me) {
122                        $gridstack[] = $me;
123                }
124        } else if ($gridwalk=="back") {
125                # pop a single grid off stack.
126                if (end($gridstack) != $me) {
127                        array_pop($gridstack);
128                }
129        }
130
131        $gridstack_str = join(">", $gridstack);
132        $gridstack_url = rawurlencode($gridstack_str);
133
134        if ($initgrid or $gridwalk) {
135                # Use cookie so we dont have to pass gridstack around within this site.
136                # Cookie values are automatically urlencoded. Expires in a day.
137                setcookie("gs", $gridstack_str, time() + 86400);
138        }
139
140        # Invariant: back pointer is second-to-last element of gridstack. Grid stack never
141        # has duplicate entries.
142        list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
143
144        # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
145        # destination server that we're walking foward in the grid tree.
146        if (strstr($clustername, "http://")) {
147                $tpl->assign("refresh", "0");
148                $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
149                echo "<h2>Redirecting, please wait...</h2>";
150                $tpl->printToScreen();
151                exit;
152        }
153
154        if( $view != "search" )
155                $tpl->assign( "refresh", $default_refresh );
156
157        $tpl->assign( "date", date("r") );
158        $tpl->assign( "page_title", $title );
159
160        # The page to go to when "Get Fresh Data" is pressed.
161        $tpl->assign("page","./");
162
163        # Templated Logo image
164        $tpl->assign("images","./templates/$template_name/images");
165
166        #
167        # Used when making graphs via graph.php. Included in most URLs
168        #
169        $sort_url=rawurlencode($sort);
170        $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
171
172        if ($jobrange and $jobstart)
173                $get_metric_string .= "&jr=$jobrange&js=$jobstart";
174
175        # Set the Alternate view link.
176        $cluster_url=rawurlencode($clustername);
177        $node_url=rawurlencode($hostname);
178
179        # Make some information available to templates.
180        $tpl->assign("cluster_url", $cluster_url);
181        # Build the node_menu
182        $node_menu = "";
183
184        if ($parentgrid) {
185                $node_menu .= "<B>$parentgrid $meta_designator</B> ";
186                $node_menu .= "<B>&gt;</B>\n";
187        }
188
189        # Show grid.
190        $mygrid =  ($self == "unspecified") ? "" : $self;
191        $node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> ";
192        $node_menu .= "<B>&gt;</B>\n";
193
194        if ($physical)
195                $node_menu .= hiddenvar("p", $physical);
196
197        if ( $clustername ) {
198                $url = rawurlencode($clustername);
199                $node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
200                $node_menu .= "<B>&gt;</B>\n";
201                $node_menu .= hiddenvar("c", $clustername);
202        }
203
204        if (!count($metrics)) {
205                echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";       echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
206                exit;
207        }
208        $firsthost = key($metrics);
209        foreach ($metrics[$firsthost] as $m => $foo)
210                $context_metrics[] = $m;
211
212        foreach ($reports as $r => $foo)
213                $context_metrics[] = $r;
214
215        $node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
216
217        if( isset( $hostname ) ) {
218
219                $node_menu .= "<B>&gt;</B>\n";
220                $href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
221                $node_menu .= "<B>$href";
222                $node_menu .= "host: $hostname</A></B> ";
223        }
224
225        if( count( $filter ) > 0 && $view != "search" ) {
226
227                $my_ct = 1;
228                $filter_nr = count( $filter );
229
230                foreach( $filter as $filtername=>$filterval ) {
231
232                        $node_menu .= "<B>&gt;</B>\n";
233
234                        $href = "<A HREF=\"./?c=".rawurlencode($clustername);
235                        $temp_ct = 0;
236                        $n_filter = $filter;
237                        $my_filterorder = "";
238                        $my_filters = array_keys( $filter );
239
240                        foreach( $n_filter as $n_filtername=>$n_filterval ) {
241
242                                if( $temp_ct < $my_ct ) {
243                                        $href .= "&". $n_filtername . "=" . $n_filterval;
244
245                                        if( $my_filterorder == "" )
246                                                $my_filterorder = $my_filters[$temp_ct];
247                                        else
248                                                $my_filterorder .= "," . $my_filters[$temp_ct];
249                                }
250
251                                $temp_ct++;
252                        }
253                        $href .= "&filterorder=$my_filterorder\">";
254
255                        if( $my_ct < $filter_nr )
256                                $node_menu .= "<B>$href$filtername: $filterval</A></B> ";
257                        else
258                                $node_menu .= "<B>$filtername: $filterval</B> ";
259
260                        $my_ct++;
261                }
262        }
263
264        $m = $metricname;
265
266
267        $tpl->gotoBlock( "_ROOT" );
268        $tpl->assignGlobal("view", $view);
269
270        if( array_key_exists( "id", $filter ) or isset($hostname) ) {
271
272                //print_r( $context_metrics );
273
274                if( !isset( $hostname ) ) {
275
276                        if (is_array($context_metrics) ) {
277                                $metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
278                                        ."<SELECT NAME=\"m\" OnChange=\"".$form_name.".submit();\">\n";
279
280                                sort($context_metrics);
281                                foreach( $context_metrics as $k ) {
282                                        $url = rawurlencode($k);
283                                        $metric_menu .= "<OPTION VALUE=\"$url\" ";
284                                        if ($k == $metricname )
285                                                $metric_menu .= "SELECTED";
286                                        $metric_menu .= ">$k\n";
287                                }
288                                $metric_menu .= "</SELECT>\n";
289
290                        }
291                }
292
293                $tpl->assign("metric_menu", $metric_menu );
294
295                if( $view == "search" or $view == "host" ) {
296                        $tpl->newBlock("timeperiod");
297                        if( is_numeric( $period_start ) ) {
298                                $period_start = epochToDatetime( $period_start );
299                        }
300                        if( is_numeric( $period_stop ) ) {
301                                $period_stop = epochToDatetime( $period_stop );
302                        }
303                        $tpl->assign("period_start", $period_start );
304                        $tpl->assign("period_stop", $period_stop );
305                        $tpl->assign("hostname", $hostname );
306
307                        if( $view == "host" ) {
308                                $tpl->newBlock("hostview");
309                                $tpl->assign("job_start", $job_start );
310                                $tpl->assign("job_stop", $job_stop );
311                        }
312                }
313
314        }
315
316        //$ex_fn = $tpl->getVarValue( "_ROOT", "form_name" );
317
318        if( $view == "search" or $view == "host" ) {
319
320                $node_menu .= "<B>&gt;</B>\n";
321                $node_menu .= "<B>Jobarchive</B> ";
322                $form_name = "archive_search_form";
323                $tpl->assignGlobal("form_name", $form_name );
324
325        } else {
326                $form_name = "toga_form";
327                $tpl->assignGlobal("form_name", $form_name );
328        }
329
330        if( $JOB_ARCHIVE && $page_call == 'index' ) {
331                $tpl->newBlock( "search" );
332                $tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
333                $tpl->assignGlobal( "cluster", $clustername );
334        }
335        $tpl->gotoBlock( "_ROOT" );
336        $tpl->assignGlobal( "cluster", $clustername );
337        $tpl->assign("node_menu", $node_menu);
338
339        # Make sure that no data is cached..
340        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
341        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
342        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
343        header ("Pragma: no-cache");                          # HTTP/1.0
344}
345
346function makeFooter() {
347        global $tpl, $version, $parsetime, $monarchversion;
348
349        $tpl->gotoBlock( "_ROOT" );
350        $tpl->assign("webfrontend-version",$version["webfrontend"]);
351        $tpl->assign("monarch-version", $monarchversion);
352
353        if ($version["gmetad"]) {
354                $tpl->assign("webbackend-component", "gmetad");
355                $tpl->assign("webbackend-version",$version["gmetad"]);
356        } else if ($version["gmond"]) {
357                $tpl->assign("webbackend-component", "gmond");
358                $tpl->assign("webbackend-version", $version["gmond"]);
359        }
360
361        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
362}
363
364function includeSearchpage() {
365        global $tpl;
366
367        $tpl->assignInclude( "main", "templates/search.tpl" );
368
369}
370
371function includeOverview() {
372        global $tpl;
373
374        $tpl->assignInclude( "main", "templates/overview.tpl" );
375}
376
377function includeHostPage() {
378
379        global $tpl;
380
381        $tpl->assignInclude( "main", "templates/host_view.tpl" );
382}
383
384$tpl = new TemplatePower( "templates/index.tpl" );
385
386$tpl->assignInclude( "header", "templates/header.tpl" );
387
388if( isset( $h ) and $h != '' ) {
389        $hostname = $h;
390        //$view = "host";
391}
392
393switch( $view ) {
394
395        case "overview":
396
397                includeOverview();
398                break;
399
400        case "search":
401
402                includeSearchPage();
403                break;
404
405        //case "host":
406
407        //      includeHostPage();
408        //      break;
409
410        default:
411
412                includeOverview();
413                break;
414}
415
416$tpl->assignInclude( "footer", "templates/footer.tpl" );
417$tpl->prepare();
418
419$title = "Batch Report";
420makeHeader( 'index' );
421$tpl->assign("cluster_url", rawurlencode($clustername) );
422$tpl->assign("cluster", $clustername );
423
424switch( $view ) {
425
426        case "overview":
427
428                include "./overview.php";
429                makeOverview();
430                break;
431
432        case "search":
433
434                include "./search.php";
435                makeSearchPage();
436                break;
437
438        //case "host":
439
440        //      include "./host_view.php";
441        //      makeHostView();
442        //      break;
443
444        default:
445
446                makeOverview();
447                break;
448}
449
450makeFooter();
451$tpl->printToScreen();
452?>
Note: See TracBrowser for help on using the repository browser.