SGE.pm

filter: Statementstmt 64.9% 37 / 57 Branchbran 32.3% 11 / 34 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 54.4% 61 / 112 CC 23 SCAR 34.5
CC
23
Cov
52%
executable
60.0
new
14.4
BEGIN
5.7
CRAP 31.6
« SGE/Run.pm ↑ Summary SGE/Control.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Schedule::SGE::Run qw/command execute environment name project output_file error_file use_cwd notify mailto job_id/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Schedule::SGE::Status qw/user status brief_job_stats all_jobs/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Schedule::SGE::Control qw/qdel/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=17.5
28 # set some default environment variables. These are default for me, but we'll provide a method to handle them too
29 1 ▶ !$ENV{'SGE_CELL'} && ($ENV{'SGE_CELL'}="orionmulti");
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SGE_CELL"} or $ENV{"SGE_CELL"} = "orionmulti" 0 1 1
30 1 ▶ !$ENV{'SGE_EXECD_PORT'} && ($ENV{'SGE_EXECD_PORT'}="537");
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SGE_EXECD_PORT"} or $ENV{"SGE_EXECD_PORT"} = 537 0 1 1
31 1 ▶ !$ENV{'SGE_QMASTER_PORT'} && ($ENV{'SGE_QMASTER_PORT'}="536");
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SGE_QMASTER_PORT"} or $ENV{"SGE_QMASTER_PORT"} = 536 0 1 1
32 1 ▶ !$ENV{'SGE_ROOT'} && ($ENV{'SGE_ROOT'}="/opt/sge");
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"SGE_ROOT"} or $ENV{"SGE_ROOT"} = "/opt/sge" 0 1 1
33 1 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 1 ▶sub new {
Subroutine new: called CC=5 SCAR=26.7
Pod documented
50 1 my ($class, %args)=@_;
51 1 my $self = bless{},$class;
52
53 # just start with verbosity = 0. This avoids an error in the >= checks
54 1 $self->{'verbose'}=0;
55  
56 # load up if we know what we have
57 1 foreach my $key (keys %args) {
58 0 my $nodash=$key;
59 0 $nodash =~ s/^\-//;
60 0 ▶ if ($nodash eq "executable") {
Branch: 3 branches
BranchTrueFalseTotal
if ($nodash eq 'executable') { } 0 0 0
elsif ($nodash eq 'use_cwd') { } 0 0 0
elsif ($nodash eq 'name') { } 0 0 0
61 0 $self->executable($args{$key});
62 }
63 elsif ($nodash eq "use_cwd") {
64 0 $self->use_cwd($args{$key});
65 }
66 0 elsif ($nodash eq "name") {$self->name($args{$key})}
67 else {
68 0 $self->{$nodash}=$args{$key};
69 }
70 }
71 1 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 1 ▶sub verbose {
Subroutine verbose: called CC=2 SCAR=7.0
Pod documented
82 1 my ($self, $val)=@_;
83 1 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 1 0 1
84 1 $self->{'verbose'}=$val;
85 }
86 1 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 1 ▶sub executable {
Subroutine executable: called CC=14 SCAR=41.0
Pod documented
122 1 my ($self, $exec, $path)=@_;
123  
124 1 ▶ print STDERR "Trying to find $exec\n" if ($exec && $self->{'verbose'} >= 2);
Branch: 1 branch
BranchTrueFalseTotal
if $exec and $self->{"verbose"} >= 2 0 1 1
Condition33%1/3
$exec and $self->{"verbose"} >= 2
!ll&&!rl&&r
100
MC/DC0%0/2
$exec and $self->{"verbose"} >= 2
$exec $self->{"verbose"} >= 2
Truth table33%1/3
A and B
A= $execB= $self->{"verbose"} >= 2
ABresult
0X0
100
111
125 # these are the executables that we care about:
126 1 my @want=(qw[qsub qstat qdel]);
127  
128 # first, if it is a reference add it
129 1 ▶ if (ref($exec) eq "HASH") {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $exec eq 'HASH') { } 0 1 1
elsif ($exec and $path) { } 0 1 1
elsif ($exec) { } 0 1 1
130 0 foreach my $e (@want) {
131 0 ▶ if ($exec->{$e}) {$self->{'execute'}->{$e}=$exec->{$e}}
Branch: 1 branch
BranchTrueFalseTotal
if ($exec->{$e}) 0 0 0
132 }
133 0 return $self->{'execute'};
134 }
135  
136 # now if we have both arg/var
137 ▶ elsif ($exec && $path) {
Condition33%1/3
$exec and $path
!ll&&!rl&&r
100
MC/DC0%0/2
$exec and $path
$exec $path
Truth table33%1/3
A and B
A= $execB= $path
ABresult
0X0
100
111
138 0 $self->{'execute'}->{$exec}=$path;
139 0 return $path;
140 }
141  
142 # now if we only have arg
143 elsif ($exec) {
144 0 ▶ if ($self->{'execute'}->{$exec}) {return $self->{'execute'}->{$exec}}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"execute"}{$exec}) 0 0 0
145 }
146  
147 # if we get here we need to guess the locations
148 1 foreach my $e (@want) {
149 1 my $guess=`which $e`; chomp($guess);
150 1 ▶ if ($self->{'verbose'} >=2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"} >= 2) 0 1 1
151 0 print STDERR "Looking for $e and found $guess\n";
152 }
153
154 1 ▶ if ($guess) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guess) { } 0 1 1
155 0 $self->{'execute'}->{$e}=$guess;
156 } else {
157 1 &_dieout("trying to get $e");
158 }
159 }
160  
161 0 ▶ if ($exec) {return $self->{'execute'}->{$exec}}
Branch: 1 branch
BranchTrueFalseTotal
if ($exec) { } 0 0 0
162 0 else {return $self->{'execute'}}
163 }
164
165  
166  
167 1 1;
« SGE/Run.pm ↑ Summary SGE/Control.pm »