Skip to content

Commit

Permalink
BUDA: debug cmdline arg features
Browse files Browse the repository at this point in the history
- file sandbox: add 'Get web file' option
- docker wrapper: always write container log output to stderr
- worker: write cmdline args to stderr
- worker: version# is 4
- fix bug in file sandbox display
- fix bug in BUDA variant delete
- BUDA variant name defaults to 'cpu'
- update examples files in samples/docker_wrapper/test_buda
  • Loading branch information
davidpanderson committed Dec 4, 2024
1 parent e38016d commit e14f715
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 49 deletions.
2 changes: 1 addition & 1 deletion html/inc/sandbox.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function sandbox_parse_info_file($user, $name) {
if ($info) {
return $info;
}
[$size, $md5] = get_file_info("$dir/$name");
[$md5, $size] = get_file_info("$dir/$name");
write_info_file($info_path, $md5, $size);
return [$md5, $size];
}
Expand Down
5 changes: 3 additions & 2 deletions html/user/buda.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function variant_view() {
}
end_table();
show_button_small(
"buda.php?action=variant_delete&app=$dir&variant=$variant",
"buda.php?action=variant_delete&app=$app&variant=$variant",
'Delete variant'
);
page_tail();
Expand Down Expand Up @@ -167,6 +167,7 @@ function copy_and_stage_file($user, $fname, $dir, $app, $variant) {
function variant_action($user) {
global $buda_root;
$variant = get_str('variant');
if (!$variant) $variant = 'cpu';
if (!is_valid_filename($variant)) die('bad arg');
$app = get_str('app');
if (!is_valid_filename($app)) die('bad arg');
Expand Down Expand Up @@ -300,7 +301,7 @@ function app_form() {
function app_action() {
global $buda_root;
$name = get_str('name');
if (!is_valid_filename($name)) die('bad arg');
if (!is_valid_filename($name)) die("bad arg: $name");
$dir = "$buda_root/$name";
if (file_exists($dir)) {
error_page("App $name already exists.");
Expand Down
4 changes: 2 additions & 2 deletions html/user/buda_submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function unzip_batch_file($user, $batch_file) {

// Scan a batch dir.
// Check its validity:
// - Top level can have only infiles (shared)
// - Subdirs (job dirs) can have only remaining infiles and possibly cmdline
// - optional dir 'shared_input_files' has shared input files
// - other dirs (job dirs) can have only remaining infiles and possibly cmdline
//
// Return a structure describing its contents, and the md5/size of files
//
Expand Down
25 changes: 24 additions & 1 deletion html/user/sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function list_files($user, $notice) {
}
echo "
<p>
<h3>Upload files</h3>
<h3>Upload files from this computer</h3>
<p>
NOTE: if you upload text files from Windows,
they will be given CRLF line endings.
Expand All @@ -63,6 +63,15 @@ function list_files($user, $notice) {
form_input_textarea('Contents', 'contents');
form_submit('OK');
form_end();
echo "
<hr>
<h3>Get web file</h3>
";
form_start('sandbox.php', 'post');
form_input_hidden('action', 'get_file');
form_input_text('URL', 'url');
form_submit('OK');
form_end();
echo "
<hr>
<h3>Sandbox contents</h3>
Expand Down Expand Up @@ -150,6 +159,19 @@ function add_file($user) {
list_files($user, $notice);
}

function get_file($user) {
$dir = sandbox_dir($user);
$url = post_str('url');
$fname = basename($url);
$path = "$dir/$fname";
if (file_exists($path)) {
error_page("File $fname exists; delete it first.");
}
copy($url, $path);
$notice = "Fetched file from <strong>$url</strong><br/>";
list_files($user, $notice);
}

// delete a sandbox file.
//
function delete_file($user) {
Expand Down Expand Up @@ -189,6 +211,7 @@ function view_file($user) {
case '': list_files($user,""); break;
case 'upload_file': upload_file($user); break;
case 'add_file': add_file($user); break;
case 'get_file': get_file($user); break;
case 'delete_file': delete_file($user); break;
case 'download_file': download_file($user); break;
case 'view_file': view_file($user); break;
Expand Down
15 changes: 7 additions & 8 deletions samples/docker_wrapper/docker_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,20 @@ int container_op(const char *op) {
}

// Clean up at end of job.
// Show log output if verbose;
// Show log output.
// remove container and image
//
void cleanup() {
char cmd[1024];
vector<string> out;

if (verbose) {
sprintf(cmd, "logs %s", container_name);
docker_conn.command(cmd, out);
fprintf(stderr, "container log:\n");
for (string line : out) {
fprintf(stderr, " %s\n", line.c_str());
}
sprintf(cmd, "logs %s", container_name);
docker_conn.command(cmd, out);
fprintf(stderr, "stderr from container:\n");
for (string line : out) {
fprintf(stderr, "%s\n", line.c_str());
}
fprintf(stderr, "stderr end\n");

container_op("stop");

Expand Down
3 changes: 0 additions & 3 deletions samples/docker_wrapper/test_buda/Dockerfile_worker_1

This file was deleted.

4 changes: 4 additions & 0 deletions samples/docker_wrapper/test_buda/Dockerfile_worker_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM debian
WORKDIR /app
ENV ARGS ""
CMD ./main_3.sh ${ARGS}
3 changes: 0 additions & 3 deletions samples/docker_wrapper/test_buda/main_2.sh

This file was deleted.

3 changes: 3 additions & 0 deletions samples/docker_wrapper/test_buda/main_3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

./worker_4_x86_64-pc-linux-gnu $ARGS in out
6 changes: 3 additions & 3 deletions samples/worker/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS += -g
#CXXFLAGS += -g
CXX ?= g++

ifdef ANDROID
Expand All @@ -20,8 +20,8 @@ clean: distclean
distclean:
rm -f $(PROGS) $(addsuffix .exe, $(PROGS)) *.o

worker$(WORKER_RELEASE_SUFFIX): worker.o
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o worker$(WORKER_RELEASE_SUFFIX) worker.o
worker$(WORKER_RELEASE_SUFFIX): worker.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -o worker$(WORKER_RELEASE_SUFFIX) worker.cpp

install: all

Expand Down
63 changes: 38 additions & 25 deletions samples/worker/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,59 +47,72 @@ static double do_a_giga_flop(int foo) {
return x;
}

void copy_uc(FILE* fin, FILE* fout) {
int c;
int copy_uc(FILE* fin, FILE* fout) {
int c, n=0;
while (1) {
c = fgetc(fin);
if (c == EOF) break;
fputc(toupper(c), fout);
n++;
}
return n;
}

int main(int argc, char** argv) {
const char *infile=NULL, *outfile=NULL;
FILE* in=0, *out=0;
int i, nsecs = 0;

for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "--nsecs")) {
nsecs = atoi(argv[++i]);
} else if (!in) {
if (!strcmp(argv[i], "stdin")) {
in = stdin;
} else {
in = fopen(argv[i], "r");
if (!in) {
fprintf(stderr, "missing input file %s\n", argv[i]);
exit(1);
}
}
} else if (!infile) {
infile = argv[i];
} else {
if (!strcmp(argv[i], "stdout")) {
out = stdout;
} else {
out = fopen(argv[i], "w");
if (!out) {
fprintf(stderr, "missing output file %s\n", argv[i]);
exit(1);
}
}
outfile = argv[i];
}
}
if (!in || !out) {
fprintf(stderr, "worker: no files specified\n");
if (!infile) {
fprintf(stderr, "worker: no input file specified\n");
exit(1);
}
if (!outfile) {
fprintf(stderr, "worker: no output file specified\n");
exit(1);
}
fprintf(stderr, "worker: infile=%s outfile=%s nsecs=%d\n",
infile, outfile, nsecs
);

if (!strcmp(infile, "stdin")) {
in = stdin;
} else {
in = fopen(infile, "r");
if (!in) {
fprintf(stderr, "missing input file %s\n", infile);
exit(1);
}
}
if (!strcmp(outfile, "stdout")) {
out = stdout;
} else {
out = fopen(outfile, "w");
if (!out) {
fprintf(stderr, "can't open output file %s\n", outfile);
exit(1);
}
}

fprintf(stderr, "worker: starting\n");

copy_uc(in, out);
int nchars = copy_uc(in, out);

i=0;
while (clock()/(double)CLOCKS_PER_SEC < nsecs) {
do_a_giga_flop(i++);
}

fprintf(stderr, "worker: done\n");
fprintf(stderr, "worker: done; copied %d chars\n", nchars);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#define VBOXWRAPPER_RELEASE 26209

// worker version number
#define WORKER_RELEASE 2
#define WORKER_RELEASE 4

// client version number as string
#define BOINC_VERSION_STRING "8.1.0"
Expand Down

0 comments on commit e14f715

Please sign in to comment.