source: trunk/cluster_status.php@ 25

Last change on this file since 25 was 25, checked in by gegorbet, 7 years ago

merge us3iab/airavata gridctl code

File size: 11.2 KB
Line 
1<?php
2
3$us3bin = exec( "ls -d ~us3/lims/bin" );
4include "$us3bin/listen-config.php";
5
6if ( ! preg_match( "/localhost/", $dbhost ) )
7{
8 $xml = get_data();
9
10 if ( $xml != "" )
11 parse( $xml );
12}
13
14$data = array();
15
16local_status();
17
18foreach ( $data as $item )
19{
20 update( $item[ 'cluster' ], $item[ 'queued' ], $item[ 'status' ], $item[ 'running' ] );
21}
22
23exit();
24
25// Get the cluster status
26
27function get_data()
28{
29 global $self;
30 $url = "http://community.ucs.indiana.edu:19444/orps-service/XML/gateway/ultrascan";
31
32 try
33 {
34 $post = new HttpRequest( $url, HttpRequest::METH_GET );
35 $http = $post->send();
36 $xml = $post->getResponseBody();
37 }
38 catch ( HttpException $e )
39 {
40// write_log( "$self: Cluster Status not available" );
41 return "";
42 }
43
44 return $xml;
45}
46
47// Parse the xml
48
49function parse( $xml )
50{
51 global $data;
52
53 $data = array();
54
55 $x = new XML_Array( $xml );
56 $d = $x->ReturnArray();
57
58 if ( ! isset( $d[ 'summaries' ] ) ) exit(); // Bad input
59
60 foreach ( $d[ 'summaries' ] as $item )
61 {
62 $a = Array();
63
64
65 $a[ 'queued' ] = $item[ 'waitingJobs' ];
66 $a[ 'running' ] = $item[ 'runningJobs' ];
67
68 if ( $a[ 'queued' ] == "" || $a[ 'queued' ] < 0 ) $a[ 'queued' ] = 0;
69 if ( $a[ 'running' ] == "" || $a[ 'running' ] < 0 ) $a[ 'running' ] = 0;
70
71 $clusterParts = explode( ".", $item[ 'resourceId' ] );
72 $cluster = preg_replace( '/\d+$/', "", $clusterParts[ 0 ] );
73
74 if ( $cluster == 'uthscsa-bcf' ) $cluster = 'bcf';
75 if ( $cluster == 'uthscsa-alamo' ) $cluster = 'alamo';
76
77 $a[ 'cluster' ] = $cluster;
78
79 switch ( $item[ 'resourceStatus' ] )
80 {
81 case 'UP' :
82 $status = "up";
83 break;
84
85 case 'DOWN' :
86 $status = "down";
87 break;
88
89 case 'WARN' :
90 $status = "warn";
91 break;
92
93 case 'FAILED' :
94 default :
95 $status = "unknown";
96 break;
97 }
98
99 $a[ 'status' ] = $status;
100
101 $data[] = $a;
102 }
103}
104
105// Put it in the DB
106
107function update( $cluster, $queued, $status, $running )
108{
109 global $dbhost;
110 global $guser;
111 global $gpasswd;
112 global $gDB;
113 global $self;
114//echo " $cluster $queued, $status, $running\n";
115
116 $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
117 $result = mysql_select_db( $gDB, $gfac_link );
118
119 if ( ! $result )
120 {
121 write_log( "$self: Could not connect to DB $gDB" );
122 echo "Could not connect to DB $gDB.\n";
123 exit();
124 }
125
126 $query = "SELECT * FROM cluster_status WHERE cluster='$cluster'";
127 $result = mysql_query( $query, $gfac_link );
128
129 if ( ! $result )
130 {
131 write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
132 echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
133 exit();
134 }
135
136 $rows = mysql_num_rows( $result );
137
138 if ( $rows == 0 ) // INSERT
139 {
140 $query = "INSERT INTO cluster_status SET " .
141 "cluster='$cluster', " .
142 "queued=$queued, " .
143 "running=$running, " .
144 "status='$status'";
145 }
146 else // UPDATE
147 {
148 $query = "UPDATE cluster_status SET " .
149 "queued=$queued, " .
150 "running=$running, " .
151 "status='$status' " .
152 "WHERE cluster='$cluster'";
153 }
154
155 $result = mysql_query( $query, $gfac_link );
156
157 if ( ! $result )
158 {
159 write_log( "$self: Query failed $query - " . mysql_error( $gfac_link ) );
160 echo "$self: Query failed $query - " . mysql_error( $gfac_link ) . "\n";
161 }
162}
163
164// Get local cluster status
165
166function local_status()
167{
168 global $self;
169 global $data;
170 global $dbhost;
171 global $org_domain;
172
173 if ( preg_match( "/localhost/", $dbhost ) )
174 {
175 if ( preg_match( "/attlocal/", $org_domain ) )
176 $clusters = array( "us3iab-devel" );
177 else
178 $clusters = array( "us3iab-node0" );
179 }
180 else
181 {
182 $clusters = array( "alamo", "lonestar5", "stampede", "comet",
183 "gordon", "jureca", "jacinto" );
184 }
185
186 foreach ( $clusters as $clname )
187 {
188 $a = Array();
189//echo "$self: clname=$clname\n";
190
191 switch( $clname )
192 {
193 case 'us3iab-node0':
194 case 'us3iab-node1':
195 case 'us3iab-devel':
196 {
197 $qstat = `/usr/bin/qstat -B 2>&1|tail -1`;
198
199 $sparts = preg_split( '/\s+/', $qstat );
200 $que = $sparts[ 3 ];
201 $run = $sparts[ 4 ];
202 $sta = $sparts[ 10 ];
203 if ( $sta == "Active" )
204 $sta = "up";
205 else
206 $sta = "down";
207 break;
208 }
209 case 'alamo':
210 {
211 $host = "us3@alamo.uthscsa.edu";
212 $qstat = `ssh $host '/usr/bin/qstat -B 2>&1|tail -1'`;
213 $sparts = preg_split( '/\s+/', $qstat );
214 $que = $sparts[ 3 ];
215 $run = $sparts[ 4 ];
216 $sta = $sparts[ 10 ];
217 if ( $sta == "Active" )
218 $sta = "up";
219 else
220 $sta = "down";
221 break;
222 }
223 case 'jacinto':
224 {
225 $host = "us3@jacinto.uthscsa.edu";
226 $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
227 $sparts = preg_split( '/\s+/', $qstat );
228 $que = $sparts[ 3 ];
229 $run = $sparts[ 4 ];
230 $sta = $sparts[ 9 ];
231 if ( $sta == "Active" )
232 $sta = "up";
233 else
234 $sta = "down";
235 break;
236 }
237 case 'stampede':
238 {
239 $host = "us3@stampede.tacc.utexas.edu";
240 $qstat = `ssh $host '/usr/local/bin/showq 2>&1|grep "Total Jobs"'`;
241 $sparts = preg_split( '/\s+/', $qstat );
242 $tot = $sparts[ 2 ];
243 $run = $sparts[ 5 ];
244 $que = $sparts[ 8 ];
245 $sta = "up";
246 if ( $tot == '' || $tot == '0' )
247 $sta = "down";
248 break;
249 }
250 case 'lonestar5':
251 {
252 $host = "us3@ls5.tacc.utexas.edu";
253 $qstat = `ssh $host '/usr/local/bin/showq 2>&1|grep "Total Jobs"'`;
254 $sparts = preg_split( '/\s+/', $qstat );
255 $tot = $sparts[ 2 ];
256 $run = '0';
257 $que = '0';
258 $sta = "up";
259 if ( $tot == '' || $tot == '0' )
260 {
261 $sta = "down";
262 }
263 else
264 {
265 $run = $sparts[ 5 ];
266 $que = $sparts[ 8 ];
267 }
268 break;
269 }
270 case 'comet':
271 {
272 $host = "us3@comet.sdsc.edu";
273 $qstat = `ssh $host '/usr/bin/sinfo -s -p compute -o "%a %F" |tail -1'`;
274 $sparts = preg_split( '/\s+/', $qstat );
275 $sta = $sparts[ 0 ];
276 $knts = $sparts[ 1 ];
277 $sparts = preg_split( '/\//', $knts );
278 $run = $sparts[ 0 ];
279 $que = $sparts[ 1 ];
280 if ( $sta == "" )
281 $sta = "down";
282 break;
283 }
284 case 'gordon':
285 {
286 $host = "us3@gordon.sdsc.edu";
287 $qstat = `ssh $host '/opt/torque/bin/qstat -B 2>&1|tail -1'`;
288 $sparts = preg_split( '/\s+/', $qstat );
289 $que = $sparts[ 3 ];
290 $run = $sparts[ 4 ];
291 $sta = $sparts[ 10 ];
292 if ( $sta == "Active" )
293 $sta = "up";
294 else
295 $sta = "down";
296 break;
297 }
298 case 'jureca':
299 {
300 $host = "swus1@jureca.fz-juelich.de";
301 $qstat = `ssh $host '~swus1/scripts/qstat-jureca 2>&1'`;
302 $sparts = preg_split( '/\s+/', $qstat );
303 $sta = $sparts[ 0 ];
304 $run = $sparts[ 1 ];
305 $que = $sparts[ 2 ];
306 break;
307 }
308 }
309
310 if ( $sta == "" )
311 $sta = "down";
312
313 if ( $sta == "down" )
314 {
315 $que = "0";
316 $run = "0";
317 }
318
319 $a[ 'cluster' ] = $clname;
320 $a[ 'queued' ] = $que;
321 $a[ 'running' ] = $run;
322 $a[ 'status' ] = $sta;
323//echo "$self: $clname $que $run $sta\n";
324
325 $data[] = $a;
326
327 if ( $clname == 'alamo' || $clname == 'jacinto' )
328 {
329 $a[ 'cluster' ] = $clname . "-local";
330 $data[] = $a;
331 }
332 }
333}
334
335class XML_Array
336{
337 var $_data = Array();
338 var $_name = Array();
339 var $_rep = Array();
340 var $_parser = 0;
341 var $_level = 0;
342 var $_index = 0;
343
344 function XML_Array( &$data )
345 {
346 $this->_parser = xml_parser_create();
347
348 xml_set_object ( $this->_parser, $this );
349 xml_parser_set_option ( $this->_parser, XML_OPTION_CASE_FOLDING, false );
350 xml_set_element_handler ( $this->_parser, "_startElement", "_endElement" );
351 xml_set_character_data_handler( $this->_parser, "_cdata" );
352
353 $this->_data = array();
354 $this->_level = 0;
355
356 if ( ! xml_parse( $this->_parser, $data, true ) )
357 return false;
358
359 xml_parser_free( $this->_parser );
360 }
361
362 function & ReturnArray()
363 {
364 return $this->_data[ 0 ];
365 }
366
367 function _startElement( $parser, $name, $attrs )
368 {
369 if ( $name == "resourceHealth" )
370 {
371## $name .= $this->_index;
372 $this->_index++;
373 }
374
375 if ( ! isset( $this->_rep[ $name ] ) ) $this->_rep[ $name ] = 0;
376
377 $this->_addElement( $name, $this->_data[ $this->_level ], $attrs );
378 $this->_name[ $this->_level ] = $name;
379 $this->_level++;
380 }
381
382 function _endElement( $parser, $name )
383 {
384 if ( isset( $this->_data[ $this->_level ] ) )
385 {
386 $this->_addElement( $this->_name[ $this->_level - 1 ],
387 $this->_data[ $this->_level - 1 ],
388 $this->_data[ $this->_level ]
389 );
390 }
391
392 unset( $this->_data[ $this->_level ] );
393 $this->_level--;
394 $this->_rep[ $name ]++;
395 }
396
397 function _cdata( $parser, $data )
398 {
399 if ( $this->_name[ $this->_level - 1 ] )
400 {
401 $this->_addElement( $this->_name[ $this->_level - 1 ],
402 $this->_data[ $this->_level - 1 ],
403 str_replace( array( "&gt;", "&lt;","&quot;", "&amp;" ),
404 array( ">" , "<" , '"' , "&" ),
405 $data
406 )
407 );
408 }
409 }
410
411 function _addElement( &$name, &$start, $add = array() )
412 {
413 if ( ( sizeof( $add ) == 0 && is_array( $add ) ) || ! $add )
414 {
415 if ( ! isset( $start[ $name ] ) ) $start[ $name ] = '';
416 $add = '';
417 }
418
419 $update = &$start[ $name ];
420
421 if ( is_array( $add) &&
422 is_array( $update ) ) $update += $add;
423 elseif ( is_array( $update ) ) return;
424 elseif ( is_array( $add ) ) $update = $add;
425 elseif ( $add ) $update .= $add;
426 }
427}
428?>
Note: See TracBrowser for help on using the repository browser.