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