Parent Directory
|
Revision Log
Revision 1.1 - (view) (download) (as text)
1 : | olson | 1.1 | package joblib; |
2 : | |||
3 : | # | ||
4 : | # A package of routines to aid in the setup and execution of remote computational jobs. | ||
5 : | # | ||
6 : | # These make SOAP calls against the job manager server. | ||
7 : | # | ||
8 : | |||
9 : | use strict; | ||
10 : | |||
11 : | use Data::Dumper; | ||
12 : | use SOAP::Lite; | ||
13 : | |||
14 : | our $namespace = "http://www.mcs.anl.gov/fl/research/SEED/schemas/jobmgr"; | ||
15 : | our $default_jobmgr = "http://www-unix.mcs.anl.gov/~olson/SEED/jobmgr.cgi"; | ||
16 : | |||
17 : | package joblib::JobManagerClient; | ||
18 : | |||
19 : | use HTTP::Request::Common; | ||
20 : | use LWP::UserAgent; | ||
21 : | |||
22 : | use File::Basename; | ||
23 : | |||
24 : | use strict; | ||
25 : | |||
26 : | use Data::Dumper; | ||
27 : | use SOAP::Lite; | ||
28 : | |||
29 : | sub new | ||
30 : | { | ||
31 : | my($class, $url) = @_; | ||
32 : | |||
33 : | defined($url) or $url = $joblib::default_jobmgr; | ||
34 : | |||
35 : | print "Using $url\n"; | ||
36 : | |||
37 : | my $proxy = SOAP::Lite->uri($joblib::namespace)->proxy($url); | ||
38 : | |||
39 : | my $self = { | ||
40 : | url => $url, | ||
41 : | proxy => $proxy, | ||
42 : | }; | ||
43 : | |||
44 : | return bless($self, $class); | ||
45 : | } | ||
46 : | |||
47 : | sub job_create | ||
48 : | { | ||
49 : | my($self, $email, $type, $name) = @_; | ||
50 : | |||
51 : | my $reply = $self->call("job_create", $email, $type, $name); | ||
52 : | |||
53 : | if ($reply) | ||
54 : | { | ||
55 : | return $reply; | ||
56 : | } | ||
57 : | else | ||
58 : | { | ||
59 : | return undef; | ||
60 : | } | ||
61 : | } | ||
62 : | |||
63 : | sub job_add_file | ||
64 : | { | ||
65 : | my($self, $job_id, $local_file, $remote_name) = @_; | ||
66 : | |||
67 : | # | ||
68 : | # add a new file. | ||
69 : | # | ||
70 : | # Invoke the soap call, which will return a file upload url. | ||
71 : | # | ||
72 : | |||
73 : | if (! -f $local_file) | ||
74 : | { | ||
75 : | die "Local file $local_file does not exist"; | ||
76 : | } | ||
77 : | |||
78 : | if ($remote_name eq '') | ||
79 : | { | ||
80 : | $remote_name = basename($local_file); | ||
81 : | } | ||
82 : | elsif ($remote_name =~ m,/,) | ||
83 : | { | ||
84 : | die "Remote name not (yet) allowed to contain /"; | ||
85 : | } | ||
86 : | |||
87 : | if ($job_id !~ /^\d+/) | ||
88 : | { | ||
89 : | die "Invalid job_id '$job_id'\n"; | ||
90 : | } | ||
91 : | |||
92 : | my $size = -s $local_file; | ||
93 : | |||
94 : | my $reply = $self->call("job_add_file", $job_id, $remote_name, $size); | ||
95 : | |||
96 : | if ($reply) | ||
97 : | { | ||
98 : | my ($file_id, $upload_url) = @$reply; | ||
99 : | |||
100 : | $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; | ||
101 : | |||
102 : | print "Uploading file...\n"; | ||
103 : | my $req = POST($upload_url, | ||
104 : | Content_Type => 'form-data', | ||
105 : | Content => [job_id => $job_id, | ||
106 : | file_id => $file_id, | ||
107 : | file => [$local_file]]); | ||
108 : | my $ua = new LWP::UserAgent; | ||
109 : | |||
110 : | my $resp = $ua->request($req); | ||
111 : | |||
112 : | if ($resp->is_success) | ||
113 : | { | ||
114 : | print "Successful upload:\n"; | ||
115 : | print $resp->content; | ||
116 : | } | ||
117 : | else | ||
118 : | { | ||
119 : | print "Failed upload\n"; | ||
120 : | print $resp->error_as_HTML(); | ||
121 : | } | ||
122 : | } | ||
123 : | } | ||
124 : | |||
125 : | sub job_set_params | ||
126 : | { | ||
127 : | my($self, $job_id, $params_file) = @_; | ||
128 : | |||
129 : | # | ||
130 : | # add a parameters file. | ||
131 : | # | ||
132 : | # Invoke the soap call, which will return a file upload url. | ||
133 : | # | ||
134 : | |||
135 : | if (! -f $params_file) | ||
136 : | { | ||
137 : | die "Local file $params_file does not exist"; | ||
138 : | } | ||
139 : | |||
140 : | if ($job_id !~ /^\d+/) | ||
141 : | { | ||
142 : | die "Invalid job_id '$job_id'\n"; | ||
143 : | } | ||
144 : | |||
145 : | my $size = -s $params_file; | ||
146 : | |||
147 : | my $reply = $self->call("job_set_params", $job_id, $size); | ||
148 : | |||
149 : | if ($reply) | ||
150 : | { | ||
151 : | my ($upload_url) = @$reply; | ||
152 : | |||
153 : | $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; | ||
154 : | |||
155 : | print "Uploading file...\n"; | ||
156 : | my $req = POST($upload_url, | ||
157 : | Content_Type => 'form-data', | ||
158 : | Content => [job_id => $job_id, | ||
159 : | params_file => 1, | ||
160 : | file => [$params_file]]); | ||
161 : | my $ua = new LWP::UserAgent; | ||
162 : | |||
163 : | my $resp = $ua->request($req); | ||
164 : | |||
165 : | if ($resp->is_success) | ||
166 : | { | ||
167 : | print "Successful upload:\n"; | ||
168 : | print $resp->content; | ||
169 : | } | ||
170 : | else | ||
171 : | { | ||
172 : | print "Failed upload\n"; | ||
173 : | print $resp->error_as_HTML(); | ||
174 : | } | ||
175 : | } | ||
176 : | } | ||
177 : | |||
178 : | sub job_run | ||
179 : | { | ||
180 : | my($self, $job_id) = @_; | ||
181 : | |||
182 : | if ($job_id !~ /^\d+/) | ||
183 : | { | ||
184 : | die "Invalid job_id '$job_id'\n"; | ||
185 : | } | ||
186 : | |||
187 : | my $reply = $self->call("job_run", $job_id); | ||
188 : | |||
189 : | if ($reply) | ||
190 : | { | ||
191 : | return $reply; | ||
192 : | } | ||
193 : | } | ||
194 : | |||
195 : | sub job_get_status | ||
196 : | { | ||
197 : | my($self, $job_id) = @_; | ||
198 : | |||
199 : | if ($job_id !~ /^\d+/) | ||
200 : | { | ||
201 : | die "Invalid job_id '$job_id'\n"; | ||
202 : | } | ||
203 : | |||
204 : | my $reply = $self->call("job_get_status", $job_id); | ||
205 : | |||
206 : | if ($reply) | ||
207 : | { | ||
208 : | return $reply; | ||
209 : | } | ||
210 : | } | ||
211 : | |||
212 : | sub job_get_output | ||
213 : | { | ||
214 : | my($self, $job_id) = @_; | ||
215 : | |||
216 : | if ($job_id !~ /^\d+/) | ||
217 : | { | ||
218 : | die "Invalid job_id '$job_id'\n"; | ||
219 : | } | ||
220 : | |||
221 : | my $reply = $self->call("job_get_output", $job_id); | ||
222 : | |||
223 : | if ($reply) | ||
224 : | { | ||
225 : | return $reply; | ||
226 : | } | ||
227 : | } | ||
228 : | |||
229 : | |||
230 : | sub call | ||
231 : | { | ||
232 : | my($self, $method, @args) = @_; | ||
233 : | |||
234 : | my $reply = $self->{proxy}->$method(@args); | ||
235 : | |||
236 : | if ($reply->fault) | ||
237 : | { | ||
238 : | die "$method failed: ", $reply->faultcode, " ", $reply->faultstring; | ||
239 : | } | ||
240 : | return $reply->result; | ||
241 : | } | ||
242 : | |||
243 : | 1; |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |