No search criteria set!"; } if( !is_numeric($id) and !$error and $id != '') { $error = 1; $error_msg = "Id must be a number"; } // doe checks en set error en error_msg in case shit if( $error) { $tpl->assign( "form_error_msg", $error_msg ); return 0; } else { return 1; } } function makeTime( $time ) { $days = intval( $time / 86400 ); $time = ($days>0) ? $time % ($days * 86400) : $time; //printf( "time = %s, days = %s\n", $time, $days ); $date_str = ''; $day_str = ''; if( $days > 0 ) { if( $days > 1 ) $day_str .= $days . ' days'; else $day_str .= $days . ' day'; } $hours = intval( $time / 3600 ); $time = $hours ? $time % ($hours * 3600) : $time; //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours ); if( $hours > 0 ) { $date_str .= $hours . ':'; $date_unit = 'hours'; } $minutes = intval( $time / 60 ); $seconds = $minutes ? $time % ($minutes * 60) : $time; if( $minutes > 0 ) { if( $minutes >= 10 ) $date_str .= $minutes . ':'; else $date_str .= '0' . $minutes . ':'; $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; } else { if($hours > 0 ) { $date_str .= '00:'; $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit; } } $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit; if( $seconds > 0 ) { if( $seconds >= 10 ) $date_str .= $seconds . ' ' . $date_unit; else $date_str .= '0' . $seconds . ' ' . $date_unit; } else if ( $hours > 0 or $minutes > 0 ) $date_str .= '00 ' . $date_unit; if( $days > 0) { if( $hours > 0 or $minutes > 0 or $seconds > 0 ) $date_str = $day_str . ' - ' . $date_str; else $date_str = $day_str; } return $date_str; } function makeDate( $time ) { return strftime( "%a %d %b %Y %H:%M:%S", $time ); } 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 epochToDatetime( $epoch ) { return strftime( "%d-%m-%Y %H:%M:%S", $epoch ); } 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 makeSearchPage() { global $clustername, $tpl, $id, $user, $name, $start_from_time, $start_to_time, $queue; global $end_from_time, $end_to_time, $filter, $default_showhosts, $m, $hosts_up; global $period_start, $period_stop; $metricname = $m; //printf("job_start = %s job_stop = %s\n", $job_start, $job_stop ); //printf("start = %s stop = %s\n", $start, $stop ); $tpl->assign( "cluster", $clustername ); $tpl->assign( "id_value", $id ); $tpl->assign( "user_value", $user ); $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" ); $tdb = new TarchDbase(); 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, $user, $name, $start_from_time, $start_to_time, $end_from_time, $end_to_time ); foreach( $search_ids as $foundid ) { $job = $tdb->getJobArray( $foundid ); $nodes = $tdb->getNodesForJob( $foundid ); $tpl->newBlock( "node" ); $tpl->assign( "id", $job[id] ); $tpl->assign( "state", $job[status] ); $tpl->assign( "user", $job[owner] ); $tpl->assign( "queue", $job[queue] ); $tpl->assign( "name", $job[name] ); $tpl->assign( "req_cpu", makeTime( TimeToEpoch( $job[requested_time] ) ) ); $tpl->assign( "req_memory", $job[requested_memory] ); $nodes_nr = count( $nodes ); // need to replace later with domain stored from dbase // //$job_domain = $job[domain]; //$myhost = $_SERVER[HTTP_HOST]; //$myhf = explode( '.', $myhost ); //$myhf = array_reverse( $myhf ); //array_pop( $myhf ); //$myhf = array_reverse( $myhf ); //$job_domain = implode( '.', $myhf ); //print_r( $job ); //printf( "job domain = %s\n", $job_domain); $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 ) ); //print_r( $job ); //print_r( $nodes ); } if( count( $search_ids ) == 1 ) { $tpl->newBlock( "showhosts" ); $showhosts = isset($sh) ? $sh : $default_showhosts; //if( !$showhosts) $showhosts = $default_showhosts; $tpl->assign("checked$showhosts", "checked"); # Present a width list $cols_menu = "