16
16
# under the License.
17
17
18
18
require_relative 'logging'
19
+ include Elasticsearch ::RestAPIYAMLTests ::Logging
19
20
20
21
module Elasticsearch
21
22
module RestAPIYAMLTests
@@ -67,12 +68,10 @@ def wipe_cluster(client)
67
68
wipe_all_templates ( client )
68
69
end
69
70
wipe_cluster_settings ( client )
70
-
71
71
if platinum?
72
72
clear_ml_jobs ( client )
73
73
clear_datafeeds ( client )
74
74
end
75
-
76
75
delete_all_ilm_policies ( client ) if @has_ilm
77
76
delete_all_follow_patterns ( client ) if @has_ccr
78
77
delete_all_node_shutdown_metadata ( client )
@@ -88,9 +87,11 @@ def ensure_no_initializing_shards(client)
88
87
def check_for_unexpectedly_recreated_objects ( client )
89
88
unexpected_ilm_policies = client . index_lifecycle_management . get_lifecycle
90
89
unexpected_ilm_policies . reject! { |k , _ | PRESERVE_ILM_POLICY_IDS . include? k }
91
- Elasticsearch ::RestAPIYAMLTests ::Logging . logger . info (
92
- "Expected no ILM policies after deletions, but found #{ unexpected_ilm_policies . keys . join ( ',' ) } "
93
- ) unless unexpected_ilm_policies . empty?
90
+ unless unexpected_ilm_policies . empty?
91
+ logger . info (
92
+ "Expected no ILM policies after deletions, but found #{ unexpected_ilm_policies . keys . join ( ',' ) } "
93
+ )
94
+ end
94
95
return unless platinum?
95
96
96
97
templates = client . indices . get_index_template
@@ -101,9 +102,11 @@ def check_for_unexpectedly_recreated_objects(client)
101
102
legacy_templates = client . indices . get_template
102
103
unexpected_templates << legacy_templates . keys . reject { |t | PLATINUM_TEMPLATES . include? t }
103
104
104
- Elasticsearch ::RestAPIYAMLTests ::Logging . logger . info (
105
- "Expected no templates after deletions, but found #{ unexpected_templates . join ( ',' ) } "
106
- ) unless unexpected_templates . empty?
105
+ unless unexpected_templates . empty?
106
+ logger . info (
107
+ "Expected no templates after deletions, but found #{ unexpected_templates . join ( ',' ) } "
108
+ )
109
+ end
107
110
end
108
111
109
112
def platinum?
@@ -141,7 +144,7 @@ def wait_for_pending_rollup_tasks(client)
141
144
results . each do |task |
142
145
next if task . empty?
143
146
144
- Elasticsearch :: RestAPIYAMLTests :: Logging . logger . debug ( "Pending task: #{ task } " )
147
+ logger . debug ( "Pending task: #{ task } " )
145
148
count += 1 if task . include? ( filter )
146
149
end
147
150
break unless count . positive? && Time . now . to_i < ( time + 30 )
@@ -161,12 +164,12 @@ def wipe_searchable_snapshot_indices(client)
161
164
return unless indices . dig ( 'metadata' , 'indices' )
162
165
163
166
indices [ 'metadata' ] [ 'indices' ] . each do |index |
164
- case index . class
165
- when Array
166
- client . indices . delete ( index : index [ 0 ] , ignore : 404 )
167
- when Hash
168
- client . indices . delete ( index : index . keys . first , ignore : 404 )
169
- end
167
+ index_name = if index . is_a? ( Array )
168
+ index [ 0 ]
169
+ elsif index . is_a? ( Hash )
170
+ index . keys . first
171
+ end
172
+ client . indices . delete ( index : index_name , ignore : 404 )
170
173
end
171
174
end
172
175
@@ -176,11 +179,13 @@ def wipe_snapshots(client)
176
179
repositories = client . snapshot . get_repository ( repository : '_all' )
177
180
break if repositories . empty?
178
181
179
- repositories = client . snapshot . get_repository ( repository : '_all' )
180
182
repositories . each_key do |repository |
181
183
if repositories [ repository ] [ 'type' ] == 'fs'
182
184
response = client . snapshot . get ( repository : repository , snapshot : '_all' , ignore_unavailable : true )
183
185
response [ 'snapshots' ] . each do |snapshot |
186
+ if snapshot [ 'state' ] != 'SUCCESS'
187
+ logger . debug ( "Found snapshot that did not succeed #{ snapshot } " )
188
+ end
184
189
client . snapshot . delete ( repository : repository , snapshot : snapshot [ 'snapshot' ] , ignore : 404 )
185
190
end
186
191
end
@@ -193,7 +198,7 @@ def wipe_datastreams(client)
193
198
begin
194
199
client . indices . delete_data_stream ( name : '*' , expand_wildcards : 'all' )
195
200
rescue StandardError => e
196
- Elasticsearch :: RestAPIYAMLTests :: Logging . logger . error "Caught exception attempting to delete data streams: #{ e } "
201
+ logger . error "Caught exception attempting to delete data streams: #{ e } "
197
202
client . indices . delete_data_stream ( name : '*' )
198
203
end
199
204
end
@@ -229,7 +234,7 @@ def wipe_templates_for_xpack(client)
229
234
begin
230
235
client . indices . delete_template ( name : name )
231
236
rescue StandardError => e
232
- Elasticsearch :: RestAPIYAMLTests :: Logging . logger . info ( "Unable to remove index template #{ name } " )
237
+ logger . info ( "Unable to remove index template #{ name } " )
233
238
end
234
239
end
235
240
end
@@ -240,7 +245,7 @@ def wipe_all_templates(client)
240
245
client . indices . delete_index_template ( name : '*' )
241
246
client . cluster . delete_component_template ( name : '*' )
242
247
rescue StandardError => e
243
- Elasticsearch :: RestAPIYAMLTests :: Logging . logger . info ( 'Using a version of ES that doesn\'t support index templates v2 yet, so it\'s safe to ignore' )
248
+ logger . info ( 'Using a version of ES that doesn\'t support index templates v2 yet, so it\'s safe to ignore' )
244
249
end
245
250
end
246
251
@@ -260,7 +265,7 @@ def wait_for_cluster_tasks(client)
260
265
results [ 'tasks' ] . each do |task |
261
266
next if task . empty?
262
267
263
- Elasticsearch :: RestAPIYAMLTests :: Logging . logger . debug "Pending cluster task: #{ task } "
268
+ logger . debug "Pending cluster task: #{ task } "
264
269
count += 1
265
270
end
266
271
break unless count . positive? && Time . now . to_i < ( time + 30 )
0 commit comments