"; $show_msg = 0; $none_set = 0; if( $id == '' and $owner== '' and $name == '' and $start_from_time == '' and $start_to_time == '' and $queue == '' and $end_from_time == '' and $end_to_time == '') { $error = 1; $show_msg = 1; $error_msg .= "No search criteria set!"; } if( !is_numeric($id) and !$error and $id != '') { $error = 1; $show_msg = 1; $error_msg .= "Id must be a number"; } if( !$error and $period_start != '' ) { $pstart_epoch = datetimeToEpoch( $period_start ); if( $period_stop != '' ) { $pstop_epoch = datetimeToEpoch( $period_stop ); if( $pstart_epoch > $pstop_epoch ) { $show_msg = 1; $error_msg .= "Graph timeperiod reset: start date/time can't be later than end"; $period_stop = ''; $period_start = ''; } else if( $pstop_epoch == $pstart_epoch ) { $show_msg = 1; $error_msg .= "Graph timeperiod reset: start and end date/time can't be the same"; $period_stop = ''; $period_start = ''; } } } $error_msg .= ""; // doe checks en set error en error_msg in case shit if( $show_msg ) $tpl->assign( "form_error_msg", $error_msg ); return ($error ? 0 : 1 ); } function datetimeToEpoch( $datetime ) { $datetime_fields = explode( ' ', $datetime ); $date = $datetime_fields[0]; $time = $datetime_fields[1]; $date_fields = explode( '-', $date ); $days = $date_fields[0]; $months = $date_fields[1]; $years = $date_fields[2]; $time_fields = explode( ':', $time ); $hours = $time_fields[0]; $minutes = $time_fields[1]; $seconds = $time_fields[2]; $timestamp = mktime( $hours, $minutes, $seconds, $months, $days, $years ); return $timestamp; } function timeToEpoch( $time ) { $time_fields = explode( ':', $time ); if( count($time_fields) == 3 ) { $hours = $time_fields[0]; $minutes = $time_fields[1]; $seconds = $time_fields[2]; } else if( count($time_fields) == 2 ) { $hours = 0; $minutes = $time_fields[0]; $seconds = $time_fields[1]; } else if( count($time_fields) == 1 ) { $hours = 0; $minutes = 0; $seconds = $time_fields[0]; } $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) ); return $myepoch; } function sortJobs( $jobs, $nodes, $sortby, $sortorder ) { $sorted = array(); $cmp = create_function( '$a, $b', "global \$sortby, \$sortorder;". "if( \$a == \$b ) return 0;". "if (\$sortorder==\"desc\")". "return ( \$a < \$b ) ? 1 : -1;". "else if (\$sortorder==\"asc\")". "return ( \$a > \$b ) ? 1 : -1;" ); foreach( $jobs as $jobid => $jobattrs ) { $state = $jobattrs['status']; $owner = $jobattrs['owner']; $queue = $jobattrs['queue']; $name = $jobattrs['name']; $req_cpu = $jobattrs['requested_time']; $req_memory = $jobattrs['requested_memory']; $mynodes = count( $nodes[$jobid] ); $ppn = (int) $jobattrs['ppn'] ? $jobattrs['ppn'] : 1; $cpus = $mynodes * $ppn; $start_time = (int) $jobattrs['start_timestamp']; $stop_time = (int) $jobattrs['stop_timestamp']; $runningtime = $stop_time - $start_time; switch( $sortby ) { case "id": $sorted[$jobid] = $jobid; break; case "state": $sorted[$jobid] = $state; break; case "owner": $sorted[$jobid] = $owner; break; case "queue": $sorted[$jobid] = $queue; break; case "name": $sorted[$jobid] = $name; break; case "req_cpu": $sorted[$jobid] = timeToEpoch( $req_cpu ); break; case "req_mem": $sorted[$jobid] = $req_memory; break; case "nodes": $sorted[$jobid] = $mynodes; break; case "cpus": $sorted[$jobid] = $cpus; break; case "start": $sorted[$jobid] = $start_time; break; case "finished": $sorted[$jobid] = $stop_time; break; case "runningtime": $sorted[$jobid] = $runningtime; break; default: break; } } if( $sortorder == "asc" ) arsort( $sorted ); else if( $sortorder == "desc" ) asort( $sorted ); return array_keys( $sorted ); } function makeSearchPage() { global $clustername, $tpl, $id, $owner, $name, $start_from_time, $start_to_time, $queue; global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up, $hc; global $period_start, $period_stop, $sortby, $sortorder, $COLUMN_REQUESTED_MEMORY; global $SEARCH_RESULT_LIMIT, $COLUMN_NODES, $metricname; $longtitle = "Batch Archive Search :: Powered by Job Monarch!"; $title = "Batch Archive Search"; makeHeader( 'search', $title, $longtitle ); $tpl->assign( "cluster", $clustername ); $tpl->assign( "id_value", $id ); $tpl->assign( "owner_value", $owner); $tpl->assign( "queue_value", $queue ); $tpl->assign( "name_value", $name ); $tpl->assign( "start_from_value", rawurldecode( $start_from_time ) ); $tpl->assign( "start_to_value", rawurldecode( $start_to_time ) ); $tpl->assign( "end_from_value", rawurldecode( $end_from_time ) ); $tpl->assign( "end_to_value", rawurldecode( $end_to_time ) ); if( validateFormInput() ) { $tpl->newBlock( "search_results" ); $tpl->assign( "sortby", $sortby); $tpl->assign( "sortorder", $sortorder); $tdb = new TarchDbase( "127.0.0.1" ); if( $start_from_time ) $start_from_time = datetimeToEpoch( $start_from_time ); if( $start_to_time ) $start_to_time = datetimeToEpoch( $start_to_time ); if( $end_from_time ) $end_from_time = datetimeToEpoch( $end_from_time ); if( $end_to_time ) $end_to_time = datetimeToEpoch( $end_to_time ); $search_ids = $tdb->searchDbase( $id, $queue, $owner, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); if( ($tdb->resultcount) > (int) $SEARCH_RESULT_LIMIT ) { $tpl->gotoBlock( "_ROOT" ); $tpl->assign( "form_error_msg", "Got " . $tdb->resultcount . " search results, output limited to last " . $SEARCH_RESULT_LIMIT . " jobs." ); $tpl->gotoBlock( "search_results" ); } $jobs = array(); $nodes = array(); $even = 1; foreach( $search_ids as $myid ) { $jobs[$myid] = $tdb->getJobArray( $myid ); $nodes[$myid] = $tdb->getNodesForJob( $myid ); } if( $COLUMN_REQUESTED_MEMORY ) { $tpl->newBlock( "column_header_req_mem" ); } if( $COLUMN_NODES ) { $tpl->newBlock( "column_header_nodes" ); } $sorted_search = sortJobs( $jobs, $nodes, $sortby, $sortorder ); foreach( $sorted_search as $sortid ) { $job = $jobs[$sortid]; $foundid = $job['id']; $tpl->newBlock( "node" ); $tpl->assign( "id", $job['id'] ); $tpl->assign( "state", $job['status'] ); $tpl->assign( "owner", $job['owner'] ); $tpl->assign( "queue", $job['queue'] ); $tpl->assign( "name", $job['name'] ); $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job['requested_time'] ) ) ); if( $COLUMN_REQUESTED_MEMORY ) { $tpl->newBlock( "column_req_mem" ); $tpl->assign( "req_memory", $job['requested_memory'] ); $tpl->gotoBlock( "node" ); } if( $COLUMN_NODES) { $job_nodes = array(); foreach( $nodes[$foundid] as $mynode ) $job_nodes[] = $mynode['hostname']; $tpl->newBlock( "column_nodes" ); $nodes_hostnames = implode( " ", $job_nodes ); $tpl->assign( "nodes_hostnames", $nodes_hostnames ); $tpl->gotoBlock( "node" ); } $nodes_nr = count( $nodes[$foundid] ); if( $even ) { $tpl->assign("nodeclass", "even"); $even = 0; } else { $tpl->assign("nodeclass", "odd"); $even = 1; } $ppn = (int) $job['ppn'] ? $job['ppn'] : 1; $cpus = $nodes_nr * $ppn; $tpl->assign( "nodes", $nodes_nr ); $tpl->assign( "cpus", $cpus ); $job_start = $job['start_timestamp']; $job_stop = $job['stop_timestamp']; $runningtime = intval( $job_stop - $job_start ); $tpl->assign( "started", makeDate( $job_start ) ); $tpl->assign( "finished", makeDate( $job_stop ) ); $tpl->assign( "runningtime", makeTime( $runningtime ) ); } if( count( $search_ids ) == 1 ) { $tpl->newBlock( "showhosts" ); $showhosts = isset($sh) ? $sh : $default_showhosts; $tpl->assign("checked$showhosts", "checked"); # Present a width list $cols_menu = "