lib/NBU/Robot.pm

filter: Statementstmt 15.2% 28 / 184 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 25.9% 7 / 27 Podpod 0.0% 0 / 20 totaltotal 10.5% 35 / 332 CC 47 SCAR 45.8
CC
47
Cov
10%
populate
342.0
new
56.0
loadRobotDetail
42.0
CRAP 97.5
« script/nbutop.pl ↑ Summary lib/NBU/Schedule.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::Robot;
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(%robotLevel);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 $VERSION = do { my @r=(q$Revision: 1.23 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
17 1 @ISA = qw();
18 1 @EXPORT = qw(%robotLevel);
19 1 @EXPORT_OK = qw();
20 1 %EXPORT_TAGS = qw();
21 }
22  
23 1 my @farm;
24  
25 1 my %robotTypes = (
26 1 => 'ACS',
27 2 => 'TS8',
28 3 => 'TC8',
29 5 => 'ODL',
30 6 => 'TL8',
31 7 => 'TL4',
32 8 => 'TLD',
33 9 => 'TC4',
34 10 => 'TSD',
35 11 => 'TSH',
36 12 => 'TLH',
37 13 => 'TLM',
38 17 => 'LMF',
39 0 => '-',
40 );
41  
42 #
43 # new(robot-number, robot-type [, robot-host-name])
44 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
45 0 my $Class = shift;
46 0 my $robot = {};
47  
48  
49 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
50 0 my $id = shift;
51  
52 0 my $type = shift;
53 0 ▶ if ($type =~ /^[\d]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^[\d]+$/) { } 0 0 0
54 0 ▶ if (!exists($robotTypes{$type}) || ($type == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $robotTypes{$type} or $type == 0) { } 0 0 0
Condition0%0/3
not exists $robotTypes{$type} or $type == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $robotTypes{$type} or $type == 0
not exists $robotTypes{$type} $type == 0
Truth table0%0/3
not(A) or B
A= not exists $robotTypes{$type}B= $type == 0
ABresult
1X1
011
000
55 0 return undef;
56 }
57 else {
58 0 $type = $robotTypes{$type};
59 }
60 }
61 else {
62 0 ▶ return undef if ($type eq "-");
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "-" 0 0 0
63 }
64  
65 0 ▶ if ($farm[$id]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($farm[$id]) { } 0 0 0
66 0 $robot = $farm[$id];
67 }
68 else {
69 0 bless $robot, $Class;
70 0 $robot->{ID} = $id;
71 0 $farm[$id] = $robot;
72  
73 0 $robot->{DEVICEPATH} = undef;
74 0 $robot->{MAILSLOTSIZE} = 14;
75 0 $robot->{SLOTS} = {};
76 0 $robot->{DRIVES} = [];
77 0 $robot->{KNOWNTO} = [];
78 0 $robot->{TYPE} = $type;
79 }
80 }
81  
82 0 return $robot;
83 }
84  
85 0 ▶sub populate {
Subroutine populate: not called CC=18 SCAR=58.3
Pod undocumented
86 0 my $self = shift;
87  
88 0 my $lastSlot;
89  
90 0 my $type = $self->type;
91 0 $type =~ tr/A-Z/a-z/;
92  
93 0 ▶ if (!defined($self->host)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->host) { } 0 0 0
94 0 $lastSlot = 0;
95 }
96 else {
97 0 my $pipe = NBU->cmd("vmcheckxxx ".
98 " -rt $type".
99 " -rn ".$self->id.
100 " -rh ".$self->host->name.
101 " -list |");
102  
103 0 ▶ if ($self->host->NBUVersion eq "3.2.0") {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->host->NBUVersion eq '3.2.0') { } 0 0 0
elsif ($self->host->NBUVersion eq '3.4.0' or $self->host->NBUVersion eq '4.5.0' or $self->host->NBUVersion eq '5.1.0' or $self->host->NBUVersion eq '6.5.0') { } 0 0 0
104 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
105 0 ▶ if (/^Slot = [\s]*([\d]+), Barcode = ([\S]+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^Slot = [\s]*([\d]+), Barcode = ([\S]+)$/) { } 0 0 0
elsif (/^Slot = [\s]*([\d]+), <EMPTY>/) { } 0 0 0
106 0 ▶ if (defined(my $volume = NBU::Media->byBarcode($2))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $volume = 'NBU::Media'->byBarcode($2))) { } 0 0 0
107 0 $self->insert($1, $volume);
108 }
109 else {
110 0 print STDERR "Unknown barcode $2 in slot $1 of robot ".$self->id."\n";
111 0 $self->empty($1);
112 }
113 0 $lastSlot = $1;
114 }
115 elsif (/^Slot = [\s]*([\d]+), <EMPTY>/) {
116 0 $self->empty($1);
117 0 $lastSlot = $1;
118 }
119 else {
120 0 print STDERR "Ignoring $_";
121 }
122 }
123 }
124 ▶ elsif (($self->host->NBUVersion eq "3.4.0")
Condition0%0/9
$self->host->NBUVersion eq "3.4.0" or $self->host->NBUVersion eq "4.5.0" or $self->host->NBUVersion eq "5.1.0" or $self->host->NBUVersion eq "6.5.0"
l!l&&r!l&&!r
000
$self->host->NBUVersion eq "3.4.0" or $self->host->NBUVersion eq "4.5.0" or $self->host->NBUVersion eq "5.1.0"
l!l&&r!l&&!r
000
$self->host->NBUVersion eq "3.4.0" or $self->host->NBUVersion eq "4.5.0"
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->host->NBUVersion eq "3.4.0" or $self->host->NBUVersion eq "4.5.0" or $self->host->NBUVersion eq "5.1.0" or $self->host->NBUVersion eq "6.5.0"
$self->host->NBUVersion eq "3.4.0" $self->host->NBUVersion eq "4.5.0" $self->host->NBUVersion eq "5.1.0" $self->host->NBUVersion eq "6.5.0"
Truth table0%0/5
A or B or C or D
A= $self->host->NBUVersion eq "3.4.0"B= $self->host->NBUVersion eq "4.5.0"C= $self->host->NBUVersion eq "5.1.0"D= $self->host->NBUVersion eq "6.5.0"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
125 || ($self->host->NBUVersion eq "4.5.0")
126 || ($self->host->NBUVersion eq "5.1.0")
127 || ($self->host->NBUVersion eq "6.5.0")
128 ) {
129 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
130 0 ▶ last if (/^===/);
Branch: 1 branch
BranchTrueFalseTotal
if /^===/ 0 0 0
131 }
132 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
133 0 ▶ if (/^[\s]*([\d]+)[\s]+[\S]+[\s]+([\S]+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^[\s]*([\d]+)[\s]+[\S]+[\s]+([\S]+)/) { } 0 0 0
elsif (/^[\s]*([\d]+)[\s]+No/) { } 0 0 0
134 0 ▶ if (defined(my $volume = NBU::Media->byBarcode($2))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $volume = 'NBU::Media'->byBarcode($2))) { } 0 0 0
135 0 $self->insert($1, $volume);
136 }
137 else {
138 0 print STDERR "Unknown barcode $2 in slot $1 of robot ".$self->id."\n";
139 0 $self->empty($1);
140 }
141 0 $lastSlot = $1;
142 }
143 elsif (/^[\s]*([\d]+)[\s]+No/) {
144 0 $self->empty($1);
145 0 $lastSlot = $1;
146 }
147 else {
148 0 print STDERR "Ignoring $_";
149 }
150 }
151 }
152 else {
153 0 print STDERR "Unknown NetBackup version \"".$self->host->NBUVersion."\"\n";
154 0 $lastSlot = 0;
155 }
156 }
157  
158 0 ▶ $self->{CAPACITY} = defined($lastSlot) ? $lastSlot : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $lastSlot ? : 0 0 0
159 }
160  
161 0 ▶sub byID {
Subroutine byID: not called CC=1 SCAR=6.9
Pod undocumented
162 0 my $class = shift;
163 0 my $id = shift;
164  
165 0 return $farm[$id];
166 }
167  
168 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
169 0 my $self = shift;
170  
171 0 return $self->{ID};
172 }
173  
174 0 ▶sub type {
Subroutine type: not called CC=3 SCAR=24.8
Pod undocumented
175 0 my $self = shift;
176  
177 0 ▶ $self->loadRobotDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
178 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
179 0 $self->{TYPE} = shift;
180 }
181 0 return $self->{TYPE};
182 }
183  
184 0 ▶sub host {
Subroutine host: not called CC=3 SCAR=24.8
Pod undocumented
185 0 my $self = shift;
186  
187 0 ▶ $self->loadRobotDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
188 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
189 0 $self->{CONTROLHOST} = shift;
190 }
191 0 return $self->{CONTROLHOST};
192 }
193  
194 0 ▶sub voldbHost {
Subroutine voldbHost: not called CC=3 SCAR=24.8
Pod undocumented
195 0 my $self = shift;
196  
197 0 ▶ $self->loadRobotDetail if (!defined($self->{DETAILED}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DETAILED"} 0 0 0
198 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
199 0 $self->{VOLDBHOST} = shift;
200 }
201 0 return $self->{VOLDBHOST};
202 }
203  
204 0 ▶sub controlDrive {
Subroutine controlDrive: not called CC=1 SCAR=6.9
Pod undocumented
205 0 my $self = shift;
206 0 my $drive = shift;
207  
208  
209 0 my $driveList = $self->{DRIVES};
210 0 push @$driveList, $drive;
211  
212 0 return $drive;
213 }
214  
215 0 ▶sub drives {
Subroutine drives: not called CC=1 SCAR=6.9
Pod undocumented
216 0 my $self = shift;
217  
218 0 my $driveList = $self->{DRIVES};
219 0 return @$driveList;
220 }
221  
222 #
223 # Robots are accessed through storage units. Every time a new robotic
224 # storage unit is defined, the robot in question is informed of this by
225 # a call to the known method.
226 # Without arguments a list of storage units using the robot is returned.
227 0 ▶sub known {
Subroutine known: not called CC=2 SCAR=17.9
Pod undocumented
228 0 my $self = shift;
229  
230 0 my $stuList = $self->{KNOWNTO};
231 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
232 0 my $stu = shift;
233 0 push @$stuList, $stu;
234 }
235 0 return @$stuList;
236 }
237  
238 0 ▶sub insert {
Subroutine insert: not called CC=3 SCAR=24.8
Pod undocumented
239 0 my $self = shift;
240 0 my $slotList = $self->{SLOTS};
241 0 my ($position, $volume) = @_;
242  
243 0 ▶ if (exists($$slotList{$position})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $slotList->{$position}) { } 0 0 0
244 0 ▶ if ($$slotList{$position} != $volume) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slotList->{$position} != $volume) { } 0 0 0
245 0 print STDERR "Slot $position in ".$self->id." already filled; no room for ".$volume->id."\n";
246 }
247 else {
248 }
249 }
250 else {
251 0 $$slotList{$position} = $volume;
252 }
253 0 return $$slotList{$position};
254 }
255  
256 0 ▶sub empty {
Subroutine empty: not called CC=2 SCAR=17.9
Pod undocumented
257 0 my $self = shift;
258 0 my $slotList = $self->{SLOTS};
259 0 my $position = shift;
260  
261 0 ▶ if (exists($$slotList{$position})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $slotList->{$position}) 0 0 0
262 0 my $volume = $$slotList{$position};
263 0 delete $$slotList{$position};
264  
265 0 $volume->robot(undef);
266 0 $volume->slot(undef);
267 }
268  
269 0 return undef;
270 }
271  
272 0 ▶sub nextEmptySlot {
Subroutine nextEmptySlot: not called CC=3 SCAR=24.8
Pod undocumented
273 0 my $self = shift;
274 0 my $slotList = $self->{SLOTS};
275  
276 0 for my $s (1..$self->capacity) {
277 0 ▶ return $s if (!exists($$slotList{$s}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $slotList->{$s} 0 0 0
278 }
279 0 return undef;
280 }
281  
282 0 ▶sub slot {
Subroutine slot: not called CC=2 SCAR=17.9
Pod undocumented
283 0 my $self = shift;
284 0 my $slotList = $self->{SLOTS};
285 0 my $position = shift;
286
287  
288 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
289 0 my $volume = shift;
290 0 return $self->insert($position, $volume);
291 }
292 0 return $$slotList{$position};
293 }
294  
295 0 ▶sub capacity {
Subroutine capacity: not called CC=2 SCAR=17.9
Pod undocumented
296 0 my $self = shift;
297  
298 0 ▶ if (!defined($self->{CAPACITY})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"CAPACITY"}) 0 0 0
299 0 $self->populate;
300 }
301  
302 0 return $self->{CAPACITY};
303 }
304  
305 0 ▶sub slotList {
Subroutine slotList: not called CC=3 SCAR=24.8
Pod undocumented
306 0 my $self = shift;
307 0 my $slotList = $self->{SLOTS};
308 0 my @list;
309  
310 #
311 # Undefined or unreachable robots have no capacity thus
312 # should result in completely empty lists
313 0 ▶ if (my $lastSlot = $self->capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lastSlot = $self->capacity) 0 0 0
314 # slot 0 is not used but PERL arrays default to 0 based indexing...
315 0 push @list, undef;
316 0 for my $s (1..$lastSlot) {
317 0 push @list, $$slotList{$s};
318 }
319 }
320  
321 0 return @list;
322 }
323  
324 0 ▶sub mediaList {
Subroutine mediaList: not called CC=1 SCAR=6.9
Pod undocumented
325 0 my $self = shift;
326 0 my $slotList = $self->{SLOTS};
327  
328 0 return (values %$slotList);
329 }
330  
331 0 ▶sub farm {
Subroutine farm: not called CC=1 SCAR=6.9
Pod undocumented
332 0 my $Class = shift;
333  
334 0 return (@farm);
335 }
336  
337 0 ▶sub updateInventory {
Subroutine updateInventory: not called CC=3 SCAR=24.8
Pod undocumented
338 0 my $self = shift;
339 0 my $importCAP = shift;
340  
341 0 ▶ NBU->cmd("vmupdate "." -rt ".$self->type." -rn ".$self->id." -rh ".$self->host->name
Branch: 1 branch
BranchTrueFalseTotal
defined $importCAP && $importCAP ? : 0 0 0
Condition0%0/3
defined $importCAP and $importCAP
!ll&&!rl&&r
000
MC/DC0%0/2
defined $importCAP and $importCAP
defined $importCAP $importCAP
Truth table0%0/3
A and B
A= defined $importCAPB= $importCAP
ABresult
0X0
100
111
342 ." -use_barcode_rules"
343 .((defined($importCAP) && $importCAP) ? " -empty_ie" : "")
344 , 0);
345  
346 0 $self->populate;
347 }
348  
349 1 1;
350  
351 #
352 # Try to get more detail on this robot.
353 # If the host to query is not specified, first look to the robot's
354 # host or else the local master server for this information
355 0 ▶sub loadRobotDetail {
Subroutine loadRobotDetail: not called CC=6 SCAR=37.4
Pod undocumented
356 0 my $self = shift;
357 0 my $server = shift;
358  
359 0 ▶ if (!defined($server)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $server) 0 0 0
360 0 my @masters = NBU->masters; $server = $masters[0];
361 }
362  
363 0 my $pipe = NBU->cmd("vmglob -h ".$server->name." -listall -java |");
364 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
365 0 ▶ next unless (/VMGLOB... robot /);
Branch: 1 branch
BranchTrueFalseTotal
unless /VMGLOB... robot / 0 0 0
366 0 chop;
367  
368 0 my($key, $d, $number, $serial, $host, $voldbHostName, $robotNumber, $na1, $type, $na2, $flags,
369 $wwName, $wwNameType, $inquiry, $libraryName, $vendorName, $controlHostName) =
370 split;
371  
372 # Any media server with drives controlled by this robot will generate an entry for this robot
373 # However, we only care about the entry from the host which is the controlling host.
374 0 ▶ next unless ($controlHostName eq "-");
Branch: 1 branch
BranchTrueFalseTotal
unless $controlHostName eq "-" 0 0 0
375  
376 0 ▶ if (my $robot = NBU::Robot->byID($robotNumber)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $robot = "NBU::Robot"->byID($robotNumber)) 0 0 0
377 0 $robot->{SERIALNUMBER} = $serial;
378 0 $robot->{VOLDBHOST} = NBU::Host->new($voldbHostName);
379 0 $robot->{CONTROLHOST} = NBU::Host->new($host);
380  
381 0 $robot->{DETAILED} = 1;
382 }
383 }
384 0 $self->{DETAILED} = 1;
385 }
386  
387 __END__
« script/nbutop.pl ↑ Summary lib/NBU/Schedule.pm »