| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Consul::API::Catalog; |
|
2
|
|
|
|
|
|
|
$Consul::API::Catalog::VERSION = '0.026'; |
|
3
|
9
|
|
|
9
|
|
5161
|
use namespace::autoclean; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
59
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
9
|
|
|
9
|
|
673
|
use Moo::Role; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
49
|
|
|
6
|
9
|
|
|
9
|
|
2874
|
use Types::Standard qw(Str); |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
58
|
|
|
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
|
|
5053
|
use Moo; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
45
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
9
|
|
|
9
|
|
2668
|
use Carp qw(croak); |
|
|
9
|
|
|
|
|
25
|
|
|
|
9
|
|
|
|
|
4437
|
|
|
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.026'; |
|
73
|
9
|
|
|
9
|
|
68
|
use Moo; |
|
|
9
|
|
|
|
|
39
|
|
|
|
9
|
|
|
|
|
35
|
|
|
74
|
9
|
|
|
9
|
|
2619
|
use Types::Standard qw(Str); |
|
|
9
|
|
|
|
|
25
|
|
|
|
9
|
|
|
|
|
37
|
|
|
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.026'; |
|
81
|
9
|
|
|
9
|
|
4021
|
use Moo; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
40
|
|
|
82
|
9
|
|
|
9
|
|
2695
|
use Types::Standard qw(Str Int ArrayRef); |
|
|
9
|
|
|
|
|
31
|
|
|
|
9
|
|
|
|
|
44
|
|
|
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.026'; |
|
94
|
9
|
|
|
9
|
|
6743
|
use Moo; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
43
|
|
|
95
|
9
|
|
|
9
|
|
2760
|
use Types::Standard qw(HashRef); |
|
|
9
|
|
|
|
|
24
|
|
|
|
9
|
|
|
|
|
38
|
|
|
96
|
9
|
|
|
9
|
|
3556
|
use Type::Utils qw(class_type); |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
54
|
|
|
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 |