mirror of https://github.com/BOINC/boinc.git
202 lines
6.5 KiB
C
202 lines
6.5 KiB
C
// The contents of this file are subject to the BOINC Public License
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
//
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
// License for the specific language governing rights and limitations
|
|
// under the License.
|
|
//
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
//
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
//
|
|
// Contributor(s):
|
|
//
|
|
|
|
// Create a workunit.
|
|
// Input files must be in the download dir.
|
|
// See the docs for a description of WU and result template files
|
|
// This program must be run in the project's root directory
|
|
//
|
|
// create_work
|
|
// -appname name
|
|
// -wu_name name
|
|
// -wu_template filename relative to project root; usually in templates/
|
|
// -result_template filename relative to project root; usually in templates/
|
|
// the following are read from config.xml if available
|
|
// [ -upload_url x ]
|
|
// [ -download_url x ]
|
|
// [ -download_dir x ]
|
|
// [ -keyfile path ]
|
|
// the following can be supplied in WU template; see defaults below
|
|
// [ -rsc_fpops_est n ]
|
|
// [ -rsc_fpops_bound n ]
|
|
// [ -rsc_memory_bound n ]
|
|
// [ -rsc_disk_bound n ]
|
|
// [ -delay_bound x ]
|
|
// [ -min_quorum x ]
|
|
// [ -target_nresults x ]
|
|
// [ -max_error_results x ]
|
|
// [ -max_total_results x ]
|
|
// [ -max_success_results x ]
|
|
// infile1 infile2 ...
|
|
//
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include "boinc_db.h"
|
|
#include "crypt.h"
|
|
#include "backend_lib.h"
|
|
#include "sched_config.h"
|
|
|
|
int main(int argc, char** argv) {
|
|
DB_APP app;
|
|
DB_WORKUNIT wu;
|
|
int retval;
|
|
char wu_template[LARGE_BLOB_SIZE];
|
|
char wu_template_file[256], result_template_file[256];
|
|
char keyfile[256];
|
|
char** infiles = NULL;
|
|
int i, ninfiles;
|
|
R_RSA_PRIVATE_KEY key;
|
|
char download_dir[256], db_name[256], db_passwd[256],db_user[256],db_host[256];
|
|
char upload_url[256], download_url[256];
|
|
char buf[256];
|
|
SCHED_CONFIG config;
|
|
|
|
strcpy(result_template_file, "");
|
|
strcpy(app.name, "");
|
|
strcpy(db_passwd, "");
|
|
strcpy(keyfile, "");
|
|
i = 1;
|
|
ninfiles = 0;
|
|
wu.clear();
|
|
|
|
wu.min_quorum = 2;
|
|
wu.target_nresults = 5;
|
|
wu.max_error_results = 10;
|
|
wu.max_total_results = 20;
|
|
wu.max_success_results = 10;
|
|
wu.rsc_fpops_est = 1e9;
|
|
wu.rsc_fpops_bound = 1e10;
|
|
wu.rsc_memory_bound = 1e8;
|
|
wu.rsc_disk_bound = 1e8;
|
|
wu.delay_bound = 100000;
|
|
|
|
retval = config.parse_file();
|
|
if (retval) {
|
|
fprintf(stderr, "Can't parse config file\n");
|
|
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_url, config.download_url);
|
|
strcpy(download_dir, config.download_dir);
|
|
strcpy(upload_url, config.upload_url);
|
|
sprintf(keyfile, "%s/upload_private", config.key_dir);
|
|
}
|
|
|
|
while (i < argc) {
|
|
if (!strcmp(argv[i], "-appname")) {
|
|
strcpy(app.name, argv[++i]);
|
|
} else if (!strcmp(argv[i], "-wu_name")) {
|
|
strcpy(wu.name, argv[++i]);
|
|
} else if (!strcmp(argv[i], "-wu_template")) {
|
|
strcpy(wu_template_file, argv[++i]);
|
|
} else if (!strcmp(argv[i], "-result_template")) {
|
|
strcpy(result_template_file, argv[++i]);
|
|
} 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]);
|
|
} else if (!strcmp(argv[i], "-delay_bound")) {
|
|
wu.delay_bound = atoi(argv[++i]);
|
|
} 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]);
|
|
} else {
|
|
if (!strncmp("-",argv[i],1)) {
|
|
fprintf(stderr, "create_work: bad argument '%s'\n", argv[i]);
|
|
exit(1);
|
|
}
|
|
infiles = argv+i;
|
|
ninfiles = argc - i;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
|
|
#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");
|
|
CHKARG_STR(wu.name , "need -wu_name");
|
|
CHKARG_STR(wu_template_file , "need -wu_template");
|
|
CHKARG_STR(result_template_file , "need -result_template");
|
|
#undef CHKARG
|
|
#undef CHKARG_STR
|
|
|
|
retval = boinc_db.open(db_name, db_host, db_user, db_passwd);
|
|
if (retval) {
|
|
fprintf(stderr, "create_work: error opening database: %d\n", retval );
|
|
exit(1);
|
|
}
|
|
sprintf(buf, "where name='%s'", app.name);
|
|
retval = app.lookup(buf);
|
|
if (retval) {
|
|
fprintf(stderr, "create_work: app not found\n");
|
|
exit(1);
|
|
}
|
|
|
|
retval = read_filename(wu_template_file, wu_template, sizeof(wu_template));
|
|
if (retval) {
|
|
fprintf(stderr, "create_work: can't open WU template: %d\n", retval);
|
|
exit(1);
|
|
}
|
|
|
|
wu.appid = app.id;
|
|
|
|
retval = read_key_file(keyfile, key);
|
|
if (retval) {
|
|
fprintf(stderr, "create_work: can't read key: %d", retval);
|
|
exit(1);
|
|
}
|
|
|
|
retval = create_work(
|
|
wu,
|
|
wu_template,
|
|
result_template_file,
|
|
download_dir,
|
|
const_cast<const char **>(infiles),
|
|
ninfiles,
|
|
key,
|
|
upload_url,
|
|
download_url
|
|
);
|
|
if (retval) {
|
|
fprintf(stderr, "create_work: %d\n", retval);
|
|
exit(1);
|
|
}
|
|
boinc_db.close();
|
|
}
|