1 | <?php |
---|
2 | |
---|
3 | $clustername = "GINA Cluster"; |
---|
4 | $cluster= "GINA Cluster"; |
---|
5 | $c= "GINA Cluster"; |
---|
6 | |
---|
7 | global $c, $clustername, $cluster; |
---|
8 | |
---|
9 | include_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 | |
---|
17 | global $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 | |
---|
31 | if( isset($_POST['task']) ) |
---|
32 | { |
---|
33 | $task = $_POST['task']; |
---|
34 | } |
---|
35 | if( isset( $HTTP_POST_VARS['task' ] ) ) |
---|
36 | { |
---|
37 | $task = $HTTP_POST_VARS['task']; |
---|
38 | } |
---|
39 | |
---|
40 | //getList(); |
---|
41 | |
---|
42 | switch($task) |
---|
43 | { |
---|
44 | case "LISTING": |
---|
45 | getList(); |
---|
46 | break; |
---|
47 | default: |
---|
48 | echo "{failure:true}"; |
---|
49 | break; |
---|
50 | } |
---|
51 | |
---|
52 | function 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 | if( $reported != $heartbeat ) |
---|
70 | { // Old job: skip |
---|
71 | continue; |
---|
72 | } |
---|
73 | |
---|
74 | $jr['jid'] = strval( $jobid ); |
---|
75 | $jr['status'] = $jobattrs['status']; |
---|
76 | $jr['owner'] = $jobattrs['owner']; |
---|
77 | $jr['queue'] = $jobattrs['queue']; |
---|
78 | $jr['name'] = $jobattrs['name']; |
---|
79 | $jr['requested_time'] = makeTime( timeToEpoch( $jobattrs['requested_time'] ) ); |
---|
80 | |
---|
81 | if( $jobattrs[status] == 'R' ) |
---|
82 | { |
---|
83 | $nodes = count( $jobattrs[nodes] ); |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | $nodes = (int) $jobattrs[nodes]; |
---|
88 | } |
---|
89 | |
---|
90 | //unset( $jr['nodes'] ); |
---|
91 | //unset( $jr['poll_interval'] ); |
---|
92 | //unset( $jr['reported'] ); |
---|
93 | |
---|
94 | $jr['ppn'] = strval( $jobattrs[ppn] ? $jobattrs[ppn] : 1 ); |
---|
95 | $jr['cpu'] = strval( $nodes * (int) $ppn ); |
---|
96 | |
---|
97 | |
---|
98 | if( $jobattrs[status] == 'R' ) |
---|
99 | { |
---|
100 | $jr['nodes'] = implode( ",", $jobattrs['nodes'] ); |
---|
101 | } |
---|
102 | |
---|
103 | $jr['queued_timestamp'] = makeDate( $jobattrs['queued_timestamp'] ); |
---|
104 | $jr['start_timestamp'] = ($jobattrs['start_timestamp'] ? makeDate( $jobattrs['start_timestamp'] ) : ""); |
---|
105 | |
---|
106 | $jobresults[] = $jr; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | //$results = array(); |
---|
111 | |
---|
112 | //foreach( $jobresults as $resid => $jr ) |
---|
113 | //{ |
---|
114 | // $jr_count = 0; |
---|
115 | // $job_record = array(); |
---|
116 | |
---|
117 | // foreach( $jr as $atrname => $atrval ) |
---|
118 | // { |
---|
119 | // $job_record[$jr_count] = $atrval; |
---|
120 | // $job_record[$atrname] = $atrval; |
---|
121 | |
---|
122 | // $jr_count = $jr_count + 1; |
---|
123 | // } |
---|
124 | |
---|
125 | // $results[] = $job_record; |
---|
126 | //} |
---|
127 | |
---|
128 | $jsonresults = JEncode( $jobresults ); |
---|
129 | |
---|
130 | echo '{"total":"'. count( $jobresults) .'","results":'. $jsonresults .'}'; |
---|
131 | |
---|
132 | return 0; |
---|
133 | } |
---|
134 | |
---|
135 | // Encodes a SQL array into a JSON formated string |
---|
136 | function JEncode( $arr ) |
---|
137 | { |
---|
138 | if (version_compare(PHP_VERSION,"5.2","<")) |
---|
139 | { |
---|
140 | require_once("./JSON.php"); //if php<5.2 need JSON class |
---|
141 | |
---|
142 | $json = new Services_JSON();//instantiate new json object |
---|
143 | $data = $json->encode($arr); //encode the data in json format |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | $data = json_encode($arr); //encode the data in json format |
---|
148 | } |
---|
149 | |
---|
150 | return $data; |
---|
151 | } |
---|
152 | |
---|
153 | ?> |
---|