Model/Alias.pm

filter: Statementstmt 28.0% 16 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 44.4% 4 / 9 Podpod 100% 4 / 4 totaltotal 28.9% 24 / 83 CC 6 SCAR 25.1
CC
6
Cov
24%
_add_aliases
30.0
aliased_to
6.0
to
2.0
CRAP 12.3
« Model/Scope.pm ↑ Summary Model/TypeMap/Structured.pm »
1 package Elastic::Model::Alias;
2 23 $Elastic::Model::Alias::VERSION = '0.52';
3 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 with 'Elastic::Model::Role::Index';
6  
7 23 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #===================================
12 0 ▶sub to {
Subroutine to: not called CC=1 SCAR=6.9
Pod documented
13 #===================================
14 0 my $self = shift;
15  
16 0 my $name = $self->name;
17 0 my $store = $self->model->store;
18 my %indices = (
19 0 ( map { $_ => { remove => { index => $_, alias => $name } } }
20 0 keys %{ $store->get_aliases( index => $name ) }
21 ),
22 $self->_add_aliases(@_)
23 );
24  
25 0 $store->put_aliases( actions => [ values %indices ] );
26 0 $self->model->domain($name)->clear_default_routing;
27 0 $self->model->clear_domain_namespace;
28 0 return $self;
29 }
30  
31 #===================================
32 0 ▶sub add {
Subroutine add: not called CC=1 SCAR=6.9
Pod documented
33 #===================================
34 0 my $self = shift;
35 0 my %indices = $self->_add_aliases(@_);
36 0 $self->model->store->put_aliases( actions => [ values %indices ] );
37 0 $self->model->domain( $self->name )->clear_default_routing;
38 0 return $self;
39 }
40  
41 #===================================
42 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
43 #===================================
44 0 my $self = shift;
45 0 my $name = $self->name;
46 0 my @actions = map { { remove => { index => $_, alias => $name } } } @_;
47 0 $self->model->store->put_aliases( actions => \@actions );
48 0 $self->model->clear_domain_namespace;
49 0 return $self;
50 }
51  
52 #===================================
53 0 ▶sub aliased_to {
Subroutine aliased_to: not called CC=2 SCAR=17.9
Pod documented
54 #===================================
55 0 my $self = shift;
56 0 my $name = $self->name;
57  
58 0 my $indices = $self->model->store->get_aliases( index => $name );
59 croak "($name) is an index, not an alias"
60 0 ▶ if $indices->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $indices->{$name} 0 0 0
61  
62 0 +{ map { $_ => $indices->{$_}{aliases}{$name} } keys %$indices };
63 }
64  
65 #===================================
66 0 ▶sub _add_aliases {
Subroutine _add_aliases: not called CC=5 SCAR=34.0
67 #===================================
68 0 my $self = shift;
69 0 my $name = $self->name;
70 0 my $store = $self->model->store;
71 0 my %indices;
72  
73 my $builder;
74 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
75 0 my $index = shift @_;
76 my %params = (
77 0 ▶ ref $_[0] ? %{ shift @_ } : (),
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
78 index => $index,
79 alias => $name
80 );
81 0 ▶ if ( my $filter = delete $params{filterb} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = delete $params{"filterb"}) 0 0 0
82 0 ▶ $builder ||= $self->model->view->search_builder;
Condition0%0/3
$builder ||= $self->model->view->search_builder
l!l&&r!l&&!r
000
MC/DC0%0/2
$builder ||= $self->model->view->search_builder
$builder $self->model->view->search_builder
Truth table0%0/3
A ||= B
A= $builderB= $self->model->view->search_builder
ABresult
1X1
011
000
83 0 $params{filter} = $builder->filter($filter)->{filter};
84 }
85 0 $indices{$index} = { add => \%params };
86 }
87 0 return %indices;
88 }
89  
90 23 __PACKAGE__->meta->make_immutable;
91  
92 23 1;
93  
94 =pod
95  
96 =encoding UTF-8
97  
98 =head1 NAME
99  
100 Elastic::Model::Alias - Administer aliases in Elasticsearch
101  
102 =head1 VERSION
103  
104 version 0.52
105  
106 =head1 SYNOPSIS
107  
108 $alias = $model->namespace('myapp')->alias;
109 $alias = $model->namespace('myapp')->alias('alias_name');
110  
111 $alias->to( 'index_1', 'index_2' );
112 $alias->to( 'index_1' => \%settings, index_2 => \%settings);
113  
114 $alias->add( 'index_1', 'index_2' );
115 $alias->add( 'index_1' => \%settings, index_2 => \%settings);
116  
117 $alias->remove( 'index_1', 'index_2' );
118  
119 \%indices = $alias->aliased_to;
120  
121 See also L<Elastic::Model::Role::Index/SYNOPSIS>.
122  
123 =head1 DESCRIPTION
124  
125 L<Elastic::Model::Alias> objects are used to create and administer
126 L<index aliases|Elastic::Manual::Terminology/Alias> in an Elasticsearch cluster.
127  
128 See L<Elastic::Model::Role::Index> for more about usage.
129 See L<Elastic::Manual::Scaling> for more about how aliases can be used in your
130 application.
131  
132 =head1 METHODS
133  
134 =head2 to()
135  
136 $alias = $alias->to(@index_names);
137 $alias = $alias->to(
138 index_name => \%alias_settings,
139 ...
140 );
141  
142 Creates or updates the alias L</name> and sets it to point
143 to the listed indices. If it already exists and points to indices not specified
144 in C<@index_names>, then those indices will be removed from the alias.
145  
146 You can delete an alias completely with:
147  
148 $alias->to();
149  
150 Aliases can have filters and routing values associated with an index, for
151 instance:
152  
153 $alias->to(
154 my_index => {
155 routing => 'client_one',
156 filterb => { client => 'client_one'}
157 }
158 );
159  
160 See L<Elastic::Manual::Scaling> for more about these options.
161  
162 =head2 add()
163  
164 $alias = $alias->add(@index_names);
165 $alias = $alias->add(
166 index_name => \%alias_settings,
167 ...
168 );
169  
170 L</add()> works in the same way as L</to()> except that
171 indices are only added - existing indices are not removed.
172  
173 =head2 remove()
174  
175 $alias = $alias->remove(@index_names);
176  
177 The listed index names are removed from alias L</name>.
178  
179 =head2 aliased_to()
180  
181 $indices = $alias->aliased_to();
182  
183 Returns a hashref of the current settings for an alias, suitable for passing to
184 L</to()>. The keys are index names, and the values are the alias settings.
185  
186 =head1 IMPORTED ATTRIBUTES
187  
188 Attributes imported from L<Elastic::Model::Role::Index>
189  
190 =head2 L<namespace|Elastic::Model::Role::Index/namespace>
191  
192 =head2 L<name|Elastic::Model::Role::Index/name>
193  
194 =head1 IMPORTED METHODS
195  
196 Methods imported from L<Elastic::Model::Role::Index>
197  
198 =head2 L<close()|Elastic::Model::Role::Index/close()>
199  
200 =head2 L<open()|Elastic::Model::Role::Index/open()>
201  
202 =head2 L<refresh()|Elastic::Model::Role::Index/refresh()>
203  
204 =head2 L<delete()|Elastic::Model::Role::Index/delete()>
205  
206 =head2 L<update_analyzers()|Elastic::Model::Role::Index/update_analyzers()>
207  
208 =head2 L<update_settings()|Elastic::Model::Role::Index/update_settings()>
209  
210 =head2 L<delete_mapping()|Elastic::Model::Role::Index/delete_mapping()>
211  
212 =head2 L<is_alias()|Elastic::Model::Role::Index/is_alias()>
213  
214 =head2 L<is_index()|Elastic::Model::Role::Index/is_index()>
215  
216 =head1 SEE ALSO
217  
218 =over
219  
220 =item *
221  
222 L<Elastic::Model::Role::Index>
223  
224 =item *
225  
226 L<Elastic::Model::Index>
227  
228 =item *
229  
230 L<Elastic::Model::Namespace>
231  
232 =item *
233  
234 L<Elastic::Manual::Scaling>
235  
236 =back
237  
238 =head1 AUTHOR
239  
240 Clinton Gormley <drtech@cpan.org>
241  
242 =head1 COPYRIGHT AND LICENSE
243  
244 This software is copyright (c) 2015 by Clinton Gormley.
245  
246 This is free software; you can redistribute it and/or modify it under
247 the same terms as the Perl 5 programming language system itself.
248  
249 =cut
250  
251 __END__
« Model/Scope.pm ↑ Summary Model/TypeMap/Structured.pm »