Пример #1
0
 def teardown_indexes(self):
     try:
         get_es().indices.delete(get_index_name())
     except NotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Пример #2
0
 def teardown_indexes(self):
     try:
         get_es().indices.delete(get_index_name())
     except NotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Пример #3
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        if empty:
            recreate_index()
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_es().cluster.health(wait_for_status='yellow')
Пример #4
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        if empty:
            recreate_index()
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_es().cluster.health(wait_for_status='yellow')
Пример #5
0
    def refresh(self, timesleep=0):
        index = get_index()

        # Any time we're doing a refresh, we're making sure that the
        # index is ready to be queried.  Given that, it's almost
        # always the case that we want to run all the generated tasks,
        # then refresh.
        # TODO: uncomment this when we have live indexing.
        # generate_tasks()

        get_es().refresh(index)
        if timesleep > 0:
            time.sleep(timesleep)
Пример #6
0
    def refresh(self, timesleep=0):
        index = get_index()

        # Any time we're doing a refresh, we're making sure that the
        # index is ready to be queried.  Given that, it's almost
        # always the case that we want to run all the generated tasks,
        # then refresh.
        # TODO: uncomment this when we have live indexing.
        # generate_tasks()

        get_es().indices.refresh(index)
        if timesleep > 0:
            time.sleep(timesleep)
Пример #7
0
def timezone_view(request):
    """Admin view showing times and timezones in data."""
    # Note: This is an admin page that gets used once in a blue moon.
    # As such, I'm taking some liberties (hand-indexing the response,
    # time.sleep, etc) that I would never take if it was used more
    # often or was viewable by users. If these two assumptions ever
    # change, then this should be rewritten.

    from fjord.feedback.models import (
        Response,
        ResponseDocType,
        ResponseDocTypeManager
    )
    from fjord.feedback.tests import ResponseFactory
    from fjord.search.index import get_es, get_index_name

    server_time = datetime.now()

    # Create a new response.
    resp = ResponseFactory()
    resp_time = resp.created

    # Index the response by hand so we know it gets to
    # Elasticsearch. Otherwise it gets done by celery and we don't
    # know how long that'll take.
    doc = ResponseDocType.extract_doc(resp)
    ResponseDocTypeManager.bulk_index(docs=[doc])

    # Fetch the response from the db.
    resp = Response.objects.get(id=resp.id)
    resp2_time = resp.created

    # Refresh and sleep 5 seconds as a hand-wavey way to make sure
    # that Elasticsearch has had time to refresh the index.
    get_es().indices.refresh(get_index_name())
    time.sleep(5)

    s = ResponseDocTypeManager.search().filter('term', id=resp.id).execute()
    es_time = s[0].created

    # Delete the test response which also deletes it in the index.
    resp.delete()

    return render(request, 'admin/timezone_view.html', {
        'server_time': server_time,
        'resp_time': resp_time,
        'resp2_time': resp2_time,
        'es_time': es_time
    })
Пример #8
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        from fjord.search.index import es_reindex_cmd

        if empty:
            # Removes the index and creates a new one with nothing in
            # it (by abusing the percent argument).
            es_reindex_cmd(percent=0)
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_es().health(wait_for_status='yellow')
Пример #9
0
    def setUpClass(cls):
        super(ElasticTestCase, cls).setUpClass()

        if not getattr(settings, 'ES_URLS', None):
            cls.skipme = True
            return

        # try to connect to ES and if it fails, skip ElasticTestCases.
        try:
            get_es().health()
        except (Timeout, ConnectionError):
            cls.skipme = True
            return

        cls._old_es_index_prefix = settings.ES_INDEX_PREFIX
        settings.ES_INDEX_PREFIX = settings.ES_INDEX_PREFIX + 'test'
Пример #10
0
    def setup_indexes(self, empty=False, wait=True):
        """(Re-)create ES indexes."""
        from fjord.search.index import es_reindex_cmd

        if empty:
            # Removes the index and creates a new one with nothing in
            # it (by abusing the percent argument).
            es_reindex_cmd(percent=0)
        else:
            # Removes the index, creates a new one, and indexes
            # existing data into it.
            es_reindex_cmd()

        self.refresh()
        if wait:
            get_es().cluster.health(wait_for_status='yellow')
Пример #11
0
    def setUpClass(cls):
        super(ElasticTestCase, cls).setUpClass()

        if not getattr(settings, 'ES_URLS', None):
            cls.skipme = True
            return

        # try to connect to ES and if it fails, skip ElasticTestCases.
        try:
            get_es().health()
        except (Timeout, ConnectionError):
            cls.skipme = True
            return

        cls._old_es_index_prefix = settings.ES_INDEX_PREFIX
        settings.ES_INDEX_PREFIX = settings.ES_INDEX_PREFIX + 'test'
Пример #12
0
 def teardown_indexes(self):
     es = get_es()
     try:
         es.delete_index(get_index())
     except ElasticHttpNotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Пример #13
0
 def teardown_indexes(self):
     es = get_es()
     try:
         es.delete_index(get_index())
     except ElasticHttpNotFoundError:
         # If we get this error, it means the index didn't exist
         # so there's nothing to delete.
         pass
Пример #14
0
 def refresh(self, timesleep=0):
     get_es().indices.refresh()
     if timesleep > 0:
         time.sleep(timesleep)
Пример #15
0
 def refresh(self, timesleep=0):
     get_es().indices.refresh()
     if timesleep > 0:
         time.sleep(timesleep)