2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2008-03-04 23:50:38 +00:00
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2008-03-04 23:50:38 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2008-03-04 23:50:38 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2008-05-06 19:53:49 +00:00
|
|
|
|
2008-03-04 23:50:38 +00:00
|
|
|
// assimilator for single jobs.
|
|
|
|
// - if success, move the output file(s) to job directory
|
|
|
|
// - delete job description file
|
|
|
|
// - delete WU template file
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
2008-04-02 19:33:12 +00:00
|
|
|
#include <cstring>
|
2008-03-04 23:50:38 +00:00
|
|
|
|
|
|
|
#include "boinc_db.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "sched_msgs.h"
|
|
|
|
#include "validate_util.h"
|
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_util.h"
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
int assimilate_handler(
|
|
|
|
WORKUNIT& wu, vector<RESULT>& /*results*/, RESULT& canonical_result
|
|
|
|
) {
|
|
|
|
int retval;
|
2008-07-04 19:41:58 +00:00
|
|
|
char buf[1024], filename[256], job_dir[256], job_dir_file[256];
|
2008-03-04 23:50:38 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2008-07-04 19:41:58 +00:00
|
|
|
// delete the template files
|
|
|
|
//
|
2009-05-07 13:54:51 +00:00
|
|
|
unlink(config.project_path("templates/sj_wu_template_%d", wu.id));
|
|
|
|
unlink(config.project_path("templates/sj_result_template_%d", wu.id));
|
2008-07-04 19:41:58 +00:00
|
|
|
|
|
|
|
// read and delete the job directory file
|
|
|
|
//
|
2008-03-04 23:50:38 +00:00
|
|
|
sprintf(filename, "sj_%d", wu.id);
|
2008-07-04 19:41:58 +00:00
|
|
|
dir_hier_path(
|
|
|
|
filename, config.upload_dir, config.uldl_dir_fanout, job_dir_file
|
|
|
|
);
|
|
|
|
FILE* f = fopen(job_dir_file, "r");
|
2008-03-04 23:50:38 +00:00
|
|
|
if (!f) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "Can't open job file %s\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-08 18:02:07 +00:00
|
|
|
if (!fgets(buf, 1024, f)) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "Can't read job file %s\n", buf);
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-04 19:41:58 +00:00
|
|
|
fclose(f);
|
|
|
|
unlink(job_dir_file);
|
|
|
|
|
|
|
|
// parse the job directory file
|
|
|
|
//
|
2008-03-04 23:50:38 +00:00
|
|
|
char* p = strstr(buf, "<job_dir>");
|
|
|
|
if (!p) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "garbage in job file: %s\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpy(job_dir, buf+strlen("<job_dir>"));
|
|
|
|
p = strstr(job_dir, "</job_dir>");
|
|
|
|
if (!p) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "garbage in job file: %s\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-05 20:16:10 +00:00
|
|
|
*p = 0;
|
2008-07-04 19:41:58 +00:00
|
|
|
|
|
|
|
// Create a job summary file
|
|
|
|
//
|
|
|
|
sprintf(filename, "%s/job_summary_%d", job_dir, wu.id);
|
|
|
|
f = fopen(filename, "w");
|
|
|
|
|
|
|
|
// If job was successful, copy the output files
|
|
|
|
//
|
2008-03-04 23:50:38 +00:00
|
|
|
if (wu.canonical_resultid) {
|
2008-07-04 19:41:58 +00:00
|
|
|
fprintf(f,
|
|
|
|
"Job was completed by host %d.\n"
|
|
|
|
"CPU time: %f seconds\n",
|
|
|
|
canonical_result.hostid,
|
|
|
|
canonical_result.cpu_time
|
|
|
|
);
|
2008-05-29 20:11:43 +00:00
|
|
|
vector<FILE_INFO> output_files;
|
2008-03-04 23:50:38 +00:00
|
|
|
char copy_path[256];
|
2008-05-29 21:54:18 +00:00
|
|
|
get_output_file_infos(canonical_result, output_files);
|
2008-05-29 20:11:43 +00:00
|
|
|
unsigned int n = output_files.size();
|
2008-03-04 23:50:38 +00:00
|
|
|
for (i=0; i<n; i++) {
|
2008-05-29 20:11:43 +00:00
|
|
|
FILE_INFO& fi = output_files[i];
|
|
|
|
string logical_name;
|
|
|
|
retval = get_logical_name(canonical_result, fi.path, logical_name);
|
2008-03-05 20:16:10 +00:00
|
|
|
if (retval) {
|
2008-07-04 19:41:58 +00:00
|
|
|
fprintf(f,
|
2008-03-05 20:16:10 +00:00
|
|
|
"Couldn't get logical name for %s: %d\n",
|
2008-05-29 20:11:43 +00:00
|
|
|
fi.path.c_str(), retval
|
2008-03-05 20:16:10 +00:00
|
|
|
);
|
2008-07-04 19:41:58 +00:00
|
|
|
continue;
|
2008-03-05 20:16:10 +00:00
|
|
|
}
|
|
|
|
sprintf(copy_path, "%s/%s", job_dir, logical_name.c_str());
|
2008-05-29 20:11:43 +00:00
|
|
|
retval = boinc_copy(fi.path.c_str() , copy_path);
|
2008-03-04 23:50:38 +00:00
|
|
|
if (retval) {
|
2008-07-04 19:41:58 +00:00
|
|
|
fprintf(f,
|
|
|
|
"Output file %s not present.\n", logical_name.c_str()
|
2008-03-04 23:50:38 +00:00
|
|
|
);
|
2008-07-04 19:41:58 +00:00
|
|
|
continue;
|
2008-03-04 23:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-07-04 19:41:58 +00:00
|
|
|
fprintf(f,
|
|
|
|
"The job was not successfully completed.\n"
|
|
|
|
"Error: 0x%x\n", wu.error_mask
|
|
|
|
);
|
2008-03-04 23:50:38 +00:00
|
|
|
}
|
2008-07-04 19:41:58 +00:00
|
|
|
fclose(f);
|
2008-03-04 23:50:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|