| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of ElasticSearchX-Model | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2018 by Moritz Onken. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # The (three-clause) BSD License | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | package ElasticSearchX::Model::Role; | ||||||||||||||||||||||||||||
| 11 | 12 | $ElasticSearchX::Model::Role::VERSION = '2.0.0'; | |||||||||||||||||||||||||||
| 12 | 12 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 12 | ▶ | use Search::Elasticsearch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use ElasticSearchX::Model::Index; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use ElasticSearchX::Model::Document::Types qw(ES); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 12 | has es => ( is => 'rw', lazy_build => 1, coerce => 1, isa => ES ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub _build_es { | ||||||||||||||||||||||||||||
| 21 | Search::Elasticsearch->new( | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | nodes => $ENV{ES} || '127.0.0.1:9200', | ||||||||||||||||||||||||||
|
Subroutine
_build_es: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{'ES'} || '127.0.0.1:9200'
MC/DC0%0/1
$ENV{'ES'} || '127.0.0.1:9200'
$ENV{'ES'}
Truth table0%0/2
A
A= $ENV{'ES'}
| |||||||||||||||||||||||||||||
| 23 | cxn => 'HTTPTiny', | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub deploy { | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my ( $self, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
deploy: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my $t = $self->es->transport; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | foreach my $name ( $self->meta->get_index_list ) { | |||||||||||||||||||||||||||
| 32 | 0 | my $index = $self->index($name); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | next if ( $index->alias_for && $name eq $index->alias_for ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$index->alias_for and $name eq $index->alias_for
MC/DC0%0/2
$index->alias_for and $name eq $index->alias_for
$index->alias_for
$name eq $index->alias_for
Truth table0%0/3
A and B
A= $index->alias_forB= $name eq $index->alias_for
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $name = $index->alias_for if ( $index->alias_for ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | local $@; | |||||||||||||||||||||||||||
| 36 | 0 | eval { $self->es->indices->delete( index => $name ) } | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $params{delete} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | my $dep = $index->deployment_statement; | |||||||||||||||||||||||||||
| 39 | 0 | my $mapping = delete $dep->{mappings}; | |||||||||||||||||||||||||||
| 40 | 0 | eval { | |||||||||||||||||||||||||||
| 41 | 0 | $t->perform_request( | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | method => 'PUT', | ||||||||||||||||||||||||||||
| 44 | path => "/$name", | ||||||||||||||||||||||||||||
| 45 | body => $dep, | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||
| 49 | 0 | sleep(1); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | while ( my ( $k, $v ) = each %$mapping ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $t->perform_request( | |||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | method => 'PUT', | ||||||||||||||||||||||||||||
| 55 | path => "/$name/$k/_mapping", | ||||||||||||||||||||||||||||
| 56 | body => { $k => $v }, | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( my $alias = $index->alias_for ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | my @aliases = keys %{ | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $self->es->indices->get_alias( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | index => $index->name, | ||||||||||||||||||||||||||||
| 64 | ignore => [404] | ||||||||||||||||||||||||||||
| 65 | ) | ||||||||||||||||||||||||||||
| 66 | || {} | ||||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||
| 68 | my $actions = [ | ||||||||||||||||||||||||||||
| 69 | ( | ||||||||||||||||||||||||||||
| 70 | map { | ||||||||||||||||||||||||||||
| 71 | 0 | { remove => { index => $_, alias => $index->name } } | |||||||||||||||||||||||||||
| 72 | } @aliases | ||||||||||||||||||||||||||||
| 73 | ), | ||||||||||||||||||||||||||||
| 74 | { add => { index => $alias, alias => $index->name } } | ||||||||||||||||||||||||||||
| 75 | ]; | ||||||||||||||||||||||||||||
| 76 | 0 | $self->es->indices->update_aliases( | |||||||||||||||||||||||||||
| 77 | body => { actions => $actions } ); | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub bulk { | ||||||||||||||||||||||||||||
| 84 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
bulk: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 1 | return ElasticSearchX::Model::Bulk->new( es => $self->es, @_ ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub es_version { | ||||||||||||||||||||||||||||
| 89 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
es_version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 4 | my $string = $self->es->info->{version}->{number}; | |||||||||||||||||||||||||||
| 91 | 4 | $string =~ s/RC//g; | |||||||||||||||||||||||||||
| 92 | 4 | return version->parse($string)->numify; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 12 | 1; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =pod | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 NAME | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | ElasticSearchX::Model::Role | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 VERSION | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | version 2.0.0 | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Moritz Onken | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | This software is Copyright (c) 2018 by Moritz Onken. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | The (three-clause) BSD License | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||||||||||