// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2014 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
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see .
// Create workunit(s).
// see http://boinc.berkeley.edu/trac/wiki/JobSubmission
#include "config.h"
#include
#include
#include
#include
#include
#include
#include
#include "boinc_db.h"
#include "common_defs.h"
#include "crypt.h"
#include "filesys.h"
#include "sched_config.h"
#include "str_replace.h"
#include "str_util.h"
#include "util.h"
#include "backend_lib.h"
using std::string;
void usage() {
fprintf(stderr,
"usage: create_work [options] infile1 infile2 ...\n"
"\n"
"Options:\n"
" --appname name\n"
" [ --additional_xml x ]\n"
" [ --batch n ]\n"
" [ --broadcast ]\n"
" [ --broadcast_user ID ]\n"
" [ --broadcast_team ID ]\n"
" [ --command_line \"X\" ]\n"
" [ --config_dir path ]\n"
" [ -d n ]\n"
" [ --delay_bound x ]\n"
" [ --max_error_results n ]\n"
" [ --max_success_results n ]\n"
" [ --max_total_results n ]\n"
" [ --min_quorum n ]\n"
" [ --priority n ]\n"
" [ --result_template filename ] default: appname_out\n"
" [ --rsc_disk_bound x ]\n"
" [ --rsc_fpops_est x ]\n"
" [ --rsc_fpops_bound x ]\n"
" [ --rsc_memory_bound x ]\n"
" [ --size_class n ]\n"
" [ --stdin ]\n"
" [ --target_host ID ]\n"
" [ --target_nresults n ]\n"
" [ --target_team ID ]\n"
" [ --target_user ID ]\n"
" [ --wu_id ID ] ID of existing workunit record (used by boinc_submit)\n"
" [ --wu_name name ] default: generate a name based on app name\n"
" [ --wu_template filename ] default: appname_in\n"
);
exit(1);
}
bool arg(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;
}
struct JOB_DESC {
DB_WORKUNIT wu;
char wu_template[BLOB_SIZE];
char result_template_file[256], result_template_path[MAXPATHLEN];
char** infiles;
char* command_line;
char additional_xml[256];
bool assign_flag;
bool assign_multi;
int assign_id;
int assign_type;
int ninfiles;
JOB_DESC() {
wu.clear();
infiles = NULL;
command_line = NULL;
assign_flag = false;
assign_multi = false;
strcpy(result_template_file, "");
strcpy(additional_xml, "");
assign_id = 0;
assign_type = ASSIGN_NONE;
ninfiles = 0;
// defaults (in case they're not in WU template)
//
wu.id = 0;
wu.min_quorum = 2;
wu.target_nresults = 2;
wu.max_error_results = 3;
wu.max_total_results = 10;
wu.max_success_results = 6;
wu.rsc_fpops_est = 3600e9;
wu.rsc_fpops_bound = 86400e9;
wu.rsc_memory_bound = 5e8;
wu.rsc_disk_bound = 1e9;
wu.rsc_bandwidth_bound = 0.0;
wu.delay_bound = 7*86400;
}
void create();
void parse_cmdline(int, char**);
};
// parse additional job-specific info when using --stdin
//
void JOB_DESC::parse_cmdline(int argc, char** argv) {
for (int i=0; i(jd2.infiles),
jd2.ninfiles,
config,
jd2.command_line,
jd2.additional_xml,
value_buf
);
if (retval) {
fprintf(stderr, "create_work() failed: %d\n", retval);
exit(1);
}
if (values.size()) {
values += ",";
values += value_buf;
} else {
values = value_buf;
}
// MySQL can handles queries at least 1 MB
//
int n = strlen(value_buf);
if (values.size() + 2*n > 1000000) {
retval = wu.insert_batch(values);
if (retval) {
fprintf(stderr,
"wu.insert_batch() failed: %d\n", retval
);
exit(1);
}
values.clear();
}
}
if (values.size()) {
retval = wu.insert_batch(values);
if (retval) {
fprintf(stderr,
"wu.insert_batch() failed: %d\n", retval
);
exit(1);
}
}
} else {
jd.create();
if (show_wu_name) {
printf("workunit name: %s\n", jd.wu.name);
}
}
boinc_db.close();
}
void JOB_DESC::create() {
char buf[256];
int retval = create_work(
wu,
wu_template,
result_template_file,
result_template_path,
const_cast(infiles),
ninfiles,
config,
command_line,
additional_xml
);
if (retval) {
fprintf(stderr, "create_work: %s\n", boincerror(retval));
exit(1);
}
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: %s\n", boincerror(retval)
);
exit(1);
}
sprintf(buf, "transitioner_flags=%d",
assign_multi?TRANSITION_NONE:TRANSITION_NO_NEW_RESULTS
);
retval = wu.update_field(buf);
if (retval) {
fprintf(stderr, "wu.update() failed: %s\n", boincerror(retval));
exit(1);
}
}
}
const char *BOINC_RCSID_3865dbbf46 = "$Id$";