From 7d84870ac691867bbed1be0df7f1d4713c3de0b7 Mon Sep 17 00:00:00 2001 From: msvechla Date: Sun, 21 Oct 2018 20:17:05 +0200 Subject: [PATCH] add checks for reindex task failures and number of created docs --- curator/actions.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/curator/actions.py b/curator/actions.py index 9b5e07ad7..fe7b65387 100644 --- a/curator/actions.py +++ b/curator/actions.py @@ -1280,7 +1280,7 @@ def _get_reindex_args(self, source, dest): del reindex_args['slices'] return reindex_args - def _post_run_quick_check(self, index_name): + def _post_run_quick_check(self, index_name, task_id): # Verify the destination index is there after the fact index_exists = self.client.indices.exists(index=index_name) alias_instead = self.client.indices.exists_alias(name=index_name) @@ -1303,6 +1303,36 @@ def _post_run_quick_check(self, index_name): 'not found.'.format(index_name) ) + # Verify that the reindex task finished without errors + response = self.client.tasks.get(task_id) + failures = response['response']['failures'] + + if len(failures) > 0: + self.loggit.error( + 'The reindex task completed with {0} errors. ' + 'Check task: {1} for more information.'.format(len(failures), task_id) + ) + + raise exceptions.FailedExecution( + 'Reindex completed with {0} errors. ' + 'Check task: {1} for more information.'.format(len(failures), task_id) + ) + + # Verify that the number of docs in the source and destination index match + total_docs = response['task']['status']['total'] + created_docs = response['task']['status']['created'] + + if not created_docs == total_docs: + self.loggit.error( + 'The number of created documents ({0}) in the destination index' + 'do not match the number of total documents in the source index ({1}). ' + 'Check task: {2} for more information.'.format(created_docs, total_docs, task_id) + ) + raise exceptions.FailedExecution( + 'Reindex incomplete. The number of created documents ({0}) in the destination index' + 'do not match the number of total documents in the source index ({1}). '.format(created_docs, total_docs) + ) + def sources(self): # Generator for sources & dests dest = self.body['dest']['index'] @@ -1375,7 +1405,7 @@ def do_action(self): self.client, 'reindex', task_id=response['task'], wait_interval=self.wait_interval, max_wait=self.max_wait ) - self._post_run_quick_check(dest) + self._post_run_quick_check(dest, response['task']) else: self.loggit.warn(