YARN/Roles/AppMasterHistoryServer.pm

filter: Statementstmt 50.0% 40 / 80 Branchbran 0.0% 0 / 14 Conditioncond 21.0% 4 / 19 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 61.5% 8 / 13 Podpod n/a totaltotal 39.4% 54 / 137 CC 18 SCAR 39.5
CC
18
Cov
39%
__ANON__
132.0
_extract_valid_params
12.0
_mk_subs
9.1
CRAP 51.9
« YARN/Roles/JMX.pm ↑ Summary YARN/ApplicationMaster.pm »
1 package Net::Hadoop::YARN::Roles::AppMasterHistoryServer;
2 6 $Net::Hadoop::YARN::Roles::AppMasterHistoryServer::VERSION = '0.203';
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Hash::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 my %validation_pattern = (
12 appid => 'application_[0-9]+_[0-9]+',
13 jobid => 'job_[0-9]+_[0-9]+',
14 taskid => 'task_[0-9]+_[0-9]+_[a-z]_[0-9]+',
15 attemptid => 'attempt_[0-9]+_[0-9]+_[a-z]_[0-9]+_[0-9]+',
16 );
17  
18 my $RE_EXTRACT_VALIDS = sprintf '(?:%s)',
19 join '|',
20 6 map { $validation_pattern{$_} }
21 keys %validation_pattern;
22  
23 # used by consuming classes, for specific cases
24 0 ▶sub _validate_id {
Subroutine _validate_id: not called CC=1 SCAR=6.9
25 0 my $self = shift;
26 0 return $_[1] =~ /^$validation_pattern{$_[0]}$/;
27 }
28  
29 0 ▶sub _extract_valid_params {
Subroutine _extract_valid_params: not called CC=3 SCAR=24.8
30 # TODO: this doesn't recognise container or attempt etc ids per above hash
31 #
32 0 my $self = shift;
33 0 ▶ my $str = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
34  
35 0 my @ids;
36 0 ▶ while ( my($type) = $str =~ /$RE_EXTRACT_VALIDS/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($type) = $str =~ /$RE_EXTRACT_VALIDS/cg) 0 0 0
37 0 push @ids, $type;
38 }
39  
40 0 return @ids;
41 }
42  
43 8 ▶sub _mk_subs {
Subroutine _mk_subs: called CC=4 SCAR=22.0
44 8 my $methods_urls = shift;
45 8 ▶ my $opt = shift || {};
Condition100%2/2
shift() || {}
l!l
35
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
46 8 ▶ my $pfix = $opt->{prefix} || '';
Condition100%2/2
$opt->{'prefix'} || ''
l!l
35
MC/DC100%1/1
$opt->{'prefix'} || ''
$opt->{'prefix'}
Truth table100%2/2
A
A= $opt->{'prefix'}
Aresult
11
00
47  
48 8 for my $key ( keys %{$methods_urls} ) {
49  
50 # use a closure to only run the preprocessing once per method for
51 # validation. URL params are of the form {appid}, {taskid}, hence the
52 # regexes to find them
53 88 my @param_names = $methods_urls->{$key}[0] =~ m/\{([a-z]+)\}/g;
54 my @validations = map {
55 88 my $name = $_;
56 {
57 name => $name,
58 0 ▶ validate => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
59 0 ▶ my $val = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
60 0 $val =~ /^$validation_pattern{$name}$/
61 },
62 169 };
63 } @param_names;
64  
65 88 my $url = $methods_urls->{$key}[0];
66 88 my $json_path = $methods_urls->{$key}[1];
67  
68 0 ▶ my $new_method = sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
69 0 my $self = shift;
70 # check the list of params validates against the list of
71 # placeholders gathered in the url split above
72 0 my $params_idx = 0;
73  
74 0 for my $param ( @_ ) {
75 my $v = $validations[ $params_idx ]
76 0 ▶ || do {
Condition0%0/3
$validations[$params_idx] || do { my $what = $key =~ / \A _ /msx ? do { if (my $who = (caller 1)[3]) { my($short) = (split(/ [:]{2} /msx, $who, 0))[-1]; sprintf '%s` via: `%s', $short, $who; } else { $key; } } : $key; croak(sprintf('No validator for `%s` [%s]. Be sure that `%s` is a valid API endpoint for this object', $param, $params_idx, $what)) }
l!l&&r!l&&!r
000
MC/DC0%0/2
$validations[$params_idx] || do { my $what = $key =~ / \A _ /msx ? do { if (my $who = (caller 1)[3]) { my($short) = (split(/ [:]{2} /msx, $who, 0))[-1]; sprintf '%s` via: `%s', $short, $who; } else { $key; } } : $key; croak(sprintf('No validator for `%s` [%s]. Be sure that `%s` is a valid API endpoint for this object', $param, $params_idx, $what)) }
$validations[$params_idx] do { my $what = $key =~ / \A _ /msx ? do { if (my $who = (caller 1)[3]) { my($short) = (split(/ [:]{2} /msx, $who, 0))[-1]; sprintf '%s` via: `%s', $short, $who; } else { $key; } } : $key; croak(sprintf('No validator for `%s` [%s]. Be sure that `%s` is a valid API endpoint for this object', $param, $params_idx, $what)) }
Truth table0%0/3
A || B
A= $validations[$params_idx]B= do { my $what = $key =~ / \A _ /msx ? do { if (my $who = (caller 1)[3]) { my($short) = (split(/ [:]{2} /msx, $who, 0))[-1]; sprintf '%s` via: `%s', $short, $who; } else { $key; } } : $key; croak(sprintf('No validator for `%s` [%s]. Be sure that `%s` is a valid API endpoint for this object', $param, $params_idx, $what)) }
ABresult
1X1
011
000
77 my $what = $key =~ m{ \A _ }xms
78 0 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
$key =~ / \A _ /msx ? : 0 0 0
79 0 ▶ if ( my $who = (caller 1)[3] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $who = (caller 1)[3]) { } 0 0 0
80 0 my($short) = (split m{ [:]{2} }xms, $who)[-1];
81 0 sprintf qq{%s` via: `%s}, $short, $who;
82 }
83 else {
84 0 $key;
85 }
86 }
87 : $key
88 ;
89 0 croak sprintf "No validator for `%s` [%s]. Be sure that `%s` is a valid API endpoint for this object",
90 $param,
91 $params_idx,
92 $what,
93 ;
94 };
95  
96 0 ▶ if ( ! ref $param && ! $v->{validate}->( $param ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $param or $v->{"validate"}->($param)) 0 0 0
Condition0%0/3
ref $param or $v->{"validate"}->($param)
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $param or $v->{"validate"}->($param)
ref $param $v->{"validate"}->($param)
Truth table0%0/3
A or B
A= ref $paramB= $v->{"validate"}->($param)
ABresult
1X1
011
000
97 croak sprintf "Param `%s` doesn't satisfy pattern /%s/ in call to `%s`.",
98 $param || '',
99 $validation_pattern{ $v->{name} },
100 0 ▶ $key,
Condition0%0/2
$param || ''
l!l
00
MC/DC0%0/1
$param || ''
$param
Truth table0%0/2
A
A= $param
Aresult
11
00
101 ;
102 }
103 0 $params_idx++;
104 }
105  
106 # now replace all url placeholders with the params we were given;
107 # extra parameters (in a hashref) will be passed as regular URL
108 # params, not interpolated in the path
109 0 my $interp_url = $url;
110 0 my $extra_params;
111 0 ▶ while (my $param = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $param = shift()) 0 0 0
112 0 ▶ if (! @_ && ref $param) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @_ and ref $param) 0 0 0
Condition0%0/3
not @_ and ref $param
!ll&&!rl&&r
000
MC/DC0%0/2
not @_ and ref $param
not @_ ref $param
Truth table0%0/3
not(A) and B
A= not @_B= ref $param
ABresult
0X0
100
111
113 0 $extra_params = $param;
114 0 last;
115 }
116 0 $interp_url =~ s/\{[a-z]+\}/$param/;
117 }
118 0 my $res = $self->_get($interp_url, { params => $extra_params });
119  
120 # Only return the JSON fragment we need
121 0 return Hash::Path->get($res, split(/\./, $json_path));
122 88 };
123 {
124 # limit the scope of non-strict-ness
125 # insert the method for the endpoint in the using class
126 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
127 88 *{ ( caller() )[0] . '::' . $pfix . $key } = $new_method;
128 }
129 }
130 }
131  
132 0 ▶sub _mk_uri {
Subroutine _mk_uri: not called CC=2 SCAR=17.9
133 0 my $self = shift;
134 0 my ($server, $path, $params) = @_;
135 0 my $uri = $server . "/" . $path;
136 0 $uri =~ s#//+#/#g;
137 0 $uri = URI->new("http://" . $uri);
138 0 ▶ if ($params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params) 0 0 0
139 0 $uri->query_form($params);
140 }
141 0 return $uri;
142 }
143  
144 6 1;
145  
146 __END__
« YARN/Roles/JMX.pm ↑ Summary YARN/ApplicationMaster.pm »