Consul/API/Agent.pm

filter: Statementstmt 53.2% 91 / 171 Branchbran 2.6% 1 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.6% 20 / 42 Podpod 0.0% 0 / 16 totaltotal 41.9% 112 / 267 CC 20 SCAR 15.5
CC
20
Cov
44%
maintenance
12.0
check_register
12.0
service_register
12.0
CRAP 4.7
« Consul/API/KV.pm ↑ Summary Consul/API/ACL.pm »
1 package Consul::API::Agent;
2 9 $Consul::API::Agent::VERSION = '0.027';
3 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Types::Standard qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 requires qw(_version_prefix _api_exec);
9  
10 9 has _agent_endpoint => ( is => 'lazy', isa => Str );
11 2 ▶sub _build__agent_endpoint {
Subroutine _build__agent_endpoint: called CC=1 SCAR=0.0
12 2 shift->_version_prefix . '/agent';
13 }
14  
15 2 ▶sub agent {
Subroutine agent: called CC=2 SCAR=7.1
Pod undocumented
16 2 my $self = shift;
17 2 ▶ $self = Consul->new(@_) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 2 0 2
18 2 return bless \$self, "Consul::API::Agent::Impl";
19 }
20  
21 package
22 Consul::API::Agent::Impl; # hide from PAUSE
23  
24 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 9 ▶use Consul::Check;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 ▶use Consul::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 9 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 9 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 0 ▶sub checks {
Subroutine checks: not called CC=1 SCAR=6.9
Pod undocumented
33 0 my ($self, %args) = @_;
34 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/checks", 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 [ map { Consul::API::Agent::Check->new(%$_) } values %{$_[0]} ]
36 0 });
37 }
38  
39 0 ▶sub services {
Subroutine services: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my ($self, %args) = @_;
41 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/services", 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 [ map { Consul::API::Agent::Service->new(%$_) } values %{$_[0]} ]
43 0 });
44 }
45  
46 4 ▶sub members {
Subroutine members: called CC=1 SCAR=2.0
Pod undocumented
47 4 my ($self, %args) = @_;
48 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/members", 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 [ map { Consul::API::Agent::Member->new(%$_) } @{$_[0]} ]
50 4 });
51 }
52  
53 0 ▶sub self {
Subroutine self: not called CC=1 SCAR=6.9
Pod undocumented
54 0 my ($self, %args) = @_;
55 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/self", 'GET', %args, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 Consul::API::Agent::Self->new(%{$_[0]})
57 0 });
58 }
59  
60 0 ▶sub maintenance {
Subroutine maintenance: not called CC=3 SCAR=24.8
Pod undocumented
61 0 my ($self, $enable, %args) = @_;
62 0 ▶ croak 'usage: $agent->maintenance($enable, [%args])' if grep { !defined } ($enable);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $enable 0 0 0
63 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/maintenance", 'PUT', enable => ($enable ? "true" : "false"), %args);
Branch: 1 branch
BranchTrueFalseTotal
$enable ? : 0 0 0
64 0 return;
65 }
66  
67 0 ▶sub join {
Subroutine join: not called CC=2 SCAR=17.9
Pod undocumented
68 0 my ($self, $address, %args) = @_;
69 0 ▶ croak 'usage: $agent->join($address, [%args])' if grep { !defined } ($address);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $address 0 0 0
70 0 $$self->_api_exec($$self->_agent_endpoint."/join/".$address, 'PUT', %args);
71 0 return;
72 }
73  
74 0 ▶sub force_leave {
Subroutine force_leave: not called CC=2 SCAR=17.9
Pod undocumented
75 0 my ($self, $node, %args) = @_;
76 0 ▶ croak 'usage: $agent->force_leave($node, [%args])' if grep { !defined } ($node);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $node 0 0 0
77 0 $$self->_api_exec($$self->_agent_endpoint."/force-leave/".$node, 'PUT', %args);
78 0 return;
79 }
80  
81 0 ▶sub check_register {
Subroutine check_register: not called CC=3 SCAR=24.8
Pod undocumented
82 0 my ($self, $check, %args) = @_;
83 0 ▶ croak 'usage: $agent->check_register($check, [%args])' if grep { !defined } ($check);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $check 0 0 0
84 {
85 0 local $Carp::CarpInternal{ (__PACKAGE__) } = 1;
86 0 ▶ $check = Consul::Check->smart_new($check) if !blessed $check;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($check) 0 0 0
87 }
88 0 $$self->_api_exec($$self->_agent_endpoint."/check/register", 'PUT', %args, _content => $check->to_json);
89 0 return;
90 }
91  
92 0 ▶sub check_deregister {
Subroutine check_deregister: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my ($self, $check_id, %args) = @_;
94 0 ▶ croak 'usage: $agent->check_deregister($check_id, [%args])' if grep { !defined } ($check_id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $check_id 0 0 0
95 0 $$self->_api_exec($$self->_agent_endpoint."/check/deregister/".$check_id, 'PUT', %args);
96 0 return;
97 }
98  
99 0 ▶sub check_pass {
Subroutine check_pass: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my ($self, $check_id, %args) = @_;
101 0 ▶ croak 'usage: $agent->check_pass($check_id, [%args])' if grep { !defined } ($check_id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $check_id 0 0 0
102 0 $$self->_api_exec($$self->_agent_endpoint."/check/pass/".$check_id, 'PUT', %args);
103 0 return;
104 }
105  
106 0 ▶sub check_warn {
Subroutine check_warn: not called CC=2 SCAR=17.9
Pod undocumented
107 0 my ($self, $check_id, %args) = @_;
108 0 ▶ croak 'usage: $agent->check_warn($check_id, [%args])' if grep { !defined } ($check_id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $check_id 0 0 0
109 0 $$self->_api_exec($$self->_agent_endpoint."/check/warn/".$check_id, 'PUT', %args);
110 0 return;
111 }
112  
113 0 ▶sub check_fail {
Subroutine check_fail: not called CC=2 SCAR=17.9
Pod undocumented
114 0 my ($self, $check_id, %args) = @_;
115 0 ▶ croak 'usage: $agent->check_fail($check_id, [%args])' if grep { !defined } ($check_id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $check_id 0 0 0
116 0 $$self->_api_exec($$self->_agent_endpoint."/check/fail/".$check_id, 'PUT', %args);
117 0 return;
118 }
119  
120 0 ▶sub service_register {
Subroutine service_register: not called CC=3 SCAR=24.8
Pod undocumented
121 0 my ($self, $service, %args) = @_;
122 0 ▶ croak 'usage: $agent->service_register($service, [%args])' if grep { !defined } ($service);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $service 0 0 0
123 0 ▶ $service = Consul::Service->new($service) if !blessed $service;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($service) 0 0 0
124 0 $$self->_api_exec($$self->_agent_endpoint."/service/register", 'PUT', %args, _content => $service->to_json);
125 0 return;
126 }
127  
128 0 ▶sub service_deregister {
Subroutine service_deregister: not called CC=2 SCAR=17.9
Pod undocumented
129 0 my ($self, $service_id, %args) = @_;
130 0 ▶ croak 'usage: $agent->service_deregister($check_id, [%args])' if grep { !defined } ($service_id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $service_id 0 0 0
131 0 $$self->_api_exec($$self->_agent_endpoint."/service/deregister/".$service_id, 'PUT', %args);
132 0 return;
133 }
134  
135 0 ▶sub service_maintenance {
Subroutine service_maintenance: not called CC=3 SCAR=24.8
Pod undocumented
136 0 my ($self, $service_id, $enable, %args) = @_;
137 0 ▶ croak 'usage: $agent->service_maintenance($service_id, $enable, [%args])' if grep { !defined } ($service_id, $enable);
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $service_id, $enable 0 0 0
138 0 ▶ $$self->_api_exec($$self->_agent_endpoint."/service/maintenance/".$service_id, 'PUT', enable => ($enable ? "true" : "false"), %args);
Branch: 1 branch
BranchTrueFalseTotal
$enable ? : 0 0 0
139 0 return;
140 }
141  
142 package Consul::API::Agent::Check;
143 9 $Consul::API::Agent::Check::VERSION = '0.027';
144 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
145 9 ▶use Types::Standard qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
146  
147 9 has node => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 );
148 9 has id => ( is => 'ro', isa => Str, init_arg => 'CheckID', required => 1 );
149 9 has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 );
150 9 has status => ( is => 'ro', isa => Str, init_arg => 'Status', required => 1 );
151 9 has notes => ( is => 'ro', isa => Str, init_arg => 'Notes', required => 1 );
152 9 has output => ( is => 'ro', isa => Str, init_arg => 'Output', required => 1 );
153 9 has service_id => ( is => 'ro', isa => Str, init_arg => 'ServiceID', required => 1 );
154 9 has service_name => ( is => 'ro', isa => Str, init_arg => 'ServiceName', required => 1 );
155  
156 package Consul::API::Agent::Service;
157 9 $Consul::API::Agent::Service::VERSION = '0.027';
158 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 9 ▶use Types::Standard qw(Str Int ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
160  
161 9 has id => ( is => 'ro', isa => Str, init_arg => 'ID', required => 1 );
162 9 has service => ( is => 'ro', isa => Str, init_arg => 'Service', required => 1 );
163 9 has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 );
164 9 has port => ( is => 'ro', isa => Int, init_arg => 'Port', required => 1 );
165 0 ▶has tags => ( is => 'ro', isa => ArrayRef[Str], init_arg => 'Tags', required => 1, coerce => sub { $_[0] || [] } );
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or [] 0 0 0
166  
167 package Consul::API::Agent::Member;
168 9 $Consul::API::Agent::Member::VERSION = '0.027';
169 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
170 9 ▶use Types::Standard qw(Str Int HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
171  
172 9 has name => ( is => 'ro', isa => Str, init_arg => 'Name', required => 1 );
173 9 has addr => ( is => 'ro', isa => Str, init_arg => 'Addr', required => 1 );
174 9 has port => ( is => 'ro', isa => Int, init_arg => 'Port', required => 1 );
175 0 ▶has tags => ( is => 'ro', isa => HashRef[Str], init_arg => 'Tags', required => 1, coerce => sub { $_[0] || {} } );
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or {} 0 0 0
176 9 has status => ( is => 'ro', isa => Int, init_arg => 'Status', required => 1 );
177 9 has protocol_min => ( is => 'ro', isa => Int, init_arg => 'ProtocolMin', required => 1 );
178 9 has protocol_max => ( is => 'ro', isa => Int, init_arg => 'ProtocolMax', required => 1 );
179 9 has protocol_cur => ( is => 'ro', isa => Int, init_arg => 'ProtocolCur', required => 1 );
180 9 has delegate_min => ( is => 'ro', isa => Int, init_arg => 'DelegateMin', required => 1 );
181 9 has delegate_max => ( is => 'ro', isa => Int, init_arg => 'DelegateMax', required => 1 );
182 9 has delegate_cur => ( is => 'ro', isa => Int, init_arg => 'DelegateCur', required => 1 );
183  
184 package Consul::API::Agent::Self;
185 9 $Consul::API::Agent::Self::VERSION = '0.027';
186 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 9 ▶use Types::Standard qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
188 9 ▶use Type::Utils qw(class_type);
Subroutine BEGIN: called CC=1 SCAR=0.0
189  
190 # XXX raw hash. not happy about this, but the list of config keys don't seem to be consistent across environments
191 0 ▶has config => ( is => 'ro', isa => HashRef, init_arg => 'Config', required => 1, coerce => sub { $_[0] || {} } );
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or {} 0 0 0
192 0 ▶has member => ( is => 'ro', isa => class_type('Consul::API::Agent::Member'), init_arg => 'Member', required => 1, coerce => sub { Consul::API::Agent::Member->new($_[0]) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
193  
194 9 1;
195  
196 =pod
197  
198 =encoding UTF-8
199  
200 =head1 NAME
201  
202 Consul::API::Agent - Agent API
203  
204 =head1 SYNOPSIS
205  
206 use Consul;
207 my $agent = Consul->agent;
208 $agent->self;
209  
210 =head1 DESCRIPTION
211  
212 The Agent API is used to interact with the local Consul agent.
213  
214 This API is fully documented at L<https://www.consul.io/docs/agent/http/agent.html>.
215  
216 =head1 METHODS
217  
218 =head2 checks
219  
220 =head2 services
221  
222 =head2 members
223  
224 =head2 self
225  
226 =head2 maintenance
227  
228 =head2 join
229  
230 =head2 force_leave
231  
232 =head2 check_register
233  
234 =head2 check_deregister
235  
236 =head2 check_pass
237  
238 =head2 check_warn
239  
240 =head2 check_fail
241  
242 =head2 service_register
243  
244 =head2 service_deregister
245  
246 =head2 service_maintenance
247  
248 =head1 SEE ALSO
249  
250 L<Consul>
251  
252 =cut
« Consul/API/KV.pm ↑ Summary Consul/API/ACL.pm »