@@ -116,8 +116,30 @@ def setup(client)
116
116
return unless @setup
117
117
118
118
actions = @setup [ 'setup' ] . select { |action | action [ 'do' ] } . map { |action | Action . new ( action [ 'do' ] ) }
119
+ count = 0
120
+
119
121
actions . each do |action |
120
- action . execute ( client )
122
+ begin
123
+ action . execute ( client )
124
+ rescue Elasticsearch ::Transport ::Transport ::Errors ::ServiceUnavailable => e
125
+ # The action sometimes gets the cluster in a recovering state, so we
126
+ # retry a few times and then raise an exception if it's still
127
+ # happening
128
+ count += 1
129
+ raise e if count > 9
130
+
131
+ redo
132
+ rescue Elasticsearch ::Transport ::Transport ::Errors ::BadRequest => e
133
+ error = JSON . parse ( e . message . gsub ( /\[ [0-9]{3}\] / , '' ) ) [ 'error' ] [ 'root_cause' ] . first
134
+ count += 1
135
+
136
+ logger = Logger . new ( $stdout)
137
+ logger . error "#{ error [ 'type' ] } : #{ error [ 'reason' ] } "
138
+ client . indices . delete ( index : error [ 'index' ] ) if error [ 'reason' ] =~ /index \[ .+\] already exists/
139
+ raise e if count > 9
140
+
141
+ redo
142
+ end
121
143
end
122
144
self
123
145
end
@@ -164,26 +186,26 @@ def wipe_cluster(client)
164
186
wait_for_pending_tasks ( client )
165
187
clear_sml_policies ( client )
166
188
end
167
-
168
189
clear_snapshots_and_repositories ( client )
169
190
clear_datastreams ( client ) if xpack?
170
191
clear_indices ( client )
171
-
172
192
if xpack?
193
+ clear_datafeeds ( client )
173
194
clear_templates_xpack ( client )
195
+ clear_ml_jobs ( client )
174
196
else
175
197
client . indices . delete_template ( name : '*' )
176
198
client . indices . delete_index_template ( name : '*' )
177
199
client . cluster . delete_component_template ( name : '*' )
178
200
end
179
-
180
201
clear_cluster_settings ( client )
181
-
182
202
return unless xpack?
183
203
184
204
clear_ilm_policies ( client )
185
205
clear_auto_follow_patterns ( client )
186
206
clear_tasks ( client )
207
+ clear_indices ( client )
208
+ clear_transforms ( client )
187
209
end
188
210
189
211
def xpack?
@@ -355,16 +377,20 @@ def clear_transforms(client)
355
377
356
378
def clear_indices ( client )
357
379
client . indices . delete ( index : '*' , expand_wildcards : 'all' , ignore : 404 )
358
- end
359
380
360
- def clear_indices_xpack ( client )
361
- indices = client . indices . get ( index : '_all' ) . keys . reject do |i |
362
- i . start_with? ( '.security' ) || i . start_with? ( '.watches' )
381
+ indices = client . indices . get ( index : '_all' , expand_wildcards : 'all' ) . keys . reject do |i |
382
+ i . start_with? ( '.security' ) || i . start_with? ( '.watches' ) || i . start_with? ( '.ds-' )
363
383
end
364
384
indices . each do |index |
365
385
client . indices . delete_alias ( index : index , name : '*' , ignore : 404 )
366
386
client . indices . delete ( index : index , ignore : 404 )
367
387
end
388
+ rescue Elasticsearch ::Transport ::Transport ::Errors ::BadRequest => e
389
+ raise e unless e . message . include? ( 'is the write index for data stream' )
390
+
391
+ error = JSON . parse ( e . message . gsub ( /\[ [0-9]{3}\] / , '' ) ) [ 'error' ] [ 'root_cause' ] . first
392
+ logger = Logger . new ( $stdout)
393
+ logger . error "#{ error [ 'type' ] } : #{ error [ 'reason' ] } "
368
394
end
369
395
end
370
396
end
0 commit comments