diff options
author | Preston Cody <codeman@gentoo.org> | 2008-01-03 03:55:50 +0000 |
---|---|---|
committer | Preston Cody <codeman@gentoo.org> | 2008-01-03 03:55:50 +0000 |
commit | 60ec495aaa37ee1836998ae8479a95c7f04fd2ef (patch) | |
tree | 0c83ee82a1e493114c2ecbb21b989d7c35cc3378 | |
parent | remove the jobfile once it's been successfully sent to the client. (diff) | |
download | scire-60ec495aaa37ee1836998ae8479a95c7f04fd2ef.tar.gz scire-60ec495aaa37ee1836998ae8479a95c7f04fd2ef.tar.bz2 scire-60ec495aaa37ee1836998ae8479a95c7f04fd2ef.zip |
adding job expansion code.
svn path=/branches/new-fu/; revision=317
-rwxr-xr-x | server/scireserver.pl | 105 |
1 files changed, 100 insertions, 5 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index 835a10d..b50e462 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -88,7 +88,7 @@ while(<>) { job_fetched($job) and print "OK\n"; } elsif ($command eq "SET_JOB_STATUS") { my ($jobid,$status) = @args; - set_job_status($jobid,$status) and print "OK\n"; + set_job_status($jobid,$client_id,$status) and print "OK\n"; } else { print "ERROR The command $command is unknown. Please try again.\n"; @@ -205,6 +205,7 @@ sub identify_client { sub get_jobs { #FIXME expand jobs for $client_id + expand_jobs(); my $query = <<'EndOfQuery'; SELECT jobs.jobid @@ -261,7 +262,7 @@ sub get_job { sub job_fetched { my $jobid = shift; - set_job_status($jobid,'Downloaded') or print "ERROR could not set job status to downloaded.\n"; + set_job_status($jobid,$client_id,'Downloaded', 'Job downloaded by client.') or print "ERROR could not set job status to downloaded.\n"; eval { my $query = 'DELETE FROM jobs_clients WHERE jobid=? AND clientid=?'; @@ -277,9 +278,12 @@ sub job_fetched { } sub set_job_status { - my ($jobid,$status) = @_; + my ($jobid,$id_of_client,$status,$eventmsg) = @_; #Validate your inputs! $jobid =~ /^\d+$/ or die("Invalid jobid $jobid"); + $id_of_client ||= $client_id; + $id_of_client =~ /^\d+$/ or die("Invalid id of client $id_of_client"); + $eventmsg ||= "Server status update."; #fixme validate status my $status_id; eval { @@ -294,10 +298,10 @@ sub set_job_status { $status_id or print "ERROR Invalid status id $status_id\n"; eval { - my $query = 'INSERT INTO job_history (jobid,clientid,statusid) VALUES (?,?,?)'; + my $query = 'INSERT INTO job_history (jobid,clientid,statusid,eventmsg) VALUES (?,?,?,?)'; debug("Query is $query"); my $sth = $dbh->prepare($query); - $sth->execute($jobid,$client_id,$status_id); + $sth->execute($jobid,$id_of_client,$status_id,$eventmsg); }; ($@) and print "ERROR Could not insert into job_history: $DBI::errstr\n"; return 1; @@ -313,3 +317,94 @@ sub parse_command { } return @parts; } + +sub expand_jobs { + #Searches for the group jobs that the client must be into and does the expansion. + my @groups = get_client_groups(); + foreach my $groupid (@groups) { + my @members = get_group_clients($groupid); + eval { + my $query = <<'EndOfQuery2'; +SELECT DISTINCT(jobs_clients.jobid) +FROM jobs_clients LEFT JOIN job_conditions on (jobs_clients.jobid=job_conditions.jobid) +WHERE jobs_clients.groupid = ? +AND (job_conditions.deploy_time < now()) +AND (job_conditions.expiration_time > now()) +AND job_conditions.last_run_date < job_conditions.deploy_time +EndOfQuery2 + my $sth = $dbh->prepare($query); + $sth->execute($groupid); + # $dbh->do('LOCK TABLES `jobs_clients` WRITE, `job_conditions` WRITE, `job_history` WRITE'); + while( my $jobid = $sth->fetchrow_hashref->{'jobid'} ) { + foreach my $member (@members) { + $query = 'INSERT INTO jobs_clients (jobid, clientid) VALUES (?,?)'; + debug("Query is $query"); + my $sth2 = $dbh->prepare($query); + $sth2->execute($jobid,$member); + + set_job_status($jobid,$member,'Pending', 'Job expanded.') or print "ERROR could not add expanded jobs to job_history.\n"; + } + $query = 'UPDATE `job_conditions` SET last_run_date = now() WHERE jobid = ?'; + debug("Query is $query"); + my $sth3 = $dbh->prepare($query); + $sth3->execute($jobid); + + } + # $dbh->do('UNLOCK TABLES'); + }; + ($@) and print "ERROR Could not expand jobs: $DBI::errstr\n"; + return undef; + } +} + +######################################################### +# PHPGACL FUNCTIONS +######################################################### + +sub get_client_groups { + my $query; + my $option = 'NO RECURSE'; + # If RECURSE it will get all ancestor groups. defaults to only get direct parents. + + debug("get_object_groups(): Object ID: $client_id, option: $option"); + my $object_type = 'axo'; + my $group_table = 'gacl_axo_groups'; + my $map_table = 'gacl_groups_axo_map'; + + if ($option eq 'RECURSE') { + $query = "SELECT DISTINCT g.id as group_id FROM $map_table gm "; + $query .= "LEFT JOIN $group_table g1 ON g1.id=gm.group_id "; + $query .= "LEFT JOIN $group_table g ON g.lft<=g1.lft AND g.rgt>=g1.rgt"; + } else { + $query = "SELECT gm.group_id FROM $map_table gm "; + } + $query .= " WHERE gm.axo_id=?"; + debug("Query is $query"); + eval { + my $sth = $dbh->prepare($query); + $sth->execute($client_id); + my $groups_ref = $sth->fetchall_arrayref(); + # Don't ask me...ask the guys in #perl :P + my @groups = map { @$_ } @$groups_ref; + return @groups; + }; + ($@) and print "ERROR Could not get client groups: $DBI::errstr\n"; + return undef; +} + +sub get_group_clients { + #This function gets the members of groups. Returns an array containing those clients, empty otherwise. + my $groupid = shift; + my $query = 'SELECT axo_id FROM gacl_groups_axo_map WHERE group_id = ?'; + debug("Query is $query"); + eval { + my $sth = $dbh->prepare($query); + $sth->execute($groupid); + my $members_ref = $sth->fetchall_arrayref(); + # Don't ask me...ask the guys in #perl :P + my @members = map { @$_ } @$members_ref; + return @members; + }; + ($@) and print "ERROR Could not get group members: $DBI::errstr\n"; + return undef; +} |