admin web: add more flexible interface for canceling jobs (from Bernd)

This commit is contained in:
David Anderson 2015-01-23 11:13:44 -08:00
parent a19ae32205
commit 45f820b30b
4 changed files with 258 additions and 1 deletions

View File

@ -355,5 +355,35 @@ if (!isset($skip_auth_ops) && array_key_exists("SERVER_PORT", $_SERVER)) {
auth_ops();
}
// TODO: use DB interface layer
//
function cancel_wus_where($clause) {
$q1 = "CREATE TEMPORARY TABLE tmp SELECT id FROM workunit WHERE $clause;";
$q2 = "UPDATE result SET server_state=5, outcome=5 WHERE server_state=2 AND workunitid in (SELECT id FROM tmp);";
$q3 = "UPDATE workunit SET error_mask=error_mask|16 WHERE id in (SELECT id FROM tmp);";
$q4 = "UPDATE workunit SET transition_time=0 WHERE id in (SELECT id FROM tmp);";
$q5 = "DROP TABLE tmp;";
if (!mysql_query($q1)) {
echo "MySQL command '$q1' failed:<br/>unable to create temporary WU id table.<br>\n";
return 1;
} else if (!mysql_query($q2)) {
echo "MySQL command '$q2' failed:<br/>unable to cancel unsent results.<br>\n";
mysql_query($q5);
return 2;
} else if (!mysql_query($q3)) {
echo "MySQL command '$q3' failed:<br/>unable to cancel workunits.<br>\n";
mysql_query($q5);
return 3;
} else if (!mysql_query($q4)) {
echo "MySQL command '$q4' failed:<br/>unable to trigger transitioner.<br>\n";
mysql_query($q5);
return 4;
}
mysql_query($q5);
echo "Successfully canceled WUs WHERE '$clause'<br>\n";
return 0;
}
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>

View File

@ -0,0 +1,158 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2015 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// web interface for canceling WUs according to a SQL where clause
// TODO: use get_int() etc.
require_once("../inc/util_ops.inc");
admin_page_head("Cancel Jobs");
$limit = 100;
if (array_key_exists('limit',$_REQUEST)) {
$nlimit=$_REQUEST['limit'];
if ($nlimit != 0) {
$limit = $nlimit;
}
}
$clause = "";
if (array_key_exists('minid',$_REQUEST) && $_REQUEST['minid'] != "" &&
array_key_exists('maxid',$_REQUEST) && $_REQUEST['maxid'] != "")
$clause = "id >=" . $_REQUEST['minid'] . " AND id <=" . $_REQUEST['maxid'];
else if (array_key_exists('list',$_REQUEST) && $_REQUEST['list'] != "")
$clause = "id IN (" . $_REQUEST['list'] . ")";
else if (array_key_exists('uclause',$_REQUEST) && $_REQUEST['uclause'] != "")
$clause = urldecode($_REQUEST['uclause']);
else if (array_key_exists('clause',$_REQUEST) && $_REQUEST['clause'] != "")
// the following line is BS, but apparently I can't find another way to pass a
// double quote (") to the query
$clause = str_replace('\"', '"', $_REQUEST['clause']);
if ($clause == "") {
// copied from old cancel_wu_form.php
echo "<p>
This form may be used to cancel unnecessary or unwanted jobs.
We recommend that you stop the project before doing this.
Note that the jobs and their corresponding
results (if any) are NOT removed from the database.
Instead, they are marked as 'no longer needed'.
In most cases you should probably only remove jobs whose results
are all unsent,
since otherwise a user will not get credit
for a result that they might return.
</p>
<p>
Please specify jobs by ID range, ID list or clause to be used in a
'SELECT FROM workunit WHERE' query.
</p>
<p>
You will be given a list of jobs matching your specification
for confirmation before these are actually canceled.
</p>
";
$page = $_SERVER["REQUEST_URI"];
echo "<form action=\"$page\" method=\"get\" enctype=\"application/x-www-form-urlencoded\">\n";
echo "<ul><li>\n";
echo ' Range: ID of first WU to cancel ';
echo '<input name="minid" type="text" size="10" maxlength="15">';
echo ' ID of last WU to cancel ';
echo '<input name="maxid" type="text" size="10" maxlength="15">';
echo "</li><li>\n";
echo ' Comma-separated list of IDs ';
echo '<input name="list" type="text" size="100" maxlength="200">';
echo "</li><li>\n";
echo ' WHERE clause (w/o "WHERE") ';
echo '<input name="clause" type="text" size="100" maxlength="200">';
echo "</li></ul>\n";
echo "<p>\n";
echo ' Limit ';
echo "<input name=\"limit\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"$limit\">";
echo "</p>\n";
echo "<p>\n";
echo '<input type="submit" value="Cancel jobs">';
echo "</p>\n";
} else { // if ($clause)
db_init(true); // try to get list of WUs from replica
$query = "SELECT id, name FROM workunit WHERE canonical_resultid = 0 AND error_mask = 0 AND $clause;";
$dbresult = mysql_query($query);
if (!$dbresult) {
echo "Error in query '$query'<br>\n";
} else {
echo "<form action=\"cancel_workunits_action.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"back\" value=\"cancelwus\"/>";
echo "<br><table border=\"1\">\n";
echo "<tr><th>WU ID</th><th>WU name</th></tr>\n";
$rescount = 0;
while ($res = mysql_fetch_object($dbresult)) {
if ($rescount < $limit) {
$id = $res->id;
echo "<tr>\n";
echo "<td align=\"left\" valign=\"top\">";
echo "<input type=\"checkbox\" name=\"WU[]\" value=\"$id\" checked>\n";
echo "<a href=db_action.php?table=workunit&detail=high&id=";
echo $id;
echo ">";
echo $id;
echo "</a>";
echo "</td>\n";
echo "<td align=\"left\" valign=\"top\">";
echo $res->name;
echo "</td>\n";
echo "</tr>\n";
}
$rescount++;
} // while (mysql_fetch_object())
mysql_free_result($dbresult);
echo "</table>\n<p>";
echo $rescount;
echo " WUs match the query ($query)\n</p>";
echo "<p>";
echo "<input type=\"hidden\" name=\"cancel\" value=\"1\"/>";
echo "<input type=\"hidden\" name=\"limit\" value=\"$limit\"/>";
$eclause = urlencode($clause);
echo "<input type=\"hidden\" name=\"clause\" value=\"$eclause\"/>";
echo "<input type=\"submit\" value=\"Cancel checked WUs\">";
echo "</p>\n";
echo "</form>\n";
} // if (!$dbresult)
} // if ($clause)
admin_page_tail();
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>

View File

@ -0,0 +1,68 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2015 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/util_ops.inc");
admin_page_head("Cancel Workunits");
// check for WUs to cancel
$WUs="";
if (array_key_exists('cancel',$_REQUEST) && ($_REQUEST['cancel'] == 1)) {
if (is_array($_REQUEST['WU'])) {
foreach ($_REQUEST['WU'] as $key => $value) {
if($WUs != "")
$WUs = $WUs . ",";
$WUs = $WUs . $value;
}
}
}
// cancel WUs (if not in rops)
if($WUs != "") {
echo "<!--- WUs to cancel: $WUs --->\n";
if (!in_rops()) {
db_init();
cancel_wus_where("id IN (" . $WUs . ")");
}
}
if (array_key_exists('back',$_REQUEST)) {
if ($_REQUEST['back'] == "errorwus") {
echo "<p><a href=\"errorwus.php\">Return to All-error Workunits page</a></p>";
} else if ($_REQUEST['back'] == "cancelwus") {
if (array_key_exists('clause',$_REQUEST)) {
$limit = 20;
if (array_key_exists('limit',$_REQUEST))
$limit=$_REQUEST['limit'];
$clause=urlencode($_REQUEST['clause']);
echo "<p><a href=\"cancel_workunits.php?limit=$limit&uclause=$clause\">";
echo "Cancel next (max $limit) Workunits</a></p>";
}
echo "<p><a href=\"cancel_workunits.php\">Return to Cancel Workunits page</a></p>";
}
}
echo "<p>";
echo "Page last updated ";
echo time_str(time());
echo "</p>\n";
admin_page_tail();
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit
?>

View File

@ -108,7 +108,8 @@ echo "
<li><a href=\"manage_app_versions.php\">Manage application versions</a></li>
<li> Manage jobs
<ul>
<li><a href=\"cancel_wu_form.php\">Cancel jobs</a>
<li><a href=\"cancel_wu_form.php\">Cancel jobs by ID</a>
<li><a href=\"cancel_workunits.php\">Cancel jobs by SQL clause</a>
<li><a href=transition_all.php>Transition jobs</a>
<p class=\"text-muted\">(this can 'unstick' old jobs)</p>
<li><a href=\"revalidate.php\">Re-validate jobs</a>