Search-Elasticsearch-Compat
view release on metacpan or search on metacpan
lib/Search/Elasticsearch/Client/Compat.pm view on Meta::CPAN
#===================================
sub cluster_health {
#===================================
shift()->_do_action(
'cluster_health',
{ prefix => '_cluster/health',
cmd => CMD_index,
qs => {
level => [ 'enum', [qw(cluster indices shards)] ],
wait_for_status => [ 'enum', [qw(green yellow red)] ],
wait_for_relocating_shards => ['int'],
wait_for_nodes => ['string'],
timeout => ['duration']
}
},
@_
);
}
#===================================
sub cluster_settings {
lib/Search/Elasticsearch/Client/Compat.pm view on Meta::CPAN
See L<http://www.elasticsearch.org/guide/reference/api/admin-cluster-state.html>
=head3 cluster_health()
$result = $es->cluster_health(
index => multi,
level => 'cluster' | 'indices' | 'shards',
timeout => $seconds
wait_for_status => 'red' | 'yellow' | 'green',
| wait_for_relocating_shards => $number_of_shards,
| wait_for_nodes => eg '>=2',
);
Returns the status of the cluster, or index|indices or shards, where the
returned status means:
=over
=item C<red>: Data not allocated
=item C<yellow>: Primary shard allocated
=item C<green>: All shards allocated
=back
It can block to wait for a particular status (or better), or can block to
wait until the specified number of shards have been relocated (where 0 means
all) or the specified number of nodes have been allocated.
If waiting, then a timeout can be specified.
For example:
$result = $es->cluster_health( wait_for_status => 'green', timeout => '10s')
See: L<http://www.elasticsearch.org/guide/reference/api/admin-cluster-health.html>
lib/Search/Elasticsearch/Client/Compat.pm view on Meta::CPAN
The cluster response will also be logged, and commented out.
Example: C<< $es->cluster_health >> is logged as:
# [Tue Oct 19 15:32:31 2010] Protocol: http, Server: 127.0.0.1:9200
curl -XGET 'http://127.0.0.1:9200/_cluster/health'
# [Tue Oct 19 15:32:31 2010] Response:
# {
# "relocating_shards" : 0,
# "active_shards" : 0,
# "status" : "green",
# "cluster_name" : "elasticsearch",
# "active_primary_shards" : 0,
# "timed_out" : false,
# "initializing_shards" : 0,
# "number_of_nodes" : 1,
# "unassigned_shards" : 0
# }
t/request_tests/cluster_health.pl view on Meta::CPAN
use Test::More;
use strict;
use warnings;
our $es;
my $r;
isa_ok $r = $es->cluster_health(), 'HASH', 'Cluster health';
ok $es->cluster_health( wait_for_status => 'green' )->{timed_out} == 0,
' - wait_for_status';
ok $es->cluster_health( wait_for_relocating_shards => 1 )->{timed_out} == 0,
' - wait_for_relocating_shards';
ok $es->cluster_health( wait_for_nodes => '>1' )->{timed_out} == 0,
' - wait_for_nodes';
ok $es->cluster_health( wait_for_nodes => 1, timeout => '1ms' )->{timed_out},
' - timeout';
$r = $es->cluster_health( level => 'cluster' );
ok $r && !$r->{indices}, ' - level cluster';
$r = $es->cluster_health( level => 'indices' )->{indices};
t/request_tests/cluster_reroute.pl view on Meta::CPAN
move => {
index => 'es_test_1',
shard => 0,
from_node => $node1,
to_node => $node3
}
}
)->{state}{routing_table}{indices}{es_test_1}{shards}{0},
' - dry run';
is $shards->[0]{state}, 'RELOCATING', ' - dry run node relocating';
is $shards->[0]{relocating_node}, $node3, ' - dry run new node';
ok $shards
= $es->cluster_reroute()
->{state}{routing_table}{indices}{es_test_1}{shards}{0},
' - post dry run';
is $shards->[0]{state}, 'STARTED', ' - node started';
is $shards->[0]{node}, $node1, ' - node not moved';
ok $shards= $es->cluster_reroute(
t/request_tests/cluster_reroute.pl view on Meta::CPAN
move => {
index => 'es_test_1',
shard => 0,
from_node => $node1,
to_node => $node3
}
}
)->{state}{routing_table}{indices}{es_test_1}{shards}{0},
' - real reroute';
is $shards->[0]{state}, 'RELOCATING', ' - real run node relocating';
is $shards->[0]{relocating_node}, $node3, ' - real run new node';
wait_for_es(3);
ok $shards
= $es->cluster_reroute()
->{state}{routing_table}{indices}{es_test_1}{shards}{0},
' - post real run';
TODO: {
local $TODO = "Shards don't move predictably";
( run in 0.537 second using v1.01-cache-2.11-cpan-5511b514fd6 )