blib/lib/Net/Hadoop/WebHDFS.pm

filter: Statementstmt 14.9% 55 / 369 Branchbran 4.5% 8 / 176 Conditioncond 19.7% 17 / 86 MC/DCmcdc 8.7% 4 / 46 Subroutinesub 19.1% 13 / 68 Podpod 58.1% 25 / 43 totaltotal 15.4% 122 / 788 CC 124 SCAR 42.3
CC
124
Cov
13%
_request
420.0
__ANON__
156.0
operate_requests
72.0
CRAP 68.6
↑ Summary
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 File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use constant GENERIC_FS_ACTION_WITH_NO_PATH => '';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our $VERSION = "0.8";
17  
18 1 our %OPT_TABLE = ();
19  
20 5 ▶sub new {
Subroutine new: called CC=9 SCAR=27.3
Pod documented
21 5 my ($this, %opts) = @_;
22 my $self = +{
23 host => $opts{host} || 'localhost',
24 port => $opts{port} || 50070,
25 standby_host => $opts{standby_host},
26 standby_port => ($opts{standby_port} || $opts{port} || 50070),
27 httpfs_mode => $opts{httpfs_mode} || 0,
28 username => $opts{username},
29 doas => $opts{doas},
30 useragent => $opts{useragent} || 'Furl Net::Hadoop::WebHDFS (perl)',
31 timeout => $opts{timeout} || 10,
32 5 ▶ suppress_errors => $opts{suppress_errors} || 0,
Condition47%8/17
$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
$opts{'suppress_errors'} || 0
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'}
MC/DC0%0/1
$opts{'suppress_errors'} || 0
$opts{'suppress_errors'}
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
Truth table50%1/2
A
A= $opts{'suppress_errors'}
Aresult
11
00
33 last_error => undef,
34 under_failover => 0,
35 };
36 5 $self->{furl} = Furl::HTTP->new(agent => $self->{useragent}, timeout => $self->{timeout}, max_redirects => 0);
37 5 return bless $self, $this;
38 }
39  
40 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATE
41 # [&overwrite=<true|false>][&blocksize=<LONG>][&replication=<SHORT>]
42 # [&permission=<OCTAL>][&buffersize=<INT>]"
43 0 ▶sub create {
Subroutine create: not called CC=3 SCAR=24.8
Pod documented
44 0 my ($self, $path, $body, %options) = @_;
45 0 ▶ if ($self->{httpfs_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"}) 0 0 0
46 0 %options = (%options, data => 'true');
47 }
48 0 my $err = $self->check_options('CREATE', %options);
49 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
50  
51 0 my $res = $self->operate_requests('PUT', $path, 'CREATE', \%options, $body);
52 0 $res->{code} == 201;
53 }
54 1 $OPT_TABLE{CREATE} = ['overwrite', 'blocksize', 'replication', 'permission', 'buffersize', 'data'];
55  
56 # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND
57 # [&buffersize=<INT>]"
58 0 ▶sub append {
Subroutine append: not called CC=3 SCAR=24.8
Pod documented
59 0 my ($self, $path, $body, %options) = @_;
60 0 ▶ if ($self->{httpfs_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"httpfs_mode"}) 0 0 0
61 0 %options = (%options, data => 'true');
62 }
63 0 my $err = $self->check_options('APPEND', %options);
64 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
65  
66 0 my $res = $self->operate_requests('POST', $path, 'APPEND', \%options, $body);
67 0 $res->{code} == 200;
68 }
69 1 $OPT_TABLE{APPEND} = ['buffersize', 'data'];
70  
71 # curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
72 # [&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
73 0 ▶sub read {
Subroutine read: not called CC=2 SCAR=17.9
Pod documented
74 0 my ($self, $path, %options) = @_;
75 0 my $err = $self->check_options('OPEN', %options);
76 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
77  
78 0 my $res = $self->operate_requests('GET', $path, 'OPEN', \%options);
79 0 $res->{body};
80 }
81 1 $OPT_TABLE{OPEN} = ['offset', 'length', 'buffersize'];
82 0 ▶sub open { (shift)->read(@_); }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
83  
84 # curl -i -X PUT "http://<HOST>:<PORT>/<PATH>?op=MKDIRS
85 # [&permission=<OCTAL>]"
86 0 ▶sub mkdir {
Subroutine mkdir: not called CC=2 SCAR=17.9
Pod documented
87 0 my ($self, $path, %options) = @_;
88 0 my $err = $self->check_options('MKDIRS', %options);
89 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
90  
91 0 my $res = $self->operate_requests('PUT', $path, 'MKDIRS', \%options);
92 0 $self->check_success_json($res, 'boolean');
93 }
94 1 $OPT_TABLE{MKDIRS} = ['permission'];
95 0 ▶sub mkdirs { (shift)->mkdir(@_); }
Subroutine mkdirs: not called CC=1 SCAR=6.9
Pod undocumented
96  
97 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=RENAME
98 # &destination=<PATH>"
99 0 ▶sub rename {
Subroutine rename: not called CC=3 SCAR=24.8
Pod documented
100 0 my ($self, $path, $dest, %options) = @_;
101 0 my $err = $self->check_options('RENAME', %options);
102 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
103  
104 0 ▶ unless ($dest =~ m!^/!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dest =~ m[^/]) 0 0 0
105 0 $dest = '/' . $dest;
106 }
107 0 my $res = $self->operate_requests('PUT', $path, 'RENAME', {%options, destination => $dest});
108 0 $self->check_success_json($res, 'boolean');
109 }
110  
111 # curl -i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?op=DELETE
112 # [&recursive=<true|false>]"
113 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
114 0 my ($self, $path, %options) = @_;
115 0 my $err = $self->check_options('DELETE', %options);
116 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
117  
118 0 my $res = $self->operate_requests('DELETE', $path, 'DELETE', \%options);
119 0 $self->check_success_json($res, 'boolean');
120 }
121 1 $OPT_TABLE{DELETE} = ['recursive'];
122  
123 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
124 0 ▶sub stat {
Subroutine stat: not called CC=2 SCAR=17.9
Pod documented
125 0 my ($self, $path, %options) = @_;
126 0 my $err = $self->check_options('GETFILESTATUS', %options);
127 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
128  
129 0 my $res = $self->operate_requests('GET', $path, 'GETFILESTATUS', \%options);
130 0 $self->check_success_json($res, 'FileStatus');
131 }
132 0 ▶sub getfilestatus { (shift)->stat(@_); }
Subroutine getfilestatus: not called CC=1 SCAR=6.9
Pod undocumented
133  
134 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
135 0 ▶sub list {
Subroutine list: not called CC=2 SCAR=17.9
Pod documented
136 0 my ($self, $path, %options) = @_;
137 0 my $err = $self->check_options('LISTSTATUS', %options);
138 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
139  
140 0 my $res = $self->operate_requests('GET', $path, 'LISTSTATUS', \%options);
141 0 $self->check_success_json($res, 'FileStatuses')->{FileStatus};
142 }
143 0 ▶sub liststatus { (shift)->list(@_); }
Subroutine liststatus: not called CC=1 SCAR=6.9
Pod undocumented
144  
145 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETCONTENTSUMMARY"
146 0 ▶sub content_summary {
Subroutine content_summary: not called CC=2 SCAR=17.9
Pod documented
147 0 my ($self, $path, %options) = @_;
148 0 my $err = $self->check_options('GETCONTENTSUMMARY', %options);
149 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
150  
151 0 my $res = $self->operate_requests('GET', $path, 'GETCONTENTSUMMARY', \%options);
152 0 $self->check_success_json($res, 'ContentSummary');
153 }
154 0 ▶sub getcontentsummary { (shift)->content_summary(@_); }
Subroutine getcontentsummary: not called CC=1 SCAR=6.9
Pod undocumented
155  
156 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
157 0 ▶sub checksum {
Subroutine checksum: not called CC=2 SCAR=17.9
Pod documented
158 0 my ($self, $path, %options) = @_;
159 0 my $err = $self->check_options('GETFILECHECKSUM', %options);
160 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
161  
162 0 my $res = $self->operate_requests('GET', $path, 'GETFILECHECKSUM', \%options);
163 0 $self->check_success_json($res, 'FileChecksum');
164 }
165 0 ▶sub getfilechecksum { (shift)->checksum(@_); }
Subroutine getfilechecksum: not called CC=1 SCAR=6.9
Pod undocumented
166  
167 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETHOMEDIRECTORY"
168 0 ▶sub homedir {
Subroutine homedir: not called CC=2 SCAR=17.9
Pod documented
169 0 my ($self, %options) = @_;
170 0 my $err = $self->check_options('GETHOMEDIRECTORY', %options);
171 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
172  
173 0 my $res = $self->operate_requests('GET', '/', 'GETHOMEDIRECTORY', \%options);
174 0 $self->check_success_json($res, 'Path');
175 }
176 0 ▶sub gethomedirectory { (shift)->homedir(@_); }
Subroutine gethomedirectory: not called CC=1 SCAR=6.9
Pod undocumented
177  
178 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION
179 # [&permission=<OCTAL>]"
180 0 ▶sub chmod {
Subroutine chmod: not called CC=2 SCAR=17.9
Pod documented
181 0 my ($self, $path, $mode, %options) = @_;
182 0 my $err = $self->check_options('SETPERMISSION', %options);
183 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
184  
185 0 my $res = $self->operate_requests('PUT', $path, 'SETPERMISSION', {%options, permission => $mode});
186 0 $res->{code} == 200;
187 }
188 0 ▶sub setpermission { (shift)->chmod(@_); }
Subroutine setpermission: not called CC=1 SCAR=6.9
Pod undocumented
189  
190 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER
191 # [&owner=<USER>][&group=<GROUP>]"
192 0 ▶sub chown {
Subroutine chown: not called CC=4 SCAR=30.0
Pod documented
193 0 my ($self, $path, %options) = @_;
194 0 my $err = $self->check_options('SETOWNER', %options);
195 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
196  
197 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
198 0 croak "'chown' needs at least one of owner or group";
199 }
200  
201 0 my $res = $self->operate_requests('PUT', $path, 'SETOWNER', \%options);
202 0 $res->{code} == 200;
203 }
204 1 $OPT_TABLE{SETOWNER} = ['owner', 'group'];
205 0 ▶sub setowner { (shift)->chown(@_); }
Subroutine setowner: not called CC=1 SCAR=6.9
Pod undocumented
206  
207 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION
208 # [&replication=<SHORT>]"
209 0 ▶sub replication {
Subroutine replication: not called CC=2 SCAR=17.9
Pod documented
210 0 my ($self, $path, $replnum, %options) = @_;
211 0 my $err = $self->check_options('SETREPLICATION', %options);
212 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
213  
214 0 my $res = $self->operate_requests('PUT', $path, 'SETREPLICATION', {%options, replication => $replnum});
215 0 $self->check_success_json($res, 'boolean');
216 }
217 0 ▶sub setreplication { (shift)->replication(@_); }
Subroutine setreplication: not called CC=1 SCAR=6.9
Pod undocumented
218  
219 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETTIMES
220 # [&modificationtime=<TIME>][&accesstime=<TIME>]"
221 # modificationtime: radix-10 long integer
222 # accesstime: radix-10 long integer
223 1 $OPT_TABLE{SETTIMES} = [ qw( modificationtime accesstime ) ];
224 0 ▶sub touch {
Subroutine touch: not called CC=4 SCAR=30.0
Pod documented
225 0 my ($self, $path, %options) = @_;
226 0 my $err = $self->check_options('SETTIMES', %options);
227 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
228  
229 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
230 0 croak "'touch' needs at least one of modificationtime or accesstime";
231 }
232  
233 0 my $res = $self->operate_requests('PUT', $path, 'SETTIMES', \%options);
234 0 $res->{code} == 200;
235 }
236  
237 #---------------------------- EXTENDED ATTRIBUTES START -----------------------#
238  
239 0 ▶sub xattr {
Subroutine xattr: not called CC=4 SCAR=30.0
Pod documented
240 0 my($self, $path, $action, @args) = @_;
241 0 ▶ croak "No action defined for xattr" if ! $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
242 0 my $target = sprintf '_%s_xattr', $action;
243 0 my $target2 = sprintf '_%s_xattrs', $action;
244 0 ▶ my $method = $self->can( $target )
Condition0%0/5
$self->can($target) || $self->can($target2) || croak("invalid action `$action`")
l!l
00
$self->can($target) or $self->can($target2)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->can($target) || $self->can($target2) || croak("invalid action `$action`")
$self->can($target) $self->can($target2)
Truth table0%0/3
A or B
A= $self->can($target)B= $self->can($target2)
ABresult
1X1
011
000
245 || $self->can( $target2 )
246 || croak "invalid action `$action`";
247 0 $self->$method( $path, @args );
248 }
249  
250 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETXATTRS
251 # &xattr.name=<XATTRNAME>&encoding=<ENCODING>"
252 #
253 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETXATTRS
254 # &xattr.name=<XATTRNAME1>&xattr.name=<XATTRNAME2>&encoding=<ENCODING>"
255 1 $OPT_TABLE{GETXATTRS} = [qw( names encoding flatten )];
256 0 ▶sub _get_xattrs {
Subroutine _get_xattrs: not called CC=7 SCAR=40.3
257 0 my($self, $path, %options) = @_;
258 0 my $err = $self->check_options('GETXATTRS', %options);
259 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
260  
261 0 my $flatten = delete $options{flatten};
262  
263 # limit to a subset? will return all of the attributes otherwise
264 0 ▶ if ( my $name = delete $options{names} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = delete $options{"names"}) 0 0 0
265 0 ▶ croak "getxattrs: name needs to be an arrayref" if ref $name ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $name ne "ARRAY" 0 0 0
266 0 $options{'xattr.name'} = $name;
267 }
268  
269 0 my $res = $self->operate_requests('GET', $path, 'GETXATTRS', \%options);
270 0 ▶ if ( my $rv = $self->check_success_json($res, 'XAttrs') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "XAttrs")) 0 0 0
271 0 ▶ croak "Unexpected return value from listxattrs: $rv"
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "ARRAY" 0 0 0
272 if ref $rv ne 'ARRAY';
273 0 ▶ return $rv if ! $flatten;
Branch: 1 branch
BranchTrueFalseTotal
unless $flatten 0 0 0
274 0 map { @{ $_ }{qw/ name value /} } @{ $rv };
275 }
276 }
277  
278 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTXATTRS"
279 0 ▶sub _list_xattrs {
Subroutine _list_xattrs: not called CC=3 SCAR=24.8
280 0 my($self, $path) = @_;
281  
282 0 my $res = $self->operate_requests('GET', $path, 'LISTXATTRS');
283 0 ▶ if ( my $rv = $self->check_success_json($res, 'XAttrNames') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "XAttrNames")) 0 0 0
284 0 my $attr = JSON::XS::decode_json $rv;
285 0 ▶ croak "Unexpected return value from listxattrs: $attr"
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr ne "ARRAY" 0 0 0
286 if ref $attr ne 'ARRAY';
287 0 return @{ $attr };
288 }
289 }
290  
291 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETXATTR
292 # &xattr.name=<XATTRNAME>&xattr.value=<XATTRVALUE>&flag=<FLAG>"
293 # https://blog.cloudera.com/blog/2014/06/why-extended-attributes-are-coming-to-hdfs/
294 # flag: [CREATE,REPLACE]
295 1 $OPT_TABLE{SETXATTR} = [qw( name value flag )];
296 0 ▶sub _set_xattr {
Subroutine _set_xattr: not called CC=5 SCAR=34.0
297 0 my($self, $path, %options) = @_;
298 0 my $err = $self->check_options('SETXATTR', %options);
299 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
300  
301 0 ▶ croak "value of xattr not set" if ! exists $options{value};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"value"} 0 0 0
302  
303 0 ▶ $options{ 'xattr.name' } = delete $options{name} || croak "name of xattr not set";
Condition0%0/2
delete $options{'name'} || croak('name of xattr not set')
l!l
00
MC/DC0%0/1
delete $options{'name'} || croak('name of xattr not set')
delete $options{'name'}
Truth table0%0/2
A
A= delete $options{'name'}
Aresult
11
00
304 0 $options{ 'xattr.value' } = delete $options{value};
305  
306 0 ▶ croak 'flag was not specified.' if ! $options{flag};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"flag"} 0 0 0
307  
308 0 my $res = $self->operate_requests( PUT => $path, 'SETXATTR', \%options);
309 0 $res->{code} == 200;
310 }
311  
312 0 ▶sub _create_xattr {
Subroutine _create_xattr: not called CC=1 SCAR=6.9
313 0 my($self, $path, $name, $value) = @_;
314 0 $self->_set_xattr(
315 $path,
316 name => $name,
317 value => $value,
318 flag => 'CREATE',
319 );
320 }
321  
322 0 ▶sub _replace_xattr {
Subroutine _replace_xattr: not called CC=1 SCAR=6.9
323 0 my($self, $path, $name, $value) = @_;
324 0 $self->_set_xattr(
325 $path,
326 name => $name,
327 value => $value,
328 flag => 'REPLACE',
329 );
330 }
331  
332 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=REMOVEXATTR
333 # &xattr.name=<XATTRNAME>"
334 0 ▶sub _remove_xattr {
Subroutine _remove_xattr: not called CC=2 SCAR=17.9
335 0 my($self, $path, $name) = @_;
336  
337 0 my %options;
338 0 ▶ $options{'xattr.name'} = $name || croak "xattr name was not specified";
Condition0%0/2
$name || croak('xattr name was not specified')
l!l
00
MC/DC0%0/1
$name || croak('xattr name was not specified')
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
339  
340 0 my $res = $self->operate_requests( PUT => $path, 'REMOVEXATTR', \%options);
341 0 $res->{code} == 200;
342 }
343  
344 #---------------------------- EXTENDED ATTRIBUTES END -------------------------#
345  
346 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CHECKACCESS
347 # &fsaction=<FSACTION>
348 # this seems to be broken in some versions. You may get a "No enum constant ..."
349 # error if this is the case.
350 # Also see https://issues.apache.org/jira/browse/HDFS-9695
351 #
352 0 ▶sub checkaccess {
Subroutine checkaccess: not called CC=3 SCAR=24.8
Pod documented
353 0 my($self, $path, $fsaction, %options) = @_;
354 0 ▶ croak "checkaccess: fsaction parameter was not specified" if ! $fsaction;
Branch: 1 branch
BranchTrueFalseTotal
unless $fsaction 0 0 0
355 0 my $err = $self->check_options('CHECKACCESS', %options);
356 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
357  
358 0 $options{fsaction} = $fsaction;
359  
360 0 my $res = $self->operate_requests('GET', $path, 'CHECKACCESS', \%options);
361 0 $res->{code} == 200;
362 }
363  
364 # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CONCAT
365 # &sources=<PATHS>"
366 0 ▶sub concat {
Subroutine concat: not called CC=2 SCAR=17.9
Pod documented
367 0 my($self, $path, @sources) = @_;
368  
369 0 ▶ croak "At least one source path needs to be specified" if ! @sources;
Branch: 1 branch
BranchTrueFalseTotal
unless @sources 0 0 0
370  
371 0 my $paths = join q{,}, @sources;
372  
373 0 my $res = $self->operate_requests(
374 POST => $path,
375 'CONCAT',
376 { sources => $paths },
377 );
378 0 $res->{code} == 200;
379 }
380  
381 # curl -i -X POST "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=TRUNCATE
382 # &newlength=<LONG>"
383 # Available after Hadoop v2.7
384 # https://issues.apache.org/jira/browse/HDFS-7655
385 #
386 0 ▶sub truncate {
Subroutine truncate: not called CC=3 SCAR=24.8
Pod documented
387 0 my($self, $path, $newlength) = @_;
388 0 ▶ $newlength = 0 if ! defined $newlength;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newlength 0 0 0
389  
390 0 my $res = $self->operate_requests(
391 POST => $path,
392 'TRUNCATE',
393 { newlength => $newlength },
394 );
395  
396 0 ▶ if ( my $rv = $self->check_success_json($res, 'boolean') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "boolean")) 0 0 0
397 0 $rv eq 'true';
398 }
399 }
400  
401 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATESYMLINK
402 # &destination=<PATH>[&createParent=<true |false>]"
403 # currently broken/disabled
404 # https://issues.apache.org/jira/browse/HADOOP-10019
405  
406 #$OPT_TABLE{CREATESYMLINK} = [qw( destination createParent )];
407 #sub createsymlink {
408 # # Not available yet
409 # # https://issues.apache.org/jira/browse/HADOOP-10019
410 # my($self, $path, $destination, $createParent) = @_;
411 #
412 # croak "createsymlink: destination not specified" if ! $destination;
413 #
414 # my %options = (
415 # destination => $destination,
416 # ($createParent ? (
417 # createParent => $createParent ? 'true' : 'false',
418 # ) : ())
419 # );
420 #
421 # my $res = $self->operate_requests( PUT => $path, 'CREATESYMLINK', \%options);
422 # $res->{code} == 200;
423 #}
424  
425 #---------------------------- DELEGATION TOKEN START --------------------------#
426 # Also see
427 # http://hadoop.apache.org/docs/r2.6.0/hadoop-hdfs-httpfs/httpfs-default.html
428  
429 # GETDELEGATIONTOKENS: Obsolete and removed after HDFS-10200, HDFS-3667
430 #
431  
432 0 ▶sub delegation_token {
Subroutine delegation_token: not called CC=3 SCAR=24.8
Pod documented
433 0 my($self, $action, @args) = @_;
434 0 ▶ croak "No action defined for delegation_token" if ! $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
435 0 my $target = sprintf '_%s_delegation_token', $action;
436 0 ▶ croak "invalid action $action" if ! $self->can( $target );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($target) 0 0 0
437 0 $self->$target( @args );
438 }
439  
440 # curl -i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETDELEGATIONTOKEN
441 # &renewer=<USER>&service=<SERVICE>&kind=<KIND>"
442 # kind: The kind of the delegation token requested
443 # <empty> (Server sets the default kind for the service)
444 # A string that represents token kind e.g "HDFS_DELEGATION_TOKEN" or "WEBHDFS delegation"
445 # service: The name of the service where the token is supposed to be used, e.g. ip:port of the namenode
446 #
447 1 $OPT_TABLE{GETDELEGATIONTOKEN} = [qw( renewer service kind )];
448 0 ▶sub _get_delegation_token {
Subroutine _get_delegation_token: not called CC=5 SCAR=34.0
449 0 my($self, $path, %options) = @_;
450 0 my $err = $self->check_options('GETDELEGATIONTOKEN', %options);
451 0 ▶ croak $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
452  
453 0 ▶ $options{renewer} ||= $self->{username} if $self->{username};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"username"} 0 0 0
Condition0%0/3
$options{"renewer"} ||= $self->{"username"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"renewer"} ||= $self->{"username"}
$options{"renewer"} $self->{"username"}
Truth table0%0/3
A ||= B
A= $options{"renewer"}B= $self->{"username"}
ABresult
1X1
011
000
454  
455 0 my $res = $self->operate_requests( GET => $path, 'GETDELEGATIONTOKEN', \%options);
456  
457 0 ▶ if ( my $rv = $self->check_success_json($res, 'Token') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "Token")) 0 0 0
458 0 $rv->{urlString};
459 }
460 }
461  
462 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/?op=RENEWDELEGATIONTOKEN
463 # &token=<TOKEN>"
464 0 ▶sub _renew_delegation_token {
Subroutine _renew_delegation_token: not called CC=3 SCAR=24.8
465 0 my($self, $token) = @_;
466  
467 0 ▶ croak "No token was specified" if ! $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
468  
469 0 my $res = $self->operate_requests(
470 PUT => GENERIC_FS_ACTION_WITH_NO_PATH,
471 'RENEWDELEGATIONTOKEN',
472 { token => $token },
473 );
474 0 ▶ if ( my $rv = $self->check_success_json($res, 'long') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "long")) 0 0 0
475 0 $rv; # new expiration time in miliseconds
476 }
477 }
478  
479 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/?op=CANCELDELEGATIONTOKEN
480 # &token=<TOKEN>"
481 0 ▶sub _cancel_delegation_token {
Subroutine _cancel_delegation_token: not called CC=2 SCAR=17.9
482 0 my($self, $token) = @_;
483  
484 0 ▶ croak "No token was specified" if ! $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
485  
486 0 my $res = $self->operate_requests(
487 PUT => GENERIC_FS_ACTION_WITH_NO_PATH,
488 'CANCELDELEGATIONTOKEN',
489 { token => $token },
490 );
491 0 $res->{code} == 200;
492 }
493  
494 #---------------------------- DELEGATION TOKEN END ----------------------------#
495  
496 #---------------------------- SNAPSHOT START ----------------------------------#
497  
498 # Needs testing, seems to be buggy and can be destructive in earlier versions
499 # i.e.: https://issues.apache.org/jira/browse/HDFS-9406
500 #
501 # Snaphotting is not enabled by default and this needs to be executed as a super user:
502 # hdfs dfsadmin -allowSnapshot $path
503 #
504 0 ▶sub snapshot {
Subroutine snapshot: not called CC=3 SCAR=24.8
Pod documented
505 0 my($self, $path, $action, @args) = @_;
506 0 ▶ croak "No action defined for delegation_token" if ! $action;
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 0 0
507 0 my $target = sprintf '_%s_snapshot', $action;
508 0 ▶ croak sprintf "%s: invalid action $action", (caller 0)[3] if ! $self->can( $target );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($target) 0 0 0
509 0 $self->$target( $path => @args );
510 }
511  
512 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATESNAPSHOT
513 # [&snapshotname=<SNAPSHOTNAME>]"
514 0 ▶sub _create_snapshot {
Subroutine _create_snapshot: not called CC=3 SCAR=24.8
515 0 my($self, $path, $snapshotname) = @_;
516  
517 0 my %options;
518 0 ▶ $options{snapshotname} = $snapshotname if $snapshotname;
Branch: 1 branch
BranchTrueFalseTotal
if $snapshotname 0 0 0
519 0 my $res = $self->operate_requests('PUT', $path, 'CREATESNAPSHOT', \%options);
520 0 ▶ if ( my $rv = $self->check_success_json($res, 'Path') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rv = $self->check_success_json($res, "Path")) 0 0 0
521 0 $rv;
522 }
523 }
524  
525 # curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=RENAMESNAPSHOT
526 # &oldsnapshotname=<SNAPSHOTNAME>&snapshotname=<SNAPSHOTNAME>"
527 0 ▶sub _rename_snapshot {
Subroutine _rename_snapshot: not called CC=1 SCAR=6.9
528 0 my($self, $path, $oldsnapshotname, $snapshotname) = @_;
529  
530 0 my %options = (
531 oldsnapshotname => $oldsnapshotname,
532 snapshotname => $snapshotname,
533 );
534  
535 0 my $res = $self->operate_requests('PUT', $path, 'RENAMESNAPSHOT', \%options);
536 0 $res->{code} == 200;
537 }
538  
539 # curl -i -X DELETE "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=DELETESNAPSHOT
540 # &snapshotname=<SNAPSHOTNAME>"
541 0 ▶sub _delete_snapshot {
Subroutine _delete_snapshot: not called CC=2 SCAR=17.9
542 0 my($self, $path, $snapshotname) = @_;
543 0 ▶ croak "No snapshotname specified" if ! $snapshotname;
Branch: 1 branch
BranchTrueFalseTotal
unless $snapshotname 0 0 0
544  
545 0 my %options = (
546 snapshotname => $snapshotname,
547 );
548 0 my $res = $self->operate_requests('DELETE', $path, 'DELETESNAPSHOT', \%options);
549 0 $res->{code} == 200;
550 }
551  
552 #---------------------------- SNAPSHOT END ------------------------------------#
553  
554 0 ▶sub touchz {
Subroutine touchz: not called CC=1 SCAR=6.9
Pod documented
555 0 my ($self, $path) = @_;
556 0 return $self->create( $path, '', overwrite => 'true' );
557 }
558  
559 0 ▶sub settimes { (shift)->touch(@_); }
Subroutine settimes: not called CC=1 SCAR=6.9
Pod undocumented
560  
561 # sub delegation_token {}
562 # sub renew_delegation_token {}
563 # sub cancel_delegation_token {}
564  
565 0 ▶sub check_options {
Subroutine check_options: not called CC=5 SCAR=34.0
Pod undocumented
566 0 my ($self, $op, %opts) = @_;
567 0 my @ex = ();
568 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
569 0 foreach my $k (keys %opts) {
570 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
571 }
572 0 ▶ return undef unless @ex;
Branch: 1 branch
BranchTrueFalseTotal
unless @ex 0 0 0
573 0 'no such option: ' . join(' ', @ex);
574 }
575  
576 8 ▶sub check_success_json {
Subroutine check_success_json: called CC=4 SCAR=13.9
Pod undocumented
577 8 my ($self, $res, $attr) = @_;
578 $res->{code} == 200 and $res->{content_type} =~ m!^application/json! and
579 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
580 }
581  
582 10 ▶sub api_path {
Subroutine api_path: called CC=2 SCAR=6.9
Pod undocumented
583 10 my ($self, $path) = @_;
584 10 ▶ return '/webhdfs/v1' . $path if $path =~ m!^/!;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[^/] 9 1 10
585 1 '/webhdfs/v1/' . $path;
586 }
587  
588 7 ▶sub build_path {
Subroutine build_path: called CC=3 SCAR=11.0
Pod undocumented
589 7 my ($self, $path, $op, %params) = @_;
590 my %opts = (('op' => $op),
591 ($self->{username} ? ('user.name' => $self->{username}) : ()),
592 7 ▶ ($self->{doas} ? ('doas' => $self->{doas}) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$self->{'username'} ? : 4 3 7
$self->{'doas'} ? : 2 5 7
593 %params);
594 7 my $u = URI->new('', 'http');
595 7 $u->query_form(%opts);
596 7 $self->api_path($path) . $u->path_query; # path_query() #=> '?foo=1&bar=2'
597 }
598  
599 0 ▶sub connect_to {
Subroutine connect_to: not called CC=2 SCAR=17.9
Pod undocumented
600 0 my $self = shift;
601 0 ▶ if ($self->{under_failover}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"under_failover"}) 0 0 0
602 0 return ($self->{standby_host}, $self->{standby_port});
603 }
604 0 return ($self->{host}, $self->{port});
605 }
606  
607 1 our %REDIRECTED_OPERATIONS = (APPEND => 1, CREATE => 1, OPEN => 1, GETFILECHECKSUM => 1);
608 0 ▶sub operate_requests {
Subroutine operate_requests: not called CC=8 SCAR=42.8
Pod undocumented
609 0 my ($self, $method, $path, $op, $params, $payload) = @_;
610  
611 0 my ($host, $port) = $self->connect_to();
612  
613 0 my $headers = []; # or undef ?
614 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
615 # empty files are ok
616 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
617 0 $headers = ['Content-Type' => 'application/octet-stream'];
618 }
619 0 return $self->request($host, $port, $method, $path, $op, $params, $payload, $headers);
620 }
621  
622 # pattern for not httpfs and redirected by namenode
623 0 my $res = $self->request($host, $port, $method, $path, $op, $params, undef);
624 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
625 0 my $code = $res->{code};
626 0 my $body = $res->{body};
627 0 croak "NameNode returns non-redirection (or without location header), code:$code, body:$body.";
628 }
629 0 my $uri = URI->new($res->{location});
630 0 $headers = ['Content-Type' => 'application/octet-stream'];
631 0 return $self->request($uri->host, $uri->port, $method, $uri->path_query, undef, {}, $payload, $headers);
632 }
633  
634 0 ▶sub request {
Subroutine request: not called CC=2 SCAR=17.9
Pod undocumented
635 0 my $self = shift;
636 0 ▶ return $self->_request(@_) unless $self->{suppress_errors};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"suppress_errors"} 0 0 0
637  
638 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
639 0 $self->_request(@_);
640 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
641 0 $self->{last_error} = $_;
642 0 0;
643 0 };
644 }
645  
646 # IllegalArgumentException 400 Bad Request
647 # UnsupportedOperationException 400 Bad Request
648 # SecurityException 401 Unauthorized
649 # IOException 403 Forbidden
650 # FileNotFoundException 404 Not Found
651 # RumtimeException 500 Internal Server Error
652 0 ▶sub _request {
Subroutine _request: not called CC=20 SCAR=60.4
653 0 my ($self, $host, $port, $method, $path, $op, $params, $payload, $header) = @_;
654  
655 0 ▶ my $request_path = $op ? $self->build_path($path, $op, %$params) : $path;
Branch: 1 branch
BranchTrueFalseTotal
$op ? : 0 0 0
656 my ($ver, $code, $msg, $headers, $body) = $self->{furl}->request(
657 0 ▶ method => $method,
Branch: 1 branch
BranchTrueFalseTotal
$payload ? : 0 0 0
658 host => $host,
659 port => $port,
660 path_query => $request_path,
661 headers => $header,
662 ($payload ? (content => $payload) : ()),
663 );
664  
665 0 my $res = { code => $code, body => $body };
666  
667 0 ▶ for (my $i = 0; $i < scalar(@$headers); $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$headers) 0 0 0
668 0 my $header = $headers->[$i];
669 0 my $value = $headers->[$i + 1];
670  
671 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
672 0 elsif ($header =~ m!^content-type$!i) { $res->{content_type} = $value; }
673 }
674  
675 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
676 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
677  
678 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
679 0 $errmsg =~ s/\n//g;
680  
681 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
682 0 elsif ($code == 401) { croak "SecurityError: $errmsg"; }
683 elsif ($code == 403) {
684 0 ▶ if ($errmsg =~ /org\.apache\.hadoop\.ipc\.StandbyException/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errmsg =~ /org\.apache\.hadoop\.ipc\.StandbyException/) 0 0 0
685 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
686 # failover is disabled
687 } elsif ($self->{retrying}) {
688 # more failover is prohibited
689 0 $self->{retrying} = 0;
690 } else {
691 0 $self->{under_failover} = not $self->{under_failover};
692 0 $self->{retrying} = 1;
693 0 my ($next_host, $next_port) = $self->connect_to();
694 0 my $val = $self->request($next_host, $next_port, $method, $path, $op, $params, $payload, $header);
695 0 $self->{retrying} = 0;
696 0 return $val;
697 }
698 }
699 0 croak "IOError: $errmsg";
700 }
701 0 elsif ($code == 404) { croak "FileNotFoundError: $errmsg"; }
702 0 elsif ($code == 500) { croak "ServerError: $errmsg"; }
703  
704 0 croak "RequestFailedError, code:$code, message:$errmsg";
705 }
706  
707 0 ▶sub exists {
Subroutine exists: not called CC=5 SCAR=34.0
Pod documented
708 0 my $self = shift;
709 0 ▶ my $path = shift || croak "No HDFS path was specified";
Condition0%0/2
shift() || croak('No HDFS path was specified')
l!l
00
MC/DC0%0/1
shift() || croak('No HDFS path was specified')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
710 0 my $stat;
711 eval {
712 0 $stat = $self->stat( $path );
713 0 1;
714 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $stat = $self->stat($path); 1 } } or do { my $eval_error = $@ || "Zombie error"; return if $eval_error =~ / FileNotFoundError\:\ \{\"RemoteException\"\:\{\"message\"\:\"File\ does\ not\ exist\: /msx; croak($eval_error) } 0 0 0
715 0 ▶ my $eval_error = $@ || 'Zombie error';
Condition0%0/2
$@ || 'Zombie error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
716 0 ▶ return if $eval_error =~ m<
Branch: 1 branch
BranchTrueFalseTotal
if $eval_error =~ / FileNotFoundError\:\ \{\"RemoteException\"\:\{\"message\"\:\"File\ does\ not\ exist\: /msx 0 0 0
717 \QFileNotFoundError: {"RemoteException":{"message":"File does not exist:\E
718 >xms;
719 # just re-throw
720 0 croak $eval_error;
721 };
722 0 return $stat;
723 }
724  
725 0 ▶sub find {
Subroutine find: not called CC=6 SCAR=37.4
Pod documented
726 0 my $self = shift;
727 0 ▶ my $file_path = shift || croak "No file path specified";
Condition0%0/2
shift() || croak('No file path specified')
l!l
00
MC/DC0%0/1
shift() || croak('No file path specified')
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
728 0 my $cb = shift;
729 0 ▶ my $opt = @_ && ref $_[-1] eq 'HASH' ? pop @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[-1] eq 'HASH' ? : 0 0 0
Condition0%0/3
@_ and ref $_[-1] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and ref $_[-1] eq "HASH"
@_ ref $_[-1] eq "HASH"
Truth table0%0/3
A and B
A= @_B= ref $_[-1] eq "HASH"
ABresult
0X0
100
111
730  
731 0 ▶ if ( ref $cb ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cb ne "CODE") 0 0 0
732 0 die "Call back needs to be a CODE ref";
733 }
734  
735 0 my $suppress = $self->{suppress_errors};
736 # can be used to quickly skip the java junk like, file names starting with
737 # underscores, etc.
738 0 ▶ my $re_ignore = $opt->{re_ignore} ? qr/$opt->{re_ignore}/ : undef;
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'re_ignore'} ? : 0 0 0
739  
740 #
741 # No such thing like symlinks (yet) in HDFS, in case you're wondering:
742 # https://issues.apache.org/jira/browse/HADOOP-10019
743 # although check that link yourself
744 #
745 0 my $looper;
746 0 ▶ $looper = sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
747 0 my $thing = shift;
748 0 ▶ if ( ! $self->exists( $thing ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists($thing)) 0 0 0
749 # should happen at the start, so this will short-circuit the recursion
750 0 warn "The HDFS directory specified ($thing) does not exist! Please guard your HDFS paths with exists()";
751 0 return;
752 }
753 0 my $list = $self->list( $thing );
754 0 foreach my $e ( @{ $list } ) {
755 0 my $path = $e->{pathSuffix};
756 0 my $type = $e->{type};
757  
758 0 ▶ next if $re_ignore && $path && $path =~ $re_ignore;
Branch: 1 branch
BranchTrueFalseTotal
if $re_ignore and $path and $path =~ /$re_ignore/ 0 0 0
Condition0%0/6
$re_ignore and $path and $path =~ /$re_ignore/
!ll&&!rl&&r
000
$re_ignore and $path
!ll&&!rl&&r
000
MC/DC0%0/3
$re_ignore and $path and $path =~ /$re_ignore/
$re_ignore $path $path =~ /$re_ignore/
Truth table0%0/4
A and B and C
A= $re_ignoreB= $pathC= $path =~ /$re_ignore/
ABCresult
0XX0
10X0
1100
1111
759  
760 0 ▶ if ( $type eq 'DIRECTORY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'DIRECTORY') { } 0 0 0
elsif ($type eq 'FILE') { } 0 0 0
761 0 $cb->( $thing, $e );
762 eval {
763 0 $looper->( File::Spec->catdir( $thing, $path ) );
764 0 1;
765 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$looper("File::Spec"->catdir($thing, $path)); 1 } } or do { my $eval_error = $@ || "Zombie error"; if ($suppress) { warn "[ERROR DOWNGRADED] Failed to check $thing/${path}: $eval_error"; next; } ; croak($eval_error) } 0 0 0
766 0 ▶ my $eval_error = $@ || 'Zombie error';
Condition0%0/2
$@ || 'Zombie error'
l!l
00
MC/DC0%0/1
$@ || 'Zombie error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
767 0 ▶ if ( $suppress ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suppress) 0 0 0
768 0 warn "[ERROR DOWNGRADED] Failed to check $thing/$path: $eval_error";
769 0 next;
770 }
771 0 croak $eval_error;
772 }
773 }
774 elsif ( $type eq 'FILE' ) {
775 0 $cb->( $thing, $e );
776 }
777 else {
778 0 my $msg = "I don't know what to do with type=$type!";
779 0 ▶ if ( $suppress ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suppress) 0 0 0
780 0 warn "[ERROR DOWNGRADED] $msg";
781 0 next;
782 }
783 0 croak $msg;
784 }
785 }
786 0 return;
787 0 };
788  
789 0 $looper->( $file_path );
790  
791 0 return;
792 }
793  
794 1 1;
795  
796 __END__
↑ Summary