@@ -54,7 +54,7 @@ has arg_cluster_info => (
5454 is => ' ro' ,
5555 isa => Bool,
5656 default => 0,
57- documentation => ' show basic info about cluster, indices and aliases ' ,
57+ documentation => ' show basic info about cluster and indices ' ,
5858);
5959
6060has arg_create_index => (
@@ -163,13 +163,6 @@ has indices_info => (
163163 default => sub { {} },
164164);
165165
166- has aliases_info => (
167- isa => HashRef,
168- traits => [' Hash' ],
169- is => ' rw' ,
170- default => sub { {} },
171- );
172-
173166sub run {
174167 my $self = shift ;
175168
@@ -204,7 +197,7 @@ sub run {
204197 if ( $self -> arg_verify_mapping ) {
205198 $self -> check_health;
206199 unless ( $self -> mappings_valid(
207- $self -> _build_mapping, $self -> _build_aliases
200+ $self -> _build_mapping
208201 ) )
209202 {
210203 $self -> print_error(" Indices Verification has failed!" );
@@ -510,7 +503,6 @@ sub show_info {
510503 my $info_rs = {
511504 ' cluster_info' => \%{ $self -> cluster_info },
512505 ' indices_info' => \%{ $self -> indices_info },
513- ' aliases_info' => \%{ $self -> aliases_info }
514506 };
515507 log_info { JSON-> new-> utf8-> pretty-> encode($info_rs ) };
516508}
@@ -532,14 +524,8 @@ sub _build_mapping {
532524 return $mappings ;
533525}
534526
535- sub _build_aliases {
536- my $self = $_ [0];
537- es_config-> aliases;
538- }
539-
540527sub deploy_mapping {
541528 my $self = shift ;
542- my $is_mapping_ok = 0;
543529
544530 $self -> are_you_sure(
545531 ' this will delete EVERYTHING and re-create the (empty) indexes' );
@@ -568,65 +554,12 @@ sub deploy_mapping {
568554 }
569555 }
570556
571- # create aliases
572-
573- my $raliases = $self -> _build_aliases;
574- for my $alias ( sort keys %$raliases ) {
575- log_info {
576- " Creating alias: '$alias ' -> '" . $raliases -> {$alias } . " '"
577- };
578- $es -> indices-> put_alias(
579- index => $raliases -> {$alias },
580- name => $alias ,
581- );
582- }
583-
584557 $self -> check_health(1);
585- $is_mapping_ok = $self -> mappings_valid( $rmappings , $raliases );
586558
587559 # done
588560 log_info {" Done." };
589561
590- return $is_mapping_ok ;
591- }
592-
593- sub aliases_valid {
594- my ( $self , $raliases ) = @_ ;
595- my $ivalid = 0;
596-
597- if ( defined $raliases && ref $raliases eq ' HASH' ) {
598- my $ralias = undef ;
599-
600- $ivalid = 1;
601-
602- for my $name ( sort keys %$raliases ) {
603- $ralias = $self -> aliases_info-> {$name };
604- if ( defined $ralias ) {
605- if ( $ralias -> {' index' } eq $raliases -> {$name } ) {
606- log_info {
607- " Correct alias: $name (index '"
608- . $ralias -> {' index' } . " ')"
609- };
610- }
611- else {
612- log_error {
613- " Broken alias: $name (index '"
614- . $ralias -> {' index' } . " ')"
615- };
616- $ivalid = 0;
617- }
618- }
619- else {
620- log_error {" Missing alias: $name " };
621- $ivalid = 0;
622- }
623- }
624- }
625- else {
626- $ivalid = 0 if ( scalar ( keys %{ $self -> aliases_info } ) == 0 );
627- }
628-
629- return $ivalid ;
562+ return $self -> mappings_valid( $rmappings );
630563}
631564
632565sub _compare_mapping {
@@ -849,7 +782,7 @@ sub _compare_mapping {
849782}
850783
851784sub mappings_valid {
852- my ( $self , $rmappings , $raliases ) = @_ ;
785+ my ( $self , $rmappings ) = @_ ;
853786 my $ivalid = 0;
854787
855788 if ( defined $rmappings && ref $rmappings eq ' HASH' ) {
@@ -898,15 +831,6 @@ sub mappings_valid {
898831 log_info {" Verification indices: failed" };
899832 }
900833
901- $ivalid = ( $ivalid && $self -> aliases_valid($raliases ) );
902-
903- if ($ivalid ) {
904- log_info {" Verification aliases: ok" };
905- }
906- else {
907- log_info {" Verification aliases: failed" };
908- }
909-
910834 return $ivalid ;
911835}
912836
@@ -926,21 +850,6 @@ sub _get_indices_info {
926850 }
927851}
928852
929- sub _get_aliases_info {
930- my ( $self , $irefresh ) = @_ ;
931-
932- if ( $irefresh || scalar ( keys %{ $self -> aliases_info } ) == 0 ) {
933- my $sinfo_rs = $self -> es-> cat-> aliases( h => [ ' alias' , ' index' ] );
934- my $saliases_parsing = qr / ^([^[:space:]]+) +([^[:space:]]+)/ m ;
935-
936- $self -> aliases_info( {} );
937-
938- while ( $sinfo_rs =~ / $saliases_parsing /g ) {
939- $self -> aliases_info-> {$1 } = { ' alias_name' => $1 , ' index' => $2 };
940- }
941- }
942- }
943-
944853sub check_health {
945854 my ( $self , $irefresh ) = @_ ;
946855 my $ihealth = 0;
@@ -958,12 +867,6 @@ sub check_health {
958867 }
959868 }
960869
961- if ($ihealth ) {
962- $self -> _get_aliases_info($irefresh );
963-
964- $ihealth = 0 if ( scalar ( keys %{ $self -> aliases_info } ) == 0 );
965- }
966-
967870 return $ihealth ;
968871}
969872
@@ -1039,10 +942,10 @@ MetaCPAN::Script::Mapping - Script to set the index and mapping the types
1039942
1040943=head1 SYNOPSIS
1041944
1042- # bin/metacpan mapping --show_cluster_info # show basic info about the cluster, indices and aliases
945+ # bin/metacpan mapping --show_cluster_info # show basic info about the cluster and indices
1043946 # bin/metacpan mapping --delete
1044947 # bin/metacpan mapping --delete --all # deletes ALL indices in the cluster
1045- # bin/metacpan mapping --verify # compare deployed indices and aliases with project definitions
948+ # bin/metacpan mapping --verify # compare deployed indices with project definitions
1046949 # bin/metacpan mapping --list_types
1047950 # bin/metacpan mapping --delete_index xxx
1048951 # bin/metacpan mapping --create_index xxx --reindex
@@ -1068,7 +971,7 @@ This Script accepts the following options
1068971=item Option C<--show_cluster_info >
1069972
1070973This option makes the Script show basic information about the I<ElasticSearch > Cluster
1071- and its indices and aliases .
974+ and its indices.
1072975This information has to be collected with the C<MetaCPAN::Role::Script::check_health() > Method.
1073976On Script start-up it is empty.
1074977
@@ -1079,7 +982,7 @@ See L<Method C<MetaCPAN::Role::Script::check_health()>>
1079982=item Option C<--delete >
1080983
1081984This option makes the Script delete all indices configured in the project and re-create them emtpy.
1082- It verifies the index integrity of the indices and aliases calling the methods
985+ It verifies the index integrity of the indices calling the methods
1083986C<MetaCPAN::Role::Script::check_health() > and C<mappings_valid() > .
1084987If the C<mappings_valid() > Method fails it will report an error.
1085988
@@ -1131,12 +1034,12 @@ This Package provides the following methods
11311034
11321035=item C<deploy_mapping() >
11331036
1134- Deletes and re-creates the indices and aliases defined in the Project.
1037+ Deletes and re-creates the indices defined in the Project.
11351038The user will be requested for manual confirmation on the command line before the elemination.
1136- The integrity of the indices and aliases will be checked with the C<mappings_valid() > Method.
1039+ The integrity of the indices will be checked with the C<mappings_valid() > Method.
11371040On successful creation it returns C< 1 > , otherwise it returns C< 0 > .
11381041
1139- B<Returns: > It returns C< 1 > when the indices and aliases are created and verified as correct.
1042+ B<Returns: > It returns C< 1 > when the indices are created and verified as correct.
11401043Otherwise it returns C< 0 > .
11411044
11421045B<Exceptions: > It can throw exceptions when the connection to I<ElasticSearch > fails
@@ -1148,12 +1051,11 @@ See L<Method C<mappings_valid()>>
11481051
11491052See L<Method C<MetaCPAN::Role::Script::check_health()> >
11501053
1151- =item C<mappings_valid( \%indices, \%aliases ) >
1054+ =item C<mappings_valid( \%indices ) >
11521055
11531056This method uses the
11541057L<C<Search::Elasticsearch::Client::2_0::Direct::get_mapping()> |https://metacpan.org/pod/Search::Elasticsearch::Client::2_0::Direct#get_mapping()>
11551058method to request the complete index mappings structure from the I<ElasticSearch > Cluster.
1156- It also uses the alias information gathered by the C<MetaCPAN::Role::Script::check_health() > method.
11571059Then it performs an in-depth structure match against the Project Definitions.
11581060Missing indices or any structure mismatch will be count as error.
11591061Errors will be reported in the activity log.
@@ -1162,9 +1064,7 @@ B<Parameters:>
11621064
11631065C<\%indices > - Reference to a hash that defines the indices required for the Project.
11641066
1165- C<\%aliases > - Reference to a hash that defines the aliases required for the Project.
1166-
1167- B<Returns: > It returns C< 1 > when the indices and aliases are created and match the defined structure.
1067+ B<Returns: > It returns C< 1 > when the indices are created and match the defined structure.
11681068Otherwise it returns C< 0 > .
11691069
11701070See L<Option C<--delete> >
@@ -1196,15 +1096,14 @@ See L<Method C<check_health()>>
11961096This method uses the
11971097L<C<Search::Elasticsearch::Client::2_0::Direct::cat()> |https://metacpan.org/pod/Search::Elasticsearch::Client::2_0::Direct#cat()>
11981098method to collect basic data about the cluster structure as the general information,
1199- the health state of the indices and the created aliases .
1200- This information is stored in C<cluster_info > , C<indices_info > and C< aliases_info > as C<HASH > structures.
1201- If the parameter C<refresh > is set to C< 1 > the structures C<indices_info > and C< aliases_info > will always
1099+ the health state of the indices.
1100+ This information is stored in C<cluster_info > , C<indices_info > as C<HASH > structures.
1101+ If the parameter C<refresh > is set to C< 1 > the structure C<indices_info > will always
12021102be updated.
12031103If the C<cluster_info > structure is empty it calls first the C<await() > method.
12041104If the service is unavailable the C<await() > method will produce an exception and the structures will be empty
12051105The method returns C< 1 > when the C<cluster_info > is populated, none of the indices in C<indices_info > has
1206- the Health State I<red > and at least one alias is created in C<aliases_info >
1207- otherwise the method returns C< 0 >
1106+ the Health State I<red > otherwise the method returns C< 0 >
12081107
12091108B<Parameters: >
12101109
0 commit comments