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
|
|
|
|
2013-07-16 20:18:46 +00:00
|
|
|
define("PROJECT", "http://casathome.ihep.ac.cn/");
|
2012-08-31 06:11:06 +00:00
|
|
|
define("APP_NAME", "uppercase");
|
2013-07-16 20:18:46 +00:00
|
|
|
define("LOCAL_DIR", "");
|
2012-08-31 06:11:06 +00:00
|
|
|
|
|
|
|
function usage() {
|
2023-05-05 18:05:20 +00:00
|
|
|
global $argv;
|
2013-07-16 20:18:46 +00:00
|
|
|
echo "
|
2012-08-31 06:11:06 +00:00
|
|
|
Usage:
|
2012-09-14 06:20:10 +00:00
|
|
|
$argv[0] submit sequence_file (submit 1 job, print batch ID)
|
2012-09-14 07:12:59 +00:00
|
|
|
$argv[0] query batch_id (get the status of a specific batch)
|
|
|
|
$argv[0] query app_name (get the status of batches for given app )
|
|
|
|
$argv[0] query all (get the status of 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)
|
2013-07-16 20:18:46 +00:00
|
|
|
";
|
|
|
|
exit(1);
|
2012-08-31 06:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_auth() {
|
2013-07-16 20:18:46 +00:00
|
|
|
return trim(file_get_contents(LOCAL_DIR."auth"));
|
2012-08-31 06:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
2013-07-16 20:18:46 +00:00
|
|
|
exit(1);
|
2012-08-31 06:11:06 +00:00
|
|
|
} else {
|
|
|
|
echo "batch ID: $id\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 07:12:59 +00:00
|
|
|
date_default_timezone_set('Asia/Chongqing');
|
|
|
|
|
|
|
|
function local_time_str($x) {
|
|
|
|
if ($x == 0) return "---";
|
|
|
|
return date('j M Y, H:i T', $x);
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_batch($batch) {
|
|
|
|
echo "ID: $batch->id
|
|
|
|
creation time: ".local_time_str($batch->create_time)."
|
|
|
|
# jobs: $batch->njobs
|
|
|
|
fraction done: $batch->fraction_done
|
|
|
|
# error jobs: $batch->nerror_jobs
|
|
|
|
state: ";
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
echo " completion time: ".local_time_str($batch->completion_time)."
|
|
|
|
credit estimate: $batch->credit_estimate
|
|
|
|
granted credit: $batch->credit_canonical
|
|
|
|
name: $batch->name
|
|
|
|
app: $batch->app_name
|
|
|
|
";
|
|
|
|
}
|
|
|
|
|
2012-09-14 08:05:16 +00:00
|
|
|
function print_state($batch) {
|
|
|
|
$status="none";
|
|
|
|
switch ($batch->state) {
|
|
|
|
case 1: $status = "In progress";break;
|
|
|
|
case 2: $status = "Completed";break;
|
|
|
|
case 3: $status = "Aborted";break;
|
|
|
|
case 4: $status = "Retired";break;
|
|
|
|
}
|
|
|
|
echo "ID: $batch->id $status\n";
|
|
|
|
}
|
|
|
|
|
2012-08-31 06:11:06 +00:00
|
|
|
function handle_query() {
|
2012-09-14 06:20:10 +00:00
|
|
|
global $argc, $argv;
|
|
|
|
if ($argc != 3) usage();
|
|
|
|
|
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";
|
2013-07-16 20:18:46 +00:00
|
|
|
exit(1);
|
2012-08-31 06:11:06 +00:00
|
|
|
}
|
2012-09-14 06:20:10 +00:00
|
|
|
if ($argv[2] == 'all') {
|
|
|
|
foreach ($batches as $batch) {
|
2012-09-14 08:05:16 +00:00
|
|
|
//print_batch($batch);
|
|
|
|
print_state($batch);
|
2012-09-14 06:20:10 +00:00
|
|
|
}
|
|
|
|
} else if (is_numeric($argv[2])) {
|
2012-09-14 07:12:59 +00:00
|
|
|
$batch_id = $argv[2];
|
|
|
|
foreach ($batches as $batch) {
|
|
|
|
if ($batch->id == $batch_id) {
|
2012-09-14 08:05:16 +00:00
|
|
|
//print_batch($batch);
|
|
|
|
print_state($batch);
|
2012-09-14 07:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$app_name = $argv[2];
|
2012-09-14 06:20:10 +00:00
|
|
|
foreach ($batches as $batch) {
|
2012-09-14 07:12:59 +00:00
|
|
|
if ($batch->app_name == $app_name) {
|
2012-09-14 08:05:16 +00:00
|
|
|
//print_batch($batch);
|
|
|
|
print_state($batch);
|
2012-09-14 06:20:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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";
|
2013-07-16 20:18:46 +00:00
|
|
|
exit(1);
|
2012-08-31 06:11:06 +00:00
|
|
|
} 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";
|
2013-07-16 20:18:46 +00:00
|
|
|
exit(1);
|
2012-08-31 06:11:06 +00:00
|
|
|
} 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();
|
|
|
|
}
|
2023-05-05 18:05:20 +00:00
|
|
|
|
2012-08-31 06:11:06 +00:00
|
|
|
?>
|