| 1 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | package Phenyx::Utils::LSF::JobInfo; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | Phenyx::Utils::LSF::JobInfo | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 SYNOPSIS | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | Get info from LSF submited jobs | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | LSF master can be remote (setting $SHELLCOMMANDPREFIX) | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 FUNCTIONS | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head3 parseBJobs($job1 [,$job2 [...]]); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head3 parseBJobs("-a"); #or whatever bjobs arguments that produce a same output | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | issue a bjobs command a returns a hash jobid => hash corresponding to bjobs output | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =head3 jobInfo($jobid, $tag); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | Returns a tag for a job (tags are bjobs command header, i.e. EXEC_HOST, QUEUE...) | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head3 isJobStarted($jobid); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | Returns is a given job has been started (STAT is (PEND|PSUSP|RUN|USUSP|SSUSP)) | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head3 isJobRunning($jobid); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Returns is a given job is currently running (STAT is 'RUN') | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head3 isJobFinished($jobid); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | Returns is a given job has completed (error or not) (STAT is (DONE|EXIT|ZOMBI)) | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head1 GLOBAL VARIABLES | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =head1 SHELLCOMMANDPREFIX | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | A shell prefix (typically 'ssh user@lsf.host.name') to be preprend to any bjobs or whatever command.t | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =head1 EXAMPLES | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | See t/ directories | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head1 SEE ALSO | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | bsub | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head1 COPYRIGHT | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Copyright (C) 2004-2005 Geneva Bioinformatics www.genebio.com | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | This library is free software; you can redistribute it and/or | ||||||||||||||||||||
| 61 | modify it under the terms of the GNU Lesser General Public | ||||||||||||||||||||
| 62 | License as published by the Free Software Foundation; either | ||||||||||||||||||||
| 63 | version 2.1 of the License, or (at your option) any later version. | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | This library is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 66 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 67 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||
| 68 | Lesser General Public License for more details. | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | You should have received a copy of the GNU Lesser General Public | ||||||||||||||||||||
| 71 | License along with this library; if not, write to the Free Software | ||||||||||||||||||||
| 72 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 AUTHORS | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | Alexandre Masselot, www.genebio.com | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 1 | our $SHELLCOMMANDPREFIX; | |||||||||||||||||||
| 82 | 1 | our $CHEAT_BJOBS_COMMAND; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | sub isJobStarted{ | ||||||||||||||||||
|
Subroutine
isJobStarted: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 85 | 0 | ▶ | my $jobid=shift or die __PACKAGE__.": must provide a jobid as first arg to jobStat()"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 86 | 0 | my $stat=jobInfo($jobid, 'STAT'); | |||||||||||||||||||
| 87 | 0 | ▶ | return $stat=~/^(PEND|PSUSP|RUN|USUSP|SSUSP)$/ || isJobFinished($jobid); | ||||||||||||||||||
|
Condition0%0/3
$stat =~ /^(PEND|PSUSP|RUN|USUSP|SSUSP)$/ || isJobFinished($jobid)
MC/DC0%0/2
$stat =~ /^(PEND|PSUSP|RUN|USUSP|SSUSP)$/ || isJobFinished($jobid)
$stat =~ /^(PEND|PSUSP|RUN|USUSP|SSUSP)$/
isJobFinished($jobid)
Truth table0%0/3
A || B
A= $stat =~ /^(PEND|PSUSP|RUN|USUSP|SSUSP)$/B= isJobFinished($jobid)
| |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | sub isJobRunning{ | ||||||||||||||||||
|
Subroutine
isJobRunning: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 91 | 0 | ▶ | my $jobid=shift or die __PACKAGE__.": must provide a jobid as first arg to jobStat()"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 0 | my $stat=jobInfo($jobid, 'STAT'); | |||||||||||||||||||
| 93 | 0 | ▶ | return $stat=~/^(RUN)$/ || isJobFinished($jobid); | ||||||||||||||||||
|
Condition0%0/3
$stat =~ /^(RUN)$/ || isJobFinished($jobid)
MC/DC0%0/2
$stat =~ /^(RUN)$/ || isJobFinished($jobid)
$stat =~ /^(RUN)$/
isJobFinished($jobid)
Truth table0%0/3
A || B
A= $stat =~ /^(RUN)$/B= isJobFinished($jobid)
| |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | 0 | ▶ | sub isJobFinished{ | ||||||||||||||||||
|
Subroutine
isJobFinished: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 96 | 0 | ▶ | my $jobid=shift or die __PACKAGE__.": must provide a jobid as first arg to jobStat()"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 0 | my $stat=jobInfo($jobid, 'STAT'); | |||||||||||||||||||
| 98 | 0 | return $stat=~/^(DONE|EXIT|ZOMBI)$/; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | sub jobInfo{ | ||||||||||||||||||
|
Subroutine
jobInfo: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 102 | 0 | ▶ | my $jobid=shift or die __PACKAGE__.": must provide a jobid as first arg to jobStat()"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | 0 | ▶ | my $tag=shift or die __PACKAGE__.": must provide a tag as second arg to jobStat()"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | my %jobs; | |||||||||||||||||||
| 105 | 0 | %jobs=parseBJobs($jobid); | |||||||||||||||||||
| 106 | 0 | return $jobs{$jobid}{$tag}; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub parseBJobs{ | ||||||||||||||||||
|
Subroutine
parseBJobs: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||
| 110 | 0 | my $cmd; | |||||||||||||||||||
| 111 | 0 | ▶ | unless($CHEAT_BJOBS_COMMAND){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | 0 | $cmd="$SHELLCOMMANDPREFIX bjobs @_"; | |||||||||||||||||||
| 113 | }else{ | ||||||||||||||||||||
| 114 | 0 | $cmd=$CHEAT_BJOBS_COMMAND; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | my $fd; | |||||||||||||||||||
| 118 | 0 | ▶ | open ($fd, "$cmd|") or die "cannot execute command $cmd: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | my $header=<$fd>; | |||||||||||||||||||
| 121 | 0 | chomp $header; | |||||||||||||||||||
| 122 | 0 | my @title2pos; | |||||||||||||||||||
| 123 | 0 | ▶ | while ($header=~/(\S+\s*)/g){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 0 | my $tag=$1; | |||||||||||||||||||
| 125 | 0 | my $start=$-[1]; | |||||||||||||||||||
| 126 | 0 | my $len=length $tag; | |||||||||||||||||||
| 127 | 0 | $tag=~s/\s*$//; | |||||||||||||||||||
| 128 | 0 | push @title2pos, {tag=>$tag, | |||||||||||||||||||
| 129 | start=>$start, | ||||||||||||||||||||
| 130 | length=>$len, | ||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | my %jobs; | |||||||||||||||||||
| 135 | my $curJob; | ||||||||||||||||||||
| 136 | 0 | ▶ | while (my $line=<$fd>){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | 0 | my %line; | |||||||||||||||||||
| 138 | 0 | foreach my $h(@title2pos){ | |||||||||||||||||||
| 139 | 0 | my $val=substr $line, $h->{start}, $h->{length}; | |||||||||||||||||||
| 140 | 0 | $val=~s/\s*$//; | |||||||||||||||||||
| 141 | 0 | $line{$h->{tag}}=$val; | |||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | 0 | ▶ | if($line{JOBID}){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | $jobs{$line{JOBID}}={ | ||||||||||||||||||||
| 145 | JOBID=>$line{JOBID}, | ||||||||||||||||||||
| 146 | 0 | EXEC_HOST=>[] | |||||||||||||||||||
| 147 | }; | ||||||||||||||||||||
| 148 | 0 | $curJob=$jobs{$line{JOBID}}; | |||||||||||||||||||
| 149 | }else{ | ||||||||||||||||||||
| 150 | 0 | ▶ | die "no JOBID was defined when reading [$line]" unless defined $curJob; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | 0 | foreach my $tag (keys %line){ | |||||||||||||||||||
| 153 | 0 | ▶ | if($tag eq 'EXEC_HOST'){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 0 | foreach (split /,/, $line{$tag}){ | |||||||||||||||||||
| 155 | 0 | ▶ | if(/(\d+)\*(.*)/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 156 | 0 | foreach (1..$1){ | |||||||||||||||||||
| 157 | 0 | push @{$curJob->{EXEC_HOST}}, $2; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||
| 160 | }else{ | ||||||||||||||||||||
| 161 | 0 | push @{$curJob->{EXEC_HOST}}, $_; | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | } | ||||||||||||||||||||
| 164 | }else{ | ||||||||||||||||||||
| 165 | 0 | ▶ | if($line{$tag}=~/\S/){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 166 | 0 | ▶ | if($curJob->{$tag}){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 167 | 0 | $curJob->{$tag}.=" $line{$tag}"; | |||||||||||||||||||
| 168 | }else{ | ||||||||||||||||||||
| 169 | 0 | $curJob->{$tag}=$line{$tag}; | |||||||||||||||||||
| 170 | } | ||||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | } | ||||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | 0 | return %jobs; | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | 1 | 1; | |||||||||||||||||||