1 | <?php |
||
2 | |||
3 | DEPRECATED |
||
4 | |||
5 | // Handler for TreeThreader remote job submission. |
||
6 | // |
||
7 | // Assumptions: |
||
8 | // - there is a file "tree_threader_templates_files" in the project root |
||
9 | // containing (one per line) the names of files containing |
||
10 | // gzipped collections of template files |
||
11 | // - These files are in the download hierarchy. |
||
12 | |||
13 | require_once("../inc/boinc_db.inc"); |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
14 | require_once("../inc/submit_db.inc"); |
||
15 | require_once("../inc/xml.inc"); |
||
16 | require_once("../inc/dir_hier.inc"); |
||
17 | require_once("../inc/result.inc"); |
||
18 | require_once("../inc/submit_util.inc"); |
||
19 | |||
20 | display_errors(); |
||
21 | |||
22 | $app_name = "treeThreader"; |
||
23 | $log = fopen("/tmp/tt_job.log","a+"); |
||
24 | |||
25 | function error($s) { |
||
26 | echo "<error>\n<message>$s</message>\n</error>\n"; |
||
27 | exit; |
||
28 | } |
||
29 | |||
30 | function handle_submit($r, $user, $app) { |
||
31 | global $app_name,$log; |
||
32 | |||
33 | $timestamp = date("Y-m-d H:i",time()); |
||
34 | // read the list of template filenames |
||
35 | // |
||
36 | $files = file("../../tree_threader_template_files"); |
||
37 | if ($files === false) { |
||
38 | fwrite($log,"$timestamp\ttemplate file tree_threader_template_files\n"); |
||
39 | error("no templates file"); |
||
40 | |||
41 | } |
||
42 | $njobs = sizeof($files); |
||
43 | $now = time(); |
||
44 | $batch_id = BoincBatch::insert( |
||
45 | "(user_id, create_time, njobs, name, app_id, state) values ($user->id, $now, $njobs, 'tree_threader batch', $app->id, ".BATCH_STATE_IN_PROGRESS.")" |
||
46 | ); |
||
47 | if (!$batch_id) { |
||
48 | $log_msg = "$timestamp\tfailed to create batch for user $user->id\n"; |
||
49 | fwrite($log, $log_msg); |
||
50 | die("couldn't create batch\n"); |
||
51 | } else { |
||
52 | $log_msg = "$timestamp\tcreated batch $batch_id for user $user->id\n"; |
||
53 | fwrite($log, $log_msg); |
||
54 | } |
||
55 | |||
56 | // move the sequence file to the download hier |
||
57 | // |
||
58 | $config = simplexml_load_string(file_get_contents("../../config.xml")); |
||
59 | $fanout = (int)$config->config->uldl_dir_fanout; |
||
60 | $download_dir = trim((string)$config->config->download_dir); |
||
61 | |||
62 | $seq_fname = "treeThreader_sequence_$batch_id.tar.gz"; |
||
63 | $seq_path = dir_hier_path($seq_fname, $download_dir, $fanout); |
||
64 | $tmp_name = $_FILES['seq_file']['tmp_name']; |
||
65 | $ret = rename($tmp_name, $seq_path); |
||
66 | if ($ret === false) { |
||
67 | error("couldn't rename sequence file"); |
||
68 | } |
||
69 | |||
70 | $i = 1; |
||
71 | foreach ($files as $file) { |
||
72 | $file = trim($file); |
||
73 | $wu_name = "ICT_".$batch_id."_$i"; |
||
74 | |||
75 | $cmd = "cd ../..; ./bin/create_work --appname $app_name --batch $batch_id --wu_name $wu_name --wu_template templates/ICT_in --result_template templates/ICT_out $seq_fname $file"; |
||
76 | fwrite($log, "$timestamp\t$cmd\n"); |
||
77 | system($cmd, $ret); |
||
78 | if ($ret != 0) { |
||
79 | fwrite($log, "can not creat job $wu_name\n"); |
||
80 | error("can't create job"); |
||
81 | } |
||
82 | $i++; |
||
83 | } |
||
84 | echo "<tt_reply>\n<batch_id>$batch_id</batch_id>\n</tt_reply>\n"; |
||
85 | } |
||
86 | |||
87 | // Enumerate all the successfully completed WUs for this batch. |
||
88 | // Each output file is a .zip that unzips into a directory ali/. |
||
89 | // Combine their output files into a zip file in /tmp, |
||
90 | // make a symbolic link to this from /download, |
||
91 | // and return the resulting URL |
||
92 | // |
||
93 | function handle_get_output($r, $batch) { |
||
94 | global $log; |
||
95 | $timestamp = date("Y-m-d H:i",time()); |
||
96 | $wus = BoincWorkUnit::enum("batch=$batch->id"); |
||
97 | $outdir = "/tmp/treeThreader_result_".$batch->id; |
||
98 | @mkdir($outdir); |
||
99 | foreach ($wus as $wu) { |
||
100 | if (!$wu->canonical_resultid) continue; |
||
101 | $result = BoincResult::lookup_id($wu->canonical_resultid); |
||
102 | if (!$result) continue; |
||
103 | $paths = get_outfile_paths($result); |
||
104 | if (sizeof($paths) < 1) continue; |
||
105 | |||
106 | // there's only one output file |
||
107 | // |
||
108 | $path = $paths[0]; |
||
109 | |||
110 | // unzip it into a directory in /tmp |
||
111 | // |
||
112 | $dir = "/tmp/$wu->name"; |
||
113 | @mkdir($dir); |
||
114 | $cmd = "cd $dir; unzip -q $path"; |
||
115 | system($cmd, $ret); |
||
116 | if ($ret != 0) { |
||
117 | error("can't unzip output file"); |
||
118 | } |
||
119 | $cmd = "cp $dir/Aln/* $outdir"; |
||
120 | system($cmd, $ret); |
||
121 | if ($ret != 0) { |
||
122 | error("can't copy output files"); |
||
123 | } |
||
124 | |||
125 | system("rm -rf $dir"); |
||
126 | } |
||
127 | |||
128 | $cmd = "zip -r -q $outdir $outdir"; |
||
129 | system($cmd, $ret); |
||
130 | if ($ret != $ret) { |
||
131 | error("can't zip output files"); |
||
132 | } |
||
133 | $fname = "treeThreader_result_".$batch->id.".zip"; |
||
134 | $treeThreader_dir="treeThreaderResult"; |
||
135 | if(!is_dir("../../download/$treeThreader_dir"))mkdir("../../download/$treeThreader_dir"); |
||
136 | @symlink("/tmp/$fname", "../../download/$treeThreader_dir/$fname"); |
||
137 | system("rm -fr $outdir"); |
||
138 | $config = simplexml_load_string(file_get_contents("../../config.xml")); |
||
139 | $download_url = trim((string)$config->config->download_url); |
||
140 | echo "<tt_reply>\n<url>$download_url/$treeThreader_dir/$fname</url>\n</tt_reply>\n"; |
||
141 | $log_msg="$timestamp\tuser $batch->user_id downloads results for batch $batch->id : $download_url/$treeThreader_dir/$fname\n"; |
||
142 | fwrite($log, $log_msg); |
||
143 | } |
||
144 | |||
145 | xml_header(); |
||
146 | |||
147 | if (1) { |
||
148 | $r = simplexml_load_string($_POST['request']); |
||
149 | } else { |
||
150 | $x = file_get_contents("xml_req"); |
||
151 | $r = simplexml_load_string($x); |
||
152 | } |
||
153 | |||
154 | if (!$r) { |
||
155 | error("can't parse request message"); |
||
156 | } |
||
157 | |||
158 | // authenticate the user |
||
159 | // |
||
160 | $auth = BoincDb::escape_string((string)$r->auth); |
||
161 | $user = BoincUser::lookup("authenticator='$auth'"); |
||
162 | if (!$user) error("invalid authenticator"); |
||
163 | $user_submit = BoincUserSubmit::lookup_userid($user->id); |
||
164 | if (!$user_submit) error("no submit access"); |
||
165 | $app = BoincApp::lookup("name='$app_name'"); |
||
166 | if (!$app) error("no tree_threader app"); |
||
167 | |||
168 | if (!$user_submit->submit_all) { |
||
169 | $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id"); |
||
170 | if (!$usa) { |
||
171 | error("no submit access"); |
||
172 | } |
||
173 | } |
||
174 | |||
175 | switch ((string)$r->action) { |
||
176 | case 'submit': |
||
177 | handle_submit($r, $user, $app); |
||
178 | break; |
||
179 | case 'get_output': |
||
180 | $batch_id = (int)$r->batch_id; |
||
181 | $batch = BoincBatch::lookup_id($batch_id); |
||
182 | if (!$batch) error("no such batch"); |
||
183 | if ($batch->user_id != $user->id) error("not owner of batch"); |
||
184 | handle_get_output($r, $batch); |
||
185 | break; |
||
186 | default: error("bad command"); |
||
0 ignored issues
–
show
|
|||
187 | } |
||
188 | |||
189 | ?> |
||
190 |