. // example of a web interface to remote job submission // // Notes: // - You'll need to adapt/extend this considerably; // e.g. the project URL, app name and user authenticator are hardwired here. // - This can run on any host, not just the project server // (that's the "remote" part). // - For convenience, this uses some functions from BOINC // (page_head() etc.). // When you adapt this to your own purposes, // you can strip out this stuff if the web site doesn't use BOINC require_once("../inc/submit.inc"); require_once("../inc/util.inc"); error_reporting(E_ALL); ini_set('display_errors', true); ini_set('display_startup_errors', true); $project = "http://isaac.ssl.berkeley.edu/test/"; $auth = "157f96a018b0b2f2b466e2ce3c7f54db"; $app_name = "uppercase"; function handle_main() { global $project, $auth, $app_name; $req->project = $project; $req->authenticator = $auth; list($batches, $errmsg) = boinc_query_batches($req); if ($errmsg) error_page($errmsg); page_head("Job submission and control"); show_button("submit_example.php?action=create_form", "Create new batch"); echo "

Batches in progress

\n"; start_table(); table_header("ID", "# jobs", "progress", "submitted"); foreach ($batches as $batch) { if ($batch->completed) continue; $pct_done = (int)($batch->fraction_done*100); table_row( "id>$batch->id", $batch->njobs, "$pct_done%", time_str($batch->create_time) ); } end_table(); echo "

Batches completed

\n"; start_table(); table_header("ID", "# jobs", "submitted"); foreach ($batches as $batch) { if (!$batch->completed) continue; table_row( "id>$batch->id", $batch->njobs, time_str($batch->create_time) ); } end_table(); page_tail(); } function handle_create_form() { global $project, $auth, $app_name; page_head("Create batch"); echo "
"; start_table(); row2("Input file URL", ""); row2("Parameter low value", ""); row2("Parameter high value", ""); row2("Parameter increment", ""); row2("", "" ); row2("", "" ); end_table(); echo "
\n"; page_tail(); } // build a request object for boinc_*_batch() from form variables // function form_to_request() { global $project, $auth, $app_name; $input_url = get_str('input_url'); if (!$input_url) error_page("missing input URL"); $param_lo = get_str('param_lo'); if (!$param_lo) error_page("missing param lo"); $param_hi = get_str('param_hi'); if (!$param_hi) error_page("missing param hi"); $param_inc = get_str('param_inc'); if (!$param_inc) error_page("missing param inc"); $req->project = $project; $req->authenticator = $auth; $req->app_name = $app_name; $req->jobs = Array(); $f->source = $input_url; $f->name = "in"; $job->input_files = Array($f); for ($x=(double)$param_lo; $x<(double)$param_hi; $x += (double)$param_inc) { $job->rsc_fpops_est = $x*1e9; $job->command_line = "--t $x"; $req->jobs[] = $job; } return $req; } function handle_create_action() { global $project, $auth, $app_name; $get_estimate = get_str('get_estimate', true); if ($get_estimate) { $req = form_to_request($project, $auth); list($e, $errmsg) = boinc_estimate_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch estimate"); echo "Estimate: $e seconds"; page_tail(); } else { $req = form_to_request($project, $auth); list($id, $errmsg) = boinc_submit_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch submitted"); echo "Batch ID: $id"; page_tail(); } } function handle_query_batch() { global $project, $auth, $app_name; $req->project = $project; $req->authenticator = $auth; $req->batch_id = get_int('batch_id'); list($reply, $errmsg) = boinc_query_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch $req->batch_id"); $url = boinc_get_output_files($req); show_button($url, "Get zipped output files"); if ($reply->completed) { echo "
"; show_button( "submit_example.php?action=cleanup_batch_confirm&batch_id=$req->batch_id", "Delete batch" ); } else { echo "
"; show_button( "submit_example.php?action=abort_batch_confirm&batch_id=$req->batch_id", "Abort batch" ); } echo "

Jobs

\n"; start_table(); table_header("Job ID", "Canonical instance"); foreach($reply->jobs as $job) { $id = (int)$job->id; $resultid = (int)$job->canonical_instance_id; if ($resultid) { $x = "$resultid"; } else { $x = "---"; } echo " $id $x "; } end_table(); page_tail(); } function handle_query_job() { global $project, $auth, $app_name; $req->project = $project; $req->authenticator = $auth; $req->job_id = get_int('job_id'); list($reply, $errmsg) = boinc_query_job($req); if ($errmsg) error_page($errmsg); page_head("Job $req->job_id"); start_table(); table_header("Instance ID", "State", "Output files"); foreach($reply->instances as $inst) { echo " id>$inst->id $inst->state "; $i = 0; foreach ($inst->outfiles as $outfile) { $req->instance_name = $inst->name; $req->file_num = $i; $url = boinc_get_output_file($req); echo "$outfile->size bytes"; $i++; } echo "\n"; } end_table(); page_tail(); } function handle_abort_batch_confirm() { $batch_id = get_int('batch_id'); page_head("Confirm abort batch"); echo " Aborting a batch will cancel all unstarted jobs. Are you sure you want to do this?

"; show_button( "submit_example.php?action=abort_batch&batch_id=$batch_id", "Yes - abort batch" ); page_tail(); } function handle_abort_batch() { global $project, $auth, $app_name; $req->project = $project; $req->authenticator = $auth; $req->batch_id = get_int('batch_id'); $errmsg = boinc_abort_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch aborted"); echo " Return to job control page. "; page_tail(); } function handle_cleanup_batch_confirm() { $batch_id = get_int('batch_id'); page_head("Confirm delete batch"); echo " Deleting a batch will remove all of its output files. Are you sure you want to do this?

"; show_button( "submit_example.php?action=cleanup_batch&batch_id=$batch_id", "Yes - delete batch" ); page_tail(); } function handle_cleanup_batch() { global $project, $auth, $app_name; $req->project = $project; $req->authenticator = $auth; $req->batch_id = get_int('batch_id'); $errmsg = boinc_cleanup_batch($req); if ($errmsg) error_page($errmsg); page_head("Batch deleted"); echo " Return to job control page. "; page_tail(); } $action = get_str('action', true); switch ($action) { case '': handle_main(); break; case 'create_form': handle_create_form(); break; case 'create_action': handle_create_action(); break; case 'query_batch': handle_query_batch(); break; case 'query_job': handle_query_job(); break; case 'abort_batch_confirm': handle_abort_batch_confirm(); break; case 'abort_batch': handle_abort_batch(); break; case 'cleanup_batch_confirm': handle_cleanup_batch_confirm(); break; case 'cleanup_batch': handle_cleanup_batch(); break; default: error_page('no such action'); } ?>