void APP_VERSION::clear_errors() { int x; unsigned int i; for (i=0; i<app_files.size();i++) { FILE_INFO* fip = app_files[i].file_info; if (fip->had_failure(x)) { fip->reset(); } } }
// if any input files had download error from previous WU, // reset them to try download again // void WORKUNIT::clear_errors() { int x; unsigned int i; for (i=0; i<input_files.size();i++) { FILE_INFO* fip = input_files[i].file_info; if (fip->had_failure(x)) { fip->reset(); } } }
int CLIENT_STATE::write_file_transfers_gui(MIOFILE& f) { unsigned int i; f.printf("<file_transfers>\n"); for (i=0; i<file_infos.size(); i++) { FILE_INFO* fip = file_infos[i]; if (fip->pers_file_xfer) { fip->write_gui(f); } } f.printf("</file_transfers>\n"); return 0; }
void APP_VERSION::get_file_errors(string& str) { int errnum; unsigned int i; FILE_INFO* fip; string msg; str = "couldn't get input files:\n"; for (i=0; i<app_files.size();i++) { fip = app_files[i].file_info; if (fip->had_failure(errnum)) { fip->failure_message(msg); str = str + msg; } } }
void WORKUNIT::get_file_errors(string& str) { int x; unsigned int i; FILE_INFO* fip; string msg; str = "couldn't get input files:\n"; for (i=0;i<input_files.size();i++) { fip = input_files[i].file_info; if (fip->had_failure(x)) { fip->failure_message(msg); str = str + msg; } } }
// Returns zero iff all the input files for a result are present // (both WU and app version) // Called from CLIENT_STATE::update_results (with verify=false) // to transition result from DOWNLOADING to DOWNLOADED. // Called from ACTIVE_TASK::start() (with verify=true) // when project has verify_files_on_app_start set. // // If fipp is nonzero, return a pointer to offending FILE_INFO on error // int CLIENT_STATE::input_files_available( RESULT* rp, bool verify_contents, FILE_INFO** fipp ) { WORKUNIT* wup = rp->wup; FILE_INFO* fip; unsigned int i; APP_VERSION* avp; FILE_REF fr; PROJECT* project = rp->project; int retval; avp = rp->avp; for (i=0; i<avp->app_files.size(); i++) { fr = avp->app_files[i]; fip = fr.file_info; if (fip->status != FILE_PRESENT) { if (fipp) *fipp = fip; return ERR_FILE_MISSING; } // don't verify app files if using anonymous platform // if (verify_contents && !project->anonymous_platform) { retval = fip->verify_file(true, true, false); if (retval) { if (fipp) *fipp = fip; return retval; } } } for (i=0; i<wup->input_files.size(); i++) { fip = wup->input_files[i].file_info; if (fip->status != FILE_PRESENT) { if (wup->input_files[i].optional) continue; if (fipp) *fipp = fip; return ERR_FILE_MISSING; } if (verify_contents) { retval = fip->verify_file(true, true, false); if (retval) { if (fipp) *fipp = fip; return retval; } } } return 0; }
// Returns true if the result's output files are all either // successfully uploaded or have unrecoverable errors // bool RESULT::is_upload_done() { unsigned int i; FILE_INFO* fip; int retval; for (i=0; i<output_files.size(); i++) { fip = output_files[i].file_info; if (fip->uploadable()) { if (fip->had_failure(retval)) continue; if (!fip->uploaded) { return false; } } } return true; }
int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) { char path[1024]; MIOFILE mf; string name; mf.init_buf_read(result.xml_doc_in); XML_PARSER xp(&mf); fis.clear(); while (!xp.get_tag()) { if (!xp.is_tag) continue; if (xp.match_tag("file_ref")) { FILE_INFO fi; int retval = fi.parse(xp); if (retval) return retval; dir_hier_path( fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path ); fi.path = path; fis.push_back(fi); } } return 0; }
// for each FILE_INFO (i.e. each project file the client knows about) // check that the file exists and is of the right size. // Called at startup. // void CLIENT_STATE::check_file_existence() { unsigned int i; char path[MAXPATHLEN]; for (i=0; i<file_infos.size(); i++) { FILE_INFO* fip = file_infos[i]; if (fip->status < 0 && fip->downloadable()) { // file had an error; reset it so that we download again get_pathname(fip, path, sizeof(path)); msg_printf(fip->project, MSG_INFO, "Resetting file %s: %s", path, boincerror(fip->status) ); fip->reset(); continue; } if (cc_config.dont_check_file_sizes) continue; if (fip->status == FILE_PRESENT) { get_pathname(fip, path, sizeof(path)); double size; int retval = file_size(path, size); if (retval) { delete_project_owned_file(path, true); fip->status = FILE_NOT_PRESENT; msg_printf(fip->project, MSG_INFO, "File %s not found", path); } else if (fip->nbytes && (size != fip->nbytes)) { if (gstate.global_prefs.dont_verify_images && is_image_file(path)) continue; delete_project_owned_file(path, true); fip->status = FILE_NOT_PRESENT; msg_printf(fip->project, MSG_INFO, "File %s has wrong size: expected %.0f, got %.0f", path, fip->nbytes, size ); } } } }
int get_output_file_info(RESULT& result, FILE_INFO& fi) { char path[1024]; string name; MIOFILE mf; mf.init_buf_read(result.xml_doc_in); XML_PARSER xp(&mf); while (!xp.get_tag()) { if (!xp.is_tag) continue; if (xp.match_tag("file_ref")) { int retval = fi.parse(xp); if (retval) return retval; dir_hier_path( fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path ); fi.path = path; return 0; } } return ERR_XML_PARSE; }
// parse a project's app_info.xml (anonymous platform) file // int CLIENT_STATE::parse_app_info(PROJECT* p, FILE* in) { char buf[256], path[MAXPATHLEN]; MIOFILE mf; mf.init_file(in); XML_PARSER xp(&mf); while (!xp.get_tag()) { if (xp.match_tag("app_info")) continue; if (xp.match_tag("/app_info")) { notices.remove_notices(p, REMOVE_APP_INFO_MSG); return 0; } if (xp.match_tag("file_info") || xp.match_tag("file")) { FILE_INFO* fip = new FILE_INFO; if (fip->parse(xp)) { delete fip; continue; } if (!fip->download_urls.empty() || !fip->upload_urls.empty()) { msg_printf(p, MSG_INFO, "Can't specify URLs in app_info.xml" ); delete fip; continue; } if (link_file_info(p, fip)) { delete fip; continue; } // check that the file is actually there // get_pathname(fip, path, sizeof(path)); if (!boinc_file_exists(path)) { safe_strcpy(buf, _("File referenced in app_info.xml does not exist: ") ); strcat(buf, fip->name); msg_printf(p, MSG_USER_ALERT, "%s", buf); delete fip; continue; } fip->status = FILE_PRESENT; fip->anonymous_platform_file = true; file_infos.push_back(fip); continue; } if (xp.match_tag("app")) { APP* app = new APP; if (app->parse(xp)) { delete app; continue; } if (lookup_app(p, app->name)) { delete app; continue; } link_app(p, app); apps.push_back(app); continue; } if (xp.match_tag("app_version")) { APP_VERSION* avp = new APP_VERSION; if (avp->parse(xp)) { delete avp; continue; } if (cc_config.dont_use_vbox && strstr(avp->plan_class, "vbox")) { msg_printf(p, MSG_INFO, "skipping vbox app in app_info.xml; vbox disabled in cc_config.xml" ); delete avp; continue; } if (strlen(avp->platform) == 0) { safe_strcpy(avp->platform, get_primary_platform()); } if (link_app_version(p, avp)) { delete avp; continue; } app_versions.push_back(avp); continue; } if (log_flags.unparsed_xml) { msg_printf(p, MSG_INFO, "Unparsed line in app_info.xml: %s", xp.parsed_tag ); } } return ERR_XML_PARSE; }
// return an error message or NULL // const char* SCHEDULER_REQUEST::parse(FILE* fin) { char buf[256]; RESULT result; int retval; strcpy(authenticator, ""); strcpy(platform.name, ""); strcpy(cross_project_id, ""); hostid = 0; core_client_major_version = 0; core_client_minor_version = 0; core_client_release = 0; rpc_seqno = 0; work_req_seconds = 0; cpu_req_secs = 0; cpu_req_instances = 0; resource_share_fraction = 1.0; rrs_fraction = 1.0; prrs_fraction = 1.0; cpu_estimated_delay = 0; strcpy(global_prefs_xml, ""); strcpy(working_global_prefs_xml, ""); strcpy(code_sign_key, ""); memset(&global_prefs, 0, sizeof(global_prefs)); memset(&host, 0, sizeof(host)); have_other_results_list = false; have_ip_results_list = false; have_time_stats_log = false; client_cap_plan_class = false; sandbox = -1; coproc_cuda = 0; coproc_ati = 0; fgets(buf, sizeof(buf), fin); if (!match_tag(buf, "<scheduler_request>")) return "no start tag"; while (fgets(buf, sizeof(buf), fin)) { // If a line is too long, ignore it. // This can happen e.g. if the client has bad global_prefs.xml // This won't be necessary if we rewrite this using XML_PARSER // if (!strchr(buf, '\n')) { while (fgets(buf, sizeof(buf), fin)) { if (strchr(buf, '\n')) break; } continue; } if (match_tag(buf, "</scheduler_request>")) { core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release; return NULL; } if (parse_str(buf, "<authenticator>", authenticator, sizeof(authenticator))) { remove_quotes(authenticator); continue; } if (parse_str(buf, "<cross_project_id>", cross_project_id, sizeof(cross_project_id))) continue; if (parse_int(buf, "<hostid>", hostid)) continue; if (parse_int(buf, "<rpc_seqno>", rpc_seqno)) continue; if (parse_str(buf, "<platform_name>", platform.name, sizeof(platform.name))) continue; if (match_tag(buf, "<alt_platform>")) { CLIENT_PLATFORM cp; retval = cp.parse(fin); if (!retval) { alt_platforms.push_back(cp); } continue; } if (match_tag(buf, "<app_versions>")) { while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</app_versions>")) break; if (match_tag(buf, "<app_version>")) { CLIENT_APP_VERSION cav; retval = cav.parse(fin); if (retval) { g_reply->insert_message( "Invalid app version description", "high" ); } else { client_app_versions.push_back(cav); } } } continue; } if (parse_int(buf, "<core_client_major_version>", core_client_major_version)) continue; if (parse_int(buf, "<core_client_minor_version>", core_client_minor_version)) continue; if (parse_int(buf, "<core_client_release>", core_client_release)) continue; if (parse_double(buf, "<work_req_seconds>", work_req_seconds)) continue; if (parse_double(buf, "<cpu_req_secs>", cpu_req_secs)) continue; if (parse_double(buf, "<cpu_req_instances>", cpu_req_instances)) continue; if (parse_double(buf, "<resource_share_fraction>", resource_share_fraction)) continue; if (parse_double(buf, "<rrs_fraction>", rrs_fraction)) continue; if (parse_double(buf, "<prrs_fraction>", prrs_fraction)) continue; if (parse_double(buf, "<estimated_delay>", cpu_estimated_delay)) continue; if (parse_double(buf, "<duration_correction_factor>", host.duration_correction_factor)) continue; if (match_tag(buf, "<global_preferences>")) { strcpy(global_prefs_xml, "<global_preferences>\n"); while (fgets(buf, sizeof(buf), fin)) { if (strstr(buf, "</global_preferences>")) break; safe_strcat(global_prefs_xml, buf); } safe_strcat(global_prefs_xml, "</global_preferences>\n"); continue; } if (match_tag(buf, "<working_global_preferences>")) { while (fgets(buf, sizeof(buf), fin)) { if (strstr(buf, "</working_global_preferences>")) break; safe_strcat(working_global_prefs_xml, buf); } continue; } if (parse_str(buf, "<global_prefs_source_email_hash>", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue; if (match_tag(buf, "<host_info>")) { host.parse(fin); continue; } if (match_tag(buf, "<time_stats>")) { host.parse_time_stats(fin); continue; } if (match_tag(buf, "<time_stats_log>")) { handle_time_stats_log(fin); have_time_stats_log = true; continue; } if (match_tag(buf, "<net_stats>")) { host.parse_net_stats(fin); continue; } if (match_tag(buf, "<disk_usage>")) { host.parse_disk_usage(fin); continue; } if (match_tag(buf, "<result>")) { result.parse_from_client(fin); static int max_results = 200; --max_results; if (max_results >= 0) results.push_back(result); continue; } if (match_tag(buf, "<code_sign_key>")) { copy_element_contents(fin, "</code_sign_key>", code_sign_key, sizeof(code_sign_key)); continue; } if (match_tag(buf, "<msg_from_host>")) { MSG_FROM_HOST_DESC md; retval = md.parse(fin); if (!retval) { msgs_from_host.push_back(md); } continue; } if (match_tag(buf, "<file_info>")) { FILE_INFO fi; retval = fi.parse(fin); if (!retval) { file_infos.push_back(fi); } continue; } if (match_tag(buf, "<host_venue>")) { continue; } if (match_tag(buf, "<other_results>")) { have_other_results_list = true; while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</other_results>")) break; if (match_tag(buf, "<other_result>")) { OTHER_RESULT o_r; retval = o_r.parse(fin); if (!retval) { other_results.push_back(o_r); } } } continue; } if (match_tag(buf, "<in_progress_results>")) { have_ip_results_list = true; int i = 0; double now = time(0); while (fgets(buf, sizeof(buf), fin)) { if (match_tag(buf, "</in_progress_results>")) break; if (match_tag(buf, "<ip_result>")) { IP_RESULT ir; retval = ir.parse(fin); if (!retval) { if (!strlen(ir.name)) { sprintf(ir.name, "ip%d", i++); } ir.report_deadline -= now; ip_results.push_back(ir); } } } continue; } if (match_tag(buf, "coprocs")) { MIOFILE mf; mf.init_file(fin); coprocs.parse(mf); coproc_cuda = (COPROC_CUDA*)coprocs.lookup("CUDA"); coproc_ati = (COPROC_ATI*)coprocs.lookup("ATI"); continue; } if (parse_bool(buf, "client_cap_plan_class", client_cap_plan_class)) continue; if (parse_int(buf, "<sandbox>", sandbox)) continue; if (match_tag(buf, "<active_task_set>")) continue; if (match_tag(buf, "<app>")) continue; if (match_tag(buf, "<app_version>")) continue; if (match_tag(buf, "<duration_variability>")) continue; if (match_tag(buf, "<new_version_check_time>")) continue; if (match_tag(buf, "<newer_version>")) continue; if (match_tag(buf, "<project>")) continue; if (match_tag(buf, "<project_files>")) continue; if (match_tag(buf, "<proxy_info>")) continue; if (match_tag(buf, "<user_network_request>")) continue; if (match_tag(buf, "<user_run_request>")) continue; if (match_tag(buf, "<master_url>")) continue; if (match_tag(buf, "<project_name>")) continue; if (match_tag(buf, "<user_name>")) continue; if (match_tag(buf, "<team_name>")) continue; if (match_tag(buf, "<email_hash>")) continue; if (match_tag(buf, "<user_total_credit>")) continue; if (match_tag(buf, "<user_expavg_credit>")) continue; if (match_tag(buf, "<user_create_time>")) continue; if (match_tag(buf, "<host_total_credit>")) continue; if (match_tag(buf, "<host_expavg_credit>")) continue; if (match_tag(buf, "<host_create_time>")) continue; if (match_tag(buf, "<nrpc_failures>")) continue; if (match_tag(buf, "<master_fetch_failures>")) continue; if (match_tag(buf, "<min_rpc_time>")) continue; if (match_tag(buf, "<short_term_debt>")) continue; if (match_tag(buf, "<long_term_debt>")) continue; if (match_tag(buf, "<resource_share>")) continue; if (match_tag(buf, "<scheduler_url>")) continue; if (match_tag(buf, "</project>")) continue; if (match_tag(buf, "<?xml")) continue; strip_whitespace(buf); if (!strlen(buf)) continue; log_messages.printf(MSG_NORMAL, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf ); MIOFILE mf; mf.init_file(fin); retval = skip_unrecognized(buf, mf); if (retval) return "unterminated unrecognized XML"; } return "no end tag"; }
int CLIENT_STATE::write_state(MIOFILE& f) { unsigned int i, j; int retval; #ifdef SIM fprintf(stderr, "simulator shouldn't write state file\n"); exit(1); #endif f.printf("<client_state>\n"); retval = host_info.write(f, true, true); if (retval) return retval; retval = time_stats.write(f, false); if (retval) return retval; retval = net_stats.write(f); if (retval) return retval; for (j=0; j<projects.size(); j++) { PROJECT* p = projects[j]; retval = p->write_state(f); if (retval) return retval; for (i=0; i<apps.size(); i++) { if (apps[i]->project == p) { retval = apps[i]->write(f); if (retval) return retval; } } for (i=0; i<file_infos.size(); i++) { if (file_infos[i]->project != p) continue; FILE_INFO* fip = file_infos[i]; // don't write file infos for anonymous platform app files // if (fip->anonymous_platform_file) continue; retval = fip->write(f, false); if (retval) return retval; } for (i=0; i<app_versions.size(); i++) { if (app_versions[i]->project == p) { app_versions[i]->write(f); } } for (i=0; i<workunits.size(); i++) { if (workunits[i]->project == p) workunits[i]->write(f); } for (i=0; i<results.size(); i++) { if (results[i]->project == p) results[i]->write(f, false); } p->write_project_files(f); #ifdef ENABLE_AUTO_UPDATE if (auto_update.present && auto_update.project==p) { auto_update.write(f); } #endif } active_tasks.write(f); f.printf( "<platform_name>%s</platform_name>\n" "<core_client_major_version>%d</core_client_major_version>\n" "<core_client_minor_version>%d</core_client_minor_version>\n" "<core_client_release>%d</core_client_release>\n" "<user_run_request>%d</user_run_request>\n" "<user_run_prev_request>%d</user_run_prev_request>\n" "<user_gpu_request>%d</user_gpu_request>\n" "<user_gpu_prev_request>%d</user_gpu_prev_request>\n" "<user_network_request>%d</user_network_request>\n" "<new_version_check_time>%f</new_version_check_time>\n" "<all_projects_list_check_time>%f</all_projects_list_check_time>\n", get_primary_platform(), core_client_version.major, core_client_version.minor, core_client_version.release, cpu_run_mode.get_perm(), cpu_run_mode.get_prev(), gpu_run_mode.get_perm(), gpu_run_mode.get_prev(), network_run_mode.get_perm(), new_version_check_time, all_projects_list_check_time ); if (strlen(language)) { f.printf("<language>%s</language>\n", language); } if (newer_version.size()) { f.printf("<newer_version>%s</newer_version>\n", newer_version.c_str()); } for (i=1; i<platforms.size(); i++) { f.printf("<alt_platform>%s</alt_platform>\n", platforms[i].name.c_str()); } if (gui_proxy_info.present) { gui_proxy_info.write(f); } if (strlen(main_host_venue)) { f.printf("<host_venue>%s</host_venue>\n", main_host_venue); } f.printf("</client_state>\n"); return 0; }
int CLIENT_STATE::parse_state_file_aux(const char* fname) { PROJECT *project=NULL; int retval=0; string stemp; FILE* f = fopen(fname, "r"); if (!f) return ERR_FOPEN; MIOFILE mf; XML_PARSER xp(&mf); mf.init_file(f); while (!xp.get_tag()) { if (xp.match_tag("/client_state")) { break; } if (xp.match_tag("client_state")) { continue; } if (xp.match_tag("project")) { PROJECT temp_project; retval = temp_project.parse_state(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse project in state file"); } else { #ifdef SIM project = new PROJECT; *project = temp_project; projects.push_back(project); #else project = lookup_project(temp_project.master_url); if (project) { project->copy_state_fields(temp_project); } else { msg_printf(&temp_project, MSG_INTERNAL_ERROR, "Project %s is in state file but no account file found", temp_project.get_project_name() ); } #endif } continue; } if (xp.match_tag("app")) { APP* app = new APP; retval = app->parse(xp); if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Application %s outside project in state file", app->name ); delete app; continue; } if (project->anonymous_platform) { delete app; continue; } if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse application in state file" ); delete app; continue; } retval = link_app(project, app); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle application %s in state file", app->name ); delete app; continue; } apps.push_back(app); continue; } if (xp.match_tag("file_info") || xp.match_tag("file")) { FILE_INFO* fip = new FILE_INFO; retval = fip->parse(xp); if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "File info outside project in state file" ); delete fip; continue; } if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't handle file info in state file" ); delete fip; continue; } retval = link_file_info(project, fip); if (project->anonymous_platform && retval == ERR_NOT_UNIQUE) { delete fip; continue; } if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle file info %s in state file", fip->name ); delete fip; continue; } file_infos.push_back(fip); #ifndef SIM // If the file had a failure before, // don't start another file transfer // int failnum; if (fip->had_failure(failnum)) { if (fip->pers_file_xfer) { delete fip->pers_file_xfer; fip->pers_file_xfer = NULL; } } if (fip->pers_file_xfer) { retval = fip->pers_file_xfer->init(fip, fip->pers_file_xfer->is_upload); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't initialize file transfer for %s", fip->name ); } retval = pers_file_xfers->insert(fip->pers_file_xfer); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't start persistent file transfer for %s", fip->name ); } } #endif continue; } if (xp.match_tag("app_version")) { APP_VERSION* avp = new APP_VERSION; retval = avp->parse(xp); if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Application version outside project in state file" ); delete avp; continue; } if (project->anonymous_platform) { delete avp; continue; } if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse application version in state file" ); delete avp; continue; } if (strlen(avp->platform) == 0) { safe_strcpy(avp->platform, get_primary_platform()); } else { if (!is_supported_platform(avp->platform)) { // if it's a platform we haven't heard of, // must be that the user tried out a 64 bit client // and then reverted to a 32-bit client. // Let's not throw away the app version and its WUs // #ifndef SIM msg_printf(project, MSG_INTERNAL_ERROR, "App version has unsupported platform %s; changing to %s", avp->platform, get_primary_platform() ); #endif safe_strcpy(avp->platform, get_primary_platform()); } } if (avp->missing_coproc) { msg_printf(project, MSG_INFO, "Application uses missing %s GPU", avp->missing_coproc_name ); } retval = link_app_version(project, avp); if (retval) { delete avp; continue; } app_versions.push_back(avp); continue; } if (xp.match_tag("workunit")) { WORKUNIT* wup = new WORKUNIT; retval = wup->parse(xp); if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Workunit outside project in state file" ); delete wup; continue; } if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse workunit in state file" ); delete wup; continue; } retval = link_workunit(project, wup); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle workunit in state file" ); delete wup; continue; } workunits.push_back(wup); continue; } if (xp.match_tag("result")) { RESULT* rp = new RESULT; retval = rp->parse_state(xp); if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Task %s outside project in state file", rp->name ); delete rp; continue; } if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse task in state file" ); delete rp; continue; } retval = link_result(project, rp); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't link task %s in state file", rp->name ); delete rp; continue; } // handle transition from old clients which didn't store result.platform; // skip for anon platform if (!project->anonymous_platform) { if (!strlen(rp->platform) || !is_supported_platform(rp->platform)) { safe_strcpy(rp->platform, get_primary_platform()); rp->version_num = latest_version(rp->wup->app, rp->platform); } } rp->avp = lookup_app_version( rp->wup->app, rp->platform, rp->version_num, rp->plan_class ); if (!rp->avp) { msg_printf(project, MSG_INTERNAL_ERROR, "No application found for task: %s %d %s; discarding", rp->platform, rp->version_num, rp->plan_class ); delete rp; continue; } if (rp->avp->missing_coproc) { msg_printf(project, MSG_INFO, "Missing coprocessor for task %s", rp->name ); rp->coproc_missing = true; } rp->wup->version_num = rp->version_num; results.push_back(rp); continue; } if (xp.match_tag("project_files")) { if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Project files outside project in state file" ); xp.skip_unexpected(); continue; } parse_project_files(xp, project->project_files); project->link_project_files(); continue; } if (xp.match_tag("host_info")) { #ifdef SIM retval = host_info.parse(xp, false); coprocs = host_info.coprocs; coprocs.bound_counts(); #else retval = host_info.parse(xp, true); #endif if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse host info in state file" ); } continue; } if (xp.match_tag("time_stats")) { retval = time_stats.parse(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse time stats in state file" ); } continue; } if (xp.match_tag("net_stats")) { retval = net_stats.parse(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse network stats in state file" ); } continue; } if (xp.match_tag("active_task_set")) { retval = active_tasks.parse(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse active tasks in state file" ); } continue; } if (xp.parse_string("platform_name", statefile_platform_name)) { continue; } if (xp.parse_string("alt_platform", stemp)) { continue; } if (xp.parse_int("user_run_request", retval)) { cpu_run_mode.set(retval, 0); continue; } if (xp.parse_int("user_run_prev_request", retval)) { cpu_run_mode.set_prev(retval); continue; } if (xp.parse_int("user_gpu_request", retval)) { gpu_run_mode.set(retval, 0); continue; } if (xp.parse_int("user_gpu_prev_request", retval)) { gpu_run_mode.set_prev(retval); continue; } if (xp.parse_int("user_network_request", retval)) { network_run_mode.set(retval, 0); continue; } if (xp.parse_int("core_client_major_version", old_major_version)) { continue; } if (xp.parse_int("core_client_minor_version", old_minor_version)) { continue; } if (xp.parse_int("core_client_release", old_release)) { continue; } if (xp.parse_str("language", language, sizeof(language))) { continue; } if (xp.match_tag("proxy_info")) { retval = gui_proxy_info.parse(xp); if (retval) { msg_printf(NULL, MSG_INTERNAL_ERROR, "Can't parse proxy info in state file" ); } continue; } if (xp.parse_str("host_venue", main_host_venue, sizeof(main_host_venue))) { continue; } if (xp.parse_double("new_version_check_time", new_version_check_time)) { continue; } if (xp.parse_double("all_projects_list_check_time", all_projects_list_check_time)) { continue; } if (xp.parse_string("newer_version", newer_version)) { continue; } #ifdef ENABLE_AUTO_UPDATE if (xp.match_tag("auto_update")) { if (!project) { msg_printf(NULL, MSG_INTERNAL_ERROR, "auto update outside project in state file" ); xp.skip_unexpected(); continue; } if (!auto_update.parse(xp) && !auto_update.validate_and_link(project)) { auto_update.present = true; } continue; } #endif if (log_flags.unparsed_xml) { msg_printf(0, MSG_INFO, "[unparsed_xml] state_file: unrecognized: %s", xp.parsed_tag ); } xp.skip_unexpected(); } sort_results(); fclose(f); // if total resource share is zero, set all shares to 1 // if (projects.size()) { unsigned int i; double x=0; for (i=0; i<projects.size(); i++) { x += projects[i]->resource_share; } if (!x) { msg_printf(NULL, MSG_INFO, "All projects have zero resource share; setting to 100" ); for (i=0; i<projects.size(); i++) { projects[i]->resource_share = 100; } } } return 0; }
// scan FILE_INFOs and create PERS_FILE_XFERs as needed. // NOTE: this doesn't start the file transfers // scan PERS_FILE_XFERs and delete finished ones. // bool CLIENT_STATE::create_and_delete_pers_file_xfers() { unsigned int i; FILE_INFO* fip; PERS_FILE_XFER *pfx; bool action = false; int retval; static double last_time; if (!clock_change && now - last_time < PERS_FILE_XFER_START_PERIOD) return false; last_time = now; // Look for FILE_INFOs for which we should start a transfer, // and make PERS_FILE_XFERs for them // for (i=0; i<file_infos.size(); i++) { fip = file_infos[i]; pfx = fip->pers_file_xfer; if (pfx) continue; if (fip->downloadable() && fip->status == FILE_NOT_PRESENT) { pfx = new PERS_FILE_XFER; pfx->init(fip, false); fip->pers_file_xfer = pfx; pers_file_xfers->insert(fip->pers_file_xfer); action = true; } else if (fip->uploadable() && fip->status == FILE_PRESENT && !fip->uploaded) { pfx = new PERS_FILE_XFER; pfx->init(fip, true); fip->pers_file_xfer = pfx; pers_file_xfers->insert(fip->pers_file_xfer); action = true; } } // Scan existing PERS_FILE_XFERs, looking for those that are done, // and deleting them // vector<PERS_FILE_XFER*>::iterator iter; iter = pers_file_xfers->pers_file_xfers.begin(); while (iter != pers_file_xfers->pers_file_xfers.end()) { pfx = *iter; // If the transfer finished, remove the PERS_FILE_XFER object // from the set and delete it // if (pfx->pers_xfer_done) { fip = pfx->fip; if (pfx->is_upload) { // file has been uploaded - delete if not sticky // if (!fip->sticky) { fip->delete_file(); } fip->uploaded = true; active_tasks.upload_notify_app(fip); } else if (fip->status >= 0) { // file transfer did not fail (non-negative status) // If this was a compressed download, rename .gzt to .gz // if (fip->download_gzipped) { char path[MAXPATHLEN], from_path[MAXPATHLEN], to_path[MAXPATHLEN]; get_pathname(fip, path, sizeof(path)); snprintf(from_path, sizeof(from_path), "%s.gzt", path); snprintf(to_path, sizeof(to_path), "%s.gz", path); boinc_rename(from_path, to_path); } // verify the file with RSA or MD5, and change permissions // retval = fip->verify_file(true, true, true); if (retval == ERR_IN_PROGRESS) { // do nothing } else if (retval) { msg_printf(fip->project, MSG_INTERNAL_ERROR, "Checksum or signature error for %s", fip->name ); fip->status = retval; } else { // Set the appropriate permissions depending on whether // it's an executable or normal file // retval = fip->set_permissions(); fip->status = FILE_PRESENT; } // if it's a user file, tell running apps to reread prefs // if (fip->is_user_file) { active_tasks.request_reread_prefs(fip->project); } // if it's a project file, make a link in project dir // if (fip->is_project_file) { PROJECT* p = fip->project; p->write_symlink_for_project_file(fip); p->update_project_files_downloaded_time(); } } iter = pers_file_xfers->pers_file_xfers.erase(iter); delete pfx; action = true; // `delete pfx' should have set pfx->fip->pfx to NULL assert (fip == NULL || fip->pers_file_xfer == NULL); } else { ++iter; } } return action; }
// return an error message or NULL // const char* SCHEDULER_REQUEST::parse(XML_PARSER& xp) { SCHED_DB_RESULT result; int retval; strcpy(authenticator, ""); strcpy(platform.name, ""); strcpy(cross_project_id, ""); hostid = 0; core_client_major_version = 0; core_client_minor_version = 0; core_client_release = 0; core_client_version = 0; rpc_seqno = 0; work_req_seconds = 0; cpu_req_secs = 0; cpu_req_instances = 0; resource_share_fraction = 1.0; rrs_fraction = 1.0; prrs_fraction = 1.0; cpu_estimated_delay = 0; strcpy(global_prefs_xml, ""); strcpy(working_global_prefs_xml, ""); strcpy(code_sign_key, ""); memset(&global_prefs, 0, sizeof(global_prefs)); memset(&host, 0, sizeof(host)); have_other_results_list = false; have_ip_results_list = false; have_time_stats_log = false; client_cap_plan_class = false; sandbox = -1; allow_multiple_clients = -1; if (xp.get_tag()) { return "xp.get_tag() failed"; } if (xp.match_tag("?xml")) { xp.get_tag(); } if (!xp.match_tag("scheduler_request")) return "no start tag"; while (!xp.get_tag()) { if (xp.match_tag("/scheduler_request")) { core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release; return NULL; } if (xp.parse_str("authenticator", authenticator, sizeof(authenticator))) { remove_quotes(authenticator); continue; } if (xp.parse_str("cross_project_id", cross_project_id, sizeof(cross_project_id))) continue; if (xp.parse_int("hostid", hostid)) continue; if (xp.parse_int("rpc_seqno", rpc_seqno)) continue; if (xp.parse_str("platform_name", platform.name, sizeof(platform.name))) continue; if (xp.match_tag("alt_platform")) { CLIENT_PLATFORM cp; retval = cp.parse(xp); if (!retval) { alt_platforms.push_back(cp); } continue; } if (xp.match_tag("app_versions")) { while (!xp.get_tag()) { if (xp.match_tag("/app_versions")) break; if (xp.match_tag("app_version")) { CLIENT_APP_VERSION cav; retval = cav.parse(xp); if (retval) { if (!strcmp(platform.name, "anonymous")) { if (retval == ERR_NOT_FOUND) { g_reply->insert_message( _("Unknown app name in app_info.xml"), "notice" ); } else { g_reply->insert_message( _("Syntax error in app_info.xml"), "notice" ); } } else { // this case happens if the app version // refers to a deprecated app } cav.app = 0; } // store the CLIENT_APP_VERSION even if it didn't parse. // This is necessary to maintain the correspondence // with result.app_version // client_app_versions.push_back(cav); } } continue; } if (xp.parse_int("core_client_major_version", core_client_major_version)) continue; if (xp.parse_int("core_client_minor_version", core_client_minor_version)) continue; if (xp.parse_int("core_client_release", core_client_release)) continue; if (xp.parse_double("work_req_seconds", work_req_seconds)) continue; if (xp.parse_double("cpu_req_secs", cpu_req_secs)) continue; if (xp.parse_double("cpu_req_instances", cpu_req_instances)) continue; if (xp.parse_double("resource_share_fraction", resource_share_fraction)) continue; if (xp.parse_double("rrs_fraction", rrs_fraction)) continue; if (xp.parse_double("prrs_fraction", prrs_fraction)) continue; if (xp.parse_double("estimated_delay", cpu_estimated_delay)) continue; if (xp.parse_double("duration_correction_factor", host.duration_correction_factor)) continue; if (xp.match_tag("global_preferences")) { strcpy(global_prefs_xml, "<global_preferences>\n"); char buf[BLOB_SIZE]; retval = xp.element_contents( "</global_preferences>", buf, sizeof(buf) ); if (retval) return "error copying global prefs"; safe_strcat(global_prefs_xml, buf); safe_strcat(global_prefs_xml, "</global_preferences>\n"); continue; } if (xp.match_tag("working_global_preferences")) { retval = xp.element_contents( "</working_global_preferences>", working_global_prefs_xml, sizeof(working_global_prefs_xml) ); if (retval) return "error copying working global prefs"; continue; } if (xp.parse_str("global_prefs_source_email_hash", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue; if (xp.match_tag("host_info")) { host.parse(xp); continue; } if (xp.match_tag("time_stats")) { host.parse_time_stats(xp); continue; } if (xp.match_tag("time_stats_log")) { handle_time_stats_log(xp.f->f); have_time_stats_log = true; continue; } if (xp.match_tag("net_stats")) { host.parse_net_stats(xp); continue; } if (xp.match_tag("disk_usage")) { host.parse_disk_usage(xp); continue; } if (xp.match_tag("result")) { retval = result.parse_from_client(xp); if (retval) continue; if (strstr(result.name, "download") || strstr(result.name, "upload")) { file_xfer_results.push_back(result); continue; } #if 0 // enable if you need to limit CGI memory size if (results.size() >= 1024) { continue; } #endif // check if client is sending the same result twice. // Shouldn't happen, but if it does bad things will happen // bool found = false; for (unsigned int i=0; i<results.size(); i++) { if (!strcmp(results[i].name, result.name)) { found = true; break; } } if (!found) { results.push_back(result); } continue; } if (xp.match_tag("code_sign_key")) { copy_element_contents(xp.f->f, "</code_sign_key>", code_sign_key, sizeof(code_sign_key)); strip_whitespace(code_sign_key); continue; } if (xp.match_tag("msg_from_host")) { MSG_FROM_HOST_DESC md; retval = md.parse(xp); if (!retval) { msgs_from_host.push_back(md); } continue; } if (xp.match_tag("file_info")) { FILE_INFO fi; retval = fi.parse(xp); if (!retval) { file_infos.push_back(fi); } continue; } if (xp.match_tag("host_venue")) { continue; } if (xp.match_tag("other_results")) { have_other_results_list = true; while (!xp.get_tag()) { if (xp.match_tag("/other_results")) break; if (xp.match_tag("other_result")) { OTHER_RESULT o_r; retval = o_r.parse(xp); if (!retval) { other_results.push_back(o_r); } } } continue; } if (xp.match_tag("in_progress_results")) { have_ip_results_list = true; int i = 0; double now = time(0); while (!xp.get_tag()) { if (xp.match_tag("/in_progress_results")) break; if (xp.match_tag("ip_result")) { IP_RESULT ir; retval = ir.parse(xp); if (!retval) { if (!strlen(ir.name)) { sprintf(ir.name, "ip%d", i++); } ir.report_deadline -= now; ip_results.push_back(ir); } } } continue; } if (xp.match_tag("coprocs")) { coprocs.parse(xp); continue; } if (xp.parse_bool("client_cap_plan_class", client_cap_plan_class)) continue; if (xp.parse_int("sandbox", sandbox)) continue; if (xp.parse_int("allow_multiple_clients", allow_multiple_clients)) continue; if (xp.parse_string("client_opaque", client_opaque)) continue; if (xp.match_tag("active_task_set")) continue; if (xp.match_tag("app")) continue; if (xp.match_tag("app_version")) continue; if (xp.match_tag("duration_variability")) continue; if (xp.match_tag("new_version_check_time")) continue; if (xp.match_tag("newer_version")) continue; if (xp.match_tag("project")) continue; if (xp.match_tag("project_files")) continue; if (xp.match_tag("proxy_info")) continue; if (xp.match_tag("user_network_request")) continue; if (xp.match_tag("user_run_request")) continue; if (xp.match_tag("master_url")) continue; if (xp.match_tag("project_name")) continue; if (xp.match_tag("user_name")) continue; if (xp.match_tag("team_name")) continue; if (xp.match_tag("email_hash")) continue; if (xp.match_tag("user_total_credit")) continue; if (xp.match_tag("user_expavg_credit")) continue; if (xp.match_tag("user_create_time")) continue; if (xp.match_tag("host_total_credit")) continue; if (xp.match_tag("host_expavg_credit")) continue; if (xp.match_tag("host_create_time")) continue; if (xp.match_tag("nrpc_failures")) continue; if (xp.match_tag("master_fetch_failures")) continue; if (xp.match_tag("min_rpc_time")) continue; if (xp.match_tag("short_term_debt")) continue; if (xp.match_tag("long_term_debt")) continue; if (xp.match_tag("resource_share")) continue; if (xp.match_tag("scheduler_url")) continue; if (xp.match_tag("/project")) continue; if (xp.match_tag("?xml")) continue; log_messages.printf(MSG_NORMAL, "SCHEDULER_REQUEST::parse(): unexpected: %s\n", xp.parsed_tag ); xp.skip_unexpected(); } return "no end tag"; }
int RESULT::write(MIOFILE& out, bool to_server) { unsigned int i; FILE_INFO* fip; int n, retval; out.printf( "<result>\n" " <name>%s</name>\n" " <final_cpu_time>%f</final_cpu_time>\n" " <final_elapsed_time>%f</final_elapsed_time>\n" " <exit_status>%d</exit_status>\n" " <state>%d</state>\n" " <platform>%s</platform>\n" " <version_num>%d</version_num>\n", name, final_cpu_time, final_elapsed_time, exit_status, state(), platform, version_num ); if (strlen(plan_class)) { out.printf(" <plan_class>%s</plan_class>\n", plan_class); } if (fpops_per_cpu_sec) { out.printf(" <fpops_per_cpu_sec>%f</fpops_per_cpu_sec>\n", fpops_per_cpu_sec); } if (fpops_cumulative) { out.printf(" <fpops_cumulative>%f</fpops_cumulative>\n", fpops_cumulative); } if (intops_per_cpu_sec) { out.printf(" <intops_per_cpu_sec>%f</intops_per_cpu_sec>\n", intops_per_cpu_sec); } if (intops_cumulative) { out.printf(" <intops_cumulative>%f</intops_cumulative>\n", intops_cumulative); } if (final_peak_working_set_size) { out.printf( " <final_peak_working_set_size>%.0f</final_peak_working_set_size>\n", final_peak_working_set_size ); } if (final_peak_swap_size) { out.printf( " <final_peak_swap_size>%.0f</final_peak_swap_size>\n", final_peak_swap_size ); } if (final_peak_disk_usage) { out.printf( " <final_peak_disk_usage>%.0f</final_peak_disk_usage>\n", final_peak_disk_usage ); } if (final_bytes_sent) { out.printf( " <final_bytes_sent>%.0f</final_bytes_sent>\n", final_bytes_sent ); } if (final_bytes_received) { out.printf( " <final_bytes_received>%.0f</final_bytes_received>\n", final_bytes_received ); } if (to_server) { out.printf( " <app_version_num>%d</app_version_num>\n", wup->version_num ); } n = (int)stderr_out.length(); if (n || to_server) { out.printf("<stderr_out>\n"); // the following is here so that it gets recorded on server // (there's no core_client_version field of result table) // if (to_server) { out.printf( "<core_client_version>%d.%d.%d</core_client_version>\n", gstate.core_client_version.major, gstate.core_client_version.minor, gstate.core_client_version.release ); } if (n) { out.printf("<![CDATA[\n"); out.printf("%s",stderr_out.c_str()); if (stderr_out[n-1] != '\n') { out.printf("\n"); } out.printf("]]>\n"); } out.printf("</stderr_out>\n"); } if (to_server) { for (i=0; i<output_files.size(); i++) { fip = output_files[i].file_info; if (fip->uploaded) { retval = fip->write(out, true); if (retval) return retval; } } } else { if (got_server_ack) out.printf(" <got_server_ack/>\n"); if (ready_to_report) out.printf(" <ready_to_report/>\n"); if (completed_time) out.printf(" <completed_time>%f</completed_time>\n", completed_time); if (suspended_via_gui) out.printf(" <suspended_via_gui/>\n"); if (report_immediately) out.printf(" <report_immediately/>\n"); out.printf( " <wu_name>%s</wu_name>\n" " <report_deadline>%f</report_deadline>\n" " <received_time>%f</received_time>\n", wu_name, report_deadline, received_time ); for (i=0; i<output_files.size(); i++) { retval = output_files[i].write(out); if (retval) return retval; } } out.printf("</result>\n"); return 0; }
// Handle the reply from a scheduler // int CLIENT_STATE::handle_scheduler_reply( PROJECT* project, char* scheduler_url ) { SCHEDULER_REPLY sr; FILE* f; int retval; unsigned int i; bool signature_valid, update_global_prefs=false, update_project_prefs=false; char buf[1024], filename[256]; std::string old_gui_urls = project->gui_urls; PROJECT* p2; vector<RESULT*>new_results; project->last_rpc_time = now; if (requested_work()) { had_or_requested_work = true; } get_sched_reply_filename(*project, filename, sizeof(filename)); f = fopen(filename, "r"); if (!f) return ERR_FOPEN; retval = sr.parse(f, project); fclose(f); if (retval) return retval; if (log_flags.sched_ops) { if (requested_work()) { sprintf(buf, ": got %d new tasks", (int)sr.results.size()); } else { strcpy(buf, ""); } msg_printf(project, MSG_INFO, "Scheduler request completed%s", buf); } if (log_flags.sched_op_debug) { if (sr.scheduler_version) { msg_printf(project, MSG_INFO, "[sched_op] Server version %d", sr.scheduler_version ); } } // check that master URL is correct // if (strlen(sr.master_url)) { canonicalize_master_url(sr.master_url); string url1 = sr.master_url; string url2 = project->master_url; downcase_string(url1); downcase_string(url2); if (url1 != url2) { p2 = lookup_project(sr.master_url); if (p2) { msg_printf(project, MSG_USER_ALERT, "You are attached to this project twice. Please remove projects named %s, then add %s", project->project_name, sr.master_url ); } else { msg_printf(project, MSG_INFO, _("You used the wrong URL for this project. When convenient, remove this project, then add %s"), sr.master_url ); } } } // make sure we don't already have a project of same name // bool dup_name = false; for (i=0; i<projects.size(); i++) { p2 = projects[i]; if (project == p2) continue; if (!strcmp(p2->project_name, project->project_name)) { dup_name = true; break; } } if (dup_name) { msg_printf(project, MSG_INFO, "Already attached to a project named %s (possibly with wrong URL)", project->project_name ); msg_printf(project, MSG_INFO, "Consider detaching this project, then trying again" ); } // show messages from server // for (i=0; i<sr.messages.size(); i++) { USER_MESSAGE& um = sr.messages[i]; int prio = (!strcmp(um.priority.c_str(), "notice"))?MSG_SCHEDULER_ALERT:MSG_INFO; string_substitute(um.message.c_str(), buf, sizeof(buf), "%", "%%"); msg_printf(project, prio, "%s", buf); } if (log_flags.sched_op_debug && sr.request_delay) { msg_printf(project, MSG_INFO, "Project requested delay of %.0f seconds", sr.request_delay ); } // if project is down, return error (so that we back off) // and don't do anything else // if (sr.project_is_down) { if (sr.request_delay) { double x = now + sr.request_delay; project->set_min_rpc_time(x, "project is down"); } return ERR_PROJECT_DOWN; } // if the scheduler reply includes global preferences, // insert extra elements, write to disk, and parse // if (sr.global_prefs_xml) { // skip this if we have host-specific prefs // and we're talking to an old scheduler // if (!global_prefs.host_specific || sr.scheduler_version >= 507) { retval = save_global_prefs( sr.global_prefs_xml, project->master_url, scheduler_url ); if (retval) { return retval; } update_global_prefs = true; } else { if (log_flags.sched_op_debug) { msg_printf(project, MSG_INFO, "ignoring prefs from old server; we have host-specific prefs" ); } } } // see if we have a new venue from this project // (this must go AFTER the above, since otherwise // global_prefs_source_project() is meaningless) // if (strcmp(project->host_venue, sr.host_venue)) { safe_strcpy(project->host_venue, sr.host_venue); msg_printf(project, MSG_INFO, "New computer location: %s", sr.host_venue); update_project_prefs = true; if (project == global_prefs_source_project()) { strcpy(main_host_venue, sr.host_venue); update_global_prefs = true; } } if (update_global_prefs) { read_global_prefs(); } // deal with project preferences (should always be there) // If they've changed, write to account file, // then parse to get our venue, and pass to running apps // if (sr.project_prefs_xml) { if (strcmp(project->project_prefs.c_str(), sr.project_prefs_xml)) { project->project_prefs = string(sr.project_prefs_xml); update_project_prefs = true; } } // the account file has GUI URLs and project prefs. // rewrite if either of these has changed // if (project->gui_urls != old_gui_urls || update_project_prefs) { retval = project->write_account_file(); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't write account file: %s", boincerror(retval) ); return retval; } } if (update_project_prefs) { project->parse_account_file(); if (strlen(project->host_venue)) { project->parse_account_file_venue(); } project->parse_preferences_for_user_files(); active_tasks.request_reread_prefs(project); } // if the scheduler reply includes a code-signing key, // accept it if we don't already have one from the project. // Otherwise verify its signature, using the key we already have. // if (sr.code_sign_key) { if (!strlen(project->code_sign_key)) { safe_strcpy(project->code_sign_key, sr.code_sign_key); } else { if (sr.code_sign_key_signature) { retval = check_string_signature2( sr.code_sign_key, sr.code_sign_key_signature, project->code_sign_key, signature_valid ); if (!retval && signature_valid) { safe_strcpy(project->code_sign_key, sr.code_sign_key); } else { msg_printf(project, MSG_INTERNAL_ERROR, "New code signing key doesn't validate" ); } } else { msg_printf(project, MSG_INTERNAL_ERROR, "Missing code sign key signature" ); } } } // copy new entities to client state // for (i=0; i<sr.apps.size(); i++) { APP* app = lookup_app(project, sr.apps[i].name); if (app) { strcpy(app->user_friendly_name, sr.apps[i].user_friendly_name); } else { app = new APP; *app = sr.apps[i]; retval = link_app(project, app); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle application %s in scheduler reply", app->name ); delete app; } else { apps.push_back(app); } } } FILE_INFO* fip; for (i=0; i<sr.file_infos.size(); i++) { fip = lookup_file_info(project, sr.file_infos[i].name); if (fip) { fip->merge_info(sr.file_infos[i]); } else { fip = new FILE_INFO; *fip = sr.file_infos[i]; retval = link_file_info(project, fip); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle file %s in scheduler reply", fip->name ); delete fip; } else { file_infos.push_back(fip); } } } for (i=0; i<sr.file_deletes.size(); i++) { fip = lookup_file_info(project, sr.file_deletes[i].c_str()); if (fip) { if (log_flags.file_xfer_debug) { msg_printf(project, MSG_INFO, "[file_xfer_debug] Got server request to delete file %s", fip->name ); } fip->sticky = false; } } for (i=0; i<sr.app_versions.size(); i++) { if (project->anonymous_platform) { msg_printf(project, MSG_INTERNAL_ERROR, "App version returned from anonymous platform project; ignoring" ); continue; } APP_VERSION& avpp = sr.app_versions[i]; if (strlen(avpp.platform) == 0) { strcpy(avpp.platform, get_primary_platform()); } else { if (!is_supported_platform(avpp.platform)) { msg_printf(project, MSG_INTERNAL_ERROR, "App version has unsupported platform %s", avpp.platform ); continue; } } if (avpp.missing_coproc) { msg_printf(project, MSG_INTERNAL_ERROR, "App version uses non-existent %s GPU", avpp.missing_coproc_name ); } APP* app = lookup_app(project, avpp.app_name); if (!app) { msg_printf(project, MSG_INTERNAL_ERROR, "Missing app %s", avpp.app_name ); continue; } APP_VERSION* avp = lookup_app_version( app, avpp.platform, avpp.version_num, avpp.plan_class ); if (avp) { // update performance-related info; // generally this shouldn't change, // but if it does it's better to use the new stuff // avp->avg_ncpus = avpp.avg_ncpus; avp->max_ncpus = avpp.max_ncpus; avp->flops = avpp.flops; strcpy(avp->cmdline, avpp.cmdline); avp->gpu_usage = avpp.gpu_usage; strlcpy(avp->api_version, avpp.api_version, sizeof(avp->api_version)); avp->dont_throttle = avpp.dont_throttle; avp->needs_network = avpp.needs_network; // if we had download failures, clear them // avp->clear_errors(); continue; } avp = new APP_VERSION; *avp = avpp; retval = link_app_version(project, avp); if (retval) { delete avp; continue; } app_versions.push_back(avp); } for (i=0; i<sr.workunits.size(); i++) { if (lookup_workunit(project, sr.workunits[i].name)) continue; WORKUNIT* wup = new WORKUNIT; *wup = sr.workunits[i]; wup->project = project; retval = link_workunit(project, wup); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle task %s in scheduler reply", wup->name ); delete wup; continue; } wup->clear_errors(); workunits.push_back(wup); } double est_rsc_runtime[MAX_RSC]; for (int j=0; j<coprocs.n_rsc; j++) { est_rsc_runtime[j] = 0; } for (i=0; i<sr.results.size(); i++) { if (lookup_result(project, sr.results[i].name)) { msg_printf(project, MSG_INTERNAL_ERROR, "Already have task %s\n", sr.results[i].name ); continue; } RESULT* rp = new RESULT; *rp = sr.results[i]; retval = link_result(project, rp); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, "Can't handle task %s in scheduler reply", rp->name ); delete rp; continue; } if (strlen(rp->platform) == 0) { strcpy(rp->platform, get_primary_platform()); rp->version_num = latest_version(rp->wup->app, rp->platform); } rp->avp = lookup_app_version( rp->wup->app, rp->platform, rp->version_num, rp->plan_class ); if (!rp->avp) { msg_printf(project, MSG_INTERNAL_ERROR, "No app version found for app %s platform %s ver %d class %s; discarding %s", rp->wup->app->name, rp->platform, rp->version_num, rp->plan_class, rp->name ); delete rp; continue; } if (rp->avp->missing_coproc) { msg_printf(project, MSG_INTERNAL_ERROR, "Missing coprocessor for task %s; aborting", rp->name ); rp->abort_inactive(EXIT_MISSING_COPROC); } else { rp->set_state(RESULT_NEW, "handle_scheduler_reply"); int rt = rp->avp->gpu_usage.rsc_type; if (rt > 0) { est_rsc_runtime[rt] += rp->estimated_runtime(); gpus_usable = true; // trigger a check of whether GPU is actually usable } else { est_rsc_runtime[0] += rp->estimated_runtime(); } } rp->wup->version_num = rp->version_num; rp->received_time = now; new_results.push_back(rp); results.push_back(rp); } sort_results(); if (log_flags.sched_op_debug) { if (sr.results.size()) { for (int j=0; j<coprocs.n_rsc; j++) { msg_printf(project, MSG_INFO, "[sched_op] estimated total %s task duration: %.0f seconds", rsc_name(j), est_rsc_runtime[j]/time_stats.availability_frac(j) ); } } } // update records for ack'ed results // for (i=0; i<sr.result_acks.size(); i++) { if (log_flags.sched_op_debug) { msg_printf(project, MSG_INFO, "[sched_op] handle_scheduler_reply(): got ack for task %s\n", sr.result_acks[i].name ); } RESULT* rp = lookup_result(project, sr.result_acks[i].name); if (rp) { rp->got_server_ack = true; } else { msg_printf(project, MSG_INTERNAL_ERROR, "Got ack for task %s, but can't find it", sr.result_acks[i].name ); } } // handle result abort requests // for (i=0; i<sr.result_abort.size(); i++) { RESULT* rp = lookup_result(project, sr.result_abort[i].name); if (rp) { ACTIVE_TASK* atp = lookup_active_task_by_result(rp); if (atp) { atp->abort_task(EXIT_ABORTED_BY_PROJECT, "aborted by project - no longer usable" ); } else { rp->abort_inactive(EXIT_ABORTED_BY_PROJECT); } } else { msg_printf(project, MSG_INTERNAL_ERROR, "Server requested abort of unknown task %s", sr.result_abort[i].name ); } } for (i=0; i<sr.result_abort_if_not_started.size(); i++) { RESULT* rp = lookup_result(project, sr.result_abort_if_not_started[i].name); if (!rp) { msg_printf(project, MSG_INTERNAL_ERROR, "Server requested conditional abort of unknown task %s", sr.result_abort_if_not_started[i].name ); continue; } if (rp->not_started) { rp->abort_inactive(EXIT_ABORTED_BY_PROJECT); } } // remove acked trickle files // if (sr.message_ack) { remove_trickle_files(project); } if (sr.send_full_workload) { project->send_full_workload = true; } project->dont_use_dcf = sr.dont_use_dcf; project->send_time_stats_log = sr.send_time_stats_log; project->send_job_log = sr.send_job_log; project->trickle_up_pending = false; // The project returns a hostid only if it has created a new host record. // In that case reset RPC seqno // if (sr.hostid) { if (project->hostid) { // if we already have a host ID for this project, // we must have sent it a stale seqno, // which usually means our state file was copied from another host. // So generate a new host CPID. // generate_new_host_cpid(); msg_printf(project, MSG_INFO, "Generated new computer cross-project ID: %s", host_info.host_cpid ); } //msg_printf(project, MSG_INFO, "Changing host ID from %d to %d", project->hostid, sr.hostid); project->hostid = sr.hostid; project->rpc_seqno = 0; } #ifdef ENABLE_AUTO_UPDATE if (sr.auto_update.present) { if (!sr.auto_update.validate_and_link(project)) { auto_update = sr.auto_update; } } #endif project->project_files = sr.project_files; project->link_project_files(); project->create_project_file_symlinks(); if (log_flags.state_debug) { msg_printf(project, MSG_INFO, "[state] handle_scheduler_reply(): State after handle_scheduler_reply():" ); print_summary(); } // the following must precede the backoff and request_delay checks, // since it overrides them // if (sr.next_rpc_delay) { project->next_rpc_time = now + sr.next_rpc_delay; } else { project->next_rpc_time = 0; } work_fetch.handle_reply(project, &sr, new_results); project->nrpc_failures = 0; project->min_rpc_time = 0; if (sr.request_delay) { double x = now + sr.request_delay; project->set_min_rpc_time(x, "requested by project"); } if (sr.got_rss_feeds) { handle_sr_feeds(sr.sr_feeds, project); } update_trickle_up_urls(project, sr.trickle_up_urls); // garbage collect in case the project sent us some irrelevant FILE_INFOs; // avoid starting transfers for them // gstate.garbage_collect_always(); return 0; }
// Handle a task that has finished. // Mark its output files as present, and delete scratch files. // Don't delete input files because they might be shared with other WUs. // Update state of result record. // int CLIENT_STATE::app_finished(ACTIVE_TASK& at) { RESULT* rp = at.result; bool had_error = false; #ifndef SIM FILE_INFO* fip; unsigned int i; char path[MAXPATHLEN]; int retval; double size; // scan the output files, check if missing or too big. // Don't bother doing this if result was aborted via GUI or by project // switch (rp->exit_status) { case EXIT_ABORTED_VIA_GUI: case EXIT_ABORTED_BY_PROJECT: break; default: for (i=0; i<rp->output_files.size(); i++) { FILE_REF& fref = rp->output_files[i]; fip = fref.file_info; if (fip->uploaded) continue; get_pathname(fip, path, sizeof(path)); retval = file_size(path, size); if (retval) { if (fref.optional) { fip->upload_urls.clear(); continue; } // an output file is unexpectedly absent. // fip->status = retval; had_error = true; msg_printf( rp->project, MSG_INFO, "Output file %s for task %s absent", fip->name, rp->name ); } else if (size > fip->max_nbytes) { // Note: this is only checked when the application finishes. // The total disk space is checked while the application is running. // msg_printf( rp->project, MSG_INFO, "Output file %s for task %s exceeds size limit.", fip->name, rp->name ); msg_printf( rp->project, MSG_INFO, "File size: %f bytes. Limit: %f bytes", size, fip->max_nbytes ); fip->delete_file(); fip->status = ERR_FILE_TOO_BIG; had_error = true; } else { if (!fip->uploadable() && !fip->sticky) { fip->delete_file(); // sets status to NOT_PRESENT } else { retval = 0; if (fip->gzip_when_done) { retval = fip->gzip(); } if (!retval) { retval = md5_file(path, fip->md5_cksum, fip->nbytes); } if (retval) { fip->status = retval; had_error = true; } else { fip->status = FILE_PRESENT; } } } } } #endif if (rp->exit_status != 0) { had_error = true; } if (had_error) { switch (rp->exit_status) { case EXIT_ABORTED_VIA_GUI: case EXIT_ABORTED_BY_PROJECT: rp->set_state(RESULT_ABORTED, "CS::app_finished"); break; default: rp->set_state(RESULT_COMPUTE_ERROR, "CS::app_finished"); } rp->project->njobs_error++; } else { #ifdef SIM rp->set_state(RESULT_FILES_UPLOADED, "CS::app_finished"); rp->set_ready_to_report(); rp->completed_time = now; #else rp->set_state(RESULT_FILES_UPLOADING, "CS::app_finished"); rp->append_log_record(); #endif rp->project->update_duration_correction_factor(&at); rp->project->njobs_success++; } double elapsed_time = now - rec_interval_start; work_fetch.accumulate_inst_sec(&at, elapsed_time); rp->project->pwf.request_if_idle_and_uploading = true; // set this to allow work fetch if idle instance, // even before upload finishes return 0; }