Changeset 716 for branches/0.4/web/addons/job_monarch/search.php
- Timestamp:
- 03/21/13 21:33:48 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/web/addons/job_monarch/search.php
r713 r716 26 26 27 27 function validateFormInput() { 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 28 global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue; 29 global $end_from_time, $end_to_time, $period_start, $period_stop; 30 31 $error = 0; 32 $error_msg = "<FONT COLOR=\"red\"><B>"; 33 $show_msg = 0; 34 35 $none_set = 0; 36 37 if( $id == '' and $owner== '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') { 38 $error = 1; 39 $show_msg = 1; 40 $error_msg .= "No search criteria set!"; 41 } 42 43 if( !is_numeric($id) and !$error and $id != '') 44 44 { 45 45 46 47 48 49 50 51 46 $error = 1; 47 $show_msg = 1; 48 $error_msg .= "Id must be a number"; 49 } 50 51 if( !$error and $period_start != '' ) 52 52 { 53 54 53 $pstart_epoch = datetimeToEpoch( $period_start ); 54 if( $period_stop != '' ) 55 55 { 56 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 57 $pstop_epoch = datetimeToEpoch( $period_stop ); 58 59 if( $pstart_epoch > $pstop_epoch ) { 60 61 $show_msg = 1; 62 $error_msg .= "Graph timeperiod reset: start date/time can't be later than end"; 63 $period_stop = ''; 64 $period_start = ''; 65 } else if( $pstop_epoch == $pstart_epoch ) { 66 67 $show_msg = 1; 68 $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same"; 69 $period_stop = ''; 70 $period_start = ''; 71 } 72 } 73 } 74 75 $error_msg .= "</B></FONT>"; 76 // doe checks en set error en error_msg in case shit 77 78 if( $show_msg ) 79 $tpl->assign( "form_error_msg", $error_msg ); 80 81 return ($error ? 0 : 1 ); 82 82 } 83 83 84 84 function datetimeToEpoch( $datetime ) { 85 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 86 $datetime_fields = explode( ' ', $datetime ); 87 88 $date = $datetime_fields[0]; 89 $time = $datetime_fields[1]; 90 91 $date_fields = explode( '-', $date ); 92 93 $days = $date_fields[0]; 94 $months = $date_fields[1]; 95 $years = $date_fields[2]; 96 97 $time_fields = explode( ':', $time ); 98 99 $hours = $time_fields[0]; 100 $minutes = $time_fields[1]; 101 $seconds = $time_fields[2]; 102 103 $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); 104 105 return $timestamp; 106 106 } 107 107 … … 206 206 break; 207 207 208 209 210 208 case "finished": 209 $sorted[$jobid] = $stop_time; 210 break; 211 211 212 212 case "runningtime": … … 229 229 230 230 function makeSearchPage() { 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 $job_nodes= array();311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 231 global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue; 232 global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up, $hc; 233 global $period_start, $period_stop, $sortby, $sortorder, $COLUMN_REQUESTED_MEMORY; 234 global $SEARCH_RESULT_LIMIT, $COLUMN_NODES, $metricname; 235 236 $longtitle = "Batch Archive Search :: Powered by Job Monarch!"; 237 $title = "Batch Archive Search"; 238 239 makeHeader( 'search', $title, $longtitle ); 240 241 $tpl->assign( "cluster", $clustername ); 242 $tpl->assign( "id_value", $id ); 243 $tpl->assign( "owner_value", $owner); 244 $tpl->assign( "queue_value", $queue ); 245 $tpl->assign( "name_value", $name ); 246 $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); 247 $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); 248 $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); 249 $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); 250 251 if( validateFormInput() ) { 252 253 $tpl->newBlock( "search_results" ); 254 $tpl->assign( "sortby", $sortby); 255 $tpl->assign( "sortorder", $sortorder); 256 $tdb = new TarchDbase( "127.0.0.1" ); 257 if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); 258 if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); 259 if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); 260 if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); 261 $search_ids = $tdb->searchDbase( $id, $queue, $owner, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); 262 263 if( ($tdb->resultcount) > (int) $SEARCH_RESULT_LIMIT ) { 264 $tpl->gotoBlock( "_ROOT" ); 265 266 $tpl->assign( "form_error_msg", "Got " . $tdb->resultcount . " search results, output limited to last " . $SEARCH_RESULT_LIMIT . " jobs." ); 267 $tpl->gotoBlock( "search_results" ); 268 } 269 270 $jobs = array(); 271 $nodes = array(); 272 273 $even = 1; 274 275 foreach( $search_ids as $myid ) { 276 277 $jobs[$myid] = $tdb->getJobArray( $myid ); 278 $nodes[$myid] = $tdb->getNodesForJob( $myid ); 279 } 280 281 if( $COLUMN_REQUESTED_MEMORY ) { 282 $tpl->newBlock( "column_header_req_mem" ); 283 } 284 if( $COLUMN_NODES ) { 285 $tpl->newBlock( "column_header_nodes" ); 286 } 287 288 $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder ); 289 290 foreach( $sorted_search as $sortid ) { 291 292 $job = $jobs[$sortid]; 293 $foundid = $job['id']; 294 295 $tpl->newBlock( "node" ); 296 $tpl->assign( "id", $job['id'] ); 297 $tpl->assign( "state", $job['status'] ); 298 $tpl->assign( "owner", $job['owner'] ); 299 $tpl->assign( "queue", $job['queue'] ); 300 $tpl->assign( "name", $job['name'] ); 301 $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job['requested_time'] ) ) ); 302 303 if( $COLUMN_REQUESTED_MEMORY ) { 304 $tpl->newBlock( "column_req_mem" ); 305 $tpl->assign( "req_memory", $job['requested_memory'] ); 306 $tpl->gotoBlock( "node" ); 307 } 308 if( $COLUMN_NODES) { 309 310 $job_nodes = array(); 311 312 foreach( $nodes[$foundid] as $mynode ) 313 $job_nodes[] = $mynode['hostname']; 314 315 $tpl->newBlock( "column_nodes" ); 316 $nodes_hostnames = implode( " ", $job_nodes ); 317 $tpl->assign( "nodes_hostnames", $nodes_hostnames ); 318 $tpl->gotoBlock( "node" ); 319 } 320 321 $nodes_nr = count( $nodes[$foundid] ); 322 323 if( $even ) { 324 325 $tpl->assign("nodeclass", "even"); 326 $even = 0; 327 } else { 328 329 $tpl->assign("nodeclass", "odd"); 330 $even = 1; 331 } 332 333 $ppn = (int) $job['ppn'] ? $job['ppn'] : 1; 334 $cpus = $nodes_nr * $ppn; 335 336 $tpl->assign( "nodes", $nodes_nr ); 337 $tpl->assign( "cpus", $cpus ); 338 339 $job_start = $job['start_timestamp']; 340 $job_stop = $job['stop_timestamp']; 341 $runningtime = intval( $job_stop - $job_start ); 342 $tpl->assign( "started", makeDate( $job_start ) ); 343 $tpl->assign( "finished", makeDate( $job_stop ) ); 344 $tpl->assign( "runningtime", makeTime( $runningtime ) ); 345 346 } 347 348 if( count( $search_ids ) == 1 ) { 349 350 $tpl->newBlock( "showhosts" ); 351 352 $showhosts = isset($sh) ? $sh : $default_showhosts; 353 $tpl->assign("checked$showhosts", "checked"); 354 355 # Present a width list 356 $cols_menu = "<SELECT NAME=\"hc\" OnChange=\"archive_search_form.submit();\">\n"; 357 358 $hostcols = ($hc) ? $hc : 4; 359 360 foreach(range(1,25) as $cols) { 361 $cols_menu .= "<OPTION VALUE=$cols "; 362 if ($cols == $hostcols) 363 $cols_menu .= "SELECTED"; 364 $cols_menu .= ">$cols\n"; 365 } 366 $cols_menu .= "</SELECT>\n"; 367 368 $tpl->assign("metric","$metricname $units"); 369 $tpl->assign("id", $id); 370 # Host columns menu defined in header.php 371 $tpl->assign("cols_menu", $cols_menu); 372 373 if( $showhosts ) { 374 375 if( !$period_start ) // Add an extra 10% to graphstart 376 $period_start = intval( $job_start - (intval( $runningtime * 0.10 ) ) ); 377 else 378 $period_start = datetimeToEpoch( $period_start ); 379 380 if( !$period_stop ) // Add an extra 10% to graphend 381 $period_stop = intval( $job_stop + (intval( $runningtime * 0.10 ) ) ); 382 else 383 $period_stop = datetimeToEpoch( $period_stop ); 384 385 $tpl->gotoBlock( "timeperiod" ); 386 387 $tpl->assign("period_start", epochToDatetime( $period_start ) ); 388 $tpl->assign("period_stop", epochToDatetime( $period_stop ) ); 389 390 $tpl->gotoBlock( "_ROOT" ); 391 392 $hosts_up = array(); 393 394 foreach( $nodes[$id] as $mynode ) 395 $hosts_up[] = $mynode['hostname']; 396 397 $sorted_hosts = array(); 398 399 foreach ($hosts_up as $host ) { 400 $cpus = $metrics[$host]["cpu_num"]['VAL']; 401 if (!$cpus) $cpus=1; 402 $load_one = $metrics[$host]["load_one"]['VAL']; 403 $load = ((float) $load_one)/$cpus; 404 $host_load[$host] = $load; 405 $percent_hosts['load_color'.($load)] += 1; 406 if ($metricname=="load_one") 407 $sorted_hosts[$host] = $load; 408 else 409 $sorted_hosts[$host] = $metrics[$host][$metricname]['VAL']; 410 } 411 switch ($sort) { 412 case "descending": 413 arsort($sorted_hosts); 414 break; 415 case "by hostname": 416 ksort($sorted_hosts); 417 break; 418 default: 419 case "ascending": 420 asort($sorted_hosts); 421 break; 422 } 423 424 # First pass to find the max value in all graphs for this 425 # metric. The $start,$end variables comes from get_context.php, 426 # included in index.php. 427 list($min, $max) = find_limits($sorted_hosts, $metricname); 428 429 # Second pass to output the graphs or metrics. 430 $i = 1; 431 foreach ( $sorted_hosts as $host=>$value ) { 432 $tpl->newBlock ("sorted_list"); 433 $host_url = rawurlencode($host); 434 $cluster_url = rawurlencode($clustername); 435 436 $textval = ""; 437 $val = $metrics[$host][$metricname]; 438 $class = "metric"; 439 $host_link="\"?j_view=host&c=$cluster_url&h=$host_url&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop\""; 440 441 if ($val['TYPE']=="timestamp" or $always_timestamp[$metricname]) { 442 $textval = date("r", $val['VAL']); 443 } elseif ($val['TYPE']=="string" or $val['SLOPE']=="zero" or $always_constant[$metricname] or ($max_graphs > 0 and $i > $max_graphs )) { 444 $textval = "$val['VAL'] $val['UNITS']"; 445 } else { 446 $graphargs = "z=small&c=$cluster_url&m=$metricname&h=$host_url&v=$val['VAL']&x=$max&n=$min&job_start=$job_start&job_stop=$job_stop&period_start=$period_start&period_stop=$period_stop&min=$min&max=$max"; 447 } 448 if ($textval) { 449 $cell="<td class=$class>". "<b><a href=$host_link>$host</a></b><br>". "<i>$metricname:</i> <b>$textval</b></td>"; 450 } else { 451 $cell="<td><a href=$host_link>". "<img src=\"./graph.php?$graphargs\" ". "alt=\"$host\" border=0></a></td>"; 452 } 453 454 $tpl->assign("metric_image", $cell); 455 if (! ($i++ % $hostcols) ) 456 $tpl->assign ("br", "</tr><tr>"); 457 } 458 459 } 460 } 461 462 } 463 463 } 464 464 ?>
Note: See TracChangeset
for help on using the changeset viewer.