2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-08-15 23:04:36 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-08-15 23:04:36 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-07-02 19:17:53 +00:00
|
|
|
// Create a workunit.
|
|
|
|
// Input files must be in the download dir.
|
|
|
|
// See the docs for a description of WU and result template files
|
2011-07-22 22:47:41 +00:00
|
|
|
// This program must be run in the project's root directory
|
2004-07-02 19:17:53 +00:00
|
|
|
//
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <ctime>
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <string>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "backend_lib.h"
|
2010-12-07 19:28:08 +00:00
|
|
|
#include "boinc_db.h"
|
2008-02-26 17:24:29 +00:00
|
|
|
#include "common_defs.h"
|
2010-12-07 19:28:08 +00:00
|
|
|
#include "crypt.h"
|
2003-09-02 21:16:55 +00:00
|
|
|
#include "sched_config.h"
|
2010-12-07 19:28:08 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2011-07-22 22:47:41 +00:00
|
|
|
void usage() {
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: create_work [options] infile1 infile2 ...\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n"
|
|
|
|
" --appname name\n"
|
|
|
|
" [ --wu_name name ] default: generate a name based on app name\n"
|
|
|
|
" [ --wu_template filename ] default: appname_in\n"
|
|
|
|
" [ --result_template filename ] default: appname_out\n"
|
|
|
|
" [ --config_dir path ]\n"
|
2012-01-02 05:53:42 +00:00
|
|
|
" [ --command_line \"X\" ]\n"
|
2011-07-22 22:47:41 +00:00
|
|
|
" [ --batch n ]\n"
|
|
|
|
" [ --rsc_fpops_est n ]\n"
|
|
|
|
" [ --rsc_fpops_bound n ]\n"
|
|
|
|
" [ --rsc_memory_bound n ]\n"
|
|
|
|
" [ --rsc_disk_bound n ]\n"
|
|
|
|
" [ --delay_bound x ]\n"
|
|
|
|
" [ --min_quorum x ]\n"
|
|
|
|
" [ --target_nresults x ]\n"
|
|
|
|
" [ --max_error_results x ]\n"
|
|
|
|
" [ --max_total_results x ]\n"
|
|
|
|
" [ --max_success_results x ]\n"
|
|
|
|
" [ --additional_xml x ]\n"
|
|
|
|
" [ --assign_all ]\n"
|
|
|
|
" [ --assign_host ID ]\n"
|
|
|
|
" [ --assign_user_one ID ]\n"
|
|
|
|
" [ --assign_user_all ID ]\n"
|
|
|
|
" [ --assign_team_one ID ]\n"
|
|
|
|
" [ --assign_team_all ID ]\n"
|
2012-01-02 05:53:42 +00:00
|
|
|
" [ --wu_id N ] ID of existing workunit record (used by boinc_submit)\n"
|
2011-07-22 22:47:41 +00:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-02-21 00:47:50 +00:00
|
|
|
bool arg(const char** argv, int i, const char* name) {
|
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "-%s", name);
|
|
|
|
if (!strcmp(argv[i], buf)) return true;
|
|
|
|
sprintf(buf, "--%s", name);
|
|
|
|
if (!strcmp(argv[i], buf)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
int main(int argc, const char** argv) {
|
2003-06-04 17:21:26 +00:00
|
|
|
DB_APP app;
|
|
|
|
DB_WORKUNIT wu;
|
2002-04-30 22:22:54 +00:00
|
|
|
int retval;
|
2008-03-31 16:19:45 +00:00
|
|
|
char wu_template[BLOB_SIZE];
|
2004-07-10 00:12:06 +00:00
|
|
|
char wu_template_file[256], result_template_file[256], result_template_path[1024];
|
2007-06-20 23:16:30 +00:00
|
|
|
const char* command_line=NULL;
|
2005-02-16 23:17:43 +00:00
|
|
|
const char** infiles = NULL;
|
2004-05-05 17:48:39 +00:00
|
|
|
int i, ninfiles;
|
2007-01-30 18:19:30 +00:00
|
|
|
char download_dir[256], db_name[256], db_passwd[256];
|
|
|
|
char db_user[256],db_host[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
char buf[256];
|
2007-01-30 18:19:30 +00:00
|
|
|
char additional_xml[256];
|
2011-06-21 22:56:15 +00:00
|
|
|
bool show_wu_name = true;
|
2008-02-21 00:47:50 +00:00
|
|
|
bool assign_flag = false;
|
|
|
|
bool assign_multi = false;
|
|
|
|
int assign_id = 0;
|
2010-06-25 18:54:37 +00:00
|
|
|
int assign_type = ASSIGN_NONE;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2010-12-07 19:28:08 +00:00
|
|
|
strcpy(wu_template_file, "");
|
2002-04-30 22:22:54 +00:00
|
|
|
strcpy(result_template_file, "");
|
|
|
|
strcpy(app.name, "");
|
2002-10-03 18:33:46 +00:00
|
|
|
strcpy(db_passwd, "");
|
2007-01-30 18:19:30 +00:00
|
|
|
strcpy(additional_xml, "");
|
2009-05-07 13:54:51 +00:00
|
|
|
const char* config_dir = 0;
|
2002-04-30 22:22:54 +00:00
|
|
|
i = 1;
|
|
|
|
ninfiles = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
wu.clear();
|
2003-09-02 21:16:55 +00:00
|
|
|
|
2008-03-03 19:33:32 +00:00
|
|
|
// defaults (in case they're not in WU template)
|
2004-11-22 19:17:13 +00:00
|
|
|
|
2008-03-04 23:50:38 +00:00
|
|
|
wu.id = 0;
|
2003-09-02 21:16:55 +00:00
|
|
|
wu.min_quorum = 2;
|
2008-03-05 20:16:10 +00:00
|
|
|
wu.target_nresults = 2;
|
|
|
|
wu.max_error_results = 3;
|
|
|
|
wu.max_total_results = 10;
|
|
|
|
wu.max_success_results = 6;
|
2009-03-30 18:38:11 +00:00
|
|
|
wu.rsc_fpops_est = 3600e9;
|
|
|
|
wu.rsc_fpops_bound = 86400e9;
|
|
|
|
wu.rsc_memory_bound = 5e8;
|
|
|
|
wu.rsc_disk_bound = 1e9;
|
2008-03-07 21:13:01 +00:00
|
|
|
wu.rsc_bandwidth_bound = 0.0;
|
2009-03-30 18:38:11 +00:00
|
|
|
wu.delay_bound = 7*86400;
|
2003-09-02 21:16:55 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
while (i < argc) {
|
2008-02-21 00:47:50 +00:00
|
|
|
if (arg(argv, i, "appname")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(app.name, argv[++i]);
|
2011-02-02 00:42:46 +00:00
|
|
|
} else if (arg(argv, i, "d")) {
|
|
|
|
int dl = atoi(argv[++i]);
|
|
|
|
log_messages.set_debug_level(dl);
|
|
|
|
if (dl ==4) g_print_queries = true;
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "wu_name")) {
|
2011-06-21 22:56:15 +00:00
|
|
|
show_wu_name = false;
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(wu.name, argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "wu_template")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(wu_template_file, argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "result_template")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(result_template_file, argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "batch")) {
|
2004-11-22 19:17:13 +00:00
|
|
|
wu.batch = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "config_dir")) {
|
2004-07-19 23:05:44 +00:00
|
|
|
config_dir = argv[++i];
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "batch")) {
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.batch = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "priority")) {
|
2004-12-06 22:41:19 +00:00
|
|
|
wu.priority = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "rsc_fpops_est")) {
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.rsc_fpops_est = atof(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "rsc_fpops_bound")) {
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.rsc_fpops_bound = atof(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "rsc_memory_bound")) {
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.rsc_memory_bound = atof(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "rsc_disk_bound")) {
|
2003-09-04 00:41:51 +00:00
|
|
|
wu.rsc_disk_bound = atof(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "delay_bound")) {
|
2002-11-07 19:31:34 +00:00
|
|
|
wu.delay_bound = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "min_quorum")) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.min_quorum = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "target_nresults")) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.target_nresults = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "max_error_results")) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.max_error_results = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "max_total_results")) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.max_total_results = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "max_success_results")) {
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.max_success_results = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "opaque")) {
|
2008-01-21 14:02:22 +00:00
|
|
|
wu.opaque = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "command_line")) {
|
2007-06-20 23:16:30 +00:00
|
|
|
command_line= argv[++i];
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "additional_xml")) {
|
2007-01-30 18:19:30 +00:00
|
|
|
strcpy(additional_xml, argv[++i]);
|
2008-03-04 23:50:38 +00:00
|
|
|
} else if (arg(argv, i, "wu_id")) {
|
|
|
|
wu.id = atoi(argv[++i]);
|
2008-02-21 00:47:50 +00:00
|
|
|
} else if (arg(argv, i, "assign_all")) {
|
2008-02-27 22:26:37 +00:00
|
|
|
assign_multi = true;
|
2008-02-21 00:47:50 +00:00
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_NONE;
|
|
|
|
} else if (arg(argv, i, "assign_host")) {
|
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_HOST;
|
|
|
|
assign_id = atoi(argv[++i]);
|
|
|
|
} else if (arg(argv, i, "assign_user_one")) {
|
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_USER;
|
|
|
|
assign_id = atoi(argv[++i]);
|
|
|
|
} else if (arg(argv, i, "assign_user_all")) {
|
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_USER;
|
|
|
|
assign_multi = true;
|
|
|
|
assign_id = atoi(argv[++i]);
|
|
|
|
} else if (arg(argv, i, "assign_team_one")) {
|
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_TEAM;
|
|
|
|
assign_id = atoi(argv[++i]);
|
|
|
|
} else if (arg(argv, i, "assign_team_all")) {
|
|
|
|
assign_flag = true;
|
|
|
|
assign_type = ASSIGN_TEAM;
|
|
|
|
assign_multi = true;
|
|
|
|
assign_id = atoi(argv[++i]);
|
2012-01-02 05:53:42 +00:00
|
|
|
} else if (arg(argv, i, "help")) {
|
|
|
|
usage();
|
|
|
|
exit(0);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2008-02-21 00:47:50 +00:00
|
|
|
if (!strncmp("-", argv[i], 1)) {
|
2003-08-15 23:04:36 +00:00
|
|
|
fprintf(stderr, "create_work: bad argument '%s'\n", argv[i]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
infiles = argv+i;
|
|
|
|
ninfiles = argc - i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2003-08-15 23:04:36 +00:00
|
|
|
|
2010-09-17 22:01:42 +00:00
|
|
|
if (!strlen(app.name)) {
|
2011-07-22 22:47:41 +00:00
|
|
|
usage();
|
2010-09-17 22:01:42 +00:00
|
|
|
}
|
|
|
|
if (!strlen(wu.name)) {
|
2010-12-07 19:28:08 +00:00
|
|
|
sprintf(wu.name, "%s_%d_%f", app.name, getpid(), dtime());
|
2010-09-17 22:01:42 +00:00
|
|
|
}
|
|
|
|
if (!strlen(wu_template_file)) {
|
2010-12-07 19:28:08 +00:00
|
|
|
sprintf(wu_template_file, "templates/%s_in", app.name);
|
2010-09-17 22:01:42 +00:00
|
|
|
}
|
|
|
|
if (!strlen(result_template_file)) {
|
2010-12-07 19:28:08 +00:00
|
|
|
sprintf(result_template_file, "templates/%s_out", app.name);
|
2010-09-17 22:01:42 +00:00
|
|
|
}
|
2003-08-15 23:04:36 +00:00
|
|
|
|
2008-02-21 00:47:50 +00:00
|
|
|
if (assign_flag) {
|
2008-02-26 17:24:29 +00:00
|
|
|
if (!strstr(wu.name, ASSIGNED_WU_STR)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Assigned WU names must contain '%s'\n", ASSIGNED_WU_STR
|
|
|
|
);
|
2008-02-21 00:47:50 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 05:53:42 +00:00
|
|
|
retval = config.parse_file(config_dir);
|
2004-07-19 23:05:44 +00:00
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "Can't parse config file: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
strcpy(db_name, config.db_name);
|
|
|
|
strcpy(db_passwd, config.db_passwd);
|
|
|
|
strcpy(db_user, config.db_user);
|
|
|
|
strcpy(db_host, config.db_host);
|
|
|
|
strcpy(download_dir, config.download_dir);
|
|
|
|
}
|
|
|
|
|
2004-07-02 22:48:33 +00:00
|
|
|
retval = boinc_db.open(db_name, db_host, db_user, db_passwd);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "create_work: error opening database: %d\n", retval );
|
2004-03-29 22:57:43 +00:00
|
|
|
exit(1);
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2003-06-04 17:21:26 +00:00
|
|
|
sprintf(buf, "where name='%s'", app.name);
|
|
|
|
retval = app.lookup(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (retval) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: app not found\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2003-06-17 20:18:56 +00:00
|
|
|
|
2004-05-14 23:08:33 +00:00
|
|
|
retval = read_filename(wu_template_file, wu_template, sizeof(wu_template));
|
2002-07-05 05:33:40 +00:00
|
|
|
if (retval) {
|
2010-12-07 19:28:08 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"create_work: can't open input template %s\n", wu_template_file
|
|
|
|
);
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
wu.appid = app.id;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2004-07-10 00:12:06 +00:00
|
|
|
strcpy(result_template_path, "./");
|
|
|
|
strcat(result_template_path, result_template_file);
|
2004-05-05 17:48:39 +00:00
|
|
|
retval = create_work(
|
|
|
|
wu,
|
|
|
|
wu_template,
|
|
|
|
result_template_file,
|
2004-08-06 11:42:41 +00:00
|
|
|
result_template_path,
|
2004-05-05 17:48:39 +00:00
|
|
|
const_cast<const char **>(infiles),
|
|
|
|
ninfiles,
|
2005-12-21 21:46:22 +00:00
|
|
|
config,
|
2007-01-30 18:19:30 +00:00
|
|
|
command_line,
|
|
|
|
additional_xml
|
2004-05-05 17:48:39 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "create_work: %d\n", retval);
|
|
|
|
exit(1);
|
2011-04-21 17:04:42 +00:00
|
|
|
} else {
|
2011-06-21 22:56:15 +00:00
|
|
|
if (show_wu_name) {
|
|
|
|
printf("workunit name: %s\n", wu.name);
|
|
|
|
}
|
2002-12-05 19:13:06 +00:00
|
|
|
}
|
2008-02-21 00:47:50 +00:00
|
|
|
if (assign_flag) {
|
|
|
|
DB_ASSIGNMENT assignment;
|
|
|
|
assignment.clear();
|
|
|
|
assignment.create_time = time(0);
|
|
|
|
assignment.target_id = assign_id;
|
|
|
|
assignment.target_type = assign_type;
|
|
|
|
assignment.multi = assign_multi;
|
|
|
|
assignment.workunitid = wu.id;
|
|
|
|
retval = assignment.insert();
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "assignment.insert() failed: %d\n", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2003-09-05 22:12:34 +00:00
|
|
|
boinc_db.close();
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_3865dbbf46 = "$Id$";
|