in curator/helpers/waiters.py [0:0]
def restore_check(client, index_list):
"""
This function calls `client.indices.`
:py:meth:`~.elasticsearch.client.IndicesClient.recovery`
with the list of indices to check for complete recovery. It will return ``True``
if recovery of those indices is complete, and ``False`` otherwise. It is
designed to fail fast: if a single shard is encountered that is still recovering
(not in ``DONE`` stage), it will immediately return ``False``, rather than
complete iterating over the rest of the response.
:param client: A client connection object
:param index_list: The list of indices to verify having been restored.
:param kwargs: Any additional keyword arguments to pass to the function
:type client: :py:class:`~.elasticsearch.Elasticsearch`
:type index_list: list
:rtype: bool
"""
logger = logging.getLogger(__name__)
response = {}
for chunk in chunk_index_list(index_list):
try:
chunk_response = client.indices.recovery(index=chunk, human=True)
except Exception as err:
msg = (
f'Unable to obtain recovery information for specified indices. '
f'Error: {err}'
)
raise CuratorException(msg) from err
if chunk_response == {}:
logger.info('_recovery returned an empty response. Trying again.')
return False
response.update(chunk_response)
logger.info('Provided indices: %s', index_list)
logger.info('Found indices: %s', list(response.keys()))
# pylint: disable=consider-using-dict-items
for index in response:
for shard in range(0, len(response[index]['shards'])):
stage = response[index]['shards'][shard]['stage']
if stage != 'DONE':
logger.info('Index "%s" is still in stage "%s"', index, stage)
return False
# If we've gotten here, all of the indices have recovered
return True