2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-08-15 23:04:36 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2003-08-15 23:04:36 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
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
|
2004-07-10 07:27:00 +00:00
|
|
|
// This program must be run in the project's root directory,
|
|
|
|
// and there must be a valid config.xml file there
|
2004-07-02 19:17:53 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// create_work
|
|
|
|
// -appname name
|
2002-11-07 19:31:34 +00:00
|
|
|
// -wu_name name
|
2004-07-02 19:17:53 +00:00
|
|
|
// -wu_template filename relative to project root; usually in templates/
|
|
|
|
// -result_template filename relative to project root; usually in templates/
|
2004-07-19 23:05:44 +00:00
|
|
|
// [ -config_dir path ]
|
2004-12-06 22:41:19 +00:00
|
|
|
// [ -batch n ]
|
2004-05-05 17:48:39 +00:00
|
|
|
// the following can be supplied in WU template; see defaults below
|
|
|
|
// [ -rsc_fpops_est n ]
|
2003-09-12 19:59:15 +00:00
|
|
|
// [ -rsc_fpops_bound n ]
|
|
|
|
// [ -rsc_memory_bound n ]
|
|
|
|
// [ -rsc_disk_bound n ]
|
|
|
|
// [ -delay_bound x ]
|
2003-09-02 21:16:55 +00:00
|
|
|
// [ -min_quorum x ]
|
|
|
|
// [ -target_nresults x ]
|
|
|
|
// [ -max_error_results x ]
|
|
|
|
// [ -max_total_results x ]
|
|
|
|
// [ -max_success_results x ]
|
2002-04-30 22:22:54 +00:00
|
|
|
// infile1 infile2 ...
|
|
|
|
//
|
|
|
|
|
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>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-04-07 19:06:00 +00:00
|
|
|
#include "boinc_db.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "backend_lib.h"
|
2003-09-02 21:16:55 +00:00
|
|
|
#include "sched_config.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
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;
|
2004-05-14 22:58:58 +00:00
|
|
|
char wu_template[LARGE_BLOB_SIZE];
|
2004-07-10 00:12:06 +00:00
|
|
|
char wu_template_file[256], result_template_file[256], result_template_path[1024];
|
2005-12-21 21:46:22 +00:00
|
|
|
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;
|
2004-03-29 22:57:43 +00:00
|
|
|
char download_dir[256], db_name[256], db_passwd[256],db_user[256],db_host[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
char buf[256];
|
2003-09-02 21:16:55 +00:00
|
|
|
SCHED_CONFIG config;
|
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, "");
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* config_dir = ".";
|
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
|
|
|
|
2004-11-22 19:17:13 +00:00
|
|
|
// defaults (in case not in WU template)
|
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
wu.min_quorum = 2;
|
|
|
|
wu.target_nresults = 5;
|
|
|
|
wu.max_error_results = 10;
|
|
|
|
wu.max_total_results = 20;
|
|
|
|
wu.max_success_results = 10;
|
2003-09-12 19:59:15 +00:00
|
|
|
wu.rsc_fpops_est = 1e9;
|
|
|
|
wu.rsc_fpops_bound = 1e10;
|
|
|
|
wu.rsc_memory_bound = 1e8;
|
|
|
|
wu.rsc_disk_bound = 1e8;
|
|
|
|
wu.delay_bound = 100000;
|
2003-09-02 21:16:55 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
while (i < argc) {
|
|
|
|
if (!strcmp(argv[i], "-appname")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(app.name, argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-wu_name")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(wu.name, argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-wu_template")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(wu_template_file, argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-result_template")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(result_template_file, argv[++i]);
|
2004-11-22 19:17:13 +00:00
|
|
|
} else if (!strcmp(argv[i], "-batch")) {
|
|
|
|
wu.batch = atoi(argv[++i]);
|
2004-07-19 23:05:44 +00:00
|
|
|
} else if (!strcmp(argv[i], "-config_dir")) {
|
|
|
|
config_dir = argv[++i];
|
2004-12-06 22:41:19 +00:00
|
|
|
} else if (!strcmp(argv[i], "-batch")) {
|
|
|
|
wu.batch = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-priority")) {
|
|
|
|
wu.priority = atoi(argv[++i]);
|
2003-09-04 00:41:51 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_fpops_est")) {
|
|
|
|
wu.rsc_fpops_est = atof(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-rsc_fpops_bound")) {
|
|
|
|
wu.rsc_fpops_bound = atof(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-rsc_memory_bound")) {
|
|
|
|
wu.rsc_memory_bound = atof(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-rsc_disk_bound")) {
|
|
|
|
wu.rsc_disk_bound = atof(argv[++i]);
|
2002-11-07 19:31:34 +00:00
|
|
|
} else if (!strcmp(argv[i], "-delay_bound")) {
|
|
|
|
wu.delay_bound = atoi(argv[++i]);
|
2003-08-15 20:35:44 +00:00
|
|
|
} else if (!strcmp(argv[i], "-min_quorum")) {
|
|
|
|
wu.min_quorum = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-target_nresults")) {
|
|
|
|
wu.target_nresults = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-max_error_results")) {
|
|
|
|
wu.max_error_results = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-max_total_results")) {
|
|
|
|
wu.max_total_results = atoi(argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-max_success_results")) {
|
|
|
|
wu.max_success_results = atoi(argv[++i]);
|
2005-12-21 21:46:22 +00:00
|
|
|
} else if (!strcmp(argv[i], "-command_line")) {
|
2005-12-23 04:12:24 +00:00
|
|
|
command_line= (char *)argv[++i];
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
2003-08-15 23:04:36 +00:00
|
|
|
if (!strncmp("-",argv[i],1)) {
|
|
|
|
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
|
|
|
|
|
|
|
#define CHKARG(x,m) do { if (!(x)) { fprintf(stderr, "create_work: bad command line: "m"\n"); exit(1); } } while (0)
|
|
|
|
#define CHKARG_STR(v,m) CHKARG(strlen(v),m)
|
|
|
|
|
|
|
|
CHKARG_STR(app.name , "need -appname");
|
2004-04-14 17:34:55 +00:00
|
|
|
CHKARG_STR(wu.name , "need -wu_name");
|
2003-08-15 23:04:36 +00:00
|
|
|
CHKARG_STR(wu_template_file , "need -wu_template");
|
|
|
|
CHKARG_STR(result_template_file , "need -result_template");
|
|
|
|
#undef CHKARG
|
|
|
|
#undef CHKARG_STR
|
|
|
|
|
2004-07-19 23:05:44 +00:00
|
|
|
retval = config.parse_file(config_dir);
|
|
|
|
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) {
|
2004-05-14 23:08:33 +00:00
|
|
|
fprintf(stderr, "create_work: can't open WU template: %d\n", retval);
|
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,
|
|
|
|
command_line
|
2004-05-05 17:48:39 +00:00
|
|
|
);
|
|
|
|
if (retval) {
|
|
|
|
fprintf(stderr, "create_work: %d\n", retval);
|
|
|
|
exit(1);
|
2002-12-05 19:13:06 +00:00
|
|
|
}
|
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$";
|