Skip to content

Commit fe04e0d

Browse files
committed
remove all code related to ES aliases
Aliases are an operational thing. They aren't something the code needs to care about. The mapping script is used for development and testing, but not really appropriate for production anymore. It can just create the indexes, without any aliases.
1 parent c75cf24 commit fe04e0d

File tree

4 files changed

+17
-154
lines changed

4 files changed

+17
-154
lines changed

lib/MetaCPAN/ESConfig.pm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ use Const::Fast qw(const);
1717

1818
const my %config => merge(
1919
{
20-
aliases => {
21-
'cpan' => 'cpan_v1_01',
22-
},
2320
indexes => {
2421
_default => {
2522
settings => 'es/settings.json',
@@ -149,12 +146,6 @@ my $DefinedHash = ( HashRef [Defined] )->plus_coercions(
149146
};
150147
},
151148
);
152-
has aliases => (
153-
is => 'ro',
154-
isa => $DefinedHash,
155-
coerce => 1,
156-
default => sub { {} },
157-
);
158149

159150
has documents => (
160151
is => 'ro',

lib/MetaCPAN/Model.pm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ for my $name ( sort keys %$docs ) {
2121
$indexes{$index}{types}{$name} = $model->meta;
2222
}
2323

24-
my $aliases = es_config->aliases;
25-
for my $alias ( sort keys %$aliases ) {
26-
my $index = $aliases->{$alias};
27-
my $index_data = $indexes{$index}
28-
or die "unknown index $index";
29-
if ( $index_data->{alias_for} ) {
30-
die "duplicate alias for $index";
31-
}
32-
$index_data->{alias_for} = $index;
33-
$indexes{$alias} = delete $indexes{$index};
34-
}
35-
3624
for my $index ( sort keys %indexes ) {
3725
index $index => %{ $indexes{$index} };
3826
}

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 17 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6060
has 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-
173166
sub 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-
540527
sub 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

632565
sub _compare_mapping {
@@ -849,7 +782,7 @@ sub _compare_mapping {
849782
}
850783

851784
sub 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-
944853
sub 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
1070973
This option makes the Script show basic information about the I<ElasticSearch> Cluster
1071-
and its indices and aliases.
974+
and its indices.
1072975
This information has to be collected with the C<MetaCPAN::Role::Script::check_health()> Method.
1073976
On 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
1081984
This 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
1083986
C<MetaCPAN::Role::Script::check_health()> and C<mappings_valid()>.
1084987
If 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.
11351038
The 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.
11371040
On 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.
11401043
Otherwise it returns C< 0 >.
11411044
11421045
B<Exceptions:> It can throw exceptions when the connection to I<ElasticSearch> fails
@@ -1148,12 +1051,11 @@ See L<Method C<mappings_valid()>>
11481051
11491052
See L<Method C<MetaCPAN::Role::Script::check_health()>>
11501053
1151-
=item C<mappings_valid( \%indices, \%aliases )>
1054+
=item C<mappings_valid( \%indices )>
11521055
11531056
This method uses the
11541057
L<C<Search::Elasticsearch::Client::2_0::Direct::get_mapping()>|https://metacpan.org/pod/Search::Elasticsearch::Client::2_0::Direct#get_mapping()>
11551058
method 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.
11571059
Then it performs an in-depth structure match against the Project Definitions.
11581060
Missing indices or any structure mismatch will be count as error.
11591061
Errors will be reported in the activity log.
@@ -1162,9 +1064,7 @@ B<Parameters:>
11621064
11631065
C<\%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.
11681068
Otherwise it returns C< 0 >.
11691069
11701070
See L<Option C<--delete>>
@@ -1196,15 +1096,14 @@ See L<Method C<check_health()>>
11961096
This method uses the
11971097
L<C<Search::Elasticsearch::Client::2_0::Direct::cat()>|https://metacpan.org/pod/Search::Elasticsearch::Client::2_0::Direct#cat()>
11981098
method 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
12021102
be updated.
12031103
If the C<cluster_info> structure is empty it calls first the C<await()> method.
12041104
If the service is unavailable the C<await()> method will produce an exception and the structures will be empty
12051105
The 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
12091108
B<Parameters:>
12101109

t/lib/MetaCPAN/TestServer.pm

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ sub wait_for_es {
9191
sub check_mappings {
9292
my $self = $_[0];
9393
my %indices = ( map +( $_ => 'yellow' ), @{ es_config->all_indexes } );
94-
my %aliases = %{ es_config->aliases };
9594

9695
local @ARGV = qw(mapping --show_cluster_info);
9796

@@ -103,9 +102,6 @@ sub check_mappings {
103102
note( Test::More::explain(
104103
{ 'indices_info' => \%{ $mapping->indices_info } }
105104
) );
106-
note( Test::More::explain(
107-
{ 'aliases_info' => \%{ $mapping->aliases_info } }
108-
) );
109105

110106
subtest 'only configured indices' => sub {
111107
ok( defined $indices{$_}, "indice '$_' is configured" )
@@ -119,17 +115,6 @@ sub check_mappings {
119115
$indices{$_}, "index '$_' correct state '$indices{$_}'" );
120116
}
121117
};
122-
subtest 'verify aliases' => sub {
123-
ok "no aliases to verify"
124-
if !%aliases;
125-
foreach ( keys %aliases ) {
126-
ok( defined $mapping->aliases_info->{$_},
127-
"alias '$_' was created" );
128-
is( $mapping->aliases_info->{$_}->{'index'},
129-
$aliases{$_},
130-
"alias '$_' correctly assigned to '$aliases{$_}'" );
131-
}
132-
};
133118
}
134119

135120
sub put_mappings {

0 commit comments

Comments
 (0)