|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// This file is part of BOINC. |
|
4
|
|
|
// http://boinc.berkeley.edu |
|
5
|
|
|
// Copyright (C) 2011 University of California |
|
6
|
|
|
// |
|
7
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
|
8
|
|
|
// under the terms of the GNU Lesser General Public License |
|
9
|
|
|
// as published by the Free Software Foundation, |
|
10
|
|
|
// either version 3 of the License, or (at your option) any later version. |
|
11
|
|
|
// |
|
12
|
|
|
// BOINC is distributed in the hope that it will be useful, |
|
13
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
15
|
|
|
// See the GNU Lesser General Public License for more details. |
|
16
|
|
|
// |
|
17
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
|
18
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
|
|
20
|
|
|
// server-side utility functions for remote job submissions and control |
|
21
|
|
|
|
|
22
|
|
|
require_once("../inc/submit_db.inc"); |
|
23
|
|
|
|
|
24
|
|
|
// in remote job submission, |
|
25
|
|
|
// for input files of type local, semilocal, and inline, |
|
26
|
|
|
// we need to give a unique physical name based on its content. |
|
27
|
|
|
// Prepend the jf_ to make the origin of the file clear |
|
28
|
|
|
// |
|
29
|
|
|
function job_file_name($md5) { |
|
30
|
|
|
return "jf_$md5"; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function authenticate_user($r, $app) { |
|
34
|
|
|
$auth = (string)$r->authenticator; |
|
35
|
|
|
if (!$auth) xml_error(-1, "no authenticator"); |
|
36
|
|
|
$auth = BoincDb::escape_string($auth); |
|
37
|
|
|
$user = BoincUser::lookup("authenticator='$auth'"); |
|
38
|
|
|
if (!$user) xml_error(-1, "bad authenticator"); |
|
39
|
|
|
$user_submit = BoincUserSubmit::lookup_userid($user->id); |
|
40
|
|
|
if (!$user_submit) xml_error(-1, "no submit access"); |
|
41
|
|
View Code Duplication |
if ($app && !$user_submit->submit_all) { |
|
42
|
|
|
$usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id"); |
|
43
|
|
|
if (!$usa) { |
|
44
|
|
|
xml_error(-1, "no submit access"); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return array($user, $user_submit); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function delete_remote_submit_user($user) { |
|
51
|
|
|
BoincUserSubmit::delete_user($user->id); |
|
52
|
|
|
BoincUserSubmitApp::delete_user($user->id); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
// given its WUs, compute progress of a batch |
|
57
|
|
|
// (fraction done, est completion time etc.) |
|
58
|
|
|
// NOTE: this is inefficient because we need all the WUs. |
|
59
|
|
|
// it could be done by server components |
|
60
|
|
|
// (transitioner, validator etc.) as jobs complete or time out |
|
61
|
|
|
// |
|
62
|
|
|
// TODO: update est_completion_time |
|
63
|
|
|
// |
|
64
|
|
|
function get_batch_params($batch, $wus) { |
|
65
|
|
|
$fp_total = 0; |
|
66
|
|
|
$fp_done = 0; |
|
67
|
|
|
$completed = true; |
|
68
|
|
|
$batch->nerror_jobs = 0; |
|
69
|
|
|
$batch->credit_canonical = 0; |
|
70
|
|
|
foreach ($wus as $wu) { |
|
71
|
|
|
$fp_total += $wu->rsc_fpops_est; |
|
72
|
|
|
if ($wu->canonical_resultid) { |
|
73
|
|
|
$fp_done += $wu->rsc_fpops_est; |
|
74
|
|
|
$batch->credit_canonical += $wu->canonical_credit; |
|
75
|
|
|
} else if ($wu->error_mask) { |
|
76
|
|
|
$batch->nerror_jobs++; |
|
77
|
|
|
} else { |
|
78
|
|
|
$completed = false; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
if ($fp_total) { |
|
82
|
|
|
$batch->fraction_done = $fp_done / $fp_total; |
|
83
|
|
|
} |
|
84
|
|
|
if ($completed && $batch->state == BATCH_STATE_IN_PROGRESS) { |
|
85
|
|
|
$batch->state = BATCH_STATE_COMPLETE; |
|
86
|
|
|
$batch->completion_time = time(); |
|
87
|
|
|
} |
|
88
|
|
|
$batch->update("fraction_done = $batch->fraction_done, nerror_jobs = $batch->nerror_jobs, state=$batch->state, completion_time = $batch->completion_time, credit_canonical = $batch->credit_canonical"); |
|
89
|
|
|
|
|
90
|
|
|
$batch->credit_estimate = flops_to_credit($fp_total); |
|
91
|
|
|
return $batch; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function get_outfile_names($result) { |
|
95
|
|
|
$names = array(); |
|
96
|
|
|
$xml = "<a>".$result->xml_doc_out."</a>"; |
|
97
|
|
|
$r = simplexml_load_string($xml); |
|
98
|
|
|
if (!$r) return $names; |
|
99
|
|
|
foreach ($r->file_info as $fi) { |
|
100
|
|
|
$names[] = (string)($fi->name); |
|
101
|
|
|
} |
|
102
|
|
|
return $names; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function get_outfile_paths($result) { |
|
106
|
|
|
$fanout = parse_config(get_config(), "<uldl_dir_fanout>"); |
|
107
|
|
|
$upload_dir = parse_config(get_config(), "<upload_dir>"); |
|
108
|
|
|
|
|
109
|
|
|
$paths = array(); |
|
110
|
|
|
$xml = "<a>".$result->xml_doc_out."</a>"; |
|
111
|
|
|
$r = simplexml_load_string($xml); |
|
112
|
|
|
if (!$r) return $paths; |
|
113
|
|
|
foreach ($r->file_info as $fi) { |
|
114
|
|
|
$path = dir_hier_path((string)($fi->name), $upload_dir, $fanout); |
|
115
|
|
|
$paths[] = $path; |
|
116
|
|
|
} |
|
117
|
|
|
return $paths; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
function abort_workunit($wu) { |
|
121
|
|
|
BoincResult::update_aux( |
|
122
|
|
|
"server_state=5, outcome=5 where server_state=2 and workunitid=$wu->id" |
|
123
|
|
|
); |
|
124
|
|
|
$wu->update("error_mask=error_mask|16"); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
function abort_batch($batch) { |
|
128
|
|
|
$wus = BoincWorkunit::enum("batch=$batch->id"); |
|
129
|
|
|
foreach ($wus as $wu) { |
|
130
|
|
|
abort_workunit($wu); |
|
131
|
|
|
} |
|
132
|
|
|
$batch->update("state=".BATCH_STATE_ABORTED); |
|
133
|
|
|
return 0; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// mark WUs as assimilated; this lets them be purged |
|
137
|
|
|
// |
|
138
|
|
|
function retire_batch($batch) { |
|
139
|
|
|
$wus = BoincWorkunit::enum("batch=$batch->id"); |
|
140
|
|
|
$now = time(); |
|
141
|
|
|
foreach ($wus as $wu) { |
|
142
|
|
|
$wu->update( |
|
143
|
|
|
"assimilate_state=".ASSIMILATE_DONE.", transition_time=$now" |
|
144
|
|
|
); |
|
145
|
|
|
} |
|
146
|
|
|
$batch->update("state=".BATCH_STATE_RETIRED); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
function expire_batch($batch) { |
|
150
|
|
|
abort_batch($batch); |
|
151
|
|
|
retire_batch($batch); |
|
152
|
|
|
$batch->update("state=".BATCH_STATE_EXPIRED); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
function batch_state_string($state) { |
|
156
|
|
|
switch ($state) { |
|
157
|
|
|
case BATCH_STATE_INIT: return "new"; |
|
158
|
|
|
case BATCH_STATE_IN_PROGRESS: return "in progress"; |
|
159
|
|
|
case BATCH_STATE_COMPLETE: return "completed"; |
|
160
|
|
|
case BATCH_STATE_ABORTED: return "aborted"; |
|
161
|
|
|
case BATCH_STATE_RETIRED: return "retired"; |
|
162
|
|
|
} |
|
163
|
|
|
return "unknown state $state"; |
|
164
|
|
|
} |
|
165
|
|
|
// get the total size of output files of a batch |
|
166
|
|
|
// |
|
167
|
|
|
function batch_output_file_size($batchid) { |
|
168
|
|
|
$batch_td_size=0; |
|
169
|
|
|
$wus = BoincWorkunit::enum("batch=$batchid"); |
|
170
|
|
|
$fanout = parse_config(get_config(), "<uldl_dir_fanout>"); |
|
171
|
|
|
$upload_dir = parse_config(get_config(), "<upload_dir>"); |
|
172
|
|
|
foreach ($wus as $wu) { |
|
173
|
|
|
if (!$wu->canonical_resultid) continue; |
|
174
|
|
|
$result = BoincResult::lookup_id($wu->canonical_resultid); |
|
175
|
|
|
$names = get_outfile_names($result); |
|
176
|
|
|
foreach ($names as $name) { |
|
177
|
|
|
$path = dir_hier_path($name, $upload_dir, $fanout); |
|
178
|
|
|
if (is_file($path)) { |
|
179
|
|
|
$s=stat($path); |
|
180
|
|
|
$size=$s['size']; |
|
181
|
|
|
$batch_td_size+=$size; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
return $batch_td_size; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
function boinc_get_output_file_url($user, $result, $i) { |
|
189
|
|
|
$name = $result->name; |
|
190
|
|
|
$auth_str = md5($user->authenticator.$name); |
|
191
|
|
|
return "get_output.php?cmd=result_file&result_name=$name&file_num=$i&auth_str=$auth_str"; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
function boinc_get_output_files_url($user, $batch_id) { |
|
195
|
|
|
$auth_str = md5($user->authenticator.$batch_id); |
|
196
|
|
|
return "get_output.php?cmd=batch_files&batch_id=$batch_id&auth_str=$auth_str"; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
function boinc_get_wu_output_files_url($user, $wu_id) { |
|
200
|
|
|
$auth_str = md5($user->authenticator.$wu_id); |
|
201
|
|
|
return "get_output.php?cmd=workunit_files&wu_id=$wu_id&auth_str=$auth_str"; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
?> |
|
205
|
|
|
|