def search_admin_view(request): """Render the admin view containing search tools""" error_messages = [] stats = None es_deets = None indexes = [] reset_requested = 'reset' in request.POST if reset_requested: try: return handle_reset(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) reindex_requested = 'reindex' in request.POST if reindex_requested: try: return handle_reindex(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) try: # This gets index stats, but also tells us whether ES is in # a bad state. try: stats = get_index_stats() except NotFoundError: stats = None indexes = get_indexes() indexes.sort(key=lambda m: m[0]) # TODO: Input has a single ES_URL and that's the ZLB and does # the balancing. If that ever changes and we have multiple # ES_URLs, then this should get fixed. es_deets = requests.get(settings.ES_URLS[0]).json() except ConnectionError: error_messages.append('Error: Elastic Search is not set up on this ' 'machine or timed out trying to respond. ' '(ConnectionError/Timeout)') except NotFoundError: error_messages.append('Error: Index is missing. Press the reindex ' 'button below. (ElasticHttpNotFoundError)') outstanding_records = Record.outstanding() recent_records = Record.objects.order_by('-creation_time')[:20] return render( request, 'admin/search_admin_view.html', { 'title': 'Search', 'es_deets': es_deets, 'mapping_type_stats': stats, 'indexes': indexes, 'index': get_index(), 'error_messages': error_messages, 'recent_records': recent_records, 'outstanding_records': outstanding_records, 'now': datetime.now(), })
def search_admin_view(request): """Render the admin view containing search tools""" error_messages = [] stats = None es_deets = None indexes = [] reset_requested = 'reset' in request.POST if reset_requested: try: return handle_reset(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) reindex_requested = 'reindex' in request.POST if reindex_requested: try: return handle_reindex(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) try: # This gets index stats, but also tells us whether ES is in # a bad state. try: stats = get_index_stats() except NotFoundError: stats = None indexes = get_indexes() indexes.sort(key=lambda m: m[0]) # TODO: Input has a single ES_URL and that's the ZLB and does # the balancing. If that ever changes and we have multiple # ES_URLs, then this should get fixed. es_deets = requests.get(settings.ES_URLS[0]).json() except ConnectionError: error_messages.append('Error: Elastic Search is not set up on this ' 'machine or timed out trying to respond. ' '(ConnectionError/Timeout)') except NotFoundError: error_messages.append('Error: Index is missing. Press the reindex ' 'button below. (ElasticHttpNotFoundError)') outstanding_records = Record.outstanding() recent_records = Record.objects.order_by('-creation_time')[:20] return render(request, 'admin/search_admin_view.html', { 'title': 'Search', 'es_deets': es_deets, 'mapping_type_stats': stats, 'indexes': indexes, 'index': get_index(), 'error_messages': error_messages, 'recent_records': recent_records, 'outstanding_records': outstanding_records, 'now': datetime.now(), })
def handle_reset(request): """Mark outstanding Records as failed. Why? You'd want to reset the system if it gets itself wedged thinking there are outstanding tasks, but there aren't. This lets you fix that. """ for rec in Record.outstanding(): rec.mark_fail('Cancelled.') return HttpResponseRedirect(request.path)
def search_admin_view(request): """Render the admin view containing search tools""" error_messages = [] stats = None indexes = [] reset_requested = 'reset' in request.POST if reset_requested: try: return handle_reset(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) reindex_requested = 'reindex' in request.POST if reindex_requested: try: return handle_reindex(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) try: # This gets index stats, but also tells us whether ES is in # a bad state. try: stats = get_index_stats() except pyes.exceptions.IndexMissingException: stats = None indexes = get_indexes() indexes.sort(key=lambda m: m[0]) except pyes.urllib3.MaxRetryError: error_messages.append('Error: Elastic Search is not set up on this ' 'machine or is not responding. (MaxRetryError)') except pyes.exceptions.IndexMissingException: error_messages.append('Error: Index is missing. Press the reindex ' 'button below. (IndexMissingException)') except pyes.urllib3.TimeoutError: error_messages.append('Error: Connection to Elastic Search timed out. ' '(TimeoutError)') outstanding_records = Record.outstanding() recent_records = Record.objects.order_by('-creation_time')[:20] return render( request, 'admin/search_admin_view.html', { 'title': 'Search', 'mapping_type_stats': stats, 'indexes': indexes, 'index': get_index(), 'error_messages': error_messages, 'recent_records': recent_records, 'outstanding_records': outstanding_records, 'now': datetime.now(), })
def search_admin_view(request): """Render the admin view containing search tools""" error_messages = [] stats = None indexes = [] reset_requested = 'reset' in request.POST if reset_requested: try: return handle_reset(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) reindex_requested = 'reindex' in request.POST if reindex_requested: try: return handle_reindex(request) except Exception as exc: error_messages.append(u'Error: %s' % exc.message) try: # This gets index stats, but also tells us whether ES is in # a bad state. try: stats = get_index_stats() except pyes.exceptions.IndexMissingException: stats = None indexes = get_indexes() indexes.sort(key=lambda m: m[0]) except pyes.urllib3.MaxRetryError: error_messages.append('Error: Elastic Search is not set up on this ' 'machine or is not responding. (MaxRetryError)') except pyes.exceptions.IndexMissingException: error_messages.append('Error: Index is missing. Press the reindex ' 'button below. (IndexMissingException)') except pyes.urllib3.TimeoutError: error_messages.append('Error: Connection to Elastic Search timed out. ' '(TimeoutError)') outstanding_records = Record.outstanding() recent_records = Record.objects.order_by('-creation_time')[:20] return render(request, 'admin/search_admin_view.html', { 'title': 'Search', 'mapping_type_stats': stats, 'indexes': indexes, 'index': get_index(), 'error_messages': error_messages, 'recent_records': recent_records, 'outstanding_records': outstanding_records, 'now': datetime.now(), })
def reset_records(): for rec in Record.outstanding(): rec.mark_fail('Cancelled.')