コード例 #1
0
    def test_raises_if_aliased_to_multiple_indices(self, client):
        """Raise if ``index`` is an alias pointing to multiple indices."""
        client.conn.indices.get_alias.return_value = {
            'index-one': {'aliases': {'foo': {}}},
            'index-two': {'aliases': {'foo': {}}},
        }

        with pytest.raises(RuntimeError):
            get_aliased_index(client)
コード例 #2
0
    def test_raises_if_aliased_to_multiple_indices(self, mock_es_client):
        """Raise if ``index`` is an alias pointing to multiple indices."""
        mock_es_client.conn.indices.get_alias.return_value = {
            "index-one": {"aliases": {"foo": {}}},
            "index-two": {"aliases": {"foo": {}}},
        }

        with pytest.raises(RuntimeError):
            get_aliased_index(mock_es_client)
コード例 #3
0
ファイル: config_test.py プロジェクト: chinmaygghag/h
    def test_raises_if_aliased_to_multiple_indices(self, client):
        """Raise if ``index`` is an alias pointing to multiple indices."""
        client.conn.indices.get_alias.return_value = {
            'index-one': {'aliases': {'foo': {}}},
            'index-two': {'aliases': {'foo': {}}},
        }

        with pytest.raises(RuntimeError):
            get_aliased_index(client)
コード例 #4
0
    def test_returns_none_when_no_alias(self, client):
        """If ``index`` is a concrete index, return None."""
        client.conn.indices.get_alias.side_effect = (
            elasticsearch.exceptions.NotFoundError('test', 'test desc')
        )

        assert get_aliased_index(client) is None
コード例 #5
0
    def test_returns_underlying_index_name(self, client):
        """If ``index`` is an alias, return the name of the concrete index."""
        client.conn.indices.get_alias.return_value = {
            'target-index': {'aliases': {'foo': {}}},
        }

        assert get_aliased_index(client) == 'target-index'
コード例 #6
0
ファイル: reindexer.py プロジェクト: ziqizh/h
def reindex(session, es, request):
    """Reindex all annotations into a new index, and update the alias."""

    if get_aliased_index(es) is None:
        raise RuntimeError('cannot reindex if current index is not aliased')

    settings = request.find_service(name='settings')

    new_index = configure_index(es)

    try:
        settings.put(SETTING_NEW_INDEX, new_index)
        request.tm.commit()

        indexer = BatchIndexer(session,
                               es,
                               request,
                               target_index=new_index,
                               op_type='create')

        errored = indexer.index()
        if errored:
            log.debug('failed to index {} annotations, retrying...'.format(
                len(errored)))
            errored = indexer.index(errored)
            if errored:
                log.warn('failed to index {} annotations: {!r}'.format(
                    len(errored), errored))

        update_aliased_index(es, new_index)

    finally:
        settings.delete(SETTING_NEW_INDEX)
        request.tm.commit()
コード例 #7
0
ファイル: config_test.py プロジェクト: chinmaygghag/h
    def test_returns_underlying_index_name(self, client):
        """If ``index`` is an alias, return the name of the concrete index."""
        client.conn.indices.get_alias.return_value = {
            'target-index': {'aliases': {'foo': {}}},
        }

        assert get_aliased_index(client) == 'target-index'
コード例 #8
0
    def test_returns_underlying_index_name(self, mock_es_client):
        """If ``index`` is an alias, return the name of the concrete index."""
        mock_es_client.conn.indices.get_alias.return_value = {
            "target-index": {"aliases": {"foo": {}}}
        }

        assert get_aliased_index(mock_es_client) == "target-index"
コード例 #9
0
ファイル: config_test.py プロジェクト: hypothesis/h
    def test_returns_none_when_no_alias(self, client):
        """If ``index`` is a concrete index, return None."""
        client.conn.indices.get_alias.side_effect = elasticsearch.exceptions.NotFoundError(
            "test", "test desc"
        )

        assert get_aliased_index(client) is None
コード例 #10
0
ファイル: config_test.py プロジェクト: hypothesis/h
    def test_returns_underlying_index_name(self, client):
        """If ``index`` is an alias, return the name of the concrete index."""
        client.conn.indices.get_alias.return_value = {
            "target-index": {"aliases": {"foo": {}}}
        }

        assert get_aliased_index(client) == "target-index"
コード例 #11
0
def reindex(session, es, request):
    """Reindex all annotations into a new index, and update the alias."""

    current_index = get_aliased_index(es)
    if current_index is None:
        raise RuntimeError('cannot reindex if current index is not aliased')

    settings = request.find_service(name='settings')

    # Preload userids of shadowbanned users.
    nipsa_svc = request.find_service(name='nipsa')
    nipsa_svc.fetch_all_flagged_userids()

    new_index = configure_index(es)
    log.info('configured new index {}'.format(new_index))
    setting_name = 'reindex.new_index'
    if es.version < (2, ):
        setting_name = 'reindex.new_index'

    try:
        settings.put(setting_name, new_index)
        request.tm.commit()

        log.info('reindexing annotations into new index {}'.format(new_index))
        indexer = BatchIndexer(session,
                               es,
                               request,
                               target_index=new_index,
                               op_type='create')

        errored = indexer.index()
        if errored:
            log.debug('failed to index {} annotations, retrying...'.format(
                len(errored)))
            errored = indexer.index(errored)
            if errored:
                log.warn('failed to index {} annotations: {!r}'.format(
                    len(errored), errored))

        log.info('making new index {} current'.format(new_index))
        update_aliased_index(es, new_index)

        log.info('removing previous index {}'.format(current_index))
        delete_index(es, current_index)

    finally:
        settings.delete(setting_name)
        request.tm.commit()
コード例 #12
0
ファイル: reindexer.py プロジェクト: hypothesis/h
def reindex(session, es, request):
    """Reindex all annotations into a new index, and update the alias."""

    current_index = get_aliased_index(es)
    if current_index is None:
        raise RuntimeError("cannot reindex if current index is not aliased")

    settings = request.find_service(name="settings")

    # Preload userids of shadowbanned users.
    nipsa_svc = request.find_service(name="nipsa")
    nipsa_svc.fetch_all_flagged_userids()

    new_index = configure_index(es)
    log.info("configured new index {}".format(new_index))
    setting_name = "reindex.new_index"

    try:
        settings.put(setting_name, new_index)
        request.tm.commit()

        log.info("reindexing annotations into new index {}".format(new_index))
        indexer = BatchIndexer(
            session, es, request, target_index=new_index, op_type="create"
        )

        errored = indexer.index()
        if errored:
            log.debug(
                "failed to index {} annotations, retrying...".format(len(errored))
            )
            errored = indexer.index(errored)
            if errored:
                log.warning(
                    "failed to index {} annotations: {!r}".format(len(errored), errored)
                )

        log.info("making new index {} current".format(new_index))
        update_aliased_index(es, new_index)

        log.info("removing previous index {}".format(current_index))
        delete_index(es, current_index)

    finally:
        settings.delete(setting_name)
        request.tm.commit()
コード例 #13
0
ファイル: reindexer.py プロジェクト: bibliotechie/h
def reindex(session, es, request):
    """Reindex all annotations into a new index, and update the alias."""

    current_index = get_aliased_index(es)
    if current_index is None:
        raise RuntimeError("cannot reindex if current index is not aliased")

    settings = request.find_service(name="settings")

    # Preload userids of shadowbanned users.
    nipsa_svc = request.find_service(name="nipsa")
    nipsa_svc.fetch_all_flagged_userids()

    new_index = configure_index(es)
    log.info("configured new index %s", new_index)
    setting_name = "reindex.new_index"

    try:
        settings.put(setting_name, new_index)
        request.tm.commit()

        log.info("reindexing annotations into new index %s", new_index)
        indexer = BatchIndexer(
            session, es, request, target_index=new_index, op_type="create"
        )

        errored = indexer.index()
        if errored:
            log.debug("failed to index %d annotations, retrying...", len(errored))
            errored = indexer.index(errored)
            if errored:
                log.warning("failed to index %d annotations: %r", len(errored), errored)

        log.info("making new index %s current", new_index)
        update_aliased_index(es, new_index)

        log.info("removing previous index %s", current_index)
        delete_index(es, current_index)

    finally:
        settings.delete(setting_name)
        request.tm.commit()
コード例 #14
0
ファイル: config_test.py プロジェクト: yumatch/h
    def test_returns_none_when_no_alias(self, client, error):
        """If ``index`` is a concrete index, return None."""
        client.conn.indices.get_alias.side_effect = error('test', 'test desc')

        assert get_aliased_index(client) is None