Client/Elasticsearch/Cat.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Client/Elasticsearch.pm ↑ Summary Client/Elasticsearch/Cluster.pm »
1 #
2 # $Id$
3 #
4 # client::elasticsearch::cat Brik
5 #
6 package Metabrik::Client::Elasticsearch::Cat;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #
11 # DOC: Search::Elasticsearch::Client::6_0::Direct::Cat
12 #
13  
14 1 ▶use base qw(Metabrik::Client::Elasticsearch);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub brik_properties {
17 return {
18 revision => '$Revision$',
19 tags => [ qw(unstable) ],
20 author => 'GomoR <GomoR[at]metabrik.org>',
21 license => 'http://opensource.org/licenses/BSD-3-Clause',
22 attributes => {
23 },
24 attributes_default => {
25 },
26 commands => {
27 show_nodes => [ ],
28 show_tasks => [ ],
29 show_shards => [ qw(indices|OPTIONAL) ],
30 show_recovery => [ qw(indices|OPTIONAL) ],
31 show_allocation => [ ],
32 loop_show_allocation => [ qw(interval|OPTIONAL) ],
33 show_health => [ ],
34 loop_show_health => [ qw(interval|OPTIONAL) ],
35 pending_tasks => [ ],
36 },
37 };
38 }
39  
40 sub brik_init {
41 my $self = shift;
42  
43 $self->open or return 0;
44  
45 return $self->SUPER::brik_init;
46 }
47  
48 sub show_nodes {
49 my $self = shift;
50  
51 my $r = $self->_es->cat->nodes;
52  
53 return [ split(/\n/, $r) ];
54 }
55  
56 sub show_tasks {
57 my $self = shift;
58  
59 my $r = $self->_es->cat->tasks;
60  
61 return [ split(/\n/, $r) ];
62 }
63  
64 sub show_shards {
65 my $self = shift;
66 my ($indices) = @_;
67  
68 my %args = ();
69 if (defined($indices)) {
70 $args{index} = $indices;
71 }
72  
73 my $r = $self->_es->cat->shards(%args);
74  
75 return [ split(/\n/, $r) ];
76 }
77  
78 sub show_recovery {
79 my $self = shift;
80 my ($indices) = @_;
81  
82 my %args = ();
83 if (defined($indices)) {
84 $args{index} = $indices;
85 }
86  
87 my $r = $self->_es->cat->recovery(%args);
88  
89 return [ split(/\n/, $r) ];
90 }
91  
92 sub show_allocation {
93 my $self = shift;
94  
95 my %args = ();
96  
97 my $r = $self->_es->cat->allocation(%args);
98  
99 return [ split(/\n/, $r) ];
100 }
101  
102 sub loop_show_allocation {
103 my $self = shift;
104 my ($interval) = @_;
105  
106 $interval ||= 60;
107  
108 while (1) {
109 my %lines = ();
110 for my $line (@{$self->show_allocation}) {
111 my @t = split(/\s+/, $line);
112 $lines{$t[-1]} = $line;
113 }
114 for (sort { $a cmp $b } keys %lines) {
115 print $lines{$_}."\n";
116 }
117 print "--\n";
118 sleep($interval);
119 }
120  
121 return 1;
122 }
123  
124 sub show_health {
125 my $self = shift;
126  
127 my %args = ();
128  
129 my $r = $self->_es->cat->health(%args);
130  
131 return [ split(/\n/, $r) ];
132 }
133  
134 sub loop_show_health {
135 my $self = shift;
136 my ($interval) = @_;
137  
138 $interval ||= 60;
139  
140 while (1) {
141 my $lines = $self->show_health;
142 for my $line (@$lines) {
143 print "$line\n";
144 }
145 sleep($interval);
146 }
147  
148 return 1;
149 }
150  
151 sub pending_tasks {
152 my $self = shift;
153  
154 return $self->_es->cat->pending_tasks;
155 }
156  
157 1;
158  
159 __END__
« Client/Elasticsearch.pm ↑ Summary Client/Elasticsearch/Cluster.pm »