2012-04-10 06:11:19 +00:00
|
|
|
#! /usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Job submission and control script for TreeThreader application
|
|
|
|
// from the Institute for Computing Technology in Beijing
|
|
|
|
//
|
|
|
|
|
2012-04-12 12:20:16 +00:00
|
|
|
define("PROJECT", "http://casbak.ihep.ac.cn/castest/");
|
2012-04-10 06:11:19 +00:00
|
|
|
|
|
|
|
function usage() {
|
|
|
|
die("
|
|
|
|
Usage:
|
|
|
|
tt_boinc submit sequence_file authenticator
|
|
|
|
submit batch, print batch ID
|
2012-04-12 07:30:45 +00:00
|
|
|
tt_boinc get_output batch_id auth
|
2012-04-10 06:11:19 +00:00
|
|
|
show URL of output file
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
2012-04-12 12:20:16 +00:00
|
|
|
function do_http_op($xml, $file=null) {
|
2012-04-12 05:18:22 +00:00
|
|
|
$ch = curl_init(PROJECT."tree_threader.php");
|
2012-04-10 06:11:19 +00:00
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
2012-04-12 12:20:16 +00:00
|
|
|
if ($file) {
|
|
|
|
$fields = array('request' => $xml, 'seq_file' => "@$file");
|
|
|
|
} else {
|
|
|
|
$fields = "request=$xml";
|
|
|
|
}
|
|
|
|
if (!curl_setopt($ch, CURLOPT_POSTFIELDS, $fields)) {
|
|
|
|
die("curl_setopt failed\n");
|
|
|
|
}
|
2012-04-10 06:11:19 +00:00
|
|
|
$reply = curl_exec($ch);
|
|
|
|
if (!$reply) return array(null, "HTTP error");
|
|
|
|
$r = simplexml_load_string($reply);
|
|
|
|
if (!$r) return array(null, "Can't parse reply XML: <pre>".htmlentities($reply)."</pre>");
|
|
|
|
return array($r, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_submit() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 4) usage();
|
2012-04-12 12:20:16 +00:00
|
|
|
if (!is_file($argv[2])) die("seq file missing");
|
2012-04-10 06:11:19 +00:00
|
|
|
$auth = $argv[3];
|
|
|
|
$req_xml = "
|
|
|
|
<tt_request>
|
|
|
|
<action>submit</action>
|
|
|
|
<auth>$auth</auth>
|
|
|
|
</tt_request>
|
|
|
|
";
|
2012-04-12 12:20:16 +00:00
|
|
|
list($reply, $errmsg) = do_http_op($req_xml, $argv[2]);
|
2012-04-10 06:11:19 +00:00
|
|
|
if ($errmsg) die("Error: $errmsg\n");
|
|
|
|
$id = (int)$reply->id;
|
2012-04-12 05:18:22 +00:00
|
|
|
echo "batch ID: $id\n";
|
2012-04-10 06:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handle_get_output() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 4) usage();
|
2012-04-12 07:30:45 +00:00
|
|
|
$batch_id = $argv[3];
|
2012-04-10 06:11:19 +00:00
|
|
|
$auth = $argv[4];
|
|
|
|
$req_xml = "
|
|
|
|
<tt_request>
|
|
|
|
<action>get_output</action>
|
2012-04-12 07:30:45 +00:00
|
|
|
<batch_id>$batch_id</batch_id>
|
2012-04-10 06:11:19 +00:00
|
|
|
<auth>$auth</auth>
|
|
|
|
</tt_request>
|
|
|
|
";
|
|
|
|
list($reply, $errmsg) = do_http_op($req_xml);
|
|
|
|
if ($errmsg) die("Error: $errmsg\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($argc < 2) usage();
|
|
|
|
switch ($argv[1]) {
|
|
|
|
case "submit": handle_submit(); break;
|
|
|
|
case "get_output": handle_get_output(); break;
|
|
|
|
default: usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|