lib/NBU/Drive.pm

filter: Statementstmt 9.5% 25 / 261 Branchbran 0.0% 0 / 108 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 16.2% 6 / 37 Podpod 0.0% 0 / 31 totaltotal 6.5% 31 / 471 CC 62 SCAR 39.0
CC
62
Cov
6%
populate
156.0
updateStatus
132.0
busyStats
72.0
CRAP 49.5
« lib/NBU/Class.pm ↑ Summary lib/NBU/Image.pm »
1 #
2 # Copyright (c) 2002 Paul Winkeler. All Rights Reserved.
3 # This program is free software; you may redistribute it and/or modify it under
4 # the same terms as Perl itself.
5 #
6 package NBU::Drive;
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶ use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 $VERSION = do { my @r=(q$Revision: 1.24 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
16 1 @ISA = qw();
17 1 @EXPORT = qw();
18 1 @EXPORT_OK = qw();
19 1 %EXPORT_TAGS = qw();
20 }
21  
22 #
23 # Drive indices are unique only local to a media manager, hence
24 # the key into the Index pool has to be a combination of
25 # index and host.
26 # Same for drive names.
27 1 my %driveIndexPool;
28 my %driveNamePool;
29  
30 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
31 0 my $proto = shift;
32 0 my $drive = {};
33  
34 0 bless $drive, $proto;
35  
36 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
37 0 my $index = shift;
38 0 $drive->{INDEX} = $index;
39  
40 0 my $mmHost = shift;
41 0 ▶ if (!defined($mmHost)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mmHost) 0 0 0
42 0 $mmHost = NBU::Host->new("localhost");
43 }
44  
45 0 $driveIndexPool{$mmHost->name.":".$index} = $drive;
46  
47 0 $drive->{STATUS} = "DOWN";
48 0 $drive->{CONTROL} = "DOWN-TLD";
49 0 $drive->{HANDLERS} = {};
50 }
51 0 return $drive;
52 }
53  
54 #
55 # Drive objects return 2, just as Media Manager storage units do
56 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my $self = shift;
58  
59 0 return 2;
60 }
61  
62 0 ▶sub byIndex {
Subroutine byIndex: not called CC=4 SCAR=30.0
Pod undocumented
63 0 my $proto = shift;
64 0 my $index = shift;
65 0 my $mmHost = shift;
66 0 my $drive;
67  
68 0 ▶ if (!defined($mmHost)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mmHost) 0 0 0
69 0 $mmHost = NBU::Host->new("localhost");
70 }
71  
72 0 ▶ if (defined($index) && !($drive = $driveIndexPool{$mmHost->name.":".$index})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index and not $drive = $driveIndexPool{$mmHost->name . ':' . $index}) 0 0 0
Condition0%0/3
defined $index and not $drive = $driveIndexPool{$mmHost->name . ':' . $index}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $index and not $drive = $driveIndexPool{$mmHost->name . ':' . $index}
defined $index not $drive = $driveIndexPool{$mmHost->name . ':' . $index}
Truth table0%0/3
A and not(B)
A= defined $indexB= not $drive = $driveIndexPool{$mmHost->name . ':' . $index}
ABresult
0X0
100
111
73 0 $drive = NBU::Drive->new($index, $mmHost);
74 }
75 0 return $drive;
76 }
77  
78 0 ▶sub byName {
Subroutine byName: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my $proto = shift;
80 0 my $driveName = shift;
81 0 my $drive;
82  
83 0 ▶ $drive = $driveNamePool{$driveName} if (defined($driveName));
Branch: 1 branch
BranchTrueFalseTotal
if defined $driveName 0 0 0
84 0 return $drive;
85 }
86  
87 1 my %driveHosts;
88 0 ▶sub populate {
Subroutine populate: not called CC=12 SCAR=50.5
Pod undocumented
89 0 my $proto = shift;
90 0 my $server = shift;
91  
92 0 ▶ return if (!$server->roboticMediaManager());
Branch: 1 branch
BranchTrueFalseTotal
unless $server->roboticMediaManager 0 0 0
93  
94 0 ▶ if (!exists($driveHosts{$server->name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $driveHosts{$server->name}) 0 0 0
95 0 my $driveCount = 0;
96 0 my $pipe = NBU->cmd("vmoprcmd -h ".$server->name." -xdraw ds |");
97 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
98 0 ▶ next unless (/^DRIVESTATUS/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^DRIVESTATUS/ 0 0 0
99 0 my ($marker, $index, $density, $control, $user, $rvsn, $evsn, $request,
100 $robotType, $robotNumber, $state, $name, $assigned, $ignore2, $lastCleaned, $comment
101 ) = split(/\s+/, $_, 16);
102 0 chop $comment;
103  
104 0 my $drive = NBU::Drive->byIndex($index, $server);
105 0 ▶ if ($robotType ne "-") {
Branch: 1 branch
BranchTrueFalseTotal
if ($robotType ne "-") 0 0 0
106 0 my $robot = NBU::Robot->new($robotNumber, $robotType);
107 0 $drive->{ROBOT} = $robot; $robot->controlDrive($drive);
108 }
109 0 $drive->{HOST} = $server;
110 0 $driveNamePool{$drive->{NAME} = $name} = $drive;
111 0 $drive->{LASTCLEANED} = $lastCleaned;
112 0 $drive->{COMMENT} = $comment;
113  
114 0 $drive->{CONTROL} = $control;
115 0 ▶ $drive->{STATUS} = ($control !~ /DOWN/) ? "UP" : "DOWN";
Branch: 1 branch
BranchTrueFalseTotal
!($control =~ /DOWN/) ? : 0 0 0
116  
117 0 $drive->{INUSE} = ($state & 0x000f);
118  
119 #
120 # If the drive is busy, and the media has no recorded ID yet, but it
121 # does have an external ID, then this media is being used for the first
122 # time and it will have its external ID recorded henceforth. So here we
123 # simply jump the gun a little...
124 0 ▶ if ($drive->busy && ($rvsn eq "-") && ($evsn ne "-")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($drive->busy and $rvsn eq "-" and $evsn ne "-") 0 0 0
Condition0%0/6
$drive->busy and $rvsn eq "-" and $evsn ne "-"
!ll&&!rl&&r
000
$drive->busy and $rvsn eq "-"
!ll&&!rl&&r
000
MC/DC0%0/3
$drive->busy and $rvsn eq "-" and $evsn ne "-"
$drive->busy $rvsn eq "-" $evsn ne "-"
Truth table0%0/4
A and B and C
A= $drive->busyB= $rvsn eq "-"C= $evsn ne "-"
ABCresult
0XX0
10X0
1100
1111
125 0 $rvsn = $evsn;
126 }
127 0 ▶ if ($rvsn ne "-") {
Branch: 1 branch
BranchTrueFalseTotal
if ($rvsn ne "-") 0 0 0
128 # Unfortunately there is no way to find out which job is using this drive :-(
129 0 ▶ if (defined(my $volume = NBU::Media->new($rvsn))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $volume = 'NBU::Media'->new($rvsn))) { } 0 0 0
130 0 my $mount = NBU::Mount->new(undef, $volume, $drive, time);
131 0 $drive->use($mount, time);
132 }
133 0 else {die("Cannot located media $rvsn?\n");}
134 }
135  
136 0 $driveCount++;
137 }
138 0 close($pipe);
139 0 $driveHosts{$server->name} = $driveCount;
140 }
141 0 return $driveHosts{$server->name};
142 }
143  
144 #
145 # Try to get more detail on this drive.
146 # If the host to query is not specified, first look to the drive's
147 # host or else the local master server for this information
148 0 ▶sub loadDriveDetail {
Subroutine loadDriveDetail: not called CC=7 SCAR=40.3
Pod undocumented
149 0 my $self = shift;
150 0 my $server = shift;
151  
152 0 ▶ if (!defined($server)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $server) 0 0 0
153 0 $server = $self->host;
154 }
155 0 ▶ if (!defined($server)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $server) 0 0 0
156 0 my @masters = NBU->masters; $server = $masters[0];
157 }
158  
159 0 my $pipe = NBU->cmd("vmglob -h ".$server->name." -listall -java |");
160 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
161 0 ▶ next unless (/VMGLOB... drive /);
Branch: 1 branch
BranchTrueFalseTotal
unless /VMGLOB... drive / 0 0 0
162 0 chop;
163  
164 0 my($key, $d, $driveName, $serial, $host, $volumeDBHost, $robotNumber, $robotDriveIndex, $density, $flags, $wwName) =
165 split;
166  
167 0 ▶ if (my $drive = NBU::Drive->byName($driveName)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $drive = "NBU::Drive"->byName($driveName)) 0 0 0
168 0 $drive->{SERIALNUMBER} = $serial;
169 0 $drive->{ROBOTDRIVEINDEX} = $robotDriveIndex;
170 0 ▶ $drive->{WWNAME} = $wwName if ($wwName ne "-");
Branch: 1 branch
BranchTrueFalseTotal
if $wwName ne "-" 0 0 0
171  
172 0 $drive->{DETAILED} = 1;
173 }
174 }
175 0 $self->{DETAILED} = 1;
176 }
177  
178 #
179 # Here known refers to whether the drive is known to NetBackup, i.e. whether
180 # it is part of a storage unit definition and thus could be used for backups.
181 0 ▶sub known {
Subroutine known: not called CC=3 SCAR=24.8
Pod undocumented
182 0 my $self = shift;
183  
184 0 ▶ if (defined(my $stu = $self->{STU})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $stu = $self->{'STU'})) { } 0 0 0
elsif (defined(my $robot = $self->robot)) { } 0 0 0
185 0 return ($stu);
186 }
187 elsif (defined(my $robot = $self->robot)) {
188 0 return ($robot->known);
189 }
190 0 return ();
191 }
192  
193 0 ▶sub updateStatus {
Subroutine updateStatus: not called CC=11 SCAR=48.8
Pod undocumented
194 0 my $proto = shift;
195 0 my $server = shift;
196  
197 #
198 # Only applies to robotic media managers
199 0 ▶ return if (!$server->roboticMediaManager());
Branch: 1 branch
BranchTrueFalseTotal
unless $server->roboticMediaManager 0 0 0
200  
201 0 my $pipe = NBU->cmd("vmoprcmd -h ".$server->name." -xdraw ds |");
202 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
203 0 ▶ next unless (/^DRIVESTATUS/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^DRIVESTATUS/ 0 0 0
204 0 my ($ignore, $id, $density, $control, $user, $rvsn, $evsn, $request,
205 $robotType, $robotNumber, $state, $name, $assigned, $ignore2, $lastCleaned, $comment
206 ) = split(/\s+/, $_, 16);
207 0 chop $comment;
208  
209 0 my $drive = NBU::Drive->byIndex($id, $server);
210  
211 0 $drive->comment($comment);
212 0 $drive->{LASTCLEANED} = $lastCleaned;
213  
214 0 $drive->{INUSE} = ($state & 0x000f);
215  
216 0 $drive->status($control);
217  
218 0 ▶ if ($drive->busy) {
Branch: 2 branches
BranchTrueFalseTotal
if ($drive->busy) { } 0 0 0
elsif (not $drive->busy and $rvsn ne '-') { } 0 0 0
219 0 my $mount = $drive->mount;
220 0 ▶ if (($rvsn eq "-") && ($evsn ne "-")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rvsn eq "-" and $evsn ne "-") 0 0 0
Condition0%0/3
$rvsn eq "-" and $evsn ne "-"
!ll&&!rl&&r
000
MC/DC0%0/2
$rvsn eq "-" and $evsn ne "-"
$rvsn eq "-" $evsn ne "-"
Truth table0%0/3
A and B
A= $rvsn eq "-"B= $evsn ne "-"
ABresult
0X0
100
111
221 0 $rvsn = $evsn;
222 }
223  
224 0 ▶ if ($rvsn eq "-") {
Branch: 2 branches
BranchTrueFalseTotal
if ($rvsn eq '-') { } 0 0 0
elsif ($mount->volume->rvsn ne $rvsn) { } 0 0 0
225 0 $drive->free(time);
226 }
227 elsif ($mount->volume->rvsn ne $rvsn) {
228 0 $drive->free(time);
229 0 $mount = NBU::Mount->new(undef, NBU::Media->new($rvsn), $drive, time);
230 0 $drive->use($mount, time);
231 }
232 }
233 ▶ elsif (!$drive->busy && ($rvsn ne "-")) {
Condition0%0/3
not $drive->busy and $rvsn ne "-"
!ll&&!rl&&r
000
MC/DC0%0/2
not $drive->busy and $rvsn ne "-"
not $drive->busy $rvsn ne "-"
Truth table0%0/3
not(A) and B
A= not $drive->busyB= $rvsn ne "-"
ABresult
0X0
100
111
234 0 my $mount = NBU::Mount->new(undef, NBU::Media->new($rvsn), $drive, time);
235 0 $drive->use($mount, time);
236 }
237 }
238 0 close($pipe);
239 }
240  
241 0 ▶sub pool {
Subroutine pool: not called CC=1 SCAR=6.9
Pod undocumented
242 0 my $proto = shift;
243  
244 0 return (values %driveIndexPool);
245 }
246  
247 0 ▶sub status {
Subroutine status: not called CC=5 SCAR=34.0
Pod undocumented
248 0 my $self = shift;
249  
250 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
251 0 my $oldStatus = $self->{STATUS};
252 0 my $control = $self->{CONTROL} = shift;
253 0 ▶ my $newStatus = ($control !~ /DOWN/) ? "UP" : "DOWN";
Branch: 1 branch
BranchTrueFalseTotal
!($control =~ /DOWN/) ? : 0 0 0
254  
255 0 ▶ if ($oldStatus ne $newStatus) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldStatus ne $newStatus) 0 0 0
256 0 my $handlers = $self->{HANDLERS};
257  
258 0 ▶ if (exists($$handlers{$newStatus})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $handlers->{$newStatus}) 0 0 0
259 0 my $handler = $$handlers{$newStatus};
260 0 &$handler($self, $newStatus);
261 }
262 }
263  
264 0 $self->{STATUS} = $newStatus;
265 }
266 0 return $self->{STATUS};
267 }
268  
269 0 ▶sub control {
Subroutine control: not called CC=1 SCAR=6.9
Pod undocumented
270 0 my $self = shift;
271  
272 0 return $self->{CONTROL};
273 }
274  
275  
276 #
277 # If the drive is not up, try to change its state to up. Then,
278 # if an argument is provided the host will be queried to see if the
279 # drive indeed came back up. Without argument the code assumes all
280 # went as planned.
281 0 ▶sub up {
Subroutine up: not called CC=3 SCAR=24.8
Pod undocumented
282 0 my $self = shift;
283  
284  
285 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
286 0 ▶ if ($self->{STATUS} ne "UP") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATUS"} ne "UP") 0 0 0
287 0 system($NBU::prefix."volmgr/bin/vmoprcmd -up ".$self->id." -h ".$self->host->name."\n");
288 0 $self->updateStatus($self->host);
289 }
290 }
291  
292 0 return $self->{STATUS} eq "UP";
293 }
294  
295 #
296 # Same story as the up routine just above
297 0 ▶sub down {
Subroutine down: not called CC=3 SCAR=24.8
Pod undocumented
298 0 my $self = shift;
299  
300 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
301 0 ▶ if ($self->{STATUS} ne "DOWN") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"STATUS"} ne "DOWN") 0 0 0
302 0 system($NBU::prefix."volmgr/bin/vmoprcmd -down ".$self->id." -h ".$self->host->name."\n");
303 0 $self->updateStatus($self->host);
304 }
305 }
306  
307 0 return $self->{STATUS} eq "DOWN";
308 }
309  
310 0 ▶sub busy {
Subroutine busy: not called CC=1 SCAR=6.9
Pod undocumented
311 0 my $self = shift;
312  
313 0 return $self->{INUSE};
314 }
315  
316 0 ▶sub index {
Subroutine index: not called CC=1 SCAR=6.9
Pod undocumented
317 0 my $self = shift;
318  
319 0 return $self->id(@_);
320 }
321  
322 0 ▶sub id {
Subroutine id: not called CC=3 SCAR=24.8
Pod undocumented
323 0 my $self = shift;
324  
325 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
326 0 my $index = shift;
327 0 $self->{INDEX} = $index;
328  
329 0 my $mmHost = shift;
330 0 ▶ if (!defined($mmHost)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mmHost) 0 0 0
331 0 $mmHost = NBU::Host->new("localhost");
332 }
333 0 $driveIndexPool{$mmHost->name.":".$index} = $self;
334 }
335  
336 0 return $self->{INDEX};
337 }
338  
339 0 ▶sub comment {
Subroutine comment: not called CC=2 SCAR=17.9
Pod undocumented
340 0 my $self = shift;
341  
342 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
343 0 $self->{COMMENT} = shift;
344 }
345  
346 0 return $self->{COMMENT};
347 }
348  
349 0 ▶sub name {
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
350 0 my $self = shift;
351  
352 0 return $self->{NAME};
353 }
354  
355 0 ▶sub serialNumber {
Subroutine serialNumber: not called CC=2 SCAR=17.9
Pod undocumented
356 0 my $self = shift;
357  
358 0 ▶ $self->loadDriveDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
359 0 return $self->{SERIALNUMBER};
360 }
361  
362 0 ▶sub worldWideName {
Subroutine worldWideName: not called CC=2 SCAR=17.9
Pod undocumented
363 0 my $self = shift;
364  
365 0 ▶ $self->loadDriveDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
366 0 return $self->{WWNAME};
367 }
368  
369 0 ▶sub host {
Subroutine host: not called CC=1 SCAR=6.9
Pod undocumented
370 0 my $self = shift;
371  
372 0 return $self->{HOST};
373 }
374  
375 0 ▶sub use {
Subroutine use: not called CC=2 SCAR=17.9
Pod undocumented
376 0 my $self = shift;
377 0 my ($mount, $tm) = @_;
378  
379 0 ▶ if ($self->{INUSE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"INUSE"}) 0 0 0
380 0 $self->free($tm);
381 }
382  
383 0 my $uses = $self->usage;
384  
385 0 my %use;
386 0 $use{'MOUNT'} = $mount;
387 0 $mount->usedBy(\%use);
388  
389 0 $self->{INUSE} = $use{'START'} = $tm;
390 0 push @$uses, \%use;
391 0 return $self;
392 }
393  
394 0 ▶sub mount {
Subroutine mount: not called CC=2 SCAR=17.9
Pod undocumented
395 0 my $self = shift;
396  
397 0 ▶ if ($self->busy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->busy) 0 0 0
398 0 my $uses = $self->usage;
399 0 my $use = $$uses[@$uses - 1];
400 0 return $$use{'MOUNT'};
401 }
402  
403 0 return undef;
404 }
405  
406 0 ▶sub free {
Subroutine free: not called CC=2 SCAR=17.9
Pod undocumented
407 0 my $self = shift;
408 0 my $tm = shift;
409  
410 0 ▶ if (!$self->{INUSE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"INUSE"}) 0 0 0
411 # it is quite common for a mount to inform the drive it is no
412 # longer using the drive sometime after the drive has been put
413 # to new use already. Hence ignore this event.
414 # print "Drive ".$self->id." already free!\n";
415 # exit(0);
416 }
417 0 $self->{INUSE} = undef;
418  
419 0 my $uses = $self->usage;
420 0 my $use = pop @$uses;
421 0 $$use{'STOP'} = $tm;
422 0 push @$uses, $use;
423  
424 0 return $self;
425 }
426  
427 0 ▶sub robot {
Subroutine robot: not called CC=1 SCAR=6.9
Pod undocumented
428 0 my $self = shift;
429  
430 0 return $self->{ROBOT};
431 }
432  
433 0 ▶sub robotDriveIndex {
Subroutine robotDriveIndex: not called CC=2 SCAR=17.9
Pod undocumented
434 0 my $self = shift;
435  
436 0 ▶ $self->loadDriveDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
437 0 return $self->{ROBOTDRIVEINDEX};
438 }
439  
440 0 ▶sub lastCleaned {
Subroutine lastCleaned: not called CC=1 SCAR=6.9
Pod undocumented
441 0 my $self = shift;
442  
443 0 return $self->{LASTCLEANED};
444 }
445  
446 0 ▶sub lastUsed {
Subroutine lastUsed: not called CC=2 SCAR=17.9
Pod undocumented
447 0 my $self = shift;
448  
449 0 my $uses = $self->usage;
450 0 ▶ if (my $use = pop @$uses) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $use = pop @$uses) { } 0 0 0
451 0 return $$use{'START'};
452 }
453 else {
454 0 return 0;
455 }
456 }
457  
458 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
Pod undocumented
459 0 my $self = shift;
460  
461 0 ▶ if (!$self->{USES}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"USES"}) 0 0 0
462 0 $self->{USES} = [];
463 }
464  
465 0 return $self->{USES};
466 }
467  
468 0 ▶sub busyStats {
Subroutine busyStats: not called CC=8 SCAR=42.8
Pod undocumented
469 0 my $self = shift;
470 0 my $asOf = shift;
471 0 my $endOfPeriod = shift;
472  
473 0 my $stepSize = 5 * 60;
474 0 ▶ $stepSize = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
475  
476 0 my $usage = $self->usage;
477  
478 0 my $step = $asOf;
479 0 my $use = shift @$usage;
480 0 my $mount = $$use{MOUNT};
481 0 my $job = $mount->job;
482 0 my $du = 1;
483  
484 0 my @driveInUse;
485 0 ▶ while ($step < $endOfPeriod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step < $endOfPeriod) 0 0 0
486 0 ▶ if (!defined($use) || ($step < $$use{START})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $use or $step < $use->{'START'}) { } 0 0 0
elsif ($step < $use->{'STOP'}) { } 0 0 0
Condition0%0/3
not defined $use or $step < $use->{"START"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $use or $step < $use->{"START"}
not defined $use $step < $use->{"START"}
Truth table0%0/3
not(A) or B
A= not defined $useB= $step < $use->{"START"}
ABresult
1X1
011
000
487 0 push @driveInUse, 0;
488 }
489 elsif ($step < $$use{STOP}) {
490 0 push @driveInUse, $du;
491 }
492 else {
493 0 $use = shift @$usage;
494 0 ▶ if (defined($use) && defined($mount = $$use{MOUNT})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $use and defined($mount = $use->{'MOUNT'})) { } 0 0 0
Condition0%0/3
defined $use and defined($mount = $use->{"MOUNT"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $use and defined($mount = $use->{"MOUNT"})
defined $use defined($mount = $use->{"MOUNT"})
Truth table0%0/3
A and B
A= defined $useB= defined($mount = $use->{"MOUNT"})
ABresult
0X0
100
111
495 0 $du = 1;
496 }
497 else {
498 0 $du = 0;
499 }
500 0 next;
501 }
502 0 $step += $stepSize;
503 }
504  
505 0 return ($asOf, $endOfPeriod, $stepSize, @driveInUse);
506 }
507  
508 0 ▶sub notifyOn {
Subroutine notifyOn: not called CC=1 SCAR=6.9
Pod undocumented
509 0 my $self = shift;
510 0 my $target = shift;
511 0 my $handler = shift;
512  
513 0 my $handlers = $self->{HANDLERS};
514 0 $$handlers{$target} = $handler;
515 }
516  
517 1 1;
518  
519 __END__
« lib/NBU/Class.pm ↑ Summary lib/NBU/Image.pm »