| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# PODNAME: App::Prove::Elasticsearch::Utils |
|
2
|
|
|
|
|
|
|
# ABSTRACT: common functions used by multiple modules in the distribution. |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package App::Prove::Elasticsearch::Utils; |
|
5
|
|
|
|
|
|
|
$App::Prove::Elasticsearch::Utils::VERSION = '0.001'; |
|
6
|
15
|
|
|
15
|
|
99438
|
use strict; |
|
|
15
|
|
|
|
|
32
|
|
|
|
15
|
|
|
|
|
337
|
|
|
7
|
15
|
|
|
15
|
|
65
|
use warnings; |
|
|
15
|
|
|
|
|
33
|
|
|
|
15
|
|
|
|
|
322
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
15
|
|
|
15
|
|
6500
|
use Config::Simple(); |
|
|
15
|
|
|
|
|
102956
|
|
|
|
15
|
|
|
|
|
311
|
|
|
10
|
15
|
|
|
15
|
|
5842
|
use File::HomeDir(); |
|
|
15
|
|
|
|
|
60087
|
|
|
|
15
|
|
|
|
|
10978
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub process_configuration { |
|
13
|
3
|
|
|
3
|
1
|
392
|
my $args = shift; |
|
14
|
3
|
|
|
|
|
5
|
my $conf = {}; |
|
15
|
|
|
|
|
|
|
|
|
16
|
3
|
|
50
|
|
|
6
|
my $homedir = File::HomeDir::my_home() || '.'; |
|
17
|
3
|
100
|
|
|
|
47
|
if (-e $homedir) { |
|
18
|
2
|
50
|
|
|
|
13
|
unless (Config::Simple->import_from("$homedir/elastest.conf", $conf)) { |
|
19
|
0
|
0
|
|
|
|
0
|
warn Config::Simple->error() if -e "$homedir/elastest.conf"; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
16
|
my @kvp = (); |
|
24
|
3
|
|
|
|
|
5
|
my ($key, $value); |
|
25
|
3
|
|
|
|
|
5
|
foreach my $arg (@$args) { |
|
26
|
4
|
|
|
|
|
11
|
@kvp = split(/=/, $arg); |
|
27
|
4
|
50
|
|
|
|
8
|
if (scalar(@kvp) < 2) { |
|
28
|
0
|
|
|
|
|
0
|
print |
|
29
|
|
|
|
|
|
|
"Unrecognized Argument '$arg' to App::Prove::Plugin::Elasticsearch, ignoring\n"; |
|
30
|
0
|
|
|
|
|
0
|
next; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
4
|
|
|
|
|
5
|
$key = shift @kvp; |
|
33
|
4
|
|
|
|
|
10
|
$value = join('', @kvp); |
|
34
|
4
|
|
|
|
|
7
|
$conf->{$key} = $value; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#Set ENV for use by harness |
|
38
|
3
|
|
|
|
|
8
|
foreach my $key (keys(%$conf)) { |
|
39
|
6
|
|
|
|
|
10
|
my $km = uc($key); |
|
40
|
6
|
|
|
|
|
15
|
$km =~ s/\./_/g; |
|
41
|
6
|
|
|
|
|
24
|
$ENV{$km} = $conf->{$key}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
16
|
return $conf; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub require_indexer { |
|
48
|
3
|
|
|
3
|
1
|
1514
|
my $conf = shift; |
|
49
|
|
|
|
|
|
|
my $index_suffix = |
|
50
|
3
|
100
|
|
|
|
16
|
$conf->{'client.indexer'} ? "::" . $conf->{'client.indexer'} : ''; |
|
51
|
3
|
|
|
|
|
7
|
my $indexer = "App::Prove::Elasticsearch::Indexer$index_suffix"; |
|
52
|
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
136
|
eval "require $indexer"; |
|
54
|
3
|
100
|
|
|
|
17
|
die $@ if $@; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#Set ENV for use by harness |
|
57
|
2
|
|
|
|
|
14
|
$ENV{CLIENT_INDEXER} = $indexer; |
|
58
|
2
|
|
|
|
|
6
|
return $indexer; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub require_searcher { |
|
62
|
1
|
|
|
1
|
1
|
528
|
my $conf = shift; |
|
63
|
1
|
|
|
|
|
5
|
return _require_generic( |
|
64
|
|
|
|
|
|
|
$conf, |
|
65
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Searcher', |
|
66
|
|
|
|
|
|
|
'client.autodiscover', |
|
67
|
|
|
|
|
|
|
'CLIENT_AUTODISCOVER' |
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub require_blamer { |
|
72
|
2
|
|
|
2
|
1
|
694
|
my $conf = shift; |
|
73
|
2
|
|
|
|
|
5
|
return _require_generic( |
|
74
|
|
|
|
|
|
|
$conf, |
|
75
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Blamer', |
|
76
|
|
|
|
|
|
|
'client.blamer', |
|
77
|
|
|
|
|
|
|
'CLIENT_BLAMER' |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub require_planner { |
|
82
|
2
|
|
|
2
|
1
|
848
|
my $conf = shift; |
|
83
|
2
|
|
|
|
|
5
|
return _require_generic( |
|
84
|
|
|
|
|
|
|
$conf, |
|
85
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Planner', |
|
86
|
|
|
|
|
|
|
'client.planner', |
|
87
|
|
|
|
|
|
|
'CLIENT_PLANNER' |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub require_platformer { |
|
92
|
2
|
|
|
2
|
1
|
1021
|
my $conf = shift; |
|
93
|
2
|
|
|
|
|
7
|
return _require_generic( |
|
94
|
|
|
|
|
|
|
$conf, |
|
95
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Platformer', |
|
96
|
|
|
|
|
|
|
'client.platformer', |
|
97
|
|
|
|
|
|
|
'CLIENT_PLATFORMER' |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub require_queue { |
|
102
|
2
|
|
|
2
|
1
|
880
|
my $conf = shift; |
|
103
|
2
|
|
|
|
|
6
|
return _require_generic( |
|
104
|
|
|
|
|
|
|
$conf, |
|
105
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Queue', |
|
106
|
|
|
|
|
|
|
'client.queue', |
|
107
|
|
|
|
|
|
|
'CLIENT_QUEUE' |
|
108
|
|
|
|
|
|
|
); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub require_versioner { |
|
112
|
2
|
|
|
2
|
1
|
866
|
my $conf = shift; |
|
113
|
2
|
|
|
|
|
6
|
return _require_generic( |
|
114
|
|
|
|
|
|
|
$conf, |
|
115
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Versioner', |
|
116
|
|
|
|
|
|
|
'client.versioner', |
|
117
|
|
|
|
|
|
|
'CLIENT_VERSIONER' |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub require_runner { |
|
122
|
2
|
|
|
2
|
1
|
1031
|
my $conf = shift; |
|
123
|
2
|
|
|
|
|
7
|
return _require_generic( |
|
124
|
|
|
|
|
|
|
$conf, |
|
125
|
|
|
|
|
|
|
'App::Prove::Elasticsearch::Runner', |
|
126
|
|
|
|
|
|
|
'client.runner', |
|
127
|
|
|
|
|
|
|
'CLIENT_RUNNER' |
|
128
|
|
|
|
|
|
|
); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub require_provisioner { |
|
132
|
2
|
|
|
2
|
1
|
1124
|
my $module = shift; |
|
133
|
2
|
|
50
|
|
|
7
|
$module //= 'Default'; |
|
134
|
2
|
|
|
|
|
5
|
my $module_full = "App::Prove::Elasticsearch::Provisioner::$module"; |
|
135
|
2
|
|
|
|
|
99
|
eval "require $module_full"; |
|
136
|
2
|
100
|
|
|
|
16
|
die $@ if $@; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#Set ENV for use by harness |
|
139
|
1
|
50
|
|
|
|
5
|
if ($ENV{CLIENT_PROVISIONERS}) { |
|
140
|
0
|
|
|
|
|
0
|
$ENV{CLIENT_PROVISIONERS} .= ":$module_full"; |
|
141
|
|
|
|
|
|
|
} else { |
|
142
|
1
|
|
|
|
|
9
|
$ENV{CLIENT_PROVISIONERS} = "$module_full"; |
|
143
|
|
|
|
|
|
|
} |
|
144
|
1
|
|
|
|
|
5
|
return $module_full; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _require_generic { |
|
148
|
13
|
|
|
13
|
|
29
|
my ($conf, $prefix, $suffix_key, $envvar) = @_; |
|
149
|
13
|
|
100
|
|
|
40
|
my $suffix = $conf->{$suffix_key} // 'Default'; |
|
150
|
13
|
|
|
|
|
24
|
my $module = "${prefix}::$suffix"; |
|
151
|
|
|
|
|
|
|
|
|
152
|
13
|
|
|
|
|
608
|
eval "require $module"; |
|
153
|
13
|
100
|
|
|
|
90
|
die $@ if $@; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#Set ENV for use by harness |
|
156
|
6
|
|
|
|
|
46
|
$ENV{$envvar} = $suffix; |
|
157
|
6
|
|
|
|
|
21
|
return $module; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub get_last_index { |
|
161
|
2
|
|
|
2
|
1
|
530
|
my ($e, $index) = @_; |
|
162
|
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
12
|
my $res = $e->search( |
|
164
|
|
|
|
|
|
|
index => $index, |
|
165
|
|
|
|
|
|
|
body => { |
|
166
|
|
|
|
|
|
|
query => {match_all => {}}, |
|
167
|
|
|
|
|
|
|
sort => {id => {order => "desc"}}, |
|
168
|
|
|
|
|
|
|
size => 1 |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
); |
|
171
|
|
|
|
|
|
|
|
|
172
|
2
|
|
|
|
|
14
|
my $hits = $res->{hits}->{hits}; |
|
173
|
2
|
100
|
|
|
|
8
|
return 0 unless scalar(@$hits); |
|
174
|
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
4
|
return $res->{hits}->{total}; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub do_paginated_query { |
|
179
|
6
|
|
|
6
|
1
|
14
|
my ($e, $max_query_size, %q) = @_; |
|
180
|
6
|
|
|
|
|
10
|
my $offset = 0; |
|
181
|
6
|
|
|
|
|
9
|
my $hits = []; |
|
182
|
6
|
|
|
|
|
6
|
my $hitcounter = $max_query_size; |
|
183
|
6
|
|
|
|
|
13
|
while ($hitcounter == $max_query_size) { |
|
184
|
6
|
|
|
|
|
8
|
$q{size} = $max_query_size; |
|
185
|
6
|
|
|
|
|
9
|
$q{from} = ($max_query_size * $offset); |
|
186
|
6
|
|
|
|
|
16
|
my $res = $e->search(%q); |
|
187
|
6
|
|
|
|
|
55
|
push(@$hits, @{$res->{hits}->{hits}}); |
|
|
6
|
|
|
|
|
11
|
|
|
188
|
6
|
|
|
|
|
8
|
$hitcounter = scalar(@{$res->{hits}->{hits}}); |
|
|
6
|
|
|
|
|
8
|
|
|
189
|
6
|
|
|
|
|
14
|
$offset++; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
6
|
|
|
|
|
12
|
return $hits; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__ |