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

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

web2:

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