File Coverage

blib/lib/Schedule/SGE.pm
Criterion Covered Total %
statement 36 56 64.2
branch 11 34 32.3
condition 2 6 33.3
subroutine 8 8 100.0
pod 3 3 100.0
total 60 107 56.0


line stmt bran cond sub pod time code
1             # Schedule::SGE
2              
3             # POD docs
4              
5             =head1 Schedule::SGE
6              
7             Interact with the Sun Grid Engine. This module locates the executables (qstat, qsub, etc), sets the level of verbosity, and other general commands related to the using the SGE.
8              
9             =head1 ABSTRACT
10              
11             Schedule::SGE is a suite of modules for interacting with the Sun Grid Engine. The base module Schedule::SGE handles locating the executables and making sure everything works fine. The three modules Schedule::SGE::Run, Schedule::SGE::Control, and Schedule::SGE::Status are for different interactions with the queues
12              
13             =head1 AUTHOR
14              
15             Rob Edwards (rob@salmonella.org)
16             3/24/05
17              
18             =cut
19              
20             package Schedule::SGE;
21 1     1   650 use strict;
  1         3  
  1         49  
22              
23 1     1   546 use Schedule::SGE::Run qw/command execute environment name project output_file error_file use_cwd notify mailto job_id/;
  1         2  
  1         117  
24 1     1   564 use Schedule::SGE::Status qw/user status brief_job_stats all_jobs/;
  1         2  
  1         70  
25 1     1   490 use Schedule::SGE::Control qw/qdel/;
  1         2  
  1         75  
26              
27             BEGIN {
28             # set some default environment variables. These are default for me, but we'll provide a method to handle them too
29 1 50   1   17 !$ENV{'SGE_CELL'} && ($ENV{'SGE_CELL'}="orionmulti");
30 1 50       6 !$ENV{'SGE_EXECD_PORT'} && ($ENV{'SGE_EXECD_PORT'}="537");
31 1 50       6 !$ENV{'SGE_QMASTER_PORT'} && ($ENV{'SGE_QMASTER_PORT'}="536");
32 1 50       5 !$ENV{'SGE_ROOT'} && ($ENV{'SGE_ROOT'}="/opt/sge");
33 1         449 our $VERSION=0.01;
34             };
35              
36             =head2 new()
37              
38             Instantiate the object, and preload some data. For example
39              
40             my $sge=Schedule::SGE->new(
41             -project=>'redwards',
42             -mailto=>'rob@salmonella.org',
43             -executable=>{qsub=>'/usr/local/bin/qsub', qstat=>'/usr/local/bin/qstat'},
44             -verbose=>1,
45             );
46              
47             =cut
48              
49             sub new {
50 1     1 1 90 my ($class, %args)=@_;
51 1         3 my $self = bless{},$class;
52            
53             # just start with verbosity = 0. This avoids an error in the >= checks
54 1         6 $self->{'verbose'}=0;
55              
56             # load up if we know what we have
57 1         5 foreach my $key (keys %args) {
58 0         0 my $nodash=$key;
59 0         0 $nodash =~ s/^\-//;
60 0 0       0 if ($nodash eq "executable") {
    0          
    0          
61 0         0 $self->executable($args{$key});
62             }
63 0         0 elsif ($nodash eq "use_cwd") {
64 0         0 $self->use_cwd($args{$key});
65             }
66             elsif ($nodash eq "name") {$self->name($args{$key})}
67             else {
68 0         0 $self->{$nodash}=$args{$key};
69             }
70             }
71 1         3 return $self;
72             }
73              
74              
75             =head2 verbose()
76              
77             Increase the level of error messages that are printed out.
78              
79             =cut
80              
81             sub verbose {
82 1     1 1 38 my ($self, $val)=@_;
83 1 50       4 if (defined $val) {
84 1         2 $self->{'verbose'}=$val;
85             }
86 1         3 return $self->{'verbose'};
87             }
88              
89              
90             =head2 executable()
91              
92             Get or set the executables that we will use. This method takes upto two arguments. With no arguments we will try and guess the settings that we need, and if we fail we will die. With a single argument we will return that executable path/program, guess it if we don't know it, and then finally fail. With two arguments we will assume that the second is the location of the executable (incl. path) of the first.
93              
94             We will also take a reference to a hash as the single argument. In this case, we will use the hash as locations of the executables.
95              
96             e.g.s:
97              
98             # using a hash to set all the executables at once (recommended as we don't have to guess anything)
99             my $exec={'qsub'=>'/usr/local/bin/qsub', 'qstat'=>'/usr/local/bin/qstat'}
100             $sge->exectuable($exec);
101             my $pid=$sge->job_id;
102              
103              
104             # guessing all the executables (not recommended)
105             $sge->exectuables();
106             my $pid=$sge->job_id;
107              
108             # getting the value for qsub
109             my $qsubexec=$sge->executable('qsub');
110              
111             # setting a single value for qsub only
112             my $qsubexec=$sge->executable('qsub', '/usr/local/bin/qsub');
113              
114             At the moment we try and figure out locations for each of the following applications
115             qstat
116             qsub
117             qdel
118              
119             =cut
120              
121             sub executable {
122 1     1 1 27 my ($self, $exec, $path)=@_;
123              
124 1 50 33     4 print STDERR "Trying to find $exec\n" if ($exec && $self->{'verbose'} >= 2);
125             # these are the executables that we care about:
126 1         4 my @want=(qw[qsub qstat qdel]);
127              
128             # first, if it is a reference add it
129 1 50 33     10 if (ref($exec) eq "HASH") {
    50          
    50          
130 0         0 foreach my $e (@want) {
131 0 0       0 if ($exec->{$e}) {$self->{'execute'}->{$e}=$exec->{$e}}
  0         0  
132             }
133 0         0 return $self->{'execute'};
134             }
135              
136             # now if we have both arg/var
137             elsif ($exec && $path) {
138 0         0 $self->{'execute'}->{$exec}=$path;
139 0         0 return $path;
140             }
141              
142             # now if we only have arg
143             elsif ($exec) {
144 0 0       0 if ($self->{'execute'}->{$exec}) {return $self->{'execute'}->{$exec}}
  0         0  
145             }
146              
147             # if we get here we need to guess the locations
148 1         12 foreach my $e (@want) {
149 1         6455 my $guess=`which $e`; chomp($guess);
  1         26  
150 1 50       50 if ($self->{'verbose'} >=2 ) {
151 0         0 print STDERR "Looking for $e and found $guess\n";
152             }
153            
154 1 50       29 if ($guess) {
155 0         0 $self->{'execute'}->{$e}=$guess;
156             } else {
157 1         749 &_dieout("trying to get $e");
158             }
159             }
160              
161 0 0         if ($exec) {return $self->{'execute'}->{$exec}}
  0            
  0            
162             else {return $self->{'execute'}}
163             }
164            
165              
166              
167             1;