line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Consul::API::Catalog; |
2
|
|
|
|
|
|
|
$Consul::API::Catalog::VERSION = '0.027'; |
3
|
9
|
|
|
9
|
|
4959
|
use namespace::autoclean; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
52
|
|
4
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
664
|
use Moo::Role; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
70
|
|
6
|
9
|
|
|
9
|
|
2797
|
use Types::Standard qw(Str); |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
53
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
requires qw(_version_prefix _api_exec); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has _catalog_endpoint => ( is => 'lazy', isa => Str ); |
11
|
|
|
|
|
|
|
sub _build__catalog_endpoint { |
12
|
0
|
|
|
0
|
|
|
shift->_version_prefix . '/catalog'; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub catalog { |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
0
|
|
|
|
|
$self = Consul->new(@_) unless ref $self; |
18
|
0
|
|
|
|
|
|
return bless \$self, "Consul::API::Catalog::Impl"; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package |
22
|
|
|
|
|
|
|
Consul::API::Catalog::Impl; # hide from PAUSE |
23
|
|
|
|
|
|
|
|
24
|
9
|
|
|
9
|
|
5361
|
use Moo; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
46
|
|
25
|
|
|
|
|
|
|
|
26
|
9
|
|
|
9
|
|
2568
|
use Carp qw(croak); |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
4535
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub datacenters { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
30
|
0
|
|
|
|
|
|
$$self->_api_exec($$self->_catalog_endpoint."/datacenters", 'GET', %args); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub nodes { |
34
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
35
|
|
|
|
|
|
|
$$self->_api_exec($$self->_catalog_endpoint."/nodes", 'GET', %args, sub { |
36
|
0
|
|
|
0
|
|
|
[ map { Consul::API::Catalog::ShortNode->new(%$_) } @{$_[0]} ] |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub services { |
41
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
42
|
0
|
|
|
|
|
|
$$self->_api_exec($$self->_catalog_endpoint."/services", 'GET', %args); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub service { |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $service, %args) = @_; |
47
|
0
|
0
|
|
|
|
|
croak 'usage: $catalog->service($service, [%args])' if grep { !defined } ($service); |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$$self->_api_exec($$self->_catalog_endpoint."/service/".$service, 'GET', %args, sub { |
49
|
0
|
|
|
0
|
|
|
[ map { Consul::API::Catalog::Service->new(%$_) } @{$_[0]} ] |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
}); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub register { |
54
|
|
|
|
|
|
|
# register |
55
|
0
|
|
|
0
|
0
|
|
croak "not yet implemented"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub deregister { |
59
|
|
|
|
|
|
|
# deregister |
60
|
0
|
|
|
0
|
0
|
|
croak "not yet implemented"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub node { |
64
|
0
|
|
|
0
|
0
|
|
my ($self, $node, %args) = @_; |
65
|
0
|
0
|
|
|
|
|
croak 'usage: $catalog->node($node, [%args])' if grep { !defined } ($node); |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$$self->_api_exec($$self->_catalog_endpoint."/node/".$node, 'GET', %args, sub { |
67
|
0
|
|
|
0
|
|
|
Consul::API::Catalog::Node->new($_[0]) |
68
|
0
|
|
|
|
|
|
}); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package Consul::API::Catalog::ShortNode; |
72
|
|
|
|
|
|
|
$Consul::API::Catalog::ShortNode::VERSION = '0.027'; |
73
|
9
|
|
|
9
|
|
62
|
use Moo; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
87
|
|
74
|
9
|
|
|
9
|
|
2872
|
use Types::Standard qw(Str); |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
36
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
has name => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 ); |
77
|
|
|
|
|
|
|
has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package Consul::API::Catalog::Service; |
80
|
|
|
|
|
|
|
$Consul::API::Catalog::Service::VERSION = '0.027'; |
81
|
9
|
|
|
9
|
|
4454
|
use Moo; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
42
|
|
82
|
9
|
|
|
9
|
|
2714
|
use Types::Standard qw(Str Int ArrayRef); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
43
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
has name => ( is => 'ro', isa => Str, init_arg => 'ServiceName', required => 1 ); |
85
|
|
|
|
|
|
|
has id => ( is => 'ro', isa => Str, init_arg => 'ServiceID', required => 1 ); |
86
|
|
|
|
|
|
|
has service_address => ( is => 'ro', isa => Str, init_arg => 'ServiceAddress', required => 1 ); |
87
|
|
|
|
|
|
|
has port => ( is => 'ro', isa => Int, init_arg => 'ServicePort', required => 1 ); |
88
|
|
|
|
|
|
|
has node => ( is => 'ro', isa => Str, init_arg => 'Node', required => 1 ); |
89
|
|
|
|
|
|
|
has address => ( is => 'ro', isa => Str, init_arg => 'Address', required => 1 ); |
90
|
|
|
|
|
|
|
has tags => ( is => 'ro', isa => ArrayRef[Str], init_arg => 'ServiceTags', required => 1, coerce => sub { $_[0] || [] } ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
package Consul::API::Catalog::Node; |
93
|
|
|
|
|
|
|
$Consul::API::Catalog::Node::VERSION = '0.027'; |
94
|
9
|
|
|
9
|
|
6987
|
use Moo; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
45
|
|
95
|
9
|
|
|
9
|
|
2717
|
use Types::Standard qw(HashRef); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
41
|
|
96
|
9
|
|
|
9
|
|
3783
|
use Type::Utils qw(class_type); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
46
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has node => ( is => 'ro', isa => class_type('Consul::API::Catalog::ShortNode'), init_arg => 'Node', required => 1, coerce => sub { Consul::API::Catalog::ShortNode->new($_[0]) } ); |
99
|
|
|
|
|
|
|
has services => ( is => 'ro', isa => HashRef[class_type('Consul::API::Agent::Service')], init_arg => 'Services', required => 1, coerce => sub { +{ map { $_ => Consul::API::Agent::Service->new($_[0]->{$_}) } keys %{$_[0]} } } ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=encoding UTF-8 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Consul::API::Catalog - Catalog (nodes and services) API |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
use Consul; |
114
|
|
|
|
|
|
|
my $catalog = Consul->catalog; |
115
|
|
|
|
|
|
|
say for map { $_->name} @{$catalog->nodes}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The catalog API is used to register and deregister nodes, services and checks. |
120
|
|
|
|
|
|
|
It also provides query endpoints. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This API is fully documented at L. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 datacenters |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 nodes |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 services |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 service |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 register |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 deregister |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 node |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SEE ALSO |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |