forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
single_job_assimilator.cpp
151 lines (138 loc) · 4.5 KB
/
single_job_assimilator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
// assimilator for single jobs.
// - if success, move the output file(s) to job directory
// - delete job description file
// - delete WU template file
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <vector>
#include <sys/resource.h>
#include "boinc_db.h"
#include "error_numbers.h"
#include "filesys.h"
#include "str_replace.h"
#include "sched_msgs.h"
#include "sched_config.h"
#include "sched_util.h"
#include "validate_util.h"
using std::vector;
using std::string;
int assimilate_handler_init(int, char**) {
return 0;
}
void assimilate_handler_usage() {
// describe the project specific arguments here
//fprintf(stderr,
// " Custom options:\n"
// " [--project_option X] a project specific option\n"
//);
}
int assimilate_handler(
WORKUNIT& wu, vector<RESULT>& /*results*/, RESULT& canonical_result
) {
int retval;
char buf[1024], filename[MAXPATHLEN], job_dir[MAXPATHLEN], job_dir_file[MAXPATHLEN];
unsigned int i;
// delete the template files
//
unlink(config.project_path("templates/sj_wu_template_%d", wu.id));
unlink(config.project_path("templates/sj_result_template_%d", wu.id));
// read and delete the job directory file
//
sprintf(filename, "sj_%lu", wu.id);
dir_hier_path(
filename, config.upload_dir, config.uldl_dir_fanout, job_dir_file
);
FILE* f = fopen(job_dir_file, "r");
if (!f) {
log_messages.printf(MSG_CRITICAL, "Can't open job file %s\n", job_dir_file);
return 0;
}
if (!fgets(buf, 1024, f)) {
log_messages.printf(MSG_CRITICAL, "Can't read job file %s\n", job_dir_file);
fclose(f);
return 0;
}
fclose(f);
unlink(job_dir_file);
// parse the job directory file
//
char* p = strstr(buf, "<job_dir>");
if (!p) {
log_messages.printf(MSG_CRITICAL, "garbage in job file: %s\n", buf);
return 0;
}
safe_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;
}
*p = 0;
// Create a job summary file
//
sprintf(filename, "%s/job_summary_%lu", job_dir, wu.id);
f = fopen(filename, "w");
if (!f) {
log_messages.printf(MSG_CRITICAL, "Can't open job summary file %s\n", filename);
return ERR_FOPEN;
}
// If job was successful, copy the output files
//
if (wu.canonical_resultid) {
fprintf(f,
"Job was completed by host %lu.\n"
"CPU time: %f seconds\n",
canonical_result.hostid,
canonical_result.cpu_time
);
vector<OUTPUT_FILE_INFO> output_files;
char copy_path[MAXPATHLEN];
get_output_file_infos(canonical_result, output_files);
unsigned int n = output_files.size();
for (i=0; i<n; i++) {
OUTPUT_FILE_INFO& fi = output_files[i];
string logical_name;
retval = get_logical_name(canonical_result, fi.path, logical_name);
if (retval) {
fprintf(f,
"Couldn't get logical name for %s: %s\n",
fi.path.c_str(), boincerror(retval)
);
continue;
}
sprintf(copy_path, "%s/%s", job_dir, logical_name.c_str());
retval = boinc_copy(fi.path.c_str() , copy_path);
if (retval) {
fprintf(f,
"Output file %s not present.\n", logical_name.c_str()
);
continue;
}
}
} else {
fprintf(f,
"The job was not successfully completed.\n"
"Error: 0x%x\n", wu.error_mask
);
}
fclose(f);
return 0;
}