| … | |
… | |
| 5 | use strict; |
5 | use strict; |
| 6 | use warnings; |
6 | use warnings; |
| 7 | use DBI; |
7 | use DBI; |
| 8 | use Data::Dumper; |
8 | use Data::Dumper; |
| 9 | use Digest::MD5 qw(md5 md5_hex ); |
9 | use Digest::MD5 qw(md5 md5_hex ); |
|
|
10 | use File::Path; |
|
|
11 | use XML::Dumper; |
| 10 | |
12 | |
| 11 | $| = 1; |
13 | $| = 1; |
| 12 | |
14 | |
| 13 | my $ETC_DIR = "/etc/scire"; |
15 | my $ETC_DIR = "/etc/scire"; |
| 14 | my $SCIRE_CONFIG_FILE = "${ETC_DIR}/scireserver.conf"; |
16 | my $SCIRE_CONFIG_FILE = "${ETC_DIR}/scireserver.conf"; |
| … | |
… | |
| 196 | } |
198 | } |
| 197 | |
199 | |
| 198 | } |
200 | } |
| 199 | |
201 | |
| 200 | sub get_jobs { |
202 | sub get_jobs { |
| 201 | my $status_id = shift; |
203 | |
|
|
204 | #FIXME expand jobs for $client_id |
|
|
205 | |
| 202 | my $query = <<'EndOfQuery'; |
206 | my $query = <<'EndOfQuery'; |
| 203 | SELECT jobs.jobid |
207 | SELECT jobs.jobid |
| 204 | FROM jobs NATURAL JOIN jobs_clients NATURAL JOIN job_conditions NATURAL JOIN job_history |
208 | FROM jobs NATURAL JOIN jobs_clients NATURAL JOIN job_conditions |
| 205 | WHERE jobs_clients.clientid = ? |
209 | WHERE jobs_clients.clientid = ? |
| 206 | AND jobs.jobid = jobs_clients.jobid |
210 | AND jobs.jobid = jobs_clients.jobid |
| 207 | AND (job_conditions.deploy_time < now()) |
211 | AND (job_conditions.deploy_time < now()) |
| 208 | AND (job_conditions.expiration_time > now()) |
212 | AND ((job_conditions.expiration_time > now()) OR (job_conditions.expiration_time IS NULL)) |
| 209 | AND (SELECT statusid FROM job_history WHERE jobid=jobs.jobid ORDER BY eventtime DESC LIMIT 1)=? |
|
|
| 210 | ORDER BY jobs.priority,jobs.created |
213 | ORDER BY jobs.priority,jobs.created |
| 211 | EndOfQuery |
214 | EndOfQuery |
| 212 | |
215 | |
|
|
216 | #FIXME ADD JOB DEPENDENCIES TO THIS QUERY. |
| 213 | debug("Query is $query"); |
217 | debug("Query is $query"); |
| 214 | $sth = $dbh->prepare($query); |
218 | my $sth = $dbh->prepare($query); |
| 215 | $sth->execute($client_id, $status_id); |
219 | $sth->execute($client_id); |
| 216 | my $jobs_ref = $sth->fetchall_arrayref(); |
220 | my $jobs_ref = $sth->fetchall_arrayref(); |
| 217 | # Don't ask me...ask the guys in #perl :P |
221 | # Don't ask me...ask the guys in #perl :P |
| 218 | my @jobs = map { @$_ } @$jobs_ref; |
222 | my @jobs = map { @$_ } @$jobs_ref; |
| 219 | return @jobs; |
223 | return @jobs; |
| 220 | } |
224 | } |
| … | |
… | |
| 222 | sub get_job { |
226 | sub get_job { |
| 223 | my $jobid = shift; |
227 | my $jobid = shift; |
| 224 | #Validate your inputs! |
228 | #Validate your inputs! |
| 225 | my $query = 'SELECT * FROM jobs LEFT JOIN job_conditions on (jobs.jobid) WHERE jobs.jobid = ?'; |
229 | my $query = 'SELECT * FROM jobs LEFT JOIN job_conditions on (jobs.jobid) WHERE jobs.jobid = ?'; |
| 226 | debug("Query is $query"); |
230 | debug("Query is $query"); |
| 227 | #my $sth = $dbh->prepare($query); |
231 | # my $sth = $dbh->prepare($query); |
| 228 | #$sth->execute($jobid); |
232 | # $sth->execute($jobid); |
| 229 | #my $job = $sth->fetchrow_hashref(); |
233 | # my $job = $sth->fetchrow_hashref(); |
| 230 | #my $scriptid = $job{'script'}; |
234 | # my $scriptid = $job->{'script'}; |
| 231 | |
235 | |
| 232 | $query = 'SELECT * FROM scripts WHERE scriptid=?'; |
236 | $query = 'SELECT * FROM scripts WHERE scriptid=?'; |
| 233 | debug("Query is $query"); |
237 | debug("Query is $query"); |
| 234 | #$sth = $dbh->prepare($query); |
238 | # $sth = $dbh->prepare($query); |
| 235 | #$sth->execute($scriptid); |
239 | # $sth->execute($scriptid); |
| 236 | #$job{'script'} = $sth->fetchrow_hashref(); |
240 | # $job->{'script'} = $sth->fetchrow_hashref(); |
| 237 | |
241 | |
|
|
242 | # debug(Dumper($job)); |
| 238 | #Write the job w/ all data to a jobfile with the following path /JOBDIR/CLIENT_ID/queue/JOBID.job |
243 | #Write the job w/ all data to a jobfile with the following path /JOBDIR/CLIENT_ID/queue/JOBID.job |
| 239 | my $filename = "$conf{job_dir}/$client_id/queue/$jobid.job"; |
244 | my $path = "$conf{job_dir}/$client_id/queue"; |
|
|
245 | my $filename = "$path/$jobid.job"; |
|
|
246 | # unless (-d $path) { |
|
|
247 | # print "WARNING! $path does not exist...creating\n"; |
|
|
248 | # mkpath( $path, {verbose => 1, mode => 0660}) |
|
|
249 | # or die("Couldn't make $path w/ perms 0660: $!"); |
|
|
250 | # } |
|
|
251 | # open(FH, ">$filename") or die("Couldn't open $filename: $!"); |
|
|
252 | # my $xml = pl2xml( $job ); |
|
|
253 | # print FH $xml."\n"; |
|
|
254 | # close(FH) or die("Couldn't close $filename : $!"); |
|
|
255 | debug("OK $filename\n"); |
| 240 | return "OK $filename\n"; |
256 | return "OK $filename\n"; |
| 241 | } |
257 | } |
| 242 | |
258 | |
| 243 | sub set_job_status { |
259 | sub set_job_status { |
| 244 | my ($jobid,$status) = @_; |
260 | my ($jobid,$status) = @_; |