Admin.pm

filter: Statementstmt 8.0% 23 / 285 Branchbran 2.7% 4 / 144 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 11.7% 6 / 51 Podpod 0.0% 0 / 41 totaltotal 5.9% 33 / 555 CC 90 SCAR 30.8
CC
90
Cov
6%
update_device
90.0
slave_modify
56.0
_set_slave_keys
42.0
CRAP 21.8
« Backend.pm ↑ Summary
1 package MogileFS::Admin;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MogileFS::Backend;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use fields qw(backend readonly);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.8
Pod undocumented
8 1 my MogileFS::Admin $self = shift;
9 1 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
10  
11 1 my %args = @_;
12  
13 1 ▶ $self->{readonly} = $args{readonly} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$args{'readonly'} ? : 0 1 1
14 1 my %backend_args = ( hosts => $args{hosts} );
15 1 ▶ $backend_args{timeout} = $args{timeout} if $args{timeout};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"timeout"} 0 1 1
16 1 ▶ $self->{backend} = MogileFS::Backend->new( %backend_args )
Branch: 1 branch
BranchTrueFalseTotal
$self->{"backend"} = "MogileFS::Backend"->new(%backend_args) or _fail("couldn't instantiate MogileFS::Backend") 1 0 1
17 or _fail("couldn't instantiate MogileFS::Backend");
18  
19 1 return $self;
20 }
21  
22 0 ▶sub readonly {
Subroutine readonly: not called CC=3 SCAR=24.8
Pod undocumented
23 0 my MogileFS::Admin $self = shift;
24 0 ▶ return $self->{readonly} = $_[0] ? 1 : 0 if @_;
Branch: 2 branches
BranchTrueFalseTotal
if @_ 0 0 0
$_[0] ? : 0 0 0
25 0 return $self->{readonly};
26 }
27  
28 0 ▶sub replicate_now {
Subroutine replicate_now: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my MogileFS::Admin $self = shift;
30  
31 0 ▶ my $res = $self->{backend}->do_request("replicate_now", {})
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("replicate_now", {}) or return undef 0 0 0
32 or return undef;
33 0 return 1;
34 }
35  
36 0 ▶sub get_hosts {
Subroutine get_hosts: not called CC=4 SCAR=30.0
Pod undocumented
37 0 my MogileFS::Admin $self = shift;
38 0 my $hostid = shift;
39  
40 0 ▶ my $args = $hostid ? { hostid => $hostid } : {};
Branch: 1 branch
BranchTrueFalseTotal
$hostid ? : 0 0 0
41 0 ▶ my $res = $self->{backend}->do_request("get_hosts", $args)
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("get_hosts", $args) or return undef 0 0 0
42 or return undef;
43  
44 0 my @ret = ();
45 0 foreach my $ct (1..$res->{hosts}) {
46 0 push @ret, { map { $_ => $res->{"host${ct}_$_"} }
47 qw(hostid status hostname hostip http_port http_get_port altip altmask) };
48 }
49  
50 0 return \@ret;
51 }
52  
53 0 ▶sub get_devices {
Subroutine get_devices: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my MogileFS::Admin $self = shift;
55 0 my $devid = shift;
56  
57 0 ▶ my $args = $devid ? { devid => $devid } : {};
Branch: 1 branch
BranchTrueFalseTotal
$devid ? : 0 0 0
58 0 ▶ my $res = $self->{backend}->do_request("get_devices", $args)
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("get_devices", $args) or return undef 0 0 0
59 or return undef;
60  
61 0 my @ret = ();
62 0 foreach my $ct (1..$res->{devices}) {
63 0 push @ret, { (map { $_ => $res->{"dev${ct}_$_"} } qw(devid hostid status observed_state utilization)),
64 0 (map { $_ => $res->{"dev${ct}_$_"}+0 } qw(mb_total mb_used weight)) };
65 }
66  
67 0 return \@ret;
68  
69 }
70  
71 # get raw information about fids, for enumerating the dataset
72 # ( $from_fid, $count )
73 # returns:
74 # { fid => { hashref with keys: domain, class, devcount, length, key } }
75 0 ▶sub list_fids {
Subroutine list_fids: not called CC=3 SCAR=24.8
Pod undocumented
76 0 my MogileFS::Admin $self = shift;
77 0 my ($fromfid, $count) = @_;
78  
79 0 ▶ my $res = $self->{backend}->do_request('list_fids', { from => $fromfid, to => $count })
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("list_fids", {"from", $fromfid, "to", $count}) or return undef 0 0 0
80 or return undef;
81  
82 0 my $ret = {};
83 0 foreach my $i (1..$res->{fid_count}) {
84 $ret->{$res->{"fid_${i}_fid"}} = {
85 key => $res->{"fid_${i}_key"},
86 length => $res->{"fid_${i}_length"},
87 class => $res->{"fid_${i}_class"},
88 domain => $res->{"fid_${i}_domain"},
89 0 devcount => $res->{"fid_${i}_devcount"},
90 };
91 }
92 0 return $ret;
93 }
94  
95 0 ▶sub clear_cache {
Subroutine clear_cache: not called CC=3 SCAR=24.8
Pod undocumented
96 0 my MogileFS::Admin $self = shift;
97 # do the request, default to request all stats if they didn't specify any
98 0 ▶ push @_, 'all' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
99 0 ▶ my $res = $self->{backend}->do_request("clear_cache", { map { $_ => 1 } @_ })
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("clear_cache", {map({$_, 1;} @_)}) or return undef 0 0 0
100 or return undef;
101 0 return 1;
102 }
103  
104 # get a hashref of the domains we know about in the format of
105 # { domain_name => { class_name => mindevcount, class_name => mindevcount, ... }, ... }
106 1 ▶sub get_domains {
Subroutine get_domains: called CC=5 SCAR=30.0
Pod undocumented
107 1 my MogileFS::Admin $self = shift;
108  
109 1 ▶ my $res = $self->{backend}->do_request("get_domains", {})
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("get_domains", {}) or return undef 0 0 0
110 or return undef;
111  
112 0 my $ret = {};
113 0 foreach my $i (1..$res->{domains}) {
114 $ret->{$res->{"domain$i"}} = {
115 map {
116 $res->{"domain${i}class${_}name"} =>
117 { mindevcount => $res->{"domain${i}class${_}mindevcount"},
118 replpolicy => $res->{"domain${i}class${_}replpolicy"} || '',
119 0 ▶ hashtype => $res->{"domain${i}class${_}hashtype"} || '',
Condition0%0/4
$$res{"domain${i}class${_}replpolicy"} || ''
l!l
00
$$res{"domain${i}class${_}hashtype"} || ''
l!l
00
MC/DC0%0/1
$$res{"domain${i}class${_}replpolicy"} || ''
$$res{"domain${i}class${_}replpolicy"}
MC/DC0%0/1
$$res{"domain${i}class${_}hashtype"} || ''
$$res{"domain${i}class${_}hashtype"}
Truth table0%0/2
A
A= $$res{"domain${i}class${_}replpolicy"}
Aresult
11
00
Truth table0%0/2
A
A= $$res{"domain${i}class${_}hashtype"}
Aresult
11
00
120 }
121 0 } (1..$res->{"domain${i}classes"})
122 };
123 }
124  
125 0 return $ret;
126 }
127  
128 # create a new domain
129 0 ▶sub create_domain {
Subroutine create_domain: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my MogileFS::Admin $self = shift;
131 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
132  
133 0 my $domain = shift;
134  
135 0 my $res = $self->{backend}->do_request("create_domain", { domain => $domain });
136 0 ▶ return undef unless $res->{domain} eq $domain;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"domain"} eq $domain 0 0 0
137  
138 0 return 1;
139 }
140  
141 # delete a domain
142 0 ▶sub delete_domain {
Subroutine delete_domain: not called CC=3 SCAR=24.8
Pod undocumented
143 0 my MogileFS::Admin $self = shift;
144 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
145  
146 0 my $domain = shift;
147  
148 0 ▶ $self->{backend}->do_request("delete_domain", { domain => $domain })
Branch: 1 branch
BranchTrueFalseTotal
$self->{"backend"}->do_request("delete_domain", {"domain", $domain}) or return undef 0 0 0
149 or return undef;
150  
151 0 return 1;
152 }
153  
154 # create a class within a domain
155 0 ▶sub create_class {
Subroutine create_class: not called CC=1 SCAR=6.9
Pod undocumented
156 0 my MogileFS::Admin $self = shift;
157  
158 # wrapper around _mod_class(create)
159 0 return $self->_mod_class(@_, 'create');
160 }
161  
162  
163 # update a class's mindevcount within a domain
164 0 ▶sub update_class {
Subroutine update_class: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my MogileFS::Admin $self = shift;
166  
167 # wrapper around _mod_class(update)
168 0 return $self->_mod_class(@_, 'update');
169 }
170  
171 # delete a class
172 0 ▶sub delete_class {
Subroutine delete_class: not called CC=3 SCAR=24.8
Pod undocumented
173 0 my MogileFS::Admin $self = shift;
174 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
175  
176 0 my ($domain, $class) = @_;
177  
178 0 ▶ $self->{backend}->do_request("delete_class", {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"backend"}->do_request("delete_class", {"domain", $domain, "class", $class}) or return undef 0 0 0
179 domain => $domain,
180 class => $class,
181 }) or return undef;
182  
183 0 return 1;
184 }
185  
186  
187 # create a host
188 0 ▶sub create_host {
Subroutine create_host: not called CC=5 SCAR=34.0
Pod undocumented
189 0 my MogileFS::Admin $self = shift;
190 0 my $host = shift;
191 0 ▶ return undef unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
192  
193 0 my $args = shift;
194 0 ▶ return undef unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 0 0
195 0 ▶ return undef unless $args->{ip} && $args->{port};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"ip"} and $args->{"port"} 0 0 0
Condition0%0/3
$args->{"ip"} and $args->{"port"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"ip"} and $args->{"port"}
$args->{"ip"} $args->{"port"}
Truth table0%0/3
A and B
A= $args->{"ip"}B= $args->{"port"}
ABresult
0X0
100
111
196  
197 0 return $self->_mod_host($host, $args, 'create');
198 }
199  
200 # edit a host
201 0 ▶sub update_host {
Subroutine update_host: not called CC=3 SCAR=24.8
Pod undocumented
202 0 my MogileFS::Admin $self = shift;
203 0 my $host = shift;
204 0 ▶ return undef unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
205  
206 0 my $args = shift;
207 0 ▶ return undef unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 0 0
208  
209 0 return $self->_mod_host($host, $args, 'update');
210 }
211  
212 # delete a host
213 0 ▶sub delete_host {
Subroutine delete_host: not called CC=4 SCAR=30.0
Pod undocumented
214 0 my MogileFS::Admin $self = shift;
215 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
216  
217 0 my $host = shift;
218 0 ▶ return undef unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
219  
220 0 ▶ $self->{backend}->do_request("delete_host", { host => $host })
Branch: 1 branch
BranchTrueFalseTotal
$self->{"backend"}->do_request("delete_host", {"host", $host}) or return undef 0 0 0
221 or return undef;
222 0 return 1;
223 }
224  
225 # create a new device
226 0 ▶sub create_device {
Subroutine create_device: not called CC=3 SCAR=24.8
Pod undocumented
227 0 my MogileFS::Admin $self = shift;
228 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
229  
230 0 my (%opts) = @_; #hostname or hostid, devid, state (optional)
231  
232 0 ▶ my $res = $self->{backend}->do_request("create_device", \%opts)
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("create_device", \%opts) or return undef 0 0 0
233 or return undef;
234  
235 0 return 1;
236 }
237  
238 # edit a device
239 0 ▶sub update_device {
Subroutine update_device: not called CC=9 SCAR=45.0
Pod undocumented
240 0 my MogileFS::Admin $self = shift;
241 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
242 0 my $host = shift;
243 0 my $device = shift;
244 0 ▶ return undef unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
245 0 ▶ return undef unless $device;
Branch: 1 branch
BranchTrueFalseTotal
unless $device 0 0 0
246  
247 0 my $args = shift;
248 0 ▶ return undef unless ref $args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 0 0
249  
250 # TODO: provide a native update_device in the MogileFS::Admin command set.
251 0 ▶ if ($args->{status}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"status"}) 0 0 0
252 0 ▶ $self->change_device_state($host, $device, $args->{status}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->change_device_state($host, $device, $args->{"status"}) or return undef 0 0 0
253 }
254 0 ▶ if ($args->{weight}){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"weight"}) 0 0 0
255 0 ▶ $self->change_device_weight($host, $device, $args->{weight}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->change_device_weight($host, $device, $args->{"weight"}) or return undef 0 0 0
256 }
257  
258 0 return 1;
259 }
260  
261 # change the state of a device; pass in the hostname of the host the
262 # device is located on, the device id number, and the state you want
263 # the host to be set to. returns 1 on success, undef on error.
264 0 ▶sub change_device_state {
Subroutine change_device_state: not called CC=3 SCAR=24.8
Pod undocumented
265 0 my MogileFS::Admin $self = shift;
266 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
267  
268 0 my ($host, $device, $state) = @_;
269  
270 0 ▶ my $res = $self->{backend}->do_request("set_state", {
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("set_state", {"host", $host, "device", $device, "state", $state}) or return undef 0 0 0
271 host => $host,
272 device => $device,
273 state => $state,
274 }) or return undef;
275  
276 0 return 1;
277 }
278  
279 # change the weight of a device by passing in the hostname and
280 # the device id
281 0 ▶sub change_device_weight {
Subroutine change_device_weight: not called CC=3 SCAR=24.8
Pod undocumented
282 0 my MogileFS::Admin $self = shift;
283 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
284  
285 0 my ($host, $device, $weight) = @_;
286 0 $weight += 0;
287  
288 0 ▶ my $res = $self->{backend}->do_request("set_weight", {
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"backend"}->do_request("set_weight", {"host", $host, "device", $device, "weight", $weight}) or return undef 0 0 0
289 host => $host,
290 device => $device,
291 weight => $weight,
292 }) or return undef;
293  
294 0 return 1;
295 }
296  
297 # returns a hash (list) of key => weight
298 0 ▶sub _get_slave_keys {
Subroutine _get_slave_keys: not called CC=5 SCAR=34.0
299 0 my MogileFS::Admin $self = shift;
300 0 my $backend = $self->{backend};
301  
302 0 my $keys_res = $backend->do_request("server_setting", {
303 key => "slave_keys",
304 });
305  
306 0 ▶ return () unless $keys_res;
Branch: 1 branch
BranchTrueFalseTotal
unless $keys_res 0 0 0
307  
308 0 my %slave_keys;
309  
310 0 foreach my $slave (split /,/, $keys_res->{value}) {
311 0 my ($key, $weight) = split /=/, $slave, 2;
312  
313 # Weight can be zero, so don't default to 1 if it's defined and longer than 0 characters.
314 0 ▶ unless (defined $weight && length $weight) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $weight and length $weight) 0 0 0
Condition0%0/3
defined $weight and length $weight
!ll&&!rl&&r
000
MC/DC0%0/2
defined $weight and length $weight
defined $weight length $weight
Truth table0%0/3
A and B
A= defined $weightB= length $weight
ABresult
0X0
100
111
315 0 $weight = 1;
316 }
317  
318 0 $slave_keys{$key} = $weight;
319 }
320  
321 0 return %slave_keys;
322 }
323  
324 # returns a hash (list) of key => options
325 0 ▶sub _set_slave_keys {
Subroutine _set_slave_keys: not called CC=6 SCAR=37.4
326 0 my MogileFS::Admin $self = shift;
327 0 my $backend = $self->{backend};
328  
329 0 my %slave_keys = @_;
330  
331 0 my @keys;
332  
333 0 foreach my $key (keys %slave_keys) {
334 0 my $weight = $slave_keys{$key};
335 0 ▶ if (defined $weight && length $weight && $weight != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $weight and length $weight and $weight != 1) 0 0 0
Condition0%0/6
defined $weight and length $weight and $weight != 1
!ll&&!rl&&r
000
defined $weight and length $weight
!ll&&!rl&&r
000
MC/DC0%0/3
defined $weight and length $weight and $weight != 1
defined $weight length $weight $weight != 1
Truth table0%0/4
A and B and C
A= defined $weightB= length $weightC= $weight != 1
ABCresult
0XX0
10X0
1100
1111
336 0 $key .= "=$weight";
337 }
338 0 push @keys, $key;
339 }
340  
341 0 my $keys_res = $backend->do_request("set_server_setting", {
342 key => "slave_keys",
343 value => join(',', @keys),
344 });
345  
346 0 ▶ return 0 unless $keys_res;
Branch: 1 branch
BranchTrueFalseTotal
unless $keys_res 0 0 0
347 0 return 1;
348 }
349  
350 # returns a hashref of key => [dsn, username, password] specifying slave nodes which can be connected to.
351 0 ▶sub slave_list {
Subroutine slave_list: not called CC=3 SCAR=24.8
Pod undocumented
352 0 my MogileFS::Admin $self = shift;
353  
354 0 my $backend = $self->{backend};
355  
356 0 my %slave_keys = $self->_get_slave_keys;
357 0 my %return;
358  
359 0 foreach my $key (keys %slave_keys) {
360 0 my $slave_res = $backend->do_request("server_setting", {
361 key => "slave_$key",
362 });
363 0 ▶ next unless $slave_res;
Branch: 1 branch
BranchTrueFalseTotal
unless $slave_res 0 0 0
364 0 my ($dsn, $username, $password) = split /\|/, $slave_res->{value};
365 0 $return{$key} = [$dsn, $username, $password];
366 }
367  
368 0 return \%return;
369 }
370  
371 0 ▶sub slave_add {
Subroutine slave_add: not called CC=3 SCAR=24.8
Pod undocumented
372 0 my MogileFS::Admin $self = shift;
373 0 my ($key, $dsn, $username, $password) = @_;
374  
375 0 my $backend = $self->{backend};
376  
377 0 my %slave_keys = $self->_get_slave_keys;
378  
379 0 ▶ if (exists $slave_keys{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $slave_keys{$key}) 0 0 0
380 0 return 0;
381 }
382  
383 0 ▶ my $res = $backend->do_request("set_server_setting", {
Branch: 1 branch
BranchTrueFalseTotal
my $res = $backend->do_request("set_server_setting", {"key", "slave_$key", "value", join("|", $dsn, $username, $password)}) or return undef 0 0 0
384 key => "slave_$key",
385 value => join('|', $dsn, $username, $password),
386 }) or return undef;
387  
388 0 $slave_keys{$key} = undef;
389  
390 0 $self->_set_slave_keys(%slave_keys);
391  
392 0 return 1;
393 }
394  
395 0 ▶sub slave_modify {
Subroutine slave_modify: not called CC=7 SCAR=40.3
Pod undocumented
396 0 my MogileFS::Admin $self = shift;
397 0 my $key = shift;
398 0 my %opts = @_;
399  
400 0 my $backend = $self->{backend};
401  
402 0 my %slave_keys = $self->_get_slave_keys;
403  
404 0 ▶ unless (exists $slave_keys{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $slave_keys{$key}) 0 0 0
405 0 return 0;
406 }
407  
408 0 ▶ my $get_res = $backend->do_request("server_setting", {
Branch: 1 branch
BranchTrueFalseTotal
my $get_res = $backend->do_request("server_setting", {"key", "slave_$key"}) or return undef 0 0 0
409 key => "slave_$key",
410 }) or return undef;
411  
412 0 my ($dsn, $username, $password) = split /\|/, $get_res->{value};
413  
414 0 ▶ $dsn = $opts{dsn} if exists $opts{dsn};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"dsn"} 0 0 0
415 0 ▶ $username = $opts{username} if exists $opts{username};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"username"} 0 0 0
416 0 ▶ $password = $opts{password} if exists $opts{password};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"password"} 0 0 0
417  
418 0 ▶ my $set_res = $backend->do_request("set_server_setting", {
Branch: 1 branch
BranchTrueFalseTotal
my $set_res = $backend->do_request("set_server_setting", {"key", "slave_$key", "value", join("|", $dsn, $username, $password)}) or return undef 0 0 0
419 key => "slave_$key",
420 value => join('|', $dsn, $username, $password),
421 }) or return undef;
422  
423 0 return 1;
424 }
425  
426 0 ▶sub slave_delete {
Subroutine slave_delete: not called CC=3 SCAR=24.8
Pod undocumented
427 0 my MogileFS::Admin $self = shift;
428 0 my $key = shift;
429  
430 0 my $backend = $self->{backend};
431  
432 0 my %slave_keys = $self->_get_slave_keys;
433  
434 0 ▶ unless (exists $slave_keys{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $slave_keys{$key}) 0 0 0
435 0 return 0;
436 }
437  
438 0 ▶ my $res = $backend->do_request("set_server_setting", {
Branch: 1 branch
BranchTrueFalseTotal
my $res = $backend->do_request("set_server_setting", {"key", "slave_$key", "value", undef}) or return undef 0 0 0
439 key => "slave_$key",
440 value => undef,
441 }) or return undef;
442  
443 0 delete $slave_keys{$key};
444  
445 0 $self->_set_slave_keys(%slave_keys);
446  
447 0 return 1;
448 }
449  
450 0 ▶sub fsck_start {
Subroutine fsck_start: not called CC=1 SCAR=6.9
Pod undocumented
451 0 my MogileFS::Admin $self = shift;
452 0 return $self->{backend}->do_request("fsck_start", {});
453 }
454  
455 0 ▶sub fsck_stop {
Subroutine fsck_stop: not called CC=1 SCAR=6.9
Pod undocumented
456 0 my MogileFS::Admin $self = shift;
457 0 return $self->{backend}->do_request("fsck_stop", {});
458 }
459  
460 0 ▶sub fsck_reset {
Subroutine fsck_reset: not called CC=2 SCAR=17.9
Pod undocumented
461 0 my MogileFS::Admin $self = shift;
462 0 my %opts = @_;
463 0 my $polonly = delete $opts{policy_only};
464 0 my $startpos = delete $opts{startpos};
465 0 ▶ Carp::croak("Unknown options: ". join(", ", keys %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 0 0 0
466 0 return $self->{backend}->do_request("fsck_reset", {
467 policy_only => $polonly,
468 startpos => $startpos,
469 });
470 }
471  
472 0 ▶sub fsck_clearlog {
Subroutine fsck_clearlog: not called CC=1 SCAR=6.9
Pod undocumented
473 0 my MogileFS::Admin $self = shift;
474 0 return $self->{backend}->do_request("fsck_clearlog", {});
475 }
476  
477 0 ▶sub fsck_status {
Subroutine fsck_status: not called CC=1 SCAR=6.9
Pod undocumented
478 0 my MogileFS::Admin $self = shift;
479 0 return $self->{backend}->do_request("fsck_status", {});
480 }
481  
482 0 ▶sub fsck_log_rows {
Subroutine fsck_log_rows: not called CC=4 SCAR=30.0
Pod undocumented
483 0 my MogileFS::Admin $self = shift;
484 0 my %args = @_;
485 0 my $after = delete $args{after_logid};
486 0 ▶ die if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 0 0
487  
488 0 my $ret = $self->{backend}->do_request("fsck_getlog", {
489 after_logid => $after,
490 });
491 0 my @ret;
492 0 ▶ for (my $i = 1; $i <= $ret->{row_count}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $ret->{"row_count"}) 0 0 0
493 0 my $rec = {};
494 0 foreach my $k (qw(logid utime fid evcode devid)) {
495 0 $rec->{$k} = $ret->{"row_${i}_$k"};
496 }
497 0 push @ret, $rec;
498 }
499 0 return @ret;
500 }
501  
502 0 ▶sub set_server_setting {
Subroutine set_server_setting: not called CC=2 SCAR=17.9
Pod undocumented
503 0 my MogileFS::Admin $self = shift;
504 0 my ($key, $val) = @_;
505 0 my $res = $self->{backend}->do_request("set_server_setting", {
506 key => $key,
507 value => $val,
508 });
509 0 ▶ return 0 unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
510 0 return 1;
511 }
512  
513 0 ▶sub server_settings {
Subroutine server_settings: not called CC=3 SCAR=24.8
Pod undocumented
514 0 my MogileFS::Admin $self = shift;
515 0 my ($key, $val) = @_;
516 0 my $res = $self->{backend}->do_request("server_settings", {});
517 0 ▶ return 0 unless $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
518 0 my $ret = {};
519 0 ▶ for (my $i = 1; $i <= $res->{key_count}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $res->{"key_count"}) 0 0 0
520 0 $ret->{$res->{"key_$i"}} = $res->{"value_$i"};
521 }
522 0 return $ret;
523 }
524  
525 0 ▶sub rebalance_status {
Subroutine rebalance_status: not called CC=1 SCAR=6.9
Pod undocumented
526 0 my MogileFS::Admin $self = shift;
527 0 return $self->{backend}->do_request("rebalance_status", {});
528 }
529  
530 0 ▶sub rebalance_start {
Subroutine rebalance_start: not called CC=1 SCAR=6.9
Pod undocumented
531 0 my MogileFS::Admin $self = shift;
532 0 return $self->{backend}->do_request("rebalance_start", {});
533 }
534  
535 0 ▶sub rebalance_test {
Subroutine rebalance_test: not called CC=1 SCAR=6.9
Pod undocumented
536 0 my MogileFS::Admin $self = shift;
537 0 return $self->{backend}->do_request("rebalance_test", {});
538 }
539  
540 0 ▶sub rebalance_stop {
Subroutine rebalance_stop: not called CC=1 SCAR=6.9
Pod undocumented
541 0 my MogileFS::Admin $self = shift;
542 0 return $self->{backend}->do_request("rebalance_stop", {});
543 }
544  
545 0 ▶sub rebalance_reset {
Subroutine rebalance_reset: not called CC=1 SCAR=6.9
Pod undocumented
546 0 my MogileFS::Admin $self = shift;
547 0 return $self->{backend}->do_request("rebalance_reset", {});
548 }
549  
550 0 ▶sub rebalance_set_policy {
Subroutine rebalance_set_policy: not called CC=1 SCAR=6.9
Pod undocumented
551 0 my MogileFS::Admin $self = shift;
552  
553 0 my $policy = shift;
554 0 return $self->{backend}->do_request("rebalance_set_policy", {
555 policy => $policy,
556 });
557 }
558  
559 ################################################################################
560 # MogileFS::Admin class methods
561 #
562  
563 0 ▶sub _fail {
Subroutine _fail: not called CC=1 SCAR=6.9
564 0 croak "MogileFS::Admin: $_[0]";
565 }
566  
567 # FIXME: is this used?
568 0 ▶sub _debug {
Subroutine _debug: not called CC=2 SCAR=17.9
569 0 ▶ return 1 unless $MogileFS::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $MogileFS::DEBUG 0 0 0
570 0 my $msg = shift;
571 0 my $ref = shift;
572 0 chomp $msg;
573 0 eval "use Data::Dumper;";
574 0 print STDERR "$msg\n" . Dumper($ref) . "\n";
575 0 return 1;
576 }
577  
578 # modify a class within a domain
579 0 ▶sub _mod_class {
Subroutine _mod_class: not called CC=4 SCAR=30.0
580 0 my MogileFS::Admin $self = shift;
581 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
582  
583 0 my ($domain, $class, $args, $verb) = @_;
584 0 ▶ $verb ||= 'create';
Condition0%0/2
$verb ||= "create"
l!l
00
MC/DC0%0/1
$verb ||= "create"
$verb
Truth table0%0/2
A
A= $verb
Aresult
11
00
585  
586 0 my $res = $self->{backend}->do_request("${verb}_class", {
587 domain => $domain,
588 class => $class,
589 %$args,
590 });
591 0 ▶ return undef unless $res->{class} eq $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"class"} eq $class 0 0 0
592  
593 0 return 1;
594 }
595  
596 # modify a host
597 0 ▶sub _mod_host {
Subroutine _mod_host: not called CC=5 SCAR=34.0
598 0 my MogileFS::Admin $self = shift;
599 0 ▶ return undef if $self->{readonly};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"readonly"} 0 0 0
600  
601 0 my ($host, $args, $verb) = @_;
602  
603 0 ▶ $args ||= {};
Condition0%0/2
$args ||= {}
l!l
00
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
604 0 $args->{host} = $host;
605 0 ▶ $verb ||= 'create';
Condition0%0/2
$verb ||= "create"
l!l
00
MC/DC0%0/1
$verb ||= "create"
$verb
Truth table0%0/2
A
A= $verb
Aresult
11
00
606  
607 0 my $res = $self->{backend}->do_request("${verb}_host", $args);
608 0 ▶ return undef unless $res->{host} eq $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"host"} eq $host 0 0 0
609  
610 0 return 1;
611 }
612  
613 0 ▶sub errstr {
Subroutine errstr: not called CC=2 SCAR=17.9
Pod undocumented
614 0 my MogileFS::Admin $self = shift;
615 0 ▶ return undef unless $self->{backend};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"backend"} 0 0 0
616 0 return $self->{backend}->errstr;
617 }
618  
619 0 ▶sub errcode {
Subroutine errcode: not called CC=2 SCAR=17.9
Pod undocumented
620 0 my MogileFS::Admin $self = shift;
621 0 ▶ return undef unless $self->{backend};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"backend"} 0 0 0
622 0 return $self->{backend}->errcode;
623 }
624  
625 0 ▶sub err {
Subroutine err: not called CC=2 SCAR=17.9
Pod undocumented
626 0 my MogileFS::Admin $self = shift;
627 0 ▶ return undef unless $self->{backend};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"backend"} 0 0 0
628 0 return $self->{backend}->err;
629 }
630  
631 2 1;
« Backend.pm ↑ Summary