2012-08-31 06:11:06 +00:00
|
|
|
#! /usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// FIRST WHACK AT A REMOTE JOB SUBMISSION TOOL; NOT FINISHED
|
|
|
|
|
|
|
|
|
2012-09-05 14:36:39 +00:00
|
|
|
require_once("submit.inc");
|
2012-08-31 06:11:06 +00:00
|
|
|
|
2012-09-05 14:36:39 +00:00
|
|
|
define("PROJECT", "http://casbak.ihep.ac.cn/casw");
|
2012-08-31 06:11:06 +00:00
|
|
|
define("APP_NAME", "uppercase");
|
|
|
|
|
|
|
|
function usage() {
|
2012-09-05 14:36:39 +00:00
|
|
|
global $argv;
|
|
|
|
die("
|
2012-08-31 06:11:06 +00:00
|
|
|
Usage:
|
2012-09-05 14:36:39 +00:00
|
|
|
$argv[0] submit sequence_file (submit 1 job, print batch ID)
|
|
|
|
$argv[0] query batch_id|all (get the status of a specific batch or all batches)
|
|
|
|
$argv[0] get_output batch_id (show URL of output file)
|
|
|
|
$argv[0] abort batch_id (abort a batch)
|
|
|
|
$argv[0] retire batch_id (retire a batch)
|
|
|
|
\n");
|
2012-08-31 06:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_auth() {
|
|
|
|
return trim(file_get_contents("auth"));
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_submit() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 3) usage();
|
|
|
|
//if (!is_file($argv[2])) die("seq file missing");
|
|
|
|
$req->project = PROJECT;
|
|
|
|
$req->authenticator = get_auth();
|
|
|
|
$req->app_name = APP_NAME;
|
|
|
|
$req->batch_name = "foobar";
|
|
|
|
|
|
|
|
$f->source = $argv[2];
|
|
|
|
$job->input_files = array($f);
|
|
|
|
$job->rsc_fpops_est = 1e12;
|
|
|
|
$job->command_line = "";
|
|
|
|
$req->jobs[] = $job;
|
|
|
|
list($id, $errmsg) = boinc_submit_batch($req);
|
|
|
|
if ($errmsg) {
|
|
|
|
echo "Error: $errmsg\n";
|
|
|
|
} else {
|
|
|
|
echo "batch ID: $id\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_query() {
|
2012-09-05 14:36:39 +00:00
|
|
|
global $argc,$argv;
|
2012-08-31 06:11:06 +00:00
|
|
|
$req->project = PROJECT;
|
|
|
|
$req->authenticator = get_auth();
|
|
|
|
list($batches, $errmsg) = boinc_query_batches($req);
|
|
|
|
if ($errmsg) {
|
|
|
|
echo "Error: $errmsg\n";
|
|
|
|
return;
|
|
|
|
}
|
2012-09-05 14:36:39 +00:00
|
|
|
if($argv[2]!='all')$batch_id=$argv[2];
|
|
|
|
else $batch_id=-1;
|
|
|
|
|
|
|
|
if($batch_id==-1){
|
|
|
|
foreach ($batches as $batch) {
|
|
|
|
echo "batch $batch->id: ";
|
|
|
|
switch ($batch->state) {
|
|
|
|
case 1: echo "In progress\n"; break;
|
|
|
|
case 2: echo "Completed\n"; break;
|
|
|
|
case 3: echo "Aborted\n"; break;
|
|
|
|
case 4: echo "Retired\n"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
foreach ($batches as $batch) {
|
|
|
|
if ($batch->id==$batch_id){
|
|
|
|
echo "batch $batch_id: ";
|
|
|
|
switch ($batch->state) {
|
|
|
|
case 1: echo "In progress\n"; break;
|
|
|
|
case 2: echo "Completed\n"; break;
|
|
|
|
case 3: echo "Aborted\n"; break;
|
|
|
|
case 4: echo "Retired\n"; break;
|
|
|
|
}//switch
|
|
|
|
} //if
|
|
|
|
}//foreach
|
|
|
|
}//else
|
|
|
|
}//query_batch()
|
2012-08-31 06:11:06 +00:00
|
|
|
|
|
|
|
function handle_get_output() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 3) usage();
|
|
|
|
$req->project = PROJECT;
|
|
|
|
$req->authenticator = get_auth();
|
|
|
|
$req->batch_id = $argv[2];
|
|
|
|
$url = boinc_get_output_files($req);
|
|
|
|
echo "Zipped output files are at $url\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_abort() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 3) usage();
|
|
|
|
$req->project = PROJECT;
|
|
|
|
$req->authenticator = get_auth();
|
|
|
|
$req->batch_id = $argv[2];
|
|
|
|
$errmsg = boinc_abort_batch($req);
|
|
|
|
if ($errmsg) {
|
|
|
|
echo "Error: $errmsg\n";
|
|
|
|
} else {
|
|
|
|
echo "Batch aborted\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle_retire() {
|
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 3) usage();
|
|
|
|
$req->project = PROJECT;
|
|
|
|
$req->authenticator = get_auth();
|
|
|
|
$req->batch_id = $argv[2];
|
|
|
|
$errmsg = boinc_retire_batch($req);
|
|
|
|
if ($errmsg) {
|
|
|
|
echo "Error: $errmsg\n";
|
|
|
|
} else {
|
|
|
|
echo "Batch retired\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 14:36:39 +00:00
|
|
|
if ($argc < 3) usage();
|
2012-08-31 06:11:06 +00:00
|
|
|
switch ($argv[1]) {
|
|
|
|
case "submit": handle_submit(); break;
|
|
|
|
case "query": handle_query(); break;
|
|
|
|
case "get_output": handle_get_output(); break;
|
|
|
|
case "abort": handle_abort(); break;
|
|
|
|
case "retire": handle_retire(); break;
|
|
|
|
default: usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|