/[scire]/branches/new-fu/server/scireserver.pl
Gentoo

Diff of /branches/new-fu/server/scireserver.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 310 Revision 311
5use strict; 5use strict;
6use warnings; 6use warnings;
7use DBI; 7use DBI;
8use Data::Dumper; 8use Data::Dumper;
9use Digest::MD5 qw(md5 md5_hex ); 9use Digest::MD5 qw(md5 md5_hex );
10use File::Path;
11use XML::Dumper;
10 12
11$| = 1; 13$| = 1;
12 14
13my $ETC_DIR = "/etc/scire"; 15my $ETC_DIR = "/etc/scire";
14my $SCIRE_CONFIG_FILE = "${ETC_DIR}/scireserver.conf"; 16my $SCIRE_CONFIG_FILE = "${ETC_DIR}/scireserver.conf";
196 } 198 }
197 199
198} 200}
199 201
200sub get_jobs { 202sub 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
211EndOfQuery 214EndOfQuery
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}
222sub get_job { 226sub 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
243sub set_job_status { 259sub set_job_status {
244 my ($jobid,$status) = @_; 260 my ($jobid,$status) = @_;

Legend:
Removed from v.310  
changed lines
  Added in v.311

  ViewVC Help
Powered by ViewVC 1.1.20