@@ -46,7 +46,7 @@ def self.run(client)
46
46
wipe_rollup_jobs ( client )
47
47
wait_for_pending_rollup_tasks ( client )
48
48
end
49
- clear_sml_policies ( client )
49
+ delete_all_slm_policies ( client )
50
50
wipe_searchable_snapshot_indices ( client ) if @has_xpack
51
51
wipe_snapshots ( client )
52
52
wipe_datastreams ( client )
@@ -56,31 +56,25 @@ def self.run(client)
56
56
else
57
57
wipe_all_templates ( client )
58
58
end
59
+ wipe_cluster_settings ( client )
60
+
59
61
if platinum?
60
- clear_datafeeds ( client )
61
62
clear_ml_jobs ( client )
62
- else
63
- client . indices . delete_template ( name : '*' )
64
- client . indices . delete_index_template ( name : '*' )
65
- client . cluster . get_component_template [ 'component_templates' ] . each do |template |
66
- next if platinum_template? template [ 'name' ]
67
-
68
- client . cluster . delete_component_template ( name : template [ 'name' ] , ignore : 404 )
69
- end
63
+ clear_datafeeds ( client )
70
64
end
71
- clear_cluster_settings ( client )
72
- return unless platinum?
73
-
74
- clear_ml_filters ( client )
75
- clear_ilm_policies ( client )
76
- clear_auto_follow_patterns ( client )
77
- clear_tasks ( client )
78
- clear_transforms ( client )
65
+
66
+ delete_all_ilm_policies ( client ) if @has_ilm
67
+ delete_all_follow_patterns ( client ) if @has_ccr
79
68
delete_all_node_shutdown_metadata ( client )
69
+ # clear_ml_filters(client)
70
+ # clear_tasks(client)
71
+ # clear_transforms(client)
80
72
wait_for_cluster_tasks ( client )
81
73
end
82
74
83
75
class << self
76
+ private
77
+
84
78
def platinum?
85
79
ENV [ 'TEST_SUITE' ] == 'platinum'
86
80
end
@@ -99,6 +93,13 @@ def read_plugins(client)
99
93
end
100
94
end
101
95
96
+ def wipe_rollup_jobs ( client )
97
+ client . rollup . get_jobs ( id : '_all' ) [ 'jobs' ] . each do |d |
98
+ client . rollup . stop_job ( id : d [ 'config' ] [ 'id' ] , wait_for_completion : true , timeout : '10s' , ignore : 404 )
99
+ client . rollup . delete_job ( id : d [ 'config' ] [ 'id' ] , ignore : 404 )
100
+ end
101
+ end
102
+
102
103
def wait_for_pending_rollup_tasks ( client )
103
104
filter = 'xpack/rollup/job'
104
105
loop do
@@ -116,49 +117,58 @@ def wait_for_pending_rollup_tasks(client)
116
117
end
117
118
end
118
119
119
- def wait_for_cluster_tasks ( client )
120
- time = Time . now . to_i
121
- count = 0
122
-
123
- loop do
124
- results = client . cluster . pending_tasks
125
- results [ 'tasks' ] . each do |task |
126
- next if task . empty?
127
-
128
- Elasticsearch ::RestAPIYAMLTests ::Logging . logger . debug "Pending cluster task: #{ task } "
129
- count += 1
130
- end
131
- break unless count . positive? && Time . now . to_i < ( time + 30 )
132
- end
133
- end
134
-
135
- def clear_sml_policies ( client )
120
+ def delete_all_slm_policies ( client )
136
121
policies = client . snapshot_lifecycle_management . get_lifecycle
137
122
138
123
policies . each do |name , _ |
139
124
client . snapshot_lifecycle_management . delete_lifecycle ( policy_id : name )
140
125
end
141
126
end
142
127
143
- def clear_ilm_policies ( client )
144
- policies = client . ilm . get_lifecycle
145
- policies . each do |policy |
146
- client . ilm . delete_lifecycle ( policy : policy [ 0 ] ) unless PRESERVE_ILM_POLICY_IDS . include? policy [ 0 ]
128
+ def wipe_searchable_snapshot_indices ( client )
129
+ indices = client . cluster . state ( metric : 'metadata' , filter_path : 'metadata.indices.*.settings.index.store.snapshot' )
130
+ return unless indices . dig ( 'metadata' , 'indices' )
131
+
132
+ indices [ 'metadata' ] [ 'indices' ] . each do |index |
133
+ case index . class
134
+ when Array
135
+ client . indices . delete ( index : index [ 0 ] , ignore : 404 )
136
+ when Hash
137
+ client . indices . delete ( index : index . keys . first , ignore : 404 )
138
+ end
147
139
end
148
140
end
149
141
150
- def clear_cluster_settings ( client )
151
- settings = client . cluster . get_settings
152
- new_settings = [ ]
153
- settings . each do |name , value |
154
- next unless !value . empty? && value . is_a? ( Array )
155
-
156
- new_settings [ name ] = [ ] if new_settings [ name ] . empty?
157
- value . each do |key , _v |
158
- new_settings [ name ] [ "#{ key } .*" ] = nil
142
+ def wipe_snapshots ( client )
143
+ # Repeatedly delete the snapshots until there aren't any
144
+ loop do
145
+ repositories = client . snapshot . get_repository ( repository : '_all' )
146
+ break if repositories . empty?
147
+
148
+ repositories = client . snapshot . get_repository ( repository : '_all' )
149
+ repositories . each_key do |repository |
150
+ if repositories [ repository ] [ 'type' ] == 'fs'
151
+ response = client . snapshot . get ( repository : repository , snapshot : '_all' , ignore_unavailable : true )
152
+ response [ 'snapshots' ] . each do |snapshot |
153
+ client . snapshot . delete ( repository : repository , snapshot : snapshot [ 'snapshot' ] , ignore : 404 )
154
+ end
155
+ end
156
+ client . snapshot . delete_repository ( repository : repository , ignore : 404 )
159
157
end
160
158
end
161
- client . cluster . put_settings ( body : new_settings ) unless new_settings . empty?
159
+ end
160
+
161
+ def wipe_datastreams ( client )
162
+ begin
163
+ client . indices . delete_data_stream ( name : '*' , expand_wildcards : 'all' )
164
+ rescue StandardError => e
165
+ Elasticsearch ::RestAPIYAMLTests ::Logging . logger . error "Caught exception attempting to delete data streams: #{ e } "
166
+ client . indices . delete_data_stream ( name : '*' )
167
+ end
168
+ end
169
+
170
+ def wipe_all_indices ( client )
171
+ client . indices . delete ( index : '*,-.ds-ilm-history-*' , expand_wildcards : 'open,closed,hidden' , ignore : 404 )
162
172
end
163
173
164
174
def wipe_templates_for_xpack ( client )
@@ -210,16 +220,51 @@ def platinum_template?(template)
210
220
PLATINUM_TEMPLATES . include? template
211
221
end
212
222
213
- def clear_auto_follow_patterns ( client )
223
+ def wait_for_cluster_tasks ( client )
224
+ time = Time . now . to_i
225
+ count = 0
226
+
227
+ loop do
228
+ results = client . cluster . pending_tasks
229
+ results [ 'tasks' ] . each do |task |
230
+ next if task . empty?
231
+
232
+ Elasticsearch ::RestAPIYAMLTests ::Logging . logger . debug "Pending cluster task: #{ task } "
233
+ count += 1
234
+ end
235
+ break unless count . positive? && Time . now . to_i < ( time + 30 )
236
+ end
237
+ end
238
+
239
+ def delete_all_ilm_policies ( client )
240
+ policies = client . ilm . get_lifecycle
241
+ policies . each do |policy |
242
+ client . ilm . delete_lifecycle ( policy : policy [ 0 ] ) unless PRESERVE_ILM_POLICY_IDS . include? policy [ 0 ]
243
+ end
244
+ end
245
+
246
+ def wipe_cluster_settings ( client )
247
+ settings = client . cluster . get_settings
248
+ new_settings = [ ]
249
+ settings . each do |name , value |
250
+ next unless !value . empty? && value . is_a? ( Array )
251
+
252
+ new_settings [ name ] = [ ] if new_settings [ name ] . empty?
253
+ value . each do |key , _v |
254
+ new_settings [ name ] [ "#{ key } .*" ] = nil
255
+ end
256
+ end
257
+ client . cluster . put_settings ( body : new_settings ) unless new_settings . empty?
258
+ end
259
+
260
+ def delete_all_follow_patterns ( client )
214
261
patterns = client . cross_cluster_replication . get_auto_follow_pattern
215
262
216
263
patterns [ 'patterns' ] . each do |pattern |
217
264
client . cross_cluster_replication . delete_auto_follow_pattern ( name : pattern )
218
265
end
219
266
end
220
267
221
- private
222
-
223
268
def create_xpack_rest_user ( client )
224
269
client . security . put_user (
225
270
username : 'x_pack_rest_user' ,
@@ -245,27 +290,13 @@ def clear_privileges(client)
245
290
end
246
291
end
247
292
248
- def clear_datafeeds ( client )
249
- client . ml . stop_datafeed ( datafeed_id : '_all' , force : true )
250
- client . ml . get_datafeeds [ 'datafeeds' ] . each do |d |
251
- client . ml . delete_datafeed ( datafeed_id : d [ 'datafeed_id' ] )
252
- end
253
- end
254
-
255
293
def clear_ml_jobs ( client )
256
294
client . ml . close_job ( job_id : '_all' , force : true )
257
295
client . ml . get_jobs [ 'jobs' ] . each do |d |
258
296
client . ml . delete_job ( job_id : d [ 'job_id' ] )
259
297
end
260
298
end
261
299
262
- def wipe_rollup_jobs ( client )
263
- client . rollup . get_jobs ( id : '_all' ) [ 'jobs' ] . each do |d |
264
- client . rollup . stop_job ( id : d [ 'config' ] [ 'id' ] , wait_for_completion : true , timeout : '10s' , ignore : 404 )
265
- client . rollup . delete_job ( id : d [ 'config' ] [ 'id' ] , ignore : 404 )
266
- end
267
- end
268
-
269
300
def clear_tasks ( client )
270
301
tasks = client . tasks . get [ 'nodes' ] . values . first [ 'tasks' ] . values . select do |d |
271
302
d [ 'cancellable' ]
@@ -287,65 +318,24 @@ def clear_index_templates(client)
287
318
end
288
319
end
289
320
290
- def wipe_snapshots ( client )
291
- repositories = client . snapshot . get_repository ( repository : '_all' )
292
-
293
- repositories . each_key do |repository |
294
- if repositories [ repository ] [ 'type' ] == 'fs'
295
- response = client . snapshot . get ( repository : repository , snapshot : '_all' , ignore_unavailable : true )
296
- response [ 'snapshots' ] . each do |snapshot |
297
- client . snapshot . delete ( repository : repository , snapshot : snapshot [ 'snapshot' ] , ignore : 404 )
298
- end
299
- end
300
- client . snapshot . delete_repository ( repository : repository , ignore : 404 )
301
- end
302
- end
303
-
304
321
def clear_transforms ( client )
305
322
client . transform . get_transform ( transform_id : '*' ) [ 'transforms' ] . each do |transform |
306
323
client . transform . delete_transform ( transform_id : transform [ :id ] )
307
324
end
308
325
end
309
326
310
- def wipe_datastreams ( client )
311
- begin
312
- client . indices . delete_data_stream ( name : '*' , expand_wildcards : 'all' )
313
- rescue StandardError => e
314
- Elasticsearch ::RestAPIYAMLTests ::Logging . logger . error "Caught exception attempting to delete data streams: #{ e } "
315
- client . indices . delete_data_stream ( name : '*' ) if @has_xpack
316
- end
317
- end
318
-
319
327
def clear_ml_filters ( client )
320
328
filters = client . ml . get_filters [ 'filters' ]
321
329
filters . each do |filter |
322
330
client . ml . delete_filter ( filter_id : filter [ 'filter_id' ] )
323
331
end
324
332
end
325
333
326
- def wipe_all_indices ( client )
327
- client . indices . delete ( index : '*,-.ds-ilm-history-*' , expand_wildcards : 'open,closed,hidden' , ignore : 404 )
328
- end
329
-
330
- def wipe_searchable_snapshot_indices ( client )
331
- indices = client . cluster . state ( metric : 'metadata' , filter_path : 'metadata.indices.*.settings.index.store.snapshot' )
332
- return unless indices . dig ( 'metadata' , 'indices' )
333
-
334
- indices [ 'metadata' ] [ 'indices' ] . each do |index |
335
- case index . class
336
- when Array
337
- client . indices . delete ( index : index [ 0 ] , ignore : 404 )
338
- when Hash
339
- client . indices . delete ( index : index . keys . first , ignore : 404 )
340
- end
341
- end
342
- end
343
-
344
334
def delete_all_node_shutdown_metadata ( client )
345
335
nodes = client . shutdown . get_node
346
- return if nodes [ '_nodes' ] && nodes [ 'cluster_name' ] || nodes &.[] ( "nodes" ) . empty?
336
+ return unless nodes
347
337
348
- nodes . each do |node |
338
+ nodes [ 'nodes' ] . each do |node |
349
339
client . shutdown . delete_node ( node [ 'node_id' ] )
350
340
end
351
341
end
0 commit comments