2024-11-13 01:49:52 +00:00
|
|
|
#! /usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// submit a job and show the WU name
|
|
|
|
//
|
|
|
|
// usage: submit_job [options] appname [infile ...]
|
|
|
|
// options:
|
2024-11-13 07:34:40 +00:00
|
|
|
// --templates in out: specify in/out template files
|
|
|
|
// --verbose
|
2024-11-13 01:49:52 +00:00
|
|
|
//
|
|
|
|
// If the app uses a sample assimilator,
|
|
|
|
// you can use query_job to query the job status and see output files.
|
|
|
|
|
|
|
|
$appname = null;
|
2024-11-13 07:34:40 +00:00
|
|
|
$input_template = null;
|
|
|
|
$output_template = null;
|
2024-11-13 01:49:52 +00:00
|
|
|
$infiles = [];
|
2024-11-13 07:34:40 +00:00
|
|
|
$verbose = false;
|
2024-11-13 01:49:52 +00:00
|
|
|
|
|
|
|
for ($i=1; $i<$argc; $i++) {
|
2024-11-13 07:34:40 +00:00
|
|
|
if ($argv[$i] == '--templates') {
|
|
|
|
$input_template = $argv[++$i];
|
|
|
|
$output_template = $argv[++$i];
|
|
|
|
} else if ($argv[$i] == '--verbose') {
|
|
|
|
$verbose = true;
|
2024-11-13 01:49:52 +00:00
|
|
|
} else if (!$appname) {
|
|
|
|
$appname = $argv[$i];
|
|
|
|
} else {
|
|
|
|
$infiles[] = $argv[$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$appname) {
|
|
|
|
die("usage: demo_submit [--template fname] [--dir dir] appname [infile ...]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir("html/ops");
|
|
|
|
require_once("../inc/boinc_db.inc");
|
|
|
|
chdir("../..");
|
|
|
|
|
|
|
|
$app = BoincApp::lookup("name='$appname'");
|
|
|
|
|
|
|
|
if (!$app) {
|
|
|
|
die("no such application: $appname\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the input template for this app,
|
|
|
|
// and make sure the right number of input files were specified
|
|
|
|
//
|
2024-11-13 07:34:40 +00:00
|
|
|
if ($input_template) {
|
|
|
|
$path = $input_template;
|
2024-11-13 01:49:52 +00:00
|
|
|
} else {
|
|
|
|
$path = sprintf('templates/%s_in', $appname);
|
|
|
|
}
|
|
|
|
if (!is_file($path)) {
|
|
|
|
die("missing input template $path\n");
|
|
|
|
}
|
|
|
|
$intemp = simplexml_load_file($path);
|
|
|
|
if (!$intemp) die("can't parse input template\n");
|
|
|
|
$frefs = $intemp->workunit->file_ref;
|
|
|
|
$nrefs = $frefs->count();
|
|
|
|
|
|
|
|
if (count($infiles) != $nrefs) {
|
|
|
|
die("wrong number of input files; expected $nrefs\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// stage the input files
|
|
|
|
//
|
2024-11-13 07:34:40 +00:00
|
|
|
$fnames = [];
|
|
|
|
foreach ($infiles as $path) {
|
|
|
|
if (!is_file("$path")) {
|
|
|
|
die("no such file: $path\n");
|
2024-11-13 01:49:52 +00:00
|
|
|
}
|
2024-11-13 07:34:40 +00:00
|
|
|
$fname = basename($path);
|
|
|
|
$fnames[] = $fname;
|
|
|
|
system("cp $path `bin/dir_hier_path $fname`", $ret);
|
2024-11-13 01:49:52 +00:00
|
|
|
if ($ret) {
|
2024-11-13 07:34:40 +00:00
|
|
|
die("Couldn't stage file $path\n");
|
2024-11-13 01:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create the job
|
|
|
|
//
|
|
|
|
$wu_name = sprintf('%s_%d', $appname, time());
|
|
|
|
$x = '';
|
2024-11-13 07:34:40 +00:00
|
|
|
if ($input_template) {
|
|
|
|
$x .= " --wu_template $input_template";
|
|
|
|
}
|
|
|
|
if ($output_template) {
|
|
|
|
$x .= " --result_template $output_template";
|
2024-11-13 01:49:52 +00:00
|
|
|
}
|
|
|
|
$cmd = sprintf('bin/create_work --appname %s --wu_name %s %s %s',
|
2024-11-13 07:34:40 +00:00
|
|
|
$appname, $wu_name, $x, implode(' ', $fnames)
|
2024-11-13 01:49:52 +00:00
|
|
|
);
|
2024-11-13 07:34:40 +00:00
|
|
|
if ($verbose) {
|
|
|
|
echo "submit_job: cmd: $cmd\n";
|
|
|
|
}
|
2024-11-13 01:49:52 +00:00
|
|
|
if (system($cmd, $ret) === false) {
|
|
|
|
die("system($cmd) failed\n");
|
|
|
|
}
|
|
|
|
if ($ret) {
|
|
|
|
die("Couldn't create job\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Job name: $wu_name\n";
|
|
|
|
|
|
|
|
?>
|