From 0038d275cd55ce414f92656db93e3b9d993458a0 Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Thu, 8 Oct 2015 12:14:45 +0200 Subject: [PATCH 1/4] Daemons: enhance assimilator framework The assimilator handler can now pass unknown arguments to the project specific handler. Projects that have there own assimilators need to implement the assimilate_handler_init() function and handle project specific arguments there. For examples see sample_assimilator.cpp or script_assimilator.cpp I also added some checks for missing arguments and clarified some error messages. --- sched/assimilate_handler.h | 7 +-- sched/assimilator.cpp | 89 ++++++++++++++++++++---------- sched/sample_assimilator.cpp | 8 ++- sched/sample_dummy_assimilator.cpp | 7 ++- sched/script_assimilator.cpp | 21 +++---- sched/single_job_assimilator.cpp | 7 ++- 6 files changed, 89 insertions(+), 50 deletions(-) diff --git a/sched/assimilate_handler.h b/sched/assimilate_handler.h index ab602369d3..56a15cde12 100644 --- a/sched/assimilate_handler.h +++ b/sched/assimilate_handler.h @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -34,7 +34,4 @@ extern int assimilate_handler( RESULT& // the canonical instance ); -extern int g_argc; -extern char** g_argv; -extern char* results_prefix; -extern char* transcripts_prefix; +extern int assimilate_handler_init(int argc, char** argv); diff --git a/sched/assimilator.cpp b/sched/assimilator.cpp index 7f0783cee9..b98db705da 100644 --- a/sched/assimilator.cpp +++ b/sched/assimilator.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2014 University of California +// Copyright (C) 2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -50,12 +50,8 @@ bool noinsert = false; int wu_id_modulus=0, wu_id_remainder=0; int sleep_interval = SLEEP_INTERVAL; int one_pass_N_WU=0; -int g_argc; -char** g_argv; -char* results_prefix = NULL; -char* transcripts_prefix = NULL; -void usage(char** argv) { +void usage(char* name) { fprintf(stderr, "This program is an 'assimilator'; it handles completed jobs.\n" "Normally it is run as a daemon from config.xml.\n" @@ -74,9 +70,8 @@ void usage(char** argv) { " [--noinsert] Don't insert records in app-specific DB\n" " [-h | --help] Show this\n" " [-v | --version] Show version information\n", - argv[0] + name ); - exit(0); } // assimilate all WUs that need it @@ -100,7 +95,7 @@ bool do_pass(APP& app) { } sprintf(buf, - "where appid=%lu and assimilate_state=%d %s limit %d", + "where appid=%ld and assimilate_state=%d %s limit %d", app.id, ASSIMILATE_READY, mod_clause, one_pass_N_WU ? one_pass_N_WU : 1000 ); @@ -127,7 +122,7 @@ bool do_pass(APP& app) { "[%s] assimilating WU %lu; state=%d\n", wu.name, wu.id, wu.assimilate_state ); - sprintf(buf, "where workunitid=%lu", wu.id); + sprintf(buf, "where workunitid=%ld", wu.id); canonical_result.clear(); bool found = false; while (1) { @@ -206,6 +201,13 @@ bool do_pass(APP& app) { return did_something; } +void missing_argument(char* name, char* arg) { + log_messages.printf(MSG_CRITICAL, + "%s requires an argument\n\n", arg + ); + usage(name); +} + int main(int argc, char** argv) { int retval; bool one_pass = false; @@ -215,22 +217,38 @@ int main(int argc, char** argv) { strcpy(app.name, ""); check_stop_daemons(); - g_argc = argc; - g_argv = argv; + + int j=1; for (i=1; i& /*results*/, RESULT& canonical_result ) { diff --git a/sched/sample_dummy_assimilator.cpp b/sched/sample_dummy_assimilator.cpp index 258bd2f642..72491f3134 100644 --- a/sched/sample_dummy_assimilator.cpp +++ b/sched/sample_dummy_assimilator.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -31,6 +31,11 @@ using std::vector; using std::string; +int assimilate_handler_init(int argc, char** argv) { + // handle project specific arguments here + return 0; +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { diff --git a/sched/script_assimilator.cpp b/sched/script_assimilator.cpp index eb02e62143..91f55ac620 100644 --- a/sched/script_assimilator.cpp +++ b/sched/script_assimilator.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2014 University of California +// Copyright (C) 2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -47,6 +47,7 @@ #include "boinc_db.h" #include "error_numbers.h" #include "sched_msgs.h" +#include "sched_util.h" #include "validate_util.h" #include "validator.h" #include "sched_config.h" @@ -54,13 +55,13 @@ using std::vector; using std::string; -bool first = true; vector script; -void parse_cmdline() { - for (int i=1; i paths; diff --git a/sched/single_job_assimilator.cpp b/sched/single_job_assimilator.cpp index 55caa05392..198799bbe9 100644 --- a/sched/single_job_assimilator.cpp +++ b/sched/single_job_assimilator.cpp @@ -1,6 +1,6 @@ // This file is part of BOINC. // http://boinc.berkeley.edu -// Copyright (C) 2008 University of California +// Copyright (C) 2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License @@ -39,6 +39,11 @@ using std::vector; using std::string; +int assimilate_handler_init(int argc, char** argv) { + // handle project specific arguments here + return 0; +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { From dd004404a1458119a98bc5b07ad68b0a8141544c Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Tue, 13 Oct 2015 16:39:04 +0200 Subject: [PATCH 2/4] Daemons: add usage function to project specific handler Projects that have there own assimilator need to implement the assimilate_handler_usage() function and should printf() a description of those custom options. For examples see sample_assimilator.cpp or script_assimilator.cpp --- sched/assimilate_handler.h | 1 + sched/assimilator.cpp | 1 + sched/sample_assimilator.cpp | 8 ++++++++ sched/sample_dummy_assimilator.cpp | 8 ++++++++ sched/script_assimilator.cpp | 9 +++++++++ sched/single_job_assimilator.cpp | 8 ++++++++ 6 files changed, 35 insertions(+) diff --git a/sched/assimilate_handler.h b/sched/assimilate_handler.h index 56a15cde12..7286c86145 100644 --- a/sched/assimilate_handler.h +++ b/sched/assimilate_handler.h @@ -35,3 +35,4 @@ extern int assimilate_handler( ); extern int assimilate_handler_init(int argc, char** argv); +extern void assimilate_handler_usage(); diff --git a/sched/assimilator.cpp b/sched/assimilator.cpp index b98db705da..5822be8ee8 100644 --- a/sched/assimilator.cpp +++ b/sched/assimilator.cpp @@ -72,6 +72,7 @@ void usage(char* name) { " [-v | --version] Show version information\n", name ); + assimilate_handler_usage(); } // assimilate all WUs that need it diff --git a/sched/sample_assimilator.cpp b/sched/sample_assimilator.cpp index 67d4240d32..f3ac3652a9 100644 --- a/sched/sample_assimilator.cpp +++ b/sched/sample_assimilator.cpp @@ -50,6 +50,14 @@ int assimilate_handler_init(int argc, char** argv) { return 0; } +void assimilate_handler_usage() { + // describe the project specific arguments here + //fprintf(stderr, + // " custom options:\n" + // " [--project_option X] a project specific option\n" + //); +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { diff --git a/sched/sample_dummy_assimilator.cpp b/sched/sample_dummy_assimilator.cpp index 72491f3134..02014ead21 100644 --- a/sched/sample_dummy_assimilator.cpp +++ b/sched/sample_dummy_assimilator.cpp @@ -36,6 +36,14 @@ int assimilate_handler_init(int argc, char** argv) { return 0; } +void assimilate_handler_usage() { + // describe the project specific arguments here + //fprintf(stderr, + // " custom options:\n" + // " [--project_option X] a project specific option\n" + //); +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { diff --git a/sched/script_assimilator.cpp b/sched/script_assimilator.cpp index 91f55ac620..bd7083196c 100644 --- a/sched/script_assimilator.cpp +++ b/sched/script_assimilator.cpp @@ -77,6 +77,15 @@ int assimilate_handler_init(int argc, char** argv) { return 0; } +void assimilate_handler_usage() { + // describe the project specific arguments here + fprintf(stderr, + " custom options:\n" + " --script \"X\" call script to assimilate job\n" + " see comment in script_assimilator.cpp for details\n" + ); +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { diff --git a/sched/single_job_assimilator.cpp b/sched/single_job_assimilator.cpp index 198799bbe9..7959159672 100644 --- a/sched/single_job_assimilator.cpp +++ b/sched/single_job_assimilator.cpp @@ -44,6 +44,14 @@ int assimilate_handler_init(int argc, char** argv) { return 0; } +void assimilate_handler_usage() { + // describe the project specific arguments here + //fprintf(stderr, + // " custom options:\n" + // " [--project_option X] a project specific option\n" + //); +} + int assimilate_handler( WORKUNIT& wu, vector& /*results*/, RESULT& canonical_result ) { From d160c7fab5a1e410330facbde11de67d2f8d05a5 Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Thu, 29 Oct 2015 09:16:11 +0100 Subject: [PATCH 3/4] Assimilator: cosmetic changes to usage output --- sched/assimilator.cpp | 3 ++- sched/sample_assimilator.cpp | 2 +- sched/sample_dummy_assimilator.cpp | 2 +- sched/script_assimilator.cpp | 2 +- sched/single_job_assimilator.cpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sched/assimilator.cpp b/sched/assimilator.cpp index 5822be8ee8..ca3d7e46b3 100644 --- a/sched/assimilator.cpp +++ b/sched/assimilator.cpp @@ -69,7 +69,8 @@ void usage(char* name) { " [--dont_update_db] Don't update DB (for testing)\n" " [--noinsert] Don't insert records in app-specific DB\n" " [-h | --help] Show this\n" - " [-v | --version] Show version information\n", + " [-v | --version] Show version information\n" + "\n", name ); assimilate_handler_usage(); diff --git a/sched/sample_assimilator.cpp b/sched/sample_assimilator.cpp index f3ac3652a9..c2562ef165 100644 --- a/sched/sample_assimilator.cpp +++ b/sched/sample_assimilator.cpp @@ -53,7 +53,7 @@ int assimilate_handler_init(int argc, char** argv) { void assimilate_handler_usage() { // describe the project specific arguments here //fprintf(stderr, - // " custom options:\n" + // " Custom options:\n" // " [--project_option X] a project specific option\n" //); } diff --git a/sched/sample_dummy_assimilator.cpp b/sched/sample_dummy_assimilator.cpp index 02014ead21..c2e9a5ea49 100644 --- a/sched/sample_dummy_assimilator.cpp +++ b/sched/sample_dummy_assimilator.cpp @@ -39,7 +39,7 @@ int assimilate_handler_init(int argc, char** argv) { void assimilate_handler_usage() { // describe the project specific arguments here //fprintf(stderr, - // " custom options:\n" + // " Custom options:\n" // " [--project_option X] a project specific option\n" //); } diff --git a/sched/script_assimilator.cpp b/sched/script_assimilator.cpp index bd7083196c..f41783f884 100644 --- a/sched/script_assimilator.cpp +++ b/sched/script_assimilator.cpp @@ -80,7 +80,7 @@ int assimilate_handler_init(int argc, char** argv) { void assimilate_handler_usage() { // describe the project specific arguments here fprintf(stderr, - " custom options:\n" + " Custom options:\n" " --script \"X\" call script to assimilate job\n" " see comment in script_assimilator.cpp for details\n" ); diff --git a/sched/single_job_assimilator.cpp b/sched/single_job_assimilator.cpp index 7959159672..f530547532 100644 --- a/sched/single_job_assimilator.cpp +++ b/sched/single_job_assimilator.cpp @@ -47,7 +47,7 @@ int assimilate_handler_init(int argc, char** argv) { void assimilate_handler_usage() { // describe the project specific arguments here //fprintf(stderr, - // " custom options:\n" + // " Custom options:\n" // " [--project_option X] a project specific option\n" //); } From d536505f7e1a405dd9ceb0e74d66345644833dd7 Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Fri, 30 Oct 2015 14:20:21 +0100 Subject: [PATCH 4/4] Assimilator: remove --noinsert option please implement this in the project specific part if needed --- sched/assimilator.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/sched/assimilator.cpp b/sched/assimilator.cpp index ca3d7e46b3..5e30c7b5ae 100644 --- a/sched/assimilator.cpp +++ b/sched/assimilator.cpp @@ -46,7 +46,6 @@ using std::vector; #define SLEEP_INTERVAL 10 bool update_db = true; -bool noinsert = false; int wu_id_modulus=0, wu_id_remainder=0; int sleep_interval = SLEEP_INTERVAL; int one_pass_N_WU=0; @@ -66,8 +65,7 @@ void usage(char* name) { " [--one_pass] Do one DB enumeration, then exit\n" " [--one_pass_N_WU N] Process at most N jobs\n" " [-d | --debug_level N] Set verbosity level (1 to 4)\n" - " [--dont_update_db] Don't update DB (for testing)\n" - " [--noinsert] Don't insert records in app-specific DB\n" + " [--dont_update_db] Don't update BOINC DB (for testing)\n" " [-h | --help] Show this\n" " [-v | --version] Show version information\n" "\n", @@ -258,11 +256,6 @@ int main(int argc, char** argv) { // your assimilator over and over again without affecting // your project. update_db = false; - } else if (is_arg(argv[i], "noinsert")) { - // This option is also for testing and is used to - // prevent the inserting of results into the *backend* - // (as opposed to the boinc) DB. - noinsert = true; } else if (is_arg(argv[i], "mod")) { if (!argv[++i]) { missing_argument(argv[0], argv[--i]);