source: trunk/web2/addons/job_monarch/jobstore.php @ 536

Last change on this file since 536 was 536, checked in by ramonb, 16 years ago

job_monarch/js/jobgrid.js:

  • remove Ext.onReady event: call from HTML
  • remove debug listeners

job_monarch/header.php:

job_monarch/jobstore.php:

  • parse clustername from POST and set it into GET to fool Ganglia
File size: 3.2 KB
Line 
1<?php
2
3$c                      = $_POST["c"];
4$clustername            = $c;
5$cluster                = $c;
6
7global $c, $clustername, $cluster;
8
9$HTTP_POST_VARS["c"]    = $c;
10$_GET["c"]              = $c;
11
12global $c, $clustername, $cluster;
13
14include_once "./libtoga.php";
15
16$ds             = new DataSource();
17$myxml_data     = &$ds->getData();
18
19//printf( "d %s\n", strlen( $myxml_data ) );
20//return 0;
21
22global $jobs;
23
24$data_gatherer  = new DataGatherer( $clustername );
25$data_gatherer->parseXML( &$myxml_data );
26
27$heartbeat      = &$data_gatherer->getHeartbeat();
28$jobs           = &$data_gatherer->getJobs();
29//$gnodes         = $data_gatherer->getNodes();
30$cpus           = &$data_gatherer->getCpus();
31$use_fqdn       = &$data_gatherer->getUsingFQDN();
32
33// The ext grid script will send  a task field which will specify what it wants to do
34//$task = '';
35
36if( isset($_POST['task']) )
37{
38        $task = $_POST['task'];
39}
40if( isset( $HTTP_POST_VARS['task' ] ) )
41{
42        $task = $HTTP_POST_VARS['task'];
43}
44
45//getList();
46
47switch($task)
48{
49    case "LISTING":
50        getList();
51        break;         
52    default:
53        echo "{failure:true}";
54        break;
55}
56
57function getList() 
58{
59        global $jobs, $hearbeat;
60
61        $job_count      = count( $jobs );
62
63        if( $job_count == 0 )
64        {
65                echo 'crap({"total":"0", "results":""})';
66                return 0;
67        }
68
69        $jobresults     = array();
70
71        foreach( $jobs as $jobid => $jobattrs )
72        {
73                //if( $jobattrs['reported'] != $heartbeat )
74                //{
75                //      continue;
76                //}
77
78                $jr['jid']              = strval( $jobid );
79                $jr['status']           = $jobattrs['status'];
80                $jr['owner']            = $jobattrs['owner'];
81                $jr['queue']            = $jobattrs['queue'];
82                $jr['name']             = $jobattrs['name'];
83                $jr['requested_time']   = makeTime( timeToEpoch( $jobattrs['requested_time'] ) );
84
85                if( $jr['status'] == 'R' )
86                {
87                        $nodes          = count( $jobattrs[nodes] );
88                }
89                else
90                {
91                        $nodes          = (int) $jobattrs[nodes];
92                }
93
94                $jr['ppn']              = strval( $jobattrs[ppn] ? $jobattrs[ppn] : 1 );
95                $jr['nodect']           = strval( $nodes );
96
97                if( $jr['status'] == 'R' )
98                {
99                        $jr['nodes']    = implode( ",", $jobattrs['nodes'] );
100                }
101                else
102                {
103                        $jr['nodes']    = "";
104                }
105
106                $jr['queued_timestamp'] = makeDate( $jobattrs['queued_timestamp'] );
107                $jr['start_timestamp']  = ($jobattrs['start_timestamp'] ? makeDate( $jobattrs['start_timestamp'] ) : "");
108
109                if( $jr['status'] == 'R' )
110                {
111                        $runningtime            = (int) $jobattrs['reported'] - (int) $jobattrs['start_timestamp'];
112                        $jr['runningtime']      = makeTime( $runningtime );
113                }
114                else
115                {
116                        $jr['runningtime']      = "";
117                }
118
119                $jobresults[]           = $jr;
120        }
121
122
123        //$results      = array();
124
125        //foreach( $jobresults as $resid => $jr )
126        //{
127        //      $jr_count       = 0;
128        //      $job_record     = array();
129
130        //      foreach( $jr as $atrname => $atrval )
131        //      {
132        //              $job_record[$jr_count]  = $atrval;
133        //              $job_record[$atrname]   = $atrval;
134
135        //              $jr_count               = $jr_count + 1;
136        //      }
137
138        //      $results[]      = $job_record;
139        //}
140
141        $jsonresults    = JEncode( $jobresults );
142
143        echo '{"total":"'. count( $jobresults) .'","results":'. $jsonresults .'}';
144
145        return 0;
146}
147
148// Encodes a SQL array into a JSON formated string
149function JEncode( $arr )
150{
151        if (version_compare(PHP_VERSION,"5.2","<"))
152        {   
153                require_once("./JSON.php"); //if php<5.2 need JSON class
154
155                $json   = new Services_JSON();//instantiate new json object
156                $data   = $json->encode($arr);  //encode the data in json format
157        } 
158        else
159        {
160                $data   = json_encode($arr);  //encode the data in json format
161        }
162
163        return $data;
164}
165
166?> 
Note: See TracBrowser for help on using the repository browser.