Skip to content

Commit

Permalink
Merge pull request #1308 from untergeek/fix/1260
Browse files Browse the repository at this point in the history
Catch reindex failures and raise an exception
  • Loading branch information
untergeek committed Nov 6, 2018
2 parents b9eb361 + 0cba584 commit 59a030c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion curator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ class FailedSnapshot(CuratorException):
class FailedRestore(CuratorException):
"""
Exception raised when a Snapshot Restore does not restore all selected indices
"""
"""

class FailedReindex(CuratorException):
"""
Exception raised when failures are found in the reindex task response
"""
10 changes: 10 additions & 0 deletions curator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,16 @@ def task_check(client, task_id=None):
)
task = task_data['task']
completed = task_data['completed']
if task['action'] == 'indices:data/write/reindex':
logger.debug('It\'s a REINDEX TASK')
logger.debug('TASK_DATA: {0}'.format(task_data))
logger.debug('TASK_DATA keys: {0}'.format(list(task_data.keys())))
if 'response' in task_data:
response = task_data['response']
if len(response['failures']) > 0:
raise exceptions.FailedReindex(
'Failures found in reindex response: {0}'.format(response['failures'])
)
running_time = 0.000000001 * task['running_time_in_nanos']
logger.debug('running_time_in_nanos = {0}'.format(running_time))
descr = task['description']
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Changelog
* Allow much older epoch timestamps (rsteneteg) #1296
* Reindex action respects ``ignore_empty_list`` flag (untergeek) #1297
* Update ILM index version minimum to 6.6.0 (untergeek)
* Catch reindex failures properly. Reported in #1260 (untergeek)

**Documentation**

Expand Down
31 changes: 31 additions & 0 deletions test/integration/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,34 @@ def test_reindex_manual_date_math(self):
],
)
self.assertEqual(expected, self.client.count(index=dest)['count'])
def test_reindex_bad_mapping(self):
# This test addresses GitHub issue #1260
wait_interval = 1
max_wait = 3
source = 'my_source'
dest = 'my_dest'
expected = 1

self.create_index(source)
self.add_docs(source)
# Create the dest index with a different mapping.
self.client.indices.create(
index=dest,
body={
'settings': {'number_of_shards': 1, 'number_of_replicas': 0},
'mappings': {'log': { 'properties': { 'doc1': { 'type': 'integer'}}}}
}
)
self.write_config(
self.args['configfile'], testvars.client_config.format(host, port))
self.write_config(self.args['actionfile'],
testvars.reindex.format(wait_interval, max_wait, source, dest))
test = clicktest.CliRunner()
_ = test.invoke(
curator.cli,
[
'--config', self.args['configfile'],
self.args['actionfile']
],
)
self.assertEqual(expected, _.exit_code)

0 comments on commit 59a030c

Please sign in to comment.