"); if(!mysql_select_db($db_name)) { echo "Unable to select database - please try again later"; exit(); } return 0; } function lookup_user_auth($auth) { $result = mysql_query("select * from user where authenticator='$auth'"); if ($result) { $user = mysql_fetch_object($result); mysql_free_result($result); return $user; } else { return 0; } } function join_query_string($s1, $s2) { if ($s1) { if ($s2) { return "$s1&s2"; } else { return $s1; } } else { return $s2; } } class SqlQueryString { var $table; var $query; var $urlquery; function SqlQueryString() { $this->table = $_GET['table']; $this->query = $_GET['query']; $this->urlquery = ""; } function add($clause) { if (!$this->query) { $this->query .= "where $clause"; } else { $this->query .= " and $clause"; } } function addclause($clause) { if ($clause) { $this->add($clause); } } function addeq($name) { $value = $_GET[$name]; if (strlen($value)) { $this->add("$name = '$value'"); $this->urlquery .= "&$name=".urlencode($value); } } function addeqnz($name) { $value = $_GET[$name]; if (strlen($value) && $value > 0) { $this->add("$name = '$value'"); $this->urlquery .= "&$name=".urlencode($value); } } function addgt($name) { $value = $_GET[$name]; if (strlen($value) && $value > 0) { $this->add("$name > '$value'"); $this->urlquery .= "&$name=".urlencode($value); } } function addsort($name) { $value = $_GET[$name]; if (strlen($value)) { $this->query .= " order by $value desc"; $this->urlquery .= "&$name=".urlencode($value); } } function count() { $count_query = "select count(*) as cnt from $this->table $this->query"; $result = mysql_query($count_query); if (!$result) return 0; $res = mysql_fetch_object($result); mysql_free_result($result); return $res->cnt; } function get_select_query($entries_to_show, $start_at) { if ($entries_to_show) { if ($start_at) { return "select * from $this->table $this->query limit $start_at,$entries_to_show"; } else { return "select * from $this->table $this->query limit $entries_to_show"; } } else { return "select * from $this->table $this->query"; } } function get_url_query($query_extra) { $q = join_query_string($this->query, $query_extra); $s = "db_action.php?table=$this->table$this->urlquery"; if ($q) { $s = "$s&query=$q"; } return $s; } } function build_sql_query() { $q = new SqlQueryString(); $q->addeq('id'); $q->addeq('platformid'); $q->addeq('appid'); $q->addeq('workunitid'); $q->addeq('hostid'); $q->addeq('userid'); $q->addeq('teamid'); if ($_GET['nsecs']) { $_GET['received_time'] = time() - $_GET['nsecs']; } $q->addgt('received_time'); $q->addeqnz('server_state'); $q->addeqnz('outcome'); $q->addeqnz('client_state'); $q->addsort('sort_by'); return $q; } function link_results($n, $mq, $query) { if ($n == '0') { // intentional compare by string return "0"; } else { return "$n"; } } function show_result_summary() { $server_state = array(); $outcome = array(); $client_state = array(); for ($ss=1; $ss<6; $ss++) { $server_state[$ss] = 0; } for ($ro=0; $ro<6; $ro++) { $outcome[$ro] = 0; } for ($cs=1; $cs<6; $cs++) { $client_state[$cs] = 0; } $_GET['table'] = 'result'; $_GET['sort_by'] = ''; // ignore sort $q = build_sql_query(); $main_query = $q->get_select_query(0,0); $urlquery = $q->urlquery; echo "
Query: $main_query
\n"; $result = mysql_query($main_query); $ntotal =0; // TODO: how to count $result? $nvalid = 0; // for SUCCESS results $ninvalid = 0; $nfile_deleted = 0; while ($res = mysql_fetch_object($result)) { $server_state[$res->server_state] += 1; $ntotal += 1; if ($res->server_state == 5) { $outcome[$res->outcome] += 1; if ($res->outcome == 3) { $client_state[$res->client_state] += 1; } if ($res->outcome == 1) { if ($res->validate_state == 1) { $nvalid += 1; } if ($res->validate_state == 2) { $ninvalid += 1; } if ($res->file_delete_state >= 1) { $nfile_deleted +=1; } } } } mysql_free_result($result); echo "
" . link_results("$ntotal results", $urlquery, '') . " | ";
echo "" . link_results("'Over' results", $urlquery, "server_state=5") . " | ";
echo "" . link_results("'Client error' results", $urlquery, "outcome=3") . " | ";
echo "Success results | ";
echo "||||||
| ";
echo "
| ";
echo "
| "; start_table(); row2("Valid", link_results($nvalid, $urlquery, "validate_state=1")); row2("Invalid", link_results($ninvalid, $urlquery, "validate_state=2")); row2("Files deleted", link_results($ninvalid, $urlquery, "file_delete_state= 1 or file_delete_state=2")); end_table(); echo " |
".htmlspecialchars($app_version->xml_doc).""); } row("Min_core_version", $app_version->min_core_version); row("Max_core_version", $app_version->max_core_version); row("Message", $app_version->message); row("Deprecated", $app_version->deprecated); end_table(); } function host_short_header() { echo "
".htmlspecialchars($wu->xml_doc).""); } row("Application", "appid>" . app_name_by_id($wu->appid) . ""); row("Batch", $wu->batch); row("FP Operations", $wu->rsc_fpops); row("Integer Operations", $wu->rsc_iops); row("Memory Requirement", $wu->rsc_memory); row("Disk Requirement", $wu->rsc_disk); row("Need validate?", $wu->need_validate?"yes":"no"); row("Canonical resultid", "canonical_resultid>".$wu->canonical_resultid.""); row("Canonical credit", $wu->canonical_credit); row("Timeout check time", time_str($wu->timeout_check_time)); row("Delay bound", $wu->delay_bound); row("Error mask", wu_error_mask_str($wu->error_mask)); row("File delete state", file_delete_state_str($wu->file_delete_state)); row("Assimilation state", assimilate_state_str($wu->assimilate_state)); // row("","id&detail=low>Show associated results"); row("","Grep logs"); end_table(); $_GET = array('workunitid' => $wu->id); show_result_summary(); echo "
";
}
function server_state_string($s) {
switch($s) {
case 1: return "Inactive";
case 2: return "Unsent";
case 4: return "In Progress";
case 5: return "Over";
}
return "Unknown";
}
function outcome_string($s) {
switch($s) {
case 1: return "Success";
case 2: return "Couldn't send";
case 3: return "Client error";
case 4: return "No reply";
case 5: return "Didn't need";
}
return "Unknown";
}
function client_state_string($s) {
switch($s) {
case 0: return "New";
case 1: return "Downloading";
case 2: return "Downloaded";
case 3: return "Computing";
case 4: return "Uploading";
case 5: return "Done";
}
return "Unknown";
}
function validate_state_str($s) {
switch($s) {
case 0: return "Initial";
case 1: return "Valid";
case 2: return "Invalid";
}
return "Unknown";
}
function client_version_string($client_version_num) {
if (!$client_version_num) {
return '---';
} else {
return sprintf("%.2f", $client_version_num/100);
}
}
function host_user_link($hostid)
{
if (!$hostid) return '----';
$h = "$hostid";
$result = mysql_query("select userid from host where id='$hostid' limit 1");
if (!$result) return $h;
$host = mysql_fetch_object($result);
mysql_free_result($result);
if (!$host->userid) return $h;
$result = mysql_query("select * from user where id='$host->userid' limit 1");
if (!$result) return $h;
$user = mysql_fetch_object($result);
mysql_free_result($result);
return "$h
(id>$user->name)";
}
function outcome_color($s) {
switch($s) {
case 0: return 'eeeeee'; // unknown (server state not over probably)
case 1: return '33cc33'; // "Success"
case 3: return 'ff3333'; // "Client error"
}
return 'white';
}
function credit_str($c) {
if ($c) {
return sprintf("%.3f", $c);
} else {
return '---';
}
}
function show_result($result, $hide_xml_docs, $hide_stderr, $hide_times)
{
$wu_name = wu_name_by_id($result->workunitid);
echo "
WU: workunitid>$wu_name"; start_table(); if (!$hide_times) { row("Created", time_str($result->create_time)); row("Sent", time_str($result->sent_time)); row("Received", time_str($result->received_time)); } row("Name", $result->name); row("Workunit", "workunitid>" . wu_name_by_id($result->workunitid) . "" ); row("Server state", server_state_string($result->server_state)); row("Outcome", outcome_string($result->outcome)); row("Client state", client_state_string($result->client_state)); row("Host ID", "hostid>" . host_name_by_id($result->hostid) . ""); row("Report deadline", time_str($result->report_deadline)); row("CPU time", $result->cpu_time); if (!$hide_xml_docs) { row("XML doc in", "
".htmlspecialchars($result->xml_doc_in).""); row("XML doc out", "
".htmlspecialchars($result->xml_doc_out).""); } if (!$hide_stderr) { row("stderr out", "
".htmlspecialchars($result->stderr_out).""); } row("Batch", $result->batch); row("File delete state", file_delete_state_str($result->file_delete_state)); row("Validate state", validate_state_str($result->validate_state)); row("claimed credit", $result->claimed_credit); row("Granted credit", $result->granted_credit); row("Client version", client_version_string($result->client_version_num)); row("","Grep logs"); end_table(); echo "
"; } function result_short_header() { echo "
" . htmlspecialchars($team->name_html) . "" ); row("Url", "url>" . $team->url . ""); row("Type", team_type_string($team->type)); row("Description", $team->description); row("", "id>List All Members"); end_table(); } function team_name_by_id($teamid) { $result = mysql_query("select * from team where id = $teamid"); $team = mysql_fetch_object($result); return $team->name; } function user_name_by_id($user_id) { $result = mysql_query("select * from user where id = $user_id"); $user = mysql_fetch_object($result); return $user->name; } function app_name_by_id($appid) { $result = mysql_query("select * from app where id = $appid"); $app = mysql_fetch_object($result); return $app->name; } function wu_name_by_id($workunitid) { $result = mysql_query("select * from workunit where id = $workunitid"); $wu = mysql_fetch_object($result); return $wu->name; } function platform_name_by_id($platformid) { $result = mysql_query("select * from platform where id = $platformid"); $plat = mysql_fetch_object($result); return $plat->name; } function host_name_by_id($hostid) { $result = mysql_query("select * from host where id = $hostid"); $host = mysql_fetch_object($result); if (!strlen($host->domain_name) && !strlen($host->last_ip_addr)) return "(blank)"; else return $host->domain_name . " (" . $host->last_ip_addr . ")"; } ?>