2012-04-10 06:11:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Handler for TreeThreader remote job submission.
|
2012-04-11 04:10:41 +00:00
|
|
|
//
|
|
|
|
// Assumptions:
|
2012-04-12 02:50:53 +00:00
|
|
|
// - there is a file "tree_threader_templates_files" in the project root
|
2012-04-11 04:10:41 +00:00
|
|
|
// containing (one per line) the names of files containing
|
|
|
|
// gzipped collections of template files
|
|
|
|
// - These files are in the download hierarchy.
|
2012-04-10 06:11:19 +00:00
|
|
|
|
|
|
|
require_once("../inc/boinc_db.inc");
|
|
|
|
require_once("../inc/submit_db.inc");
|
|
|
|
require_once("../inc/xml.inc");
|
|
|
|
require_once("../inc/dir_hier.inc");
|
|
|
|
require_once("../inc/result.inc");
|
|
|
|
require_once("../inc/submit_util.inc");
|
|
|
|
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
ini_set('display_errors', true);
|
|
|
|
ini_set('display_startup_errors', true);
|
|
|
|
|
2012-04-12 07:30:45 +00:00
|
|
|
$app_name = "treeThreader";
|
2012-09-13 11:41:23 +00:00
|
|
|
$log = fopen("/tmp/tt_job.log","a+");
|
2012-04-12 05:18:22 +00:00
|
|
|
|
2012-04-10 06:11:19 +00:00
|
|
|
function error($s) {
|
|
|
|
echo "<error>\n<message>$s</message>\n</error>\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:50:53 +00:00
|
|
|
function handle_submit($r, $user, $app) {
|
2012-09-13 11:41:23 +00:00
|
|
|
global $app_name,$log;
|
2012-04-12 07:30:45 +00:00
|
|
|
|
2012-09-13 11:41:23 +00:00
|
|
|
$timestamp = date("Y-m-d H:i",time());
|
2012-04-12 02:50:53 +00:00
|
|
|
// read the list of template filenames
|
|
|
|
//
|
|
|
|
$files = file("../../tree_threader_template_files");
|
2012-09-13 11:41:23 +00:00
|
|
|
if ($files === false) {
|
2012-09-14 11:45:13 +00:00
|
|
|
fwrite($log,"$timestamp\ttemplate file tree_threader_template_files\n");
|
2012-09-13 11:41:23 +00:00
|
|
|
error("no templates file");
|
|
|
|
|
|
|
|
}
|
2012-04-12 02:50:53 +00:00
|
|
|
$njobs = sizeof($files);
|
|
|
|
$now = time();
|
|
|
|
$batch_id = BoincBatch::insert(
|
2012-04-12 07:30:45 +00:00
|
|
|
"(user_id, create_time, njobs, name, app_id, state) values ($user->id, $now, $njobs, 'tree_threader batch', $app->id, ".BATCH_STATE_IN_PROGRESS.")"
|
2012-04-11 04:10:41 +00:00
|
|
|
);
|
2012-09-13 11:41:23 +00:00
|
|
|
if (!$batch_id) {
|
|
|
|
$log_msg = "$timestamp\tfailed to create batch for user $user->id\n";
|
|
|
|
fwrite($log, $log_msg);
|
|
|
|
die("couldn't create batch\n");
|
|
|
|
} else {
|
|
|
|
$log_msg = "$timestamp\tcreated batch $batch_id for user $user->id\n";
|
|
|
|
fwrite($log, $log_msg);
|
|
|
|
}
|
2012-04-12 07:30:45 +00:00
|
|
|
|
2012-04-12 12:20:16 +00:00
|
|
|
// move the sequence file to the download hier
|
2012-04-12 07:30:45 +00:00
|
|
|
//
|
|
|
|
$config = simplexml_load_string(file_get_contents("../../config.xml"));
|
|
|
|
$fanout = (int)$config->config->uldl_dir_fanout;
|
|
|
|
$download_dir = trim((string)$config->config->download_dir);
|
|
|
|
|
2012-09-14 11:45:13 +00:00
|
|
|
$seq_fname = "treeThreader_sequence_$batch_id.tar.gz";
|
2012-04-12 07:30:45 +00:00
|
|
|
$seq_path = dir_hier_path($seq_fname, $download_dir, $fanout);
|
2012-04-12 12:20:16 +00:00
|
|
|
$tmp_name = $_FILES['seq_file']['tmp_name'];
|
|
|
|
$ret = rename($tmp_name, $seq_path);
|
2012-04-12 07:30:45 +00:00
|
|
|
if ($ret === false) {
|
2012-04-12 12:20:16 +00:00
|
|
|
error("couldn't rename sequence file");
|
2012-04-12 07:30:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 11:41:23 +00:00
|
|
|
$i = 1;
|
2012-04-12 02:50:53 +00:00
|
|
|
foreach ($files as $file) {
|
2012-04-12 07:30:45 +00:00
|
|
|
$file = trim($file);
|
|
|
|
$wu_name = "ICT_".$batch_id."_$i";
|
2012-09-13 11:41:23 +00:00
|
|
|
|
2012-09-01 06:34:04 +00:00
|
|
|
$cmd = "cd ../..; ./bin/create_work --appname $app_name --batch $batch_id --wu_name $wu_name --wu_template templates/ICT_in --result_template templates/ICT_out $seq_fname $file";
|
2012-09-13 11:41:23 +00:00
|
|
|
fwrite($log, "$timestamp\t$cmd\n");
|
|
|
|
system($cmd, $ret);
|
|
|
|
if ($ret != 0) {
|
|
|
|
fwrite($log, "can not creat job $wu_name\n");
|
2012-04-12 02:50:53 +00:00
|
|
|
error("can't create job");
|
2012-04-12 07:30:45 +00:00
|
|
|
}
|
2012-09-01 06:28:46 +00:00
|
|
|
$i++;
|
2012-04-12 02:50:53 +00:00
|
|
|
}
|
2012-04-13 05:45:16 +00:00
|
|
|
echo "<tt_reply>\n<batch_id>$batch_id</batch_id>\n</tt_reply>\n";
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 02:50:53 +00:00
|
|
|
// Enumerate all the successfully completed WUs for this batch.
|
2012-04-13 05:45:16 +00:00
|
|
|
// Each output file is a .zip that unzips into a directory ali/.
|
2012-04-12 02:50:53 +00:00
|
|
|
// Combine their output files into a zip file in /tmp,
|
|
|
|
// make a symbolic link to this from /download,
|
|
|
|
// and return the resulting URL
|
|
|
|
//
|
|
|
|
function handle_get_output($r, $batch) {
|
2012-09-13 11:41:23 +00:00
|
|
|
global $log;
|
2012-09-14 11:45:13 +00:00
|
|
|
$timestamp = date("Y-m-d H:i",time());
|
2012-04-12 07:30:45 +00:00
|
|
|
$wus = BoincWorkUnit::enum("batch=$batch->id");
|
2012-09-14 11:45:13 +00:00
|
|
|
$outdir = "/tmp/treeThreader_result_".$batch->id;
|
2012-04-13 05:45:16 +00:00
|
|
|
@mkdir($outdir);
|
2012-04-12 02:50:53 +00:00
|
|
|
foreach ($wus as $wu) {
|
|
|
|
if (!$wu->canonical_resultid) continue;
|
|
|
|
$result = BoincResult::lookup_id($wu->canonical_resultid);
|
|
|
|
if (!$result) continue;
|
|
|
|
$paths = get_outfile_paths($result);
|
|
|
|
if (sizeof($paths) < 1) continue;
|
|
|
|
|
|
|
|
// there's only one output file
|
|
|
|
//
|
|
|
|
$path = $paths[0];
|
|
|
|
|
|
|
|
// unzip it into a directory in /tmp
|
|
|
|
//
|
2012-04-13 05:45:16 +00:00
|
|
|
$dir = "/tmp/$wu->name";
|
|
|
|
@mkdir($dir);
|
|
|
|
$cmd = "cd $dir; unzip -q $path";
|
2012-09-13 11:41:23 +00:00
|
|
|
system($cmd, $ret);
|
|
|
|
if ($ret != 0) {
|
2012-04-12 02:50:53 +00:00
|
|
|
error("can't unzip output file");
|
|
|
|
}
|
2012-09-13 11:41:23 +00:00
|
|
|
$cmd = "cp $dir/Aln/* $outdir";
|
|
|
|
system($cmd, $ret);
|
|
|
|
if ($ret != 0) {
|
2012-04-12 02:50:53 +00:00
|
|
|
error("can't copy output files");
|
|
|
|
}
|
|
|
|
|
2012-09-13 11:41:23 +00:00
|
|
|
system("rm -rf $dir");
|
2012-04-12 02:50:53 +00:00
|
|
|
}
|
2012-04-13 05:45:16 +00:00
|
|
|
|
|
|
|
$cmd = "zip -r -q $outdir $outdir";
|
2012-09-13 11:41:23 +00:00
|
|
|
system($cmd, $ret);
|
|
|
|
if ($ret != $ret) {
|
2012-04-12 02:50:53 +00:00
|
|
|
error("can't zip output files");
|
|
|
|
}
|
2012-09-14 11:45:13 +00:00
|
|
|
$fname = "treeThreader_result_".$batch->id.".zip";
|
2012-09-13 11:41:23 +00:00
|
|
|
$treeThreader_dir="treeThreaderResult";
|
|
|
|
if(!is_dir("../../download/$treeThreader_dir"))mkdir("../../download/$treeThreader_dir");
|
|
|
|
@symlink("/tmp/$fname", "../../download/$treeThreader_dir/$fname");
|
|
|
|
system("rm -fr $outdir");
|
2012-04-13 05:45:16 +00:00
|
|
|
$config = simplexml_load_string(file_get_contents("../../config.xml"));
|
|
|
|
$download_url = trim((string)$config->config->download_url);
|
2012-09-13 11:41:23 +00:00
|
|
|
echo "<tt_reply>\n<url>$download_url/$treeThreader_dir/$fname</url>\n</tt_reply>\n";
|
2012-09-14 11:45:13 +00:00
|
|
|
$log_msg="$timestamp\tuser $batch->user_id downloads results for batch $batch->id : $download_url/$treeThreader_dir/$fname\n";
|
|
|
|
fwrite($log, $log_msg);
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xml_header();
|
|
|
|
|
2012-04-12 12:20:16 +00:00
|
|
|
if (1) {
|
|
|
|
$r = simplexml_load_string($_POST['request']);
|
2012-04-12 05:18:22 +00:00
|
|
|
} else {
|
2012-04-12 12:20:16 +00:00
|
|
|
$x = file_get_contents("xml_req");
|
|
|
|
$r = simplexml_load_string($x);
|
2012-04-12 05:18:22 +00:00
|
|
|
}
|
2012-04-10 06:11:19 +00:00
|
|
|
|
|
|
|
if (!$r) {
|
|
|
|
error("can't parse request message");
|
|
|
|
}
|
|
|
|
|
2012-04-11 04:10:41 +00:00
|
|
|
// authenticate the user
|
|
|
|
//
|
|
|
|
$auth = (string)$r->auth;
|
2012-04-12 05:18:22 +00:00
|
|
|
$user = BoincUser::lookup("authenticator='$auth'");
|
2012-04-11 04:10:41 +00:00
|
|
|
if (!$user) error("invalid authenticator");
|
|
|
|
$user_submit = BoincUserSubmit::lookup_userid($user->id);
|
|
|
|
if (!$user_submit) error("no submit access");
|
2012-04-12 05:18:22 +00:00
|
|
|
$app = BoincApp::lookup("name='$app_name'");
|
2012-04-11 04:10:41 +00:00
|
|
|
if (!$app) error("no tree_threader app");
|
|
|
|
|
|
|
|
if (!$user_submit->submit_all) {
|
|
|
|
$usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id");
|
|
|
|
if (!$usa) {
|
|
|
|
error("no submit access");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 05:18:22 +00:00
|
|
|
switch ((string)$r->action) {
|
2012-04-13 05:45:16 +00:00
|
|
|
case 'submit':
|
|
|
|
handle_submit($r, $user, $app);
|
|
|
|
break;
|
2012-04-12 02:50:53 +00:00
|
|
|
case 'get_output':
|
2012-04-12 07:30:45 +00:00
|
|
|
$batch_id = (int)$r->batch_id;
|
2012-04-12 02:50:53 +00:00
|
|
|
$batch = BoincBatch::lookup_id($batch_id);
|
|
|
|
if (!$batch) error("no such batch");
|
|
|
|
if ($batch->user_id != $user->id) error("not owner of batch");
|
|
|
|
handle_get_output($r, $batch);
|
|
|
|
break;
|
2012-04-10 06:11:19 +00:00
|
|
|
default: error("bad command");
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|