2003-07-01 20:37:09 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-07-01 20:37:09 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-08-15 23:04:36 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-08-15 23:04:36 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
2003-07-01 20:37:09 +00:00
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2003-08-15 23:04:36 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// create_work
|
|
|
|
// -appname name
|
2002-11-07 19:31:34 +00:00
|
|
|
// -wu_name name
|
|
|
|
// -wu_template filename
|
|
|
|
// -result_template filename
|
|
|
|
// -db_name x
|
|
|
|
// -db_passwd x
|
|
|
|
// -upload_url x
|
|
|
|
// -download_url x
|
2002-10-03 18:33:46 +00:00
|
|
|
// -download_dir x
|
2002-04-30 22:22:54 +00:00
|
|
|
// -rsc_fpops n
|
|
|
|
// -rsc_iops n
|
|
|
|
// -rsc_memory n
|
|
|
|
// -rsc_disk n
|
2002-07-05 05:33:40 +00:00
|
|
|
// -keyfile path
|
2002-11-07 19:31:34 +00:00
|
|
|
// -delay_bound x
|
2003-08-15 20:35:44 +00:00
|
|
|
// -min_quorum x
|
|
|
|
// -target_nresults x
|
|
|
|
// -max_error_results x
|
|
|
|
// -max_total_results x
|
|
|
|
// -max_success_results x
|
2002-12-05 19:13:06 +00:00
|
|
|
// -sequence n
|
2002-04-30 22:22:54 +00:00
|
|
|
// infile1 infile2 ...
|
|
|
|
//
|
|
|
|
// Create a workunit and results.
|
|
|
|
// Input files must be in the download dir.
|
|
|
|
// template-doc is an XML WU description file, with the following macros:
|
|
|
|
// INFILEn gets replaced by the name of input file n
|
|
|
|
// MD5n gets replaced by the MD5 checksum of input file n
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-07-01 19:30:58 +00:00
|
|
|
#include <time.h>
|
2003-08-15 20:35:44 +00:00
|
|
|
#include <values.h>
|
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"
|
|
|
|
|
|
|
|
int main(int argc, 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;
|
|
|
|
char wu_template[MAX_BLOB_SIZE];
|
|
|
|
char wu_template_file[256], result_template_file[256];
|
2002-07-05 05:33:40 +00:00
|
|
|
char keyfile[256];
|
2003-06-17 20:18:56 +00:00
|
|
|
char** infiles = NULL;
|
2002-12-05 19:13:06 +00:00
|
|
|
int i, ninfiles, redundancy, sequence=0;
|
2002-07-05 05:33:40 +00:00
|
|
|
R_RSA_PRIVATE_KEY key;
|
2002-10-03 18:33:46 +00:00
|
|
|
char download_dir[256], db_name[256], db_passwd[256];
|
|
|
|
char upload_url[256], download_url[256];
|
2003-06-04 17:21:26 +00:00
|
|
|
char buf[256];
|
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, "");
|
2002-07-05 05:33:40 +00:00
|
|
|
strcpy(keyfile, "");
|
2002-12-05 19:13:06 +00:00
|
|
|
redundancy = 1;
|
2002-04-30 22:22:54 +00:00
|
|
|
i = 1;
|
|
|
|
ninfiles = 0;
|
2003-06-04 17:21:26 +00:00
|
|
|
wu.clear();
|
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-10-03 18:33:46 +00:00
|
|
|
} else if (!strcmp(argv[i], "-db_name")) {
|
|
|
|
strcpy(db_name, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-db_passwd")) {
|
|
|
|
strcpy(db_passwd, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-upload_url")) {
|
|
|
|
strcpy(upload_url, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-download_url")) {
|
|
|
|
strcpy(download_url, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-download_dir")) {
|
|
|
|
strcpy(download_dir, 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]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_fpops")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
wu.rsc_fpops = atof(argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_iops")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
wu.rsc_iops = atof(argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_memory")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
wu.rsc_memory = atof(argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_disk")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
wu.rsc_disk = atof(argv[++i]);
|
2002-07-05 05:33:40 +00:00
|
|
|
} else if (!strcmp(argv[i], "-keyfile")) {
|
2002-10-14 23:10:12 +00:00
|
|
|
strcpy(keyfile, 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]);
|
2002-12-05 19:13:06 +00:00
|
|
|
} else if (!strcmp(argv[i], "-sequence")) {
|
|
|
|
sequence = atoi(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");
|
|
|
|
CHKARG_STR(wu.name , "need -wuname");
|
|
|
|
CHKARG_STR(wu_template_file , "need -wu_template");
|
|
|
|
CHKARG_STR(result_template_file , "need -result_template");
|
|
|
|
CHKARG(wu.delay_bound , "need -delay_bound");
|
|
|
|
CHKARG(wu.min_quorum , "need -min_quorum");
|
|
|
|
CHKARG(wu.target_nresults , "need -target_nresults");
|
|
|
|
CHKARG(wu.max_error_results , "need -max_error_results");
|
|
|
|
CHKARG(wu.max_total_results , "need -max_total_results");
|
|
|
|
CHKARG(wu.max_success_results , "need -max_success_results");
|
|
|
|
#undef CHKARG
|
|
|
|
#undef CHKARG_STR
|
|
|
|
|
2003-01-09 07:24:27 +00:00
|
|
|
if (boinc_db_open(db_name, db_passwd)) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: error opening database.\n" );
|
|
|
|
exit(0);
|
|
|
|
}
|
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
|
|
|
|
2002-07-12 18:24:58 +00:00
|
|
|
//fprintf(stderr, "wu_template = %s\n", wu_template);
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = read_filename(wu_template_file, wu_template);
|
|
|
|
if (retval) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: can't open WU template\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
wu.appid = app.id;
|
2003-08-15 20:35:44 +00:00
|
|
|
wu.transition_time = MAXINT;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2002-10-14 23:10:12 +00:00
|
|
|
retval = read_key_file(keyfile, key);
|
2002-07-05 05:33:40 +00:00
|
|
|
if (retval) {
|
2002-10-14 23:10:12 +00:00
|
|
|
fprintf(stderr, "create_work: can't read key");
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-12-05 19:13:06 +00:00
|
|
|
if (sequence) {
|
2002-12-06 07:33:45 +00:00
|
|
|
retval = create_sequence_group(
|
2002-12-05 19:13:06 +00:00
|
|
|
wu,
|
|
|
|
wu_template,
|
|
|
|
result_template_file,
|
|
|
|
download_dir,
|
|
|
|
infiles,
|
|
|
|
ninfiles,
|
|
|
|
key,
|
|
|
|
upload_url,
|
|
|
|
download_url,
|
|
|
|
sequence
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
retval = create_work(
|
|
|
|
wu,
|
|
|
|
wu_template,
|
|
|
|
result_template_file,
|
|
|
|
download_dir,
|
|
|
|
infiles,
|
|
|
|
ninfiles,
|
|
|
|
key,
|
|
|
|
upload_url,
|
|
|
|
download_url
|
|
|
|
);
|
|
|
|
if (retval) fprintf(stderr, "create_work: %d\n", retval);
|
|
|
|
}
|
2003-01-09 07:24:27 +00:00
|
|
|
boinc_db_close();
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|