Skip to content

Commit

Permalink
Merge pull request #5472 from BOINC/dpa_demo_submit
Browse files Browse the repository at this point in the history
demo_submit, demo_query: allow > 1 input and output files
  • Loading branch information
AenBleidd authored Dec 22, 2023
2 parents ab7fefa + 188bb07 commit 654669a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 21 deletions.
4 changes: 3 additions & 1 deletion sched/sample_assimilator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.

// A sample assimilator that:
// 1) if success, copy the output file(s) to a directory
// 1) if success, copy the output file(s) to a directory ('sample_results')
// If 1 output file, its name is the WU name
// If >1 files, file i is named wuname_i
// 2) if failure, append a message to an error log

#include <vector>
Expand Down
25 changes: 18 additions & 7 deletions tools/demo_query
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function main($wu_name) {
}

if ($wu->error_mask) {
echo sprintf("Job error: %s\n",
echo sprintf("Job failed: %s\n",
wu_error_mask_str($wu->error_mask)
);
return;
Expand All @@ -29,7 +29,7 @@ function main($wu_name) {
echo "Job is in progress.\n";
break;
case ASSIMILATE_READY:
echo "Job waiting for assimilation.\n";
echo "Job is waiting for assimilation.\n";
break;
case ASSIMILATE_DONE:
$result = BoincResult::lookup_id($wu->canonical_resultid);
Expand All @@ -39,12 +39,23 @@ function main($wu_name) {
." Host $host->id ($host->os_name, $host->p_vendor)\n"
." User $user->id ($user->name)\n"
;
$outfile = "sample_results/$wu_name";
if (!is_file($outfile)) {
die("output file is missing: $outfile\n");
$xmlout = simplexml_load_string(
sprintf("<foo>%s</foo>", $result->xml_doc_out)
);
$ofs = $xmlout->file_info;
$nofs = $ofs->count();
for ($i=0; $i<$nofs; $i++) {
if ($nofs == 1) {
$path = "sample_results/$wu_name";
} else {
$path = sprintf("sample_results/%s_%d", $wu_name, $i);
}
if (!is_file($path)) {
die("output file is missing: $path\n");
}
echo "Output file $i ($path):\n";
readfile($path);
}
echo "Output file (sample_result/$wu_name):\n";
readfile($outfile);
break;
}
}
Expand Down
51 changes: 38 additions & 13 deletions tools/demo_submit
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,66 @@

// submit a job for existing application
//
// usage: demo_submit appname infile
// usage: demo_submit appname [infile ...]
//
// Submit a job and show its name.
// Use demo_query to query its status and get output file.
// Use demo_query to query its status and see output files.
//
// This is for demo use, not production. It assumes:
// This assumes:
// - template files are appname_in and appname_out
// - the app uses sample_trivial_validator
// - the app uses sample_assimilator
// (which puts output files in sample_results/)
// - app has 1 input file and 1 output file


if ($argc != 3) die("usage: demo_submit appname infile\n");
if ($argc < 2) die("usage: demo_submit appname [infile ...]\n");

$appname = $argv[1];

chdir("html/ops");
require_once("../inc/boinc_db.inc");
$app = BoincApp::lookup("name='$appname'");
chdir("../..");

$app = BoincApp::lookup("name='$appname'");

if (!$app) {
die("no such application: $appname\n");
}

$fname = $argv[2];
if (!is_file($fname)) {
die("no such file: $fname\n");
// load the input template for this app,
// and make sure the right number of input files was specified
//
$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 ($argc-2 != $nrefs) {
die("wrong number of input files; expected $nrefs\n");
}

system("cp $fname `bin/dir_hier_path $fname`");
// stage the input files
//
$file_list = [];
for ($i=2; $i<$argc; $i++){
$fname = $argv[2];
if (!is_file($fname)) {
die("no such file: $fname\n");
}
system("cp $fname `bin/dir_hier_path $fname`");
$file_list[] = $fname;
}

$wu_name = $appname."_".$fname."_".(string)time();
system("bin/create_work --appname $appname --wu_name $wu_name $fname");
// create the job
//
$wu_name = sprintf('%s_%d', $appname, time());
$cmd = sprintf('bin/create_work --appname %s --wu_name %s %s',
$appname, $wu_name, implode(' ', $file_list)
);
system($cmd);

echo "Job name: $wu_name\n";

Expand Down

0 comments on commit 654669a

Please sign in to comment.