void make_new_wu(DB_WORKUNIT& original_wu, char* starting_xml, int start_time) { char file_name[256], buf[BLOB_SIZE], new_file_name[256]; char new_buf[BLOB_SIZE]; char * p; int retval; DB_WORKUNIT wu = original_wu; static int file_seqno = 0, wu_seqno = 0; safe_strcpy(buf, starting_xml); p = strtok(buf, "\n"); strcpy(file_name, ""); // make new names for the WU's input files, // so clients will download them. // (don't actually copy files; URL stays the same) // while (p) { if (parse_str(p, "<name>", file_name, sizeof(file_name))) { sprintf( new_file_name, "%s__%d_%d", file_name, start_time, file_seqno++ ); safe_strcpy(new_buf, starting_xml); replace_file_name(new_buf, file_name, new_file_name); safe_strcpy(wu.xml_doc, new_buf); } p = strtok(0, "\n"); } // set various fields for new WU (all others are copied) // wu.id = 0; wu.create_time = time(0); // the name of the new WU cannot include the original WU name, // because the original one probably contains "nodelete", // but we want the copy to be eligible for file deletion // sprintf(wu.name, "wu_%d_%d", start_time, wu_seqno++); wu.need_validate = false; wu.canonical_resultid = 0; wu.canonical_credit = 0; wu.hr_class = 0; wu.transition_time = time(0); wu.error_mask = 0; wu.file_delete_state = FILE_DELETE_INIT; wu.assimilate_state = ASSIMILATE_INIT; retval = wu.insert(); if (retval) { log_messages.printf(MSG_CRITICAL, "Failed to created WU: %s; exiting\n", boincerror(retval) ); exit(retval); } original_wu.id = boinc_db.insert_id(); log_messages.printf(MSG_DEBUG, "Created %s, clone of %s\n", wu.name, original_wu.name ); }
int create_work( DB_WORKUNIT& wu, const char* _wu_template, const char* result_template_filename, const char* result_template_filepath, const char** infiles, int ninfiles, SCHED_CONFIG& config_loc, const char* command_line, const char* additional_xml ) { int retval; char _result_template[BLOB_SIZE]; char wu_template[BLOB_SIZE]; #if 0 retval = check_files(infiles, ninfiles, config_loc); if (retval) { fprintf(stderr, "Missing input file: %s\n", infiles[0]); return -1; } #endif strcpy(wu_template, _wu_template); wu.create_time = time(0); retval = process_input_template( wu, wu_template, infiles, ninfiles, config_loc, command_line, additional_xml ); if (retval) { fprintf(stderr, "process_input_template(): %d\n", retval); return retval; } retval = read_filename( result_template_filepath, _result_template, sizeof(_result_template) ); if (retval) { fprintf(stderr, "create_work: can't read result template file %s\n", result_template_filepath ); return retval; } if (strlen(result_template_filename) > sizeof(wu.result_template_file)-1) { fprintf(stderr, "result template filename is too big: %d bytes, max is %d\n", (int)strlen(result_template_filename), (int)sizeof(wu.result_template_file)-1 ); return ERR_BUFFER_OVERFLOW; } strlcpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file)); if (wu.rsc_fpops_est == 0) { fprintf(stderr, "no rsc_fpops_est given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_fpops_bound == 0) { fprintf(stderr, "no rsc_fpops_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_disk_bound == 0) { fprintf(stderr, "no rsc_disk_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.target_nresults == 0) { fprintf(stderr, "no target_nresults given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_error_results == 0) { fprintf(stderr, "no max_error_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_total_results == 0) { fprintf(stderr, "no max_total_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results == 0) { fprintf(stderr, "no max_success_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results > wu.max_total_results) { fprintf(stderr, "max_success_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.max_error_results > wu.max_total_results) { fprintf(stderr, "max_error_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.target_nresults > wu.max_success_results) { fprintf(stderr, "target_nresults > max_success_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.transitioner_flags & TRANSITION_NONE) { wu.transition_time = INT_MAX; } else { wu.transition_time = time(0); } if (wu.id) { retval = wu.update(); if (retval) { fprintf(stderr, "create_work: workunit.update() %d\n", retval); return retval; } } else { retval = wu.insert(); if (retval) { fprintf(stderr, "create_work: workunit.insert() %d\n", retval); return retval; } wu.id = boinc_db.insert_id(); } return 0; }
// variant where input files are described by INFILE_DESCS, // so you can have remote files etc. // // If query_string is present, don't actually create the job; // instead, append to the query string. // The caller is responsible for doing the query. // int create_work2( DB_WORKUNIT& wu, const char* _wu_template, const char* result_template_filename, // relative to project root; stored in DB const char* /* result_template_filepath*/, // deprecated vector<INFILE_DESC> &infiles, SCHED_CONFIG& config_loc, const char* command_line, const char* additional_xml, char* query_string ) { int retval; char wu_template[BLOB_SIZE]; #if 0 retval = check_files(infiles, ninfiles, config_loc); if (retval) { fprintf(stderr, "Missing input file: %s\n", infiles[0]); return -1; } #endif safe_strcpy(wu_template, _wu_template); wu.create_time = time(0); retval = process_input_template( wu, wu_template, infiles, config_loc, command_line, additional_xml ); if (retval) { fprintf(stderr, "process_input_template(): %s\n", boincerror(retval)); return retval; } // check for presence of result template. // we don't need to actually look at it. // const char* p = config_loc.project_path(result_template_filename); if (!boinc_file_exists(p)) { fprintf(stderr, "create_work: result template file %s doesn't exist\n", p ); return retval; } if (strlen(result_template_filename) > sizeof(wu.result_template_file)-1) { fprintf(stderr, "result template filename is too big: %d bytes, max is %d\n", (int)strlen(result_template_filename), (int)sizeof(wu.result_template_file)-1 ); return ERR_BUFFER_OVERFLOW; } strlcpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file)); if (wu.rsc_fpops_est == 0) { fprintf(stderr, "no rsc_fpops_est given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_fpops_bound == 0) { fprintf(stderr, "no rsc_fpops_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_disk_bound == 0) { fprintf(stderr, "no rsc_disk_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.target_nresults == 0) { fprintf(stderr, "no target_nresults given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_error_results == 0) { fprintf(stderr, "no max_error_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_total_results == 0) { fprintf(stderr, "no max_total_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results == 0) { fprintf(stderr, "no max_success_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results > wu.max_total_results) { fprintf(stderr, "max_success_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.max_error_results > wu.max_total_results) { fprintf(stderr, "max_error_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.target_nresults > wu.max_success_results) { fprintf(stderr, "target_nresults > max_success_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.transitioner_flags) { wu.transition_time = INT_MAX; } else { wu.transition_time = time(0); } if (query_string) { wu.db_print_values(query_string); } else if (wu.id) { retval = wu.update(); if (retval) { fprintf(stderr, "create_work: workunit.update() %s\n", boincerror(retval) ); return retval; } } else { retval = wu.insert(); if (retval) { fprintf(stderr, "create_work: workunit.insert() %s\n", boincerror(retval) ); return retval; } wu.id = boinc_db.insert_id(); } return 0; }