blib/lib/Net/Hadoop/WebHDFS.pm

filter: Statementstmt 21.7% 43 / 198 Branchbran 8.8% 8 / 90 Conditioncond 29.0% 16 / 55 MC/DCmcdc 13.3% 4 / 30 Subroutinesub 24.3% 10 / 41 Podpod 48.5% 17 / 35 totaltotal 21.8% 98 / 449 SCAR 77.9
CC
67
Cov
20%
request
420.0
operate_requests
72.0
check_options
30.0
CRAP 2405.8
↑ Summary Build »
1 package Net::Hadoop::WebHDFS;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use JSON::XS qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Furl;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = "0.6";
13  
14 1 our %OPT_TABLE = ();
15  
16 sub new {
17 5 ▶ my ($this, %opts) = @_;
Subroutine new: called CC=8 SCAR=25.5
Pod documented
18 my $self = +{
19 host => $opts{host} || 'localhost',
20 port => $opts{port} || 50070,
21 standby_host => $opts{standby_host},
22 standby_port => ($opts{standby_port} || $opts{port} || 50070),
23 httpfs_mode => $opts{httpfs_mode} || 0,
24 username => $opts{username},
25 doas => $opts{doas},
26 useragent => $opts{useragent} || 'Furl Net::Hadoop::WebHDFS (perl)',
27 5 ▶ timeout => $opts{timeout} || 10,
Condition46%7/15
$opts{'host'} || 'localhost'
l!l
05
$opts{'port'} || 50070
l!l
05
$opts{'standby_port'} || $opts{'port'} || 50070
l!l
05
$opts{"standby_port"} or $opts{"port"}
l!l&&r!l&&!r
005
$opts{'httpfs_mode'} || 0
l!l
05
$opts{'useragent'} || 'Furl Net::Hadoop::WebHDFS (perl)'
l!l
05
$opts{'timeout'} || 10
l!l
05
MC/DC0%0/1
$opts{'host'} || 'localhost'
$opts{'host'}
MC/DC0%0/1
$opts{'port'} || 50070
$opts{'port'}
MC/DC0%0/2
$opts{'standby_port'} || $opts{'port'} || 50070
$opts{"standby_port"} $opts{"port"}
MC/DC0%0/1
$opts{'httpfs_mode'} || 0
$opts{'httpfs_mode'}
MC/DC0%0/1
$opts{'useragent'} || 'Furl Net::Hadoop::WebHDFS (perl)'
$opts{'useragent'}
MC/DC0%0/1
$opts{'timeout'} || 10
$opts{'timeout'}
Truth table50%1/2
A
A= $opts{'host'}
Aresult
11
00
Truth table50%1/2
A
A= $opts{'port'}
Aresult
11
00
Truth table33%1/3
A or B
A= $opts{"standby_port"}B= $opts{"port"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $opts{'httpfs_mode'}
Aresult
11
00
Truth table50%1/2
A
A= $opts{'useragent'}
Aresult
11
00
Truth table50%1/2
A
A= $opts{'timeout'}
Aresult
11
00
28 under_failover => 0,
29 };
30 5 $self->{furl} = Furl::HTTP->new(agent => $self->{useragent}, timeout => $self->{timeout}, max_redirects => 0);
31 5 return bless $self, $this;
32 }
33  
34 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE
35 # [&overwrite=<true|false>][&blocksize=<LONG>][&replication=<SHORT>]
36 # [&permission=<OCTAL>][&buffersize=<INT>]"
37 sub create {
38 0 ▶ my ($self, $path, $body, %options) = @_;
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
39 0 ▶ if ($self->{httpfs_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"}) 0 0 0
40 0 %options = (%options, data => 'true');
41 }
42 0 my $err = $self->check_options('CREATE', %options);
43 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
44  
45 0 my $res = $self->operate_requests('PUT', $path, 'CREATE', \%options, $body);
46 0 $res->{code} == 201;
47 }
48 1 $OPT_TABLE{CREATE} = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize', 'data'];
49  
50 # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND[&buffersize=<INT>]"
51 sub append {
52 0 ▶ my ($self, $path, $body, %options) = @_;
Subroutine append: not called CC=3 SCAR=24.8
Pod documented
53 0 ▶ if ($self->{httpfs_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"}) 0 0 0
54 0 %options = (%options, data => 'true');
55 }
56 0 my $err = $self->check_options('APPEND', %options);
57 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
58  
59 0 my $res = $self->operate_requests('POST', $path, 'APPEND', \%options, $body);
60 0 $res->{code} == 200;
61 }
62 1 $OPT_TABLE{APPEND} = ['buffersize', 'data'];
63  
64 # curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
65 # [&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
66 sub read {
67 0 ▶ my ($self, $path, %options) = @_;
Subroutine read: not called CC=2 SCAR=17.9
Pod documented
68 0 my $err = $self->check_options('OPEN', %options);
69 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
70  
71 0 my $res = $self->operate_requests('GET', $path, 'OPEN', \%options);
72 0 $res->{body};
73 }
74 1 $OPT_TABLE{OPEN} = ['offset', 'length', 'buffersize'];
75 0 ▶sub open { (shift)->read(@_); }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
76  
77 # curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=MKDIRS[&permission=<OCTAL>]"
78 sub mkdir {
79 0 ▶ my ($self, $path, %options) = @_;
Subroutine mkdir: not called CC=2 SCAR=17.9
Pod documented
80 0 my $err = $self->check_options('MKDIRS', %options);
81 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
82  
83 0 my $res = $self->operate_requests('PUT', $path, 'MKDIRS', \%options);
84 0 $self->check_success_json($res, 'boolean');
85 }
86 1 $OPT_TABLE{MKDIRS} = ['permission'];
87 0 ▶sub mkdirs { (shift)->mkdir(@_); }
Subroutine mkdirs: not called CC=1 SCAR=6.9
Pod undocumented
88  
89 # curl -i -X PUT "<HOST>:<PORT>/webhdfs/v1/<PATH>?op=RENAME&destination=<PATH>"
90 sub rename {
91 0 ▶ my ($self, $path, $dest, %options) = @_;
Subroutine rename: not called CC=3 SCAR=24.8
Pod documented
92 0 my $err = $self->check_options('RENAME', %options);
93 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
94  
95 0 ▶ unless ($dest =~ m!^/!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dest =~ m[^/]) 0 0 0
96 0 $dest = '/' . $dest;
97 }
98 0 my $res = $self->operate_requests('PUT', $path, 'RENAME', {%options, destination => $dest});
99 0 $self->check_success_json($res, 'boolean');
100 }
101  
102 # curl -i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?op=DELETE
103 # [&recursive=<true|false>]"
104 sub delete {
105 0 ▶ my ($self, $path, %options) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
106 0 my $err = $self->check_options('DELETE', %options);
107 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
108  
109 0 my $res = $self->operate_requests('DELETE', $path, 'DELETE', \%options);
110 0 $self->check_success_json($res, 'boolean');
111 }
112 1 $OPT_TABLE{DELETE} = ['recursive'];
113  
114 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
115 sub stat {
116 0 ▶ my ($self, $path, %options) = @_;
Subroutine stat: not called CC=2 SCAR=17.9
Pod documented
117 0 my $err = $self->check_options('GETFILESTATUS', %options);
118 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
119  
120 0 my $res = $self->operate_requests('GET', $path, 'GETFILESTATUS', \%options);
121 0 $self->check_success_json($res, 'FileStatus');
122 }
123 0 ▶sub getfilestatus { (shift)->stat(@_); }
Subroutine getfilestatus: not called CC=1 SCAR=6.9
Pod undocumented
124  
125 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
126 sub list {
127 0 ▶ my ($self, $path, %options) = @_;
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
128 0 my $err = $self->check_options('LISTSTATUS', %options);
129 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
130  
131 0 my $res = $self->operate_requests('GET', $path, 'LISTSTATUS', \%options);
132 0 $self->check_success_json($res, 'FileStatuses')->{FileStatus};
133 }
134 0 ▶sub liststatus { (shift)->list(@_); }
Subroutine liststatus: not called CC=1 SCAR=6.9
Pod undocumented
135  
136 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETCONTENTSUMMARY"
137 sub content_summary {
138 0 ▶ my ($self, $path, %options) = @_;
Subroutine content_summary: not called CC=2 SCAR=17.9
Pod documented
139 0 my $err = $self->check_options('GETCONTENTSUMMARY', %options);
140 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
141  
142 0 my $res = $self->operate_requests('GET', $path, 'GETCONTENTSUMMARY', \%options);
143 0 $self->check_success_json($res, 'ContentSummary');
144 }
145 0 ▶sub getcontentsummary { (shift)->content_summary(@_); }
Subroutine getcontentsummary: not called CC=1 SCAR=6.9
Pod undocumented
146  
147 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
148 sub checksum {
149 0 ▶ my ($self, $path, %options) = @_;
Subroutine checksum: not called CC=2 SCAR=17.9
Pod documented
150 0 my $err = $self->check_options('GETFILECHECKSUM', %options);
151 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
152  
153 0 my $res = $self->operate_requests('GET', $path, 'GETFILECHECKSUM', \%options);
154 0 $self->check_success_json($res, 'FileChecksum');
155 }
156 0 ▶sub getfilechecksum { (shift)->checksum(@_); }
Subroutine getfilechecksum: not called CC=1 SCAR=6.9
Pod undocumented
157  
158 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETHOMEDIRECTORY"
159 sub homedir {
160 0 ▶ my ($self, %options) = @_;
Subroutine homedir: not called CC=2 SCAR=17.9
Pod documented
161 0 my $err = $self->check_options('GETHOMEDIRECTORY', %options);
162 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
163  
164 0 my $res = $self->operate_requests('GET', '/', 'GETHOMEDIRECTORY', \%options);
165 0 $self->check_success_json($res, 'Path');
166 }
167 0 ▶sub gethomedirectory { (shift)->homedir(@_); }
Subroutine gethomedirectory: not called CC=1 SCAR=6.9
Pod undocumented
168  
169 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
170 # [&permission=<OCTAL>]"
171 sub chmod {
172 0 ▶ my ($self, $path, $mode, %options) = @_;
Subroutine chmod: not called CC=2 SCAR=17.9
Pod documented
173 0 my $err = $self->check_options('SETPERMISSION', %options);
174 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
175  
176 0 my $res = $self->operate_requests('PUT', $path, 'SETPERMISSION', {%options, permission => $mode});
177 0 $res->{code} == 200;
178 }
179 0 ▶sub setpermission { (shift)->chmod(@_); }
Subroutine setpermission: not called CC=1 SCAR=6.9
Pod undocumented
180  
181 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER
182 # [&owner=<USER>][&group=<GROUP>]"
183 sub chown {
184 0 ▶ my ($self, $path, %options) = @_;
Subroutine chown: not called CC=4 SCAR=30.0
Pod documented
185 0 my $err = $self->check_options('SETOWNER', %options);
186 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
187  
188 0 ▶ unless (defined($options{owner}) or defined($options{group})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{"owner"} or defined $options{"group"}) 0 0 0
Condition0%0/3
defined $options{"owner"} or defined $options{"group"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $options{"owner"} or defined $options{"group"}
defined $options{"owner"} defined $options{"group"}
Truth table0%0/3
A or B
A= defined $options{"owner"}B= defined $options{"group"}
ABresult
1X1
011
000
189 0 croak "'chown' needs at least one of owner or group";
190 }
191  
192 0 my $res = $self->operate_requests('PUT', $path, 'SETOWNER', \%options);
193 0 $res->{code} == 200;
194 }
195 1 $OPT_TABLE{SETOWNER} = ['owner', 'group'];
196 0 ▶sub setowner { (shift)->chown(@_); }
Subroutine setowner: not called CC=1 SCAR=6.9
Pod undocumented
197  
198 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION
199 # [&replication=<SHORT>]"
200 sub replication {
201 0 ▶ my ($self, $path, $replnum, %options) = @_;
Subroutine replication: not called CC=2 SCAR=17.9
Pod documented
202 0 my $err = $self->check_options('SETREPLICATION', %options);
203 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
204  
205 0 my $res = $self->operate_requests('PUT', $path, 'SETREPLICATION', {%options, replication => $replnum});
206 0 $self->check_success_json($res, 'boolean');
207 }
208 0 ▶sub setreplication { (shift)->replication(@_); }
Subroutine setreplication: not called CC=1 SCAR=6.9
Pod undocumented
209  
210 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETTIMES
211 # [&modificationtime=<TIME>][&accesstime=<TIME>]"
212 # modificationtime: radix-10 long integer
213 # accesstime: radix-10 long integer
214 1 $OPT_TABLE{SETTIMES} = [ qw( modificationtime accesstime ) ];
215 sub touch {
216 0 ▶ my ($self, $path, %options) = @_;
Subroutine touch: not called CC=4 SCAR=30.0
Pod documented
217 0 my $err = $self->check_options('SETTIMES', %options);
218 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
219  
220 0 ▶ unless (defined($options{modificationtime}) or defined($options{accesstime})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $options{"modificationtime"} or defined $options{"accesstime"}) 0 0 0
Condition0%0/3
defined $options{"modificationtime"} or defined $options{"accesstime"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $options{"modificationtime"} or defined $options{"accesstime"}
defined $options{"modificationtime"} defined $options{"accesstime"}
Truth table0%0/3
A or B
A= defined $options{"modificationtime"}B= defined $options{"accesstime"}
ABresult
1X1
011
000
221 0 croak "'touch' needs at least one of modificationtime or accesstime";
222 }
223  
224 0 my $res = $self->operate_requests('PUT', $path, 'SETTIMES', \%options);
225 0 $res->{code} == 200;
226 }
227  
228 sub touchz {
229 0 ▶ my ($self, $path) = @_;
Subroutine touchz: not called CC=1 SCAR=6.9
Pod documented
230 0 return $self->create( $path, '', overwrite => 'true' );
231 }
232  
233 0 ▶sub settimes { (shift)->touch(@_); }
Subroutine settimes: not called CC=1 SCAR=6.9
Pod undocumented
234  
235 # sub delegation_token {}
236 # sub renew_delegation_token {}
237 # sub cancel_delegation_token {}
238  
239 sub check_options {
240 0 ▶ my ($self, $op, %opts) = @_;
Subroutine check_options: not called CC=5 SCAR=34.0
Pod undocumented
241 0 my @ex = ();
242 0 ▶ my $opts = $OPT_TABLE{$op} || [];
Condition0%0/2
$Net::Hadoop::WebHDFS::OPT_TABLE{$op} || []
l!l
00
MC/DC0%0/1
$Net::Hadoop::WebHDFS::OPT_TABLE{$op} || []
$Net::Hadoop::WebHDFS::OPT_TABLE{$op}
Truth table0%0/2
A
A= $Net::Hadoop::WebHDFS::OPT_TABLE{$op}
Aresult
11
00
243 0 foreach my $k (keys %opts) {
244 0 ▶ push @ex, $k if scalar(grep {$k eq $_} @$opts) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({$k eq $_;} @$opts) < 1 0 0 0
245 }
246 0 ▶ return undef unless @ex;
Branch: 1 branch
BranchTrueFalseTotal
unless @ex 0 0 0
247 0 'no such option: ' . join(' ', @ex);
248 }
249  
250 sub check_success_json {
251 8 ▶ my ($self, $res, $attr) = @_;
Subroutine check_success_json: called CC=4 SCAR=13.9
Pod undocumented
252 $res->{code} == 200 and $res->{content_type} =~ m!^application/json! and
253 8 ▶ (not defined($attr) or JSON::XS::decode_json($res->{body})->{$attr});
Branch: 1 branch
BranchTrueFalseTotal
$res->{"code"} == 200 and $res->{"content_type"} =~ m[^application/json] and !defined($attr) || &JSON::XS::decode_json($res->{"body"})->{$attr} 5 3 8
Condition100%9/9
$res->{'code'} == 200 && $res->{'content_type'} =~ m[^application/json] && (!defined($attr) || &JSON::XS::decode_json($res->{'body'})->{$attr})
!ll&&!rl&&r
314
$res->{"code"} == 200 and $res->{"content_type"} =~ m[^application/json]
!ll&&!rl&&r
215
not defined $attr or &JSON::XS::decode_json($res->{"body"})->{$attr}
l!l&&r!l&&!r
131
MC/DC100%4/4
$res->{'code'} == 200 && $res->{'content_type'} =~ m[^application/json] && (!defined($attr) || &JSON::XS::decode_json($res->{'body'})->{$attr})
$res->{"code"} == 200 $res->{"content_type"} =~ m[^application/json] not defined $attr &JSON::XS::decode_json($res->{"body"})->{$attr}
Truth table100%5/5
A and B && not(C) or D
A= $res->{"code"} == 200B= $res->{"content_type"} =~ m[^application/json]C= not defined $attrD= &JSON::XS::decode_json($res->{"body"})->{$attr}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
254 }
255  
256 sub api_path {
257 10 ▶ my ($self, $path) = @_;
Subroutine api_path: called CC=2 SCAR=6.9
Pod undocumented
258 10 ▶ return '/webhdfs/v1' . $path if $path =~ m!^/!;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[^/] 9 1 10
259 1 '/webhdfs/v1/' . $path;
260 }
261  
262 sub build_path {
263 7 ▶ my ($self, $path, $op, %params) = @_;
Subroutine build_path: called CC=3 SCAR=11.0
Pod undocumented
264 my %opts = (('op' => $op),
265 ($self->{username} ? ('user.name' => $self->{username}) : ()),
266 7 ▶ ($self->{doas} ? ('doas' => $self->{doas}) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$self->{'username'} ? : 4 3 7
$self->{'doas'} ? : 2 5 7
267 %params);
268 7 my $u = URI->new('', 'http');
269 7 $u->query_form(%opts);
270 7 $self->api_path($path) . $u->path_query; # path_query() #=> '?foo=1&bar=2'
271 }
272  
273 sub connect_to {
274 0 ▶ my $self = shift;
Subroutine connect_to: not called CC=2 SCAR=17.9
Pod undocumented
275 0 ▶ if ($self->{under_failover}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"under_failover"}) 0 0 0
276 0 return ($self->{standby_host}, $self->{standby_port});
277 }
278 0 return ($self->{host}, $self->{port});
279 }
280  
281 1 our %REDIRECTED_OPERATIONS = (APPEND => 1, CREATE => 1, OPEN => 1, GETFILECHECKSUM => 1);
282 sub operate_requests {
283 0 ▶ my ($self, $method, $path, $op, $params, $payload) = @_;
Subroutine operate_requests: not called CC=8 SCAR=42.8
Pod undocumented
284  
285 0 my ($host, $port) = $self->connect_to();
286  
287 0 my $headers = []; # or undef ?
288 0 ▶ if ($self->{httpfs_mode} or not $REDIRECTED_OPERATIONS{$op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"} or not $Net::Hadoop::WebHDFS::REDIRECTED_OPERATIONS{$op}) 0 0 0
Condition0%0/3
$self->{"httpfs_mode"} or not $Net::Hadoop::WebHDFS::REDIRECTED_OPERATIONS{$op}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"httpfs_mode"} or not $Net::Hadoop::WebHDFS::REDIRECTED_OPERATIONS{$op}
$self->{"httpfs_mode"} not $Net::Hadoop::WebHDFS::REDIRECTED_OPERATIONS{$op}
Truth table0%0/3
A or not(B)
A= $self->{"httpfs_mode"}B= not $Net::Hadoop::WebHDFS::REDIRECTED_OPERATIONS{$op}
ABresult
1X1
011
000
289 # empty files are ok
290 0 ▶ if ($self->{httpfs_mode} and defined($payload)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"} and defined $payload) 0 0 0
Condition0%0/3
$self->{"httpfs_mode"} and defined $payload
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"httpfs_mode"} and defined $payload
$self->{"httpfs_mode"} defined $payload
Truth table0%0/3
A and B
A= $self->{"httpfs_mode"}B= defined $payload
ABresult
0X0
100
111
291 0 $headers = ['Content-Type' => 'application/octet-stream'];
292 }
293 0 return $self->request($host, $port, $method, $path, $op, $params, $payload, $headers);
294 }
295  
296 # pattern for not httpfs and redirected by namenode
297 0 my $res = $self->request($host, $port, $method, $path, $op, $params, undef);
298 0 ▶ unless ($res->{code} >= 300 and $res->{code} <= 399 and $res->{location}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"code"} >= 300 and $res->{"code"} <= 399 and $res->{"location"}) 0 0 0
Condition0%0/6
$res->{"code"} >= 300 and $res->{"code"} <= 399 and $res->{"location"}
!ll&&!rl&&r
000
$res->{"code"} >= 300 and $res->{"code"} <= 399
!ll&&!rl&&r
000
MC/DC0%0/3
$res->{"code"} >= 300 and $res->{"code"} <= 399 and $res->{"location"}
$res->{"code"} >= 300 $res->{"code"} <= 399 $res->{"location"}
Truth table0%0/4
A and B and C
A= $res->{"code"} >= 300B= $res->{"code"} <= 399C= $res->{"location"}
ABCresult
0XX0
10X0
1100
1111
299 0 my $code = $res->{code};
300 0 my $body = $res->{body};
301 0 croak "NameNode returns non-redirection (or without location header), code:$code, body:$body.";
302 }
303 0 my $uri = URI->new($res->{location});
304 0 $headers = ['Content-Type' => 'application/octet-stream'];
305 0 return $self->request($uri->host, $uri->port, $method, $uri->path_query, undef, {}, $payload, $headers);
306 }
307  
308 # IllegalArgumentException 400 Bad Request
309 # UnsupportedOperationException 400 Bad Request
310 # SecurityException 401 Unauthorized
311 # IOException 403 Forbidden
312 # FileNotFoundException 404 Not Found
313 # RumtimeException 500 Internal Server Error
314 sub request {
315 0 ▶ my ($self, $host, $port, $method, $path, $op, $params, $payload, $header) = @_;
Subroutine request: not called CC=20 SCAR=60.4
Pod undocumented
316  
317 0 ▶ my $request_path = $op ? $self->build_path($path, $op, %$params) : $path;
Branch: 1 branch
BranchTrueFalseTotal
$op ? : 0 0 0
318 my ($ver, $code, $msg, $headers, $body) = $self->{furl}->request(
319 0 ▶ method => $method,
Branch: 1 branch
BranchTrueFalseTotal
$payload ? : 0 0 0
320 host => $host,
321 port => $port,
322 path_query => $request_path,
323 headers => $header,
324 ($payload ? (content => $payload) : ()),
325 );
326  
327 0 my $res = { code => $code, body => $body };
328  
329 0 ▶ for (my $i = 0; $i < scalar(@$headers); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$headers) 0 0 0
330 0 my $header = $headers->[$i];
331 0 my $value = $headers->[$i + 1];
332  
333 0 ▶ if ($header =~ m!^location$!i) { $res->{location} = $value; }
Branch: 2 branches
BranchTrueFalseTotal
if ($header =~ /^location$/i) { } 0 0 0
elsif ($header =~ /^content-type$/i) { } 0 0 0
334 0 elsif ($header =~ m!^content-type$!i) { $res->{content_type} = $value; }
335 }
336  
337 0 ▶ return $res if $code >= 200 and $code <= 299;
Branch: 1 branch
BranchTrueFalseTotal
if $code >= 200 and $code <= 299 0 0 0
Condition0%0/3
$code >= 200 and $code <= 299
!ll&&!rl&&r
000
MC/DC0%0/2
$code >= 200 and $code <= 299
$code >= 200 $code <= 299
Truth table0%0/3
A and B
A= $code >= 200B= $code <= 299
ABresult
0X0
100
111
338 0 ▶ return $res if $code >= 300 and $code <= 399;
Branch: 1 branch
BranchTrueFalseTotal
if $code >= 300 and $code <= 399 0 0 0
Condition0%0/3
$code >= 300 and $code <= 399
!ll&&!rl&&r
000
MC/DC0%0/2
$code >= 300 and $code <= 399
$code >= 300 $code <= 399
Truth table0%0/3
A and B
A= $code >= 300B= $code <= 399
ABresult
0X0
100
111
339  
340 0 ▶ my $errmsg = $res->{body} || 'Response body is empty...';
Condition0%0/2
$res->{'body'} || 'Response body is empty...'
l!l
00
MC/DC0%0/1
$res->{'body'} || 'Response body is empty...'
$res->{'body'}
Truth table0%0/2
A
A= $res->{'body'}
Aresult
11
00
341 0 $errmsg =~ s/\n//g;
342  
343 0 ▶ if ($code == 400) { croak "ClientError: $errmsg"; }
Branch: 5 branches
BranchTrueFalseTotal
if ($code == 400) { } 0 0 0
elsif ($code == 401) { } 0 0 0
elsif ($code == 403) { } 0 0 0
elsif ($code == 404) { } 0 0 0
elsif ($code == 500) { } 0 0 0
344 0 elsif ($code == 401) { croak "SecurityError: $errmsg"; }
345 elsif ($code == 403) {
346 0 ▶ if ($errmsg =~ /org\.apache\.hadoop\.ipc\.StandbyException/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errmsg =~ /org\.apache\.hadoop\.ipc\.StandbyException/) 0 0 0
347 0 ▶ if ($self->{httpfs_mode} || not defined($self->{standby_host})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'httpfs_mode'} or not defined $self->{'standby_host'}) { } 0 0 0
elsif ($self->{'retrying'}) { } 0 0 0
Condition0%0/3
$self->{"httpfs_mode"} or not defined $self->{"standby_host"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"httpfs_mode"} or not defined $self->{"standby_host"}
$self->{"httpfs_mode"} not defined $self->{"standby_host"}
Truth table0%0/3
A or not(B)
A= $self->{"httpfs_mode"}B= not defined $self->{"standby_host"}
ABresult
1X1
011
000
348 # failover is disabled
349 } elsif ($self->{retrying}) {
350 # more failover is prohibited
351 0 $self->{retrying} = 0;
352 } else {
353 0 $self->{under_failover} = not $self->{under_failover};
354 0 $self->{retrying} = 1;
355 0 my ($next_host, $next_port) = $self->connect_to();
356 0 my $val = $self->request($next_host, $next_port, $method, $path, $op, $params, $payload, $header);
357 0 $self->{retrying} = 0;
358 0 return $val;
359 }
360 }
361 0 croak "IOError: $errmsg";
362 }
363 0 elsif ($code == 404) { croak "FileNotFoundError: $errmsg"; }
364 0 elsif ($code == 500) { croak "ServerError: $errmsg"; }
365  
366 0 croak "RequestFailedError, code:$code, message:$errmsg";
367 }
368  
369 1 1;
370  
371 __END__
↑ Summary Build »