Changeset 117 for trunk


Ignore:
Timestamp:
05/31/05 16:13:43 (19 years ago)
Author:
bastiaans
Message:

eb/addons/toga/templates/header.tpl:

  • Added closing </FORM>

web/addons/toga/templates/index.tpl:

  • Skeleton template for base page

web/addons/toga/templates/overview.tpl:

  • Added javascript and FORM to be able to sort joblist

web/addons/toga/index.php:

  • Changed to be basis for all
  • Will present a job/queue or overview based on arguments

web/addons/toga/overview.php:

  • Changed for new index skeleton
  • Will sort joblist now

web/addons/toga/libtoga.php, web/addons/toga/image.php:

  • Some fixes/cleanup for index skeleton
Location:
trunk/web/addons/toga
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/web/addons/toga/image.php

    r114 r117  
    22include_once "./libtoga.php";
    33
    4 $httpvars = new HTTPVariables( $HTTP_GET_VARS );
     4$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
    55$view = $httpvars->getHttpVar( "view" );
    66$clustername = $httpvars->getClusterName();
  • trunk/web/addons/toga/index.php

    r113 r117  
    11<?php
    22
     3if ( !empty( $_GET ) ) {
     4        extract( $_GET );
     5}
     6
    37$my_dir = getcwd();
    48
    59include_once "./libtoga.php";
    610
    7 global $GANGLIA_PATH, $context;
     11global $GANGLIA_PATH;
    812chdir( $GANGLIA_PATH );
    9 $context = 'cluster';
    10 
    11 $title = "Torque Report";
    12 include_once "./get_context.php";
     13
    1314include_once "./class.TemplatePower.inc.php";
    1415chdir( $my_dir );
    15 include_once "header.php";
    16 
    17 include_once "overview.php";
    18 
    19 include_once "footer.php";
     16
     17$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
     18$clustername = $httpvars->getClusterName();
     19$view = $httpvars->getHttpVar( "view" );
     20
     21if( !isset($view) ) $view = "overview";
     22if( !isset($sortorder) ) $sortorder = "asc";
     23if( !isset($sortby) ) $sortby = "id";
     24
     25function makeHeader() {
     26
     27        global $tpl, $grid, $context, $initgrid;
     28        global $jobrange, $jobstart, $title;
     29        global $page, $gridwalk, $clustername;
     30        global $parentgrid, $physical, $hostname;
     31        global $self;
     32
     33        if ( $context == "control" && $controlroom < 0 )
     34                $header = "header-nobanner";
     35        else
     36                $header = "header";
     37
     38        # Maintain our path through the grid tree.
     39        $me = $self . "@" . $grid[$self][AUTHORITY];
     40
     41        if ($initgrid) {
     42                $gridstack = array();
     43                $gridstack[] = $me;
     44        } else if ($gridwalk=="fwd") {
     45                # push our info on gridstack, format is "name@url>name2@url".
     46                if (end($gridstack) != $me) {
     47                        $gridstack[] = $me;
     48                }
     49        } else if ($gridwalk=="back") {
     50                # pop a single grid off stack.
     51                if (end($gridstack) != $me) {
     52                        array_pop($gridstack);
     53                }
     54        }
     55
     56        $gridstack_str = join(">", $gridstack);
     57        $gridstack_url = rawurlencode($gridstack_str);
     58
     59        if ($initgrid or $gridwalk) {
     60                # Use cookie so we dont have to pass gridstack around within this site.
     61                # Cookie values are automatically urlencoded. Expires in a day.
     62                setcookie("gs", $gridstack_str, time() + 86400);
     63        }
     64
     65        # Invariant: back pointer is second-to-last element of gridstack. Grid stack never
     66        # has duplicate entries.
     67        list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
     68
     69        # Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
     70        # destination server that we're walking foward in the grid tree.
     71        if (strstr($clustername, "http://")) {
     72                $tpl->assign("refresh", "0");
     73                $tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
     74                echo "<h2>Redirecting, please wait...</h2>";
     75                $tpl->printToScreen();
     76                exit;
     77        }
     78
     79        $tpl->assign( "refresh", $default_refresh );
     80        $tpl->assign( "date", date("r") );
     81        $tpl->assign( "page_title", $title );
     82
     83        # The page to go to when "Get Fresh Data" is pressed.
     84        if (isset($page))
     85                $tpl->assign("page",$page);
     86        else
     87                $tpl->assign("page","./");
     88
     89        # Templated Logo image
     90        $tpl->assign("images","./templates/$template_name/images");
     91
     92        #
     93        # Used when making graphs via graph.php. Included in most URLs
     94        #
     95        $sort_url=rawurlencode($sort);
     96        $get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
     97
     98        if ($jobrange and $jobstart)
     99                $get_metric_string .= "&jr=$jobrange&js=$jobstart";
     100
     101        # Set the Alternate view link.
     102        $cluster_url=rawurlencode($clustername);
     103        $node_url=rawurlencode($hostname);
     104
     105        # Make some information available to templates.
     106        $tpl->assign("cluster_url", $cluster_url);
     107        # Build the node_menu
     108        $node_menu = "";
     109
     110        if ($parentgrid) {
     111                $node_menu .= "<B>$parentgrid $meta_designator</B> ";
     112                $node_menu .= "<B>&gt;</B>\n";
     113        }
     114
     115        # Show grid.
     116        $mygrid =  ($self == "unspecified") ? "" : $self;
     117        $node_menu .= "<B>$mygrid $meta_designator</A> ";
     118        $node_menu .= "<B>&gt;</B>\n";
     119
     120        if ($physical)
     121                $node_menu .= hiddenvar("p", $physical);
     122
     123        if ( $clustername ) {
     124                $url = rawurlencode($clustername);
     125                $node_menu .= "<B>$clustername</B> ";
     126                //$node_menu .= "<B>&gt;</B>\n";
     127                $node_menu .= hiddenvar("c", $clustername);
     128        }
     129
     130        $tpl->assign("node_menu", $node_menu);
     131
     132        # Make sure that no data is cached..
     133        header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
     134        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
     135        header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
     136        header ("Pragma: no-cache");                          # HTTP/1.0
     137}
     138
     139function makeFooter() {
     140        global $tpl, $version, $parsetime;
     141
     142        $tpl->assign("webfrontend-version",$version["webfrontend"]);
     143        $tpl->assign("togaweb-version", "0.1");
     144        $tpl->assign("togaarch-version", "0.1");
     145        $tpl->assign("togaplug-version", "0.1");
     146
     147        if ($version["gmetad"]) {
     148                $tpl->assign("webbackend-component", "gmetad");
     149                $tpl->assign("webbackend-version",$version["gmetad"]);
     150        } else if ($version["gmond"]) {
     151                $tpl->assign("webbackend-component", "gmond");
     152                $tpl->assign("webbackend-version", $version["gmond"]);
     153        }
     154
     155        $tpl->assign("parsetime", sprintf("%.4f", $parsetime) . "s");
     156}
     157
     158function includeJobview() {
     159        global $tpl;
     160
     161        $tpl->assignInclude( "main", "templates/jobview.tpl" );
     162}
     163
     164function includeOverview() {
     165        global $tpl;
     166
     167        $tpl->assignInclude( "main", "templates/overview.tpl" );
     168}
     169
     170function makeJobview() {
     171
     172}
     173
     174//function makeOverview() {
     175//
     176//      global $jobs, $nodes, $heartbeat, $clustername;
     177
     178//      foreach( $jobs as $jobid => $jobattrs ) {
     179//
     180//              $report_time = $jobattrs[reported];
     181
     182//              if( $report_time == $heartbeat ) {
     183
     184//                      $tpl->newBlock("node");
     185//                      $tpl->assign( "clustername", $clustername );
     186//                      $tpl->assign("id", $jobid );
     187//                      $tpl->assign("state", $jobattrs[status] );
     188//                      $tpl->assign("user", $jobattrs[owner] );
     189//                      $tpl->assign("queue", $jobattrs[queue] );
     190//                      $tpl->assign("name", $jobattrs[name] );
     191//                      $tpl->assign("req_cpu", $jobattrs[requested_time] );
     192//                      $tpl->assign("req_memory", $jobattrs[requested_memory] );
     193//                      $nodes = count( $jobattrs[nodes] );
     194//                      $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
     195//                      $cpus = $nodes * $ppn;
     196//                      $tpl->assign("nodes", $nodes );
     197//                      $tpl->assign("cpus", $cpus );
     198//                      $start_time = (int) $jobattrs[start_timestamp];
     199
     200//                      if( $start_time ) {
     201
     202//                              $runningtime = makeTime( $report_time - $start_time );
     203//                              $tpl->assign("started", makeDate( $start_time ) );
     204//                              $tpl->assign("runningtime", $runningtime );
     205//                      }
     206//              }
     207//      }
     208//}
     209
     210$tpl = new TemplatePower( "templates/index.tpl" );
     211
     212$tpl->assignInclude( "header", "templates/header.tpl" );
     213
     214switch( $view ) {
     215
     216        case "overview":
     217
     218                includeOverview();
     219                break;
     220
     221        case "jobview":
     222
     223                includeJobview();
     224                break;
     225
     226        default:
     227
     228                includeOverview();
     229                break;
     230}
     231
     232$tpl->assignInclude( "footer", "templates/footer.tpl" );
     233$tpl->prepare();
     234
     235$title = "Torque Report";
     236makeHeader();
     237
     238switch( $view ) {
     239
     240        case "overview":
     241
     242                include "./overview.php";
     243                makeOverview();
     244                break;
     245
     246        case "jobview":
     247
     248                makeJobview();
     249                break;
     250
     251        default:
     252
     253                makeOverview();
     254                break;
     255}
     256
     257makeFooter();
     258
     259$tpl->printToScreen();
    20260?>
  • trunk/web/addons/toga/libtoga.php

    r115 r117  
    11<?php
     2// If php is compiled without globals
     3//
     4if ( !empty( $_GET ) ) {
     5        extract( $_GET );
     6}
     7
    28class HTTPVariables {
    39
     
    511        var $restvars, $httpvars;
    612
    7         function HTTPVariables( $vars ) {
     13        function HTTPVariables( $httpvars, $getvars ) {
    814
    915                $this->restvars = array();
    1016
    11                 $this->clustername = $vars["c"] ? $vars["c"] : null;
    12                 $this->metricname = $vars["m"] ? $vars["m"] : null;
    13 
    14                 foreach( $vars as $httpvar => $httpval ) {
     17                $this->clustername = $httpvars["c"] ? $httpvars["c"] : null;
     18                $this->metricname = $httpvars["m"] ? $httpvars["m"] : null;
     19
     20                foreach( $httpvars as $httpvar => $httpval ) {
    1521                       
    1622                        if( $httpval ) {
    1723                                $this->restvars[$httpvar] = $httpval;
     24                        }
     25                }
     26
     27                foreach( $getvars as $getvar => $getval ) {
     28
     29                        if( $getval ) {
     30                                $this->restvars[$getvar] = $getval;
    1831                        }
    1932                }
     
    4053include_once "./conf.php";
    4154
    42 global $GANGLIA_PATH, $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE;
    43 
    44 include_once "$GANGLIA_PATH/conf.php";
    45 include_once "$GANGLIA_PATH/functions.php";
    46 include_once "$GANGLIA_PATH/ganglia.php";
    47 
    48 global $HTTP_GET_VARS;
    49 $httpvars = new HTTPVariables( $HTTP_GET_VARS );
     55global $GANGLIA_PATH;
     56
     57$my_dir = getcwd();
     58
     59// Load Ganglia's PHP
     60chdir( $GANGLIA_PATH );
     61
     62include_once "./conf.php";
     63include_once "./functions.php";
     64include_once "./ganglia.php";
     65include_once "./get_context.php";
     66include_once "./get_ganglia.php";
     67
     68// Back to our PHP
     69chdir( $my_dir );
     70
     71global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH, $DATA_SOURCE, $HTTP_GET_VARS, $_GET;
     72$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
    5073
    5174// Set cluster context so that Ganglia will
     
    5376//
    5477global $context, $clustername;
    55 $clustername = $httpvars->getClusterName();
    56 $context = 'cluster';
    57 
    58 include_once "$GANGLIA_PATH/get_ganglia.php";
     78//$clustername = $httpvars->getClusterName();
     79//$context = 'cluster';
    5980
    6081// Ganglia's array of host metrics
     
    6283global $metrics;
    6384
    64 // If php is compiled without globals
    65 //
    66 if ( !empty( $_GET ) ) {
    67         extract( $_GET );
    68 }
    6985
    7086class DataSource {
  • trunk/web/addons/toga/overview.php

    r116 r117  
    11<?php
    2 
    3 $my_dir = getcwd();
    4 
    5 include_once "./libtoga.php";
    6 
    7 global $GANGLIA_PATH;
    8 chdir( $GANGLIA_PATH );
    9 include_once "./class.TemplatePower.inc.php";
    10 chdir( $my_dir );
    11 
    12 $httpvars = new HTTPVariables( $HTTP_GET_VARS );
    13 $clustername = $httpvars->getClusterName();
    14 printf( "clustername = %s\n", $clustername );
    15 $queue_select = $httpvars->getHttpVar( "queue" );
    16 printf( "queue = %s\n", $queue );
     2global $GANGLIA_PATH, $clustername, $tpl;
    173
    184$data_gatherer = new DataGatherer();
    195
    20 $tpl = new TemplatePower("templates/overview.tpl");
    21 $tpl->prepare();
    22 
    23 $tpl->assign( "self", "./index.php" );
     6//$tpl->assign( "self", "./index.php" );
    247$tpl->assign( "clustername", $clustername );
    25 
    268$tpl->assign( "clusterimage", "./image.php?c=".rawurlencode($clustername)."&view=big-clusterimage" );
    279
    2810$data_gatherer->parseXML();
     11
    2912$heartbeat = $data_gatherer->getHeartbeat();
    3013$jobs = $data_gatherer->getJobs();
     
    214197}
    215198
    216 foreach( $jobs as $jobid => $jobattrs ) {
    217 
    218         $report_time = $jobattrs[reported];
    219 
    220         if( $report_time == $heartbeat ) {
    221 
    222                 $tpl->newBlock("node");
    223                 $tpl->assign( "clustername", $clustername );
    224                 $tpl->assign("id", $jobid );
    225                 $tpl->assign("state", $jobattrs[status] );
    226                 $tpl->assign("user", $jobattrs[owner] );
    227                 $tpl->assign("queue", $jobattrs[queue] );
    228                 $tpl->assign("name", $jobattrs[name] );
    229                 $tpl->assign("req_cpu", $jobattrs[requested_time] );
    230                 $tpl->assign("req_memory", $jobattrs[requested_memory] );
    231                 $nodes = count( $jobattrs[nodes] );
    232                 $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
    233                 $cpus = $nodes * $ppn;
    234                 $tpl->assign("nodes", $nodes );
    235                 $tpl->assign("cpus", $cpus );
    236                 $start_time = (int) $jobattrs[start_timestamp];
    237 
    238                 if( $start_time ) {
    239 
    240                         $runningtime = makeTime( $report_time - $start_time );
    241                         $tpl->assign("started", makeDate( $start_time ) );
    242                         $tpl->assign("runningtime", $runningtime );
     199
     200function sortJobs( $jobs, $sortby, $sortorder ) {
     201
     202        $sorted = array();
     203
     204        $cmp = create_function( '$a, $b',
     205                "global \$sortby, \$sortorder;".
     206
     207                "if( \$a == \$b ) return 0;".
     208
     209                "if (\$sortorder==\"desc\")".
     210                        "return ( \$a < \$b ) ? 1 : -1;".
     211                "else if (\$sortorder==\"asc\")".
     212                        "return ( \$a > \$b ) ? 1 : -1;" );
     213
     214        foreach( $jobs as $jobid => $jobattrs ) {
     215
     216                        $state = $jobattrs[status];
     217                        $user = $jobattrs[owner];
     218                        $queue = $jobattrs[queue];
     219                        $name = $jobattrs[name];
     220                        $req_cpu = $jobattrs[requested_time];
     221                        $req_memory = $jobattrs[requested_memory];
     222                        $nodes = count( $jobattrs[nodes] );
     223                        $ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
     224                        $cpus = $nodes * $ppn;
     225                        $start_time = (int) $jobattrs[start_timestamp];
     226                        $runningtime = $report_time - $start_time;
     227
     228                        switch( $sortby ) {
     229                                case "id":
     230                                        $sorted[$jobid] = $jobid;
     231                                        break;
     232
     233                                case "state":
     234                                        $sorted[$jobid] = $state;
     235                                        break;
     236
     237                                case "user":
     238                                        $sorted[$jobid] = $user;
     239                                        break;
     240
     241                                case "queue":
     242                                        $sorted[$jobid] = $queue;
     243                                        break;
     244
     245                                case "name":
     246                                        $sorted[$jobid] = $name;
     247                                        break;
     248
     249                                case "req_cpu":
     250                                        $sorted[$jobid] = $req_cpu;
     251                                        break;
     252
     253                                case "req_mem":
     254                                        $sorted[$jobid] = $req_memory;
     255                                        break;
     256
     257                                case "nodes":
     258                                        $sorted[$jobid] = $nodes;
     259                                        break;
     260
     261                                case "cpus":
     262                                        $sorted[$jobid] = $cpus;
     263                                        break;
     264
     265                                case "start":
     266                                        $sorted[$jobid] = $start_time;
     267                                        break;
     268
     269                                case "runningtime":
     270                                        $sorted[$jobid] = $runningtime;
     271                                        break;
     272
     273                                default:
     274                                        break;
     275
     276                        }
     277        }
     278
     279        uasort( $sorted, $cmp );
     280
     281        return $sorted;
     282}
     283
     284function makeOverview() {
     285
     286        global $jobs, $nodes, $heartbeat, $clustername, $tpl;
     287        global $sortorder, $sortby;
     288
     289        $tpl->assign("sortorder", $sortorder );
     290        $tpl->assign("sortby", $sortby );
     291
     292
     293        $sorted_jobs = sortJobs( $jobs, $sortby, $sortorder );
     294
     295        foreach( $sorted_jobs as $jobid => $sortdec ) {
     296
     297                $report_time = $jobs[$jobid][reported];
     298
     299                if( $report_time == $heartbeat ) {
     300
     301                        $tpl->newBlock("node");
     302                        $tpl->assign( "clustername", $clustername );
     303                        $tpl->assign("id", $jobid );
     304                        $tpl->assign("state", $jobs[$jobid][status] );
     305                        $tpl->assign("user", $jobs[$jobid][owner] );
     306                        $tpl->assign("queue", $jobs[$jobid][queue] );
     307                        $tpl->assign("name", $jobs[$jobid][name] );
     308                        $tpl->assign("req_cpu", $jobs[$jobid][requested_time] );
     309                        $tpl->assign("req_memory", $jobs[$jobid][requested_memory] );
     310                        $nodes = count( $jobs[$jobid][nodes] );
     311                        $ppn = (int) $jobs[$jobid][ppn] ? $jobs[$jobid][ppn] : 1;
     312                        $cpus = $nodes * $ppn;
     313                        $tpl->assign("nodes", $nodes );
     314                        $tpl->assign("cpus", $cpus );
     315                        $start_time = (int) $jobs[$jobid][start_timestamp];
     316
     317                        if( $start_time ) {
     318
     319                                $runningtime = makeTime( $report_time - $start_time );
     320                                $tpl->assign("started", makeDate( $start_time ) );
     321                                $tpl->assign("runningtime", $runningtime );
     322                        }
    243323                }
    244324        }
    245325}
    246 
    247 $tpl->printToScreen();
    248 
    249326?>
  • trunk/web/addons/toga/templates/header.tpl

    r113 r117  
    4545</TR>
    4646</TABLE>
     47</FORM>
    4748
    4849<FONT SIZE="+1">
Note: See TracChangeset for help on using the changeset viewer.