From f2fd5da3ff1f3137041c51c843e2f5f956eab5b9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 30 May 2007 20:30:28 +0000 Subject: [PATCH] - user web: added new feature to merge hosts by name. This is handy if you have a lot of hosts, and every now and then they get a new host ID (e.g. because you delete and reinstall BOINC). You can now merge all of them with a single click. html/ inc/ host.inc user/ host_edit_action.php merge_by_name.php (new) hosts_user.php svn path=/trunk/boinc/; revision=12785 --- checkin_notes | 15 +++++++ html/inc/host.inc | 80 +++++++++++++++++++++++++++++----- html/user/host_edit_action.php | 47 ++------------------ html/user/hosts_user.php | 8 +++- html/user/merge_by_name.php | 68 +++++++++++++++++++++++++++++ 5 files changed, 163 insertions(+), 55 deletions(-) create mode 100644 html/user/merge_by_name.php diff --git a/checkin_notes b/checkin_notes index e7ce95e7ae..bdc3c54b96 100755 --- a/checkin_notes +++ b/checkin_notes @@ -5587,3 +5587,18 @@ David 30 May 2007 sched/ sched_array.C sched_send.C,h + +David 30 May 2007 + - user web: added new feature to merge hosts by name. + This is handy if you have a lot of hosts, + and every now and then they get a new host ID + (e.g. because you delete and reinstall BOINC). + You can now merge all of them with a single click. + + html/ + inc/ + host.inc + user/ + host_edit_action.php + merge_by_name.php (new) + hosts_user.php diff --git a/html/inc/host.inc b/html/inc/host.inc index d1739022a5..da3576eaa2 100644 --- a/html/inc/host.inc +++ b/html/inc/host.inc @@ -257,14 +257,11 @@ function ghz($x) { } } -// return true if it's possible that the two host records -// correspond to the same host -// -function hosts_compatible($host1, $host2) { +function cpus_compatible($host1, $host2) { // we screwed around with Intel processor names, // so count them as compatible if both contain "Intel" and "Pentium", // and don't have conflicting clock rate info - + // $p1 = "$host1->p_vendor $host1->p_model"; $p2 = "$host2->p_vendor $host2->p_model"; if (strstr($p1, "Pentium") && strstr($p1, "Intel") @@ -279,26 +276,46 @@ function hosts_compatible($host1, $host2) { } } else { if ($host2->p_vendor != $host1->p_vendor) return false; + + // they're compatible if models are the same, + // or contents of [family/model/stepping] are the same + // $pos = strpos($host1->p_model, '['); $host1pm = $host1->p_model; - if($pos !== FALSE) { + if($pos) { $host1pm = trim(substr($host1->p_model, 0, $pos)); } $pos = strpos($host2->p_model, '['); $host2pm = $host2->p_model; - if($pos !== FALSE) { + if($pos) { $host2pm = trim(substr($host2->p_model, 0, $pos)); } - if($host2pm != $host1pm) return false; + if ($host1pm != $host2pm) return false; } - if ($host2->os_name != $host1->os_name) return false; + return true; +} - // one host must strictly precede the other +// does one host strictly precede the other? +// +function times_disjoint($host1, $host2) { if ($host1->rpc_time < $host2->create_time) return true; if ($host2->rpc_time < $host1->create_time) return true; return false; } +// Return true if it's possible that the two host records +// correspond to the same host +// NOTE: the cheat-proofing comes from checking +// that their time intervals are disjoint. +// So the CPU/OS checks don't have to be very strict. +// +function hosts_compatible($host1, $host2) { + if (!times_disjoint($host1, $host2)) return false; + if ($host2->os_name != $host1->os_name) return false; + if (!cpus_compatible($host1, $host2)) return false; + return true; +} + // recompute host's average credit by scanning results. // Could be expensive if lots of results! // @@ -353,4 +370,47 @@ function host_inactive_ndays($host, $ndays) { return false; } +// invariant: old_host.create_time < new_host.create_time +// +function merge_hosts($old_host, $new_host) { + if ($old_host->id == $new_host->id) { + return "same host"; + } + if (!hosts_compatible($old_host, $new_host)) { + return "Can't merge host $old_host->id into $new_host->id - they're incompatible"; + } + + echo "
Merging host $old_host->id into host $new_host->id\n"; + + // decay the average credit of both hosts + // + $now = time(); + update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); + update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); + + // update the database: + // - add credit from old to new host + // - change results to refer to new host + // - put old host in "zombie" state + // - update rpc_seqno if needed + // + $total_credit = $old_host->total_credit + $new_host->total_credit; + $recent_credit = $old_host->expavg_credit + $new_host->expavg_credit; + $result = mysql_query("update host set total_credit=$total_credit, expavg_credit=$recent_credit, expavg_time=$now where id=$new_host->id"); + if (!$result) { + return "Couldn't update credit of new computer"; + } + $result = mysql_query("update result set hostid=$new_host->id where hostid=$old_host->id"); + if (!$result) { + return "Couldn't update results"; + } + + $result = mysql_query("update host set total_credit=0, expavg_credit=0, userid=0, rpc_seqno=$new_host->id where id=$old_host->id"); + if (!$result) { + return "Couldn't retire old computer"; + } + echo "
Retired old computer $old_host->id\n"; + return 0; +} + ?> diff --git a/html/user/host_edit_action.php b/html/user/host_edit_action.php index 6870db6390..a967377ae3 100644 --- a/html/user/host_edit_action.php +++ b/html/user/host_edit_action.php @@ -17,48 +17,6 @@ function get_host($hostid, $user) { return $host; } -// invariant: old_host.create_time < new_host.create_time -// -function merge_hosts($old_host, $new_host) { - if ($old_host->id == $new_host->id) { - fail("same host"); - } - if (!hosts_compatible($old_host, $new_host)) { - fail("
Can't merge host $old_host->id into $new_host->id - they're incompatible"); - } - - echo "
Merging host $old_host->id into host $new_host->id\n"; - - // decay the average credit of both hosts - // - $now = time(); - update_average($now, 0, 0, $old_host->expavg_credit, $old_host->expavg_time); - update_average($now, 0, 0, $new_host->expavg_credit, $new_host->expavg_time); - - // update the database: - // - add credit from old to new host - // - change results to refer to new host - // - put old host in "zombie" state: userid 0, rpc_seqno = new host ID - // (this lets scheduler handle requests from old host ID) - // - $total_credit = $old_host->total_credit + $new_host->total_credit; - $recent_credit = $old_host->expavg_credit + $new_host->expavg_credit; - $result = mysql_query("update host set total_credit=$total_credit, expavg_credit=$recent_credit, expavg_time=$now where id=$new_host->id"); - if (!$result) { - fail("Couldn't update credit of new computer"); - } - $result = mysql_query("update result set hostid=$new_host->id where hostid=$old_host->id"); - if (!$result) { - fail("Couldn't update results"); - } - - $result = mysql_query("update host set total_credit=0, expavg_credit=0, userid=0, rpc_seqno=$new_host->id where id=$old_host->id"); - if (!$result) { - fail("Couldn't retire old computer"); - } - echo "
Retired old computer $old_host->id\n"; -} - db_init(); $user = get_logged_in_user(); @@ -73,7 +31,10 @@ for ($i=1; $i<$nhosts; $i++) { if (!$hostid) continue; $host = get_host($hostid, $user); if ($host->create_time > $latest_host->create_time) { - merge_hosts($latest_host, $host); + $error = merge_hosts($latest_host, $host); + if ($error) { + fail($error); + } $latest_host = $host; } else { merge_hosts($host, $latest_host); diff --git a/html/user/hosts_user.php b/html/user/hosts_user.php index 808663f71d..324f7546be 100644 --- a/html/user/hosts_user.php +++ b/html/user/hosts_user.php @@ -9,9 +9,9 @@ require_once("../inc/cache.inc"); function more_or_less($show_all) { if ($show_all) { - echo "

Show: All hosts | ".link_with_GET_variables("Only hosts active in past 30 days
", "hosts_user.php", 'show_all', '0'); + echo "

Show: All hosts | ".link_with_GET_variables("Only hosts active in past 30 days

", "hosts_user.php", 'show_all', '0'); } else { - echo "

Show: ".link_with_GET_variables("All hosts", "hosts_user.php", 'show_all', '1')." | Only hosts active in past 30 days
";; + echo "

Show: ".link_with_GET_variables("All hosts", "hosts_user.php", 'show_all', '1')." | Only hosts active in past 30 days

";; } } @@ -130,6 +130,10 @@ echo "\n"; if ($old_hosts>0) more_or_less($show_all); +echo " + Merge hosts by name +"; + if ($caching) { page_tail(true); end_cache(USER_PAGE_TTL, $cache_args); diff --git a/html/user/merge_by_name.php b/html/user/merge_by_name.php new file mode 100644 index 0000000000..7773b15478 --- /dev/null +++ b/html/user/merge_by_name.php @@ -0,0 +1,68 @@ +
Processing $newest_host->domain_name\n"; + foreach ($list as $host) { + if ($host->create_time > $newest_host->create_time) { + $newest_host = $host; + } + } + foreach ($list as $host) { + if ($host->id == $newest_host->id) { + continue; + } + $error = merge_hosts($host, $newest_host); + if (!$error) { + echo "merged $host->id into $newest_host->id\n"; + } else { + echo "
$error\n"; + } + } +} + +function merge_by_name($userid) { + $hosts = array(); + $result = mysql_query("select * from host where userid=$userid"); + while ($host = mysql_fetch_object($result)) { + $hosts[$host->domain_name][] = $host; + } + foreach($hosts as $hlist) { + merge_name($hlist); + } +} + +$user = get_logged_in_user(); + +page_head("Merge computers by name"); + +if ($_GET['confirmed']) { + merge_by_name($user->id); + echo " +

+ Return to the list of your computers. + "; +} else { + echo " + This operation will merge all of your computers + that have the same domain name. +

+ For each name, it will merge all older computers + having that name with the newest computer having that name. + Incompatible computers will not be merged. +

+ Click here + if you're sure you want to do this. +

Click here + to return to the list of your computers. + "; +} +page_tail(); +?>