lib/NBU/StorageUnit.pm

filter: Statementstmt 22.0% 28 / 127 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 30.4% 7 / 23 Podpod 0.0% 0 / 16 totaltotal 16.0% 35 / 218 CC 28 SCAR 34.5
CC
28
Cov
16%
list
72.0
populate
56.0
byLabel
56.0
CRAP 31.4
« lib/NBU.pm ↑ Summary script/volume-list.pl »
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::StorageUnit;
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 ▶use NBU::Media;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 $VERSION = do { my @r=(q$Revision: 1.21 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
18 1 @ISA = qw();
19 1 @EXPORT = qw();
20 1 @EXPORT_OK = qw();
21 1 %EXPORT_TAGS = qw();
22 }
23  
24 1 my %stuList;
25 my %populated;
26  
27 1 my %types = (
28 1 => "Disk",
29 2 => "Media Manager",
30 3 => "NDMP",
31 );
32  
33 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
34 0 my $proto = shift;
35 0 my $stu = {};
36  
37 0 bless $stu, $proto;
38  
39 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
40 0 $stu->{LABEL} = shift;
41 0 my $type;
42 0 ▶ if (@_ && exists($types{$type = shift})) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and exists $types{$type = shift()}) { } 0 0 0
Condition0%0/3
@_ and exists $types{$type = shift()}
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and exists $types{$type = shift()}
@_ exists $types{$type = shift()}
Truth table0%0/3
A and B
A= @_B= exists $types{$type = shift()}
ABresult
0X0
100
111
43 0 $stu->{TYPE} = $types{$type};
44 }
45 else {
46 0 $stu->{TYPE} = $type;
47 }
48 }
49  
50 0 $stuList{$stu->{LABEL}} = $stu;
51 0 return $stu;
52 }
53  
54 0 ▶sub populate {
Subroutine populate: not called CC=7 SCAR=40.3
Pod undocumented
55 0 my $proto = shift;
56 0 my $targetMaster = shift;
57  
58 0 ▶ if (!defined($targetMaster)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $targetMaster) 0 0 0
59 0 my @masters = NBU->masters; $targetMaster = $masters[0];
60 }
61  
62 0 $populated{$targetMaster->name} = 0;
63 0 my $pipe = NBU->cmd("bpstulist -M ".$targetMaster->name." |");
64 0 ▶ while (<$pipe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $pipe)) 0 0 0
65 0 my ($label, $type, $hostName,
66 $robotType, $robotNumber, $density,
67 $count,
68 $maxFragmentSize,
69 $path,
70 $onDemand,
71 $maxMPXperDrive,
72 $ndmpAttachHostName,
73 ) = split;
74  
75 0 my $stu;
76 0 $stu = NBU::StorageUnit->new($label);
77  
78 0 $stu->{TYPE} = $type;
79  
80 0 $stu->{MASTER} = $targetMaster;
81 0 ▶ if ($hostName !~ /_STU_NO_DEV_HOST/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($hostName =~ /_STU_NO_DEV_HOST/) 0 0 0
82 0 my $mm = $stu->{HOST} = NBU::Host->new($hostName);
83  
84 0 $mm->mediaManager(1);
85  
86 #
87 # If this is a robot storage unit, we inform the robot so it can know which storage units
88 # make use of its services.
89 0 ▶ if (defined(my $robot = $stu->{ROBOT} = NBU::Robot->new($robotNumber, $robotType, undef))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $robot = $stu->{'ROBOT'} = 'NBU::Robot'->new($robotNumber, $robotType, undef))) { } 0 0 0
90 0 $mm->roboticMediaManager(1);
91 0 $robot->known($stu);
92 }
93 else {
94 }
95 }
96  
97 0 ▶ if ($type == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
98 0 $stu->{CONCURRENTJOBS} = $count;
99 0 $stu->{PATH} = $path;
100 }
101 elsif ($type == 2) {
102 0 $stu->{DRIVECOUNT} = $count;
103 0 $stu->{DENSITY} = $density;
104 }
105  
106 0 $stu->{ONDEMAND} = $onDemand;
107 0 $stu->{MAXMPX} = $maxMPXperDrive;
108 0 $stu->{MAXFRAGSIZE} = $maxFragmentSize;
109  
110 0 $populated{$targetMaster->name} += 0;
111 }
112 0 close($pipe);
113  
114 }
115  
116 0 ▶sub list {
Subroutine list: not called CC=8 SCAR=42.8
Pod undocumented
117 0 my $proto = shift;
118 0 my $targetMaster = shift;
119  
120 0 ▶ if (!defined($targetMaster)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $targetMaster) { } 0 0 0
121 0 for my $master (NBU->masters) {
122 0 ▶ $proto->populate($master) if (!exists($populated{$master->name}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $populated{$master->name} 0 0 0
123 }
124 0 return (values %stuList);
125 }
126 else {
127 0 ▶ $proto->populate($targetMaster) if (!exists($populated{$targetMaster->name}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $populated{$targetMaster->name} 0 0 0
128 0 my @list;
129 0 for my $su (values %stuList) {
130 0 ▶ push @list, $su if (defined($su->master) && ($su->master == $targetMaster));
Branch: 1 branch
BranchTrueFalseTotal
if defined $su->master and $su->master == $targetMaster 0 0 0
Condition0%0/3
defined $su->master and $su->master == $targetMaster
!ll&&!rl&&r
000
MC/DC0%0/2
defined $su->master and $su->master == $targetMaster
defined $su->master $su->master == $targetMaster
Truth table0%0/3
A and B
A= defined $su->masterB= $su->master == $targetMaster
ABresult
0X0
100
111
131 }
132 0 return (@list);
133 }
134 }
135  
136 0 ▶sub byLabel {
Subroutine byLabel: not called CC=7 SCAR=40.3
Pod undocumented
137 0 my $proto = shift;
138 0 my $label = shift;
139 0 my $targetMaster = shift;
140  
141 0 ▶ return $stuList{$label} if (exists($stuList{$label}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $stuList{$label} 0 0 0
142  
143 0 ▶ if (!defined($targetMaster)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $targetMaster) { } 0 0 0
144 0 for my $master (NBU->masters) {
145 0 ▶ $proto->populate($master) if (!exists($populated{$master->name}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $populated{$master->name} 0 0 0
146 }
147 }
148 else {
149 0 ▶ $proto->populate($targetMaster) if (!exists($populated{$targetMaster->name}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $populated{$targetMaster->name} 0 0 0
150 }
151  
152 0 ▶ if (!exists($stuList{$label})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $stuList{$label}) 0 0 0
153 0 my $stu = $proto->new($label);
154 0 $stu->{MASTER} = $targetMaster;
155 }
156 0 return $stuList{$label};
157 }
158  
159 0 ▶sub master {
Subroutine master: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my $self = shift;
161  
162 0 return $self->{MASTER};
163 }
164  
165 0 ▶sub host {
Subroutine host: not called CC=1 SCAR=6.9
Pod undocumented
166 0 my $self = shift;
167  
168 0 return $self->{HOST};
169 }
170  
171 #
172 # Return a list of all media servers known to the target master. If no
173 # target master is supplied, return all known media servers.
174 0 ▶sub mediaServers {
Subroutine mediaServers: not called CC=4 SCAR=30.0
Pod undocumented
175 0 my $proto = shift;
176 0 my $targetMaster = shift;
177  
178  
179 0 my %names;
180 my @list;
181 0 for my $su ($proto->list($targetMaster)) {
182 0 ▶ next if (!defined($su->host));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $su->host 0 0 0
183  
184 0 ▶ if (!exists($names{$su->host->name})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $names{$su->host->name}) 0 0 0
185 0 push @list, $su->host;
186 }
187 0 $names{$su->host->name} += 1;
188 }
189  
190 0 return (@list);
191 }
192  
193 0 ▶sub type {
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
194 0 my $self = shift;
195  
196 0 return $self->{TYPE};
197 }
198  
199 0 ▶sub path {
Subroutine path: not called CC=2 SCAR=17.9
Pod undocumented
200 0 my $self = shift;
201  
202 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
203 0 my $path = shift;
204 0 $self->{PATH} = $path;
205 }
206  
207 0 return $self->{PATH};
208 }
209  
210 0 ▶sub density {
Subroutine density: not called CC=1 SCAR=6.9
Pod undocumented
211 0 my $self = shift;
212  
213 0 return $NBU::Media::densities{$self->{DENSITY}};
214 }
215  
216 0 ▶sub driveCount {
Subroutine driveCount: not called CC=1 SCAR=6.9
Pod undocumented
217 0 my $self = shift;
218  
219 0 return $self->{DRIVECOUNT};
220 }
221  
222 0 ▶sub label {
Subroutine label: not called CC=1 SCAR=6.9
Pod undocumented
223 0 my $self = shift;
224  
225 0 return $self->{LABEL};
226 }
227  
228 0 ▶sub robot {
Subroutine robot: not called CC=1 SCAR=6.9
Pod undocumented
229 0 my $self = shift;
230  
231 0 return $self->{ROBOT};
232 }
233  
234 0 ▶sub onDemand {
Subroutine onDemand: not called CC=1 SCAR=6.9
Pod undocumented
235 0 my $self = shift;
236  
237 0 return $self->{ONDEMAND};
238 }
239  
240 #
241 # NBU stores the maximum number of multiplexed jobs per storage unit but this routine
242 # maps the degenerate case to 0 so a simple test for multi-plexing can be done on its
243 # return value
244 0 ▶sub mpx {
Subroutine mpx: not called CC=2 SCAR=17.9
Pod undocumented
245 0 my $self = shift;
246  
247 0 ▶ if ($self->{MAXPX} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'MAXPX'} == 1) { } 0 0 0
248 0 return 0;
249 }
250 else {
251 0 return $self->{MAXMPX};
252 }
253 }
254  
255 0 ▶sub maximumFragmentSize {
Subroutine maximumFragmentSize: not called CC=1 SCAR=6.9
Pod undocumented
256 0 my $self = shift;
257  
258 0 return $self->{MAXFRAGSIZE};
259 }
260  
261 1 1;
262 __END__
« lib/NBU.pm ↑ Summary script/volume-list.pl »