Skip to content

Commit 2ea1921

Browse files
ElasticSearch Methods _get_indices_info() and _get_aliases_info()
1 parent 5d9647c commit 2ea1921

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

lib/MetaCPAN/Role/Script.pm

+36-28
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,37 @@ before run => sub {
246246
#Dlog_debug {"Connected to $_"} $self->remote;
247247
};
248248

249+
sub _get_indices_info {
250+
my ( $self, $irefresh ) = @_;
251+
252+
if ( $irefresh || scalar( keys %{ $self->indices_info } ) == 0 ) {
253+
my $sinfo_rs = $self->es->cat->indices( h => [ 'index', 'health' ] );
254+
my $sindices_parsing = qr/^([^[:space:]]+) +([^[:space:]]+)/m;
255+
256+
$self->indices_info( {} );
257+
258+
while ( $sinfo_rs =~ /$sindices_parsing/g ) {
259+
$self->indices_info->{$1}
260+
= { 'index_name' => $1, 'health' => $2 };
261+
}
262+
}
263+
}
264+
265+
sub _get_aliases_info {
266+
my ( $self, $irefresh ) = @_;
267+
268+
if ( $irefresh || scalar( keys %{ $self->aliases_info } ) == 0 ) {
269+
my $sinfo_rs = $self->es->cat->aliases( h => [ 'alias', 'index' ] );
270+
my $saliases_parsing = qr/^([^[:space:]]+) +([^[:space:]]+)/m;
271+
272+
$self->aliases_info( {} );
273+
274+
while ( $sinfo_rs =~ /$saliases_parsing/g ) {
275+
$self->aliases_info->{$1} = { 'alias_name' => $1, 'index' => $2 };
276+
}
277+
}
278+
}
279+
249280
sub check_health {
250281
my ( $self, $irefresh ) = @_;
251282
my $ihealth = 0;
@@ -255,39 +286,16 @@ sub check_health {
255286
$ihealth = $self->await;
256287

257288
if ($ihealth) {
258-
if ( $irefresh || scalar( keys %{ $self->indices_info } ) == 0 ) {
259-
my $sinfo_rs
260-
= $self->es->cat->indices( h => [ 'index', 'health' ] );
289+
$self->_get_indices_info($irefresh);
261290

262-
$self->indices_info( {} );
263-
264-
while ( $sinfo_rs =~ /^([^[:space:]]+) +([^[:space:]]+)/gm ) {
265-
$self->indices_info->{$1}
266-
= { 'index_name' => $1, 'health' => $2 };
267-
268-
$ihealth = 0 if ( $2 eq 'red' );
269-
}
270-
}
271-
else {
272-
foreach ( keys %{ $self->indices_info } ) {
273-
$ihealth = 0
274-
if ( $self->indices_info->{$_}->{'health'} eq 'red' );
275-
}
291+
foreach ( keys %{ $self->indices_info } ) {
292+
$ihealth = 0
293+
if ( $self->indices_info->{$_}->{'health'} eq 'red' );
276294
}
277295
}
278296

279297
if ($ihealth) {
280-
if ( $irefresh || scalar( keys %{ $self->aliases_info } ) == 0 ) {
281-
my $sinfo_rs
282-
= $self->es->cat->aliases( h => [ 'alias', 'index' ] );
283-
284-
$self->aliases_info( {} );
285-
286-
while ( $sinfo_rs =~ /^([^[:space:]]+) +([^[:space:]]+)/gm ) {
287-
$self->aliases_info->{$1}
288-
= { 'alias_name' => $1, 'index' => $2 };
289-
}
290-
}
298+
$self->_get_aliases_info($irefresh);
291299

292300
$ihealth = 0 if ( scalar( keys %{ $self->aliases_info } ) == 0 );
293301
}

0 commit comments

Comments
 (0)