当前位置: 首页>>代码示例>>Python>>正文


Python elasticsearch.ConnectionError方法代码示例

本文整理汇总了Python中elasticsearch.ConnectionError方法的典型用法代码示例。如果您正苦于以下问题:Python elasticsearch.ConnectionError方法的具体用法?Python elasticsearch.ConnectionError怎么用?Python elasticsearch.ConnectionError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elasticsearch的用法示例。


在下文中一共展示了elasticsearch.ConnectionError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_status

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def get_status():
    """Returns the status of the elastic cluster
    """
    es = get_elasticsearch()
    try:
        cluster_health = es.cluster.health()
    except ConnectionError as err:
        logging.getLogger(__name__).error("Failed to connect to ES: %s", err)
        cluster_health = {}
        es_reachable = False
    else:
        es_reachable = True

    es_cluster_health = cluster_health.get("status") in ES_RUNNING_STATUS

    # the 'ready' is used as the readyness probe.
    # for the moment idunn is ready if ES is reachable
    ready = es_cluster_health
    return {"es": {"reachable": es_reachable, "running": es_cluster_health}, "ready": ready} 
开发者ID:QwantResearch,项目名称:idunn,代码行数:21,代码来源:status.py

示例2: search

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def search(self, project_id, user_id=None, doc_id=None, search=None,
               offset=0, limit=10):
        search = search or {}
        query_dsl = self.get_search_query(
            project_id=project_id,
            user_id=user_id,
            doc_id=doc_id,
            search=search
        )
        try:
            res = self.es.search(index=self.index, doc_type=self.doc_type,
                                 size=limit, from_=offset, body=query_dsl)
        except elasticsearch.ConnectionError:
            raise freezer_api_exc.StorageEngineError(
                message='unable to connect to db server')
        except Exception as e:
            raise freezer_api_exc.StorageEngineError(
                message='search operation failed: {0}'.format(e))
        hit_list = res['hits']['hits']
        return [x['_source'] for x in hit_list] 
开发者ID:openstack,项目名称:freezer-api,代码行数:22,代码来源:elasticv2.py

示例3: test_execute_single_with_connection_error_continues

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_execute_single_with_connection_error_continues(self):
        import elasticsearch
        es = None
        params = None
        # ES client uses pseudo-status "N/A" in this case...
        runner = mock.Mock(side_effect=as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host", None)))

        ops, unit, request_meta_data = await driver.execute_single(
            self.context_managed(runner), es, params, on_error="continue")

        self.assertEqual(0, ops)
        self.assertEqual("ops", unit)
        self.assertEqual({
            # Look ma: No http-status!
            "error-description": "no route to host",
            "error-type": "transport",
            "success": False
        }, request_meta_data) 
开发者ID:elastic,项目名称:rally,代码行数:20,代码来源:driver_test.py

示例4: test_search_raise_StorageEngineError_when_ConnectionError

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_search_raise_StorageEngineError_when_ConnectionError(self,
                                                                  mock_es):
        self.mock_es.search.side_effect = elasticsearch.ConnectionError(
            'regular test failure')
        self.assertRaises(exceptions.StorageEngineError,
                          self.type_manager.search, project_id='tecs',
                          user_id='my_user_id', doc_id='mydocid') 
开发者ID:openstack,项目名称:freezer-api,代码行数:9,代码来源:test_elasticv2.py

示例5: test_search_raise_StorageEngineError_when_ConnectionError

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_search_raise_StorageEngineError_when_ConnectionError(self,
                                                                  mock_es):
        self.mock_es.search.side_effect = elasticsearch.ConnectionError(
            'regular test failure')
        self.assertRaises(exceptions.StorageEngineError,
                          self.type_manager.search,
                          user_id='my_user_id', doc_id='mydocid') 
开发者ID:openstack,项目名称:freezer-api,代码行数:9,代码来源:test_elastic.py

示例6: search

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def search(self, user_id, doc_id=None, search=None, offset=0, limit=10):
        search = search or {}
        query_dsl = self.get_search_query(user_id, doc_id, search)
        try:
            res = self.es.search(index=self.index, doc_type=self.doc_type,
                                 size=limit, from_=offset, body=query_dsl)
        except elasticsearch.ConnectionError:
            raise freezer_api_exc.StorageEngineError(
                message=_i18n._('unable to connect to db server'))
        except Exception as e:
            raise freezer_api_exc.StorageEngineError(
                message=_i18n._('search operation failed: %s') % e)
        hit_list = res['hits']['hits']
        return [x['_source'] for x in hit_list] 
开发者ID:openstack,项目名称:freezer-api,代码行数:16,代码来源:elastic.py

示例7: wait_for_rest_layer

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def wait_for_rest_layer(es, max_attempts=40):
    """
    Waits for ``max_attempts`` until Elasticsearch's REST API is available.

    :param es: Elasticsearch client to use for connecting.
    :param max_attempts: The maximum number of attempts to check whether the REST API is available.
    :return: True iff Elasticsearch's REST API is available.
    """
    # assume that at least the hosts that we expect to contact should be available. Note that this is not 100%
    # bullet-proof as a cluster could have e.g. dedicated masters which are not contained in our list of target hosts
    # but this is still better than just checking for any random node's REST API being reachable.
    expected_node_count = len(es.transport.hosts)
    logger = logging.getLogger(__name__)
    for attempt in range(max_attempts):
        logger.debug("REST API is available after %s attempts", attempt)
        import elasticsearch
        try:
            # see also WaitForHttpResource in Elasticsearch tests. Contrary to the ES tests we consider the API also
            # available when the cluster status is RED (as long as all required nodes are present)
            es.cluster.health(wait_for_nodes=">={}".format(expected_node_count))
            logger.info("REST API is available for >= [%s] nodes after [%s] attempts.", expected_node_count, attempt)
            return True
        except elasticsearch.ConnectionError as e:
            if "SSL: UNKNOWN_PROTOCOL" in str(e):
                raise exceptions.SystemSetupError("Could not connect to cluster via https. Is this an https endpoint?", e)
            else:
                logger.debug("Got connection error on attempt [%s]. Sleeping...", attempt)
                time.sleep(3)
        except elasticsearch.TransportError as e:
            # cluster block, x-pack not initialized yet, our wait condition is not reached
            if e.status_code in (503, 401, 408):
                logger.debug("Got status code [%s] on attempt [%s]. Sleeping...", e.status_code, attempt)
                time.sleep(3)
            else:
                logger.warning("Got unexpected status code [%s] on attempt [%s].", e.status_code, attempt)
                raise e
    return False 
开发者ID:elastic,项目名称:rally,代码行数:39,代码来源:client.py

示例8: test_ssl_error

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_ssl_error(self, es):
        import elasticsearch
        import urllib3.exceptions

        es.cluster.health.side_effect = elasticsearch.ConnectionError("N/A",
                                                            "[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)",
                                                            urllib3.exceptions.SSLError(
                                                                "[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:719)"))
        with self.assertRaisesRegex(expected_exception=exceptions.SystemSetupError,
                                    expected_regex="Could not connect to cluster via https. Is this an https endpoint?"):
            client.wait_for_rest_layer(es, max_attempts=3) 
开发者ID:elastic,项目名称:rally,代码行数:13,代码来源:client_test.py

示例9: test_execute_single_with_connection_error_aborts_as_fatal

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_execute_single_with_connection_error_aborts_as_fatal(self):
        import elasticsearch
        es = None
        params = None
        # ES client uses pseudo-status "N/A" in this case...
        runner = mock.Mock(side_effect=as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host", None)))

        with self.assertRaises(exceptions.RallyAssertionError) as ctx:
            await driver.execute_single(self.context_managed(runner), es, params, on_error="continue-on-non-fatal")
        self.assertEqual(
            "Request returned an error. Error type: transport, Description: no route to host",
            ctx.exception.args[0]) 
开发者ID:elastic,项目名称:rally,代码行数:14,代码来源:driver_test.py

示例10: test_retries_on_timeout_if_wanted_and_raises_if_no_recovery

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_retries_on_timeout_if_wanted_and_raises_if_no_recovery(self):
        import elasticsearch

        delegate = mock.Mock(side_effect=[
            as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host")),
            as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host")),
            as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host")),
            as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host"))
        ])
        es = None
        params = {
            "retries": 3,
            "retry-wait-period": 0.01,
            "retry-on-timeout": True,
            "retry-on-error": True
        }
        retrier = runner.Retry(delegate)

        with self.assertRaises(elasticsearch.ConnectionError):
            await retrier(es, params)

        delegate.assert_has_calls([
            mock.call(es, params),
            mock.call(es, params),
            mock.call(es, params)
        ]) 
开发者ID:elastic,项目名称:rally,代码行数:28,代码来源:runner_test.py

示例11: test_retries_on_timeout_if_wanted_and_returns_first_call

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_retries_on_timeout_if_wanted_and_returns_first_call(self):
        import elasticsearch
        failed_return_value = {"weight": 1, "unit": "ops", "success": False}

        delegate = mock.Mock(side_effect=[
            as_future(exception=elasticsearch.ConnectionError("N/A", "no route to host")),
            as_future(failed_return_value)
        ])
        es = None
        params = {
            "retries": 3,
            "retry-wait-period": 0.01,
            "retry-on-timeout": True,
            "retry-on-error": False
        }
        retrier = runner.Retry(delegate)

        result = await retrier(es, params)
        self.assertEqual(failed_return_value, result)

        delegate.assert_has_calls([
            # has returned a connection error
            mock.call(es, params),
            # has returned normally
            mock.call(es, params)
        ]) 
开发者ID:elastic,项目名称:rally,代码行数:28,代码来源:runner_test.py

示例12: test_retries_mixed_timeout_and_application_errors

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def test_retries_mixed_timeout_and_application_errors(self):
        import elasticsearch
        connection_error = elasticsearch.ConnectionError("N/A", "no route to host")
        failed_return_value = {"weight": 1, "unit": "ops", "success": False}
        success_return_value = {"weight": 1, "unit": "ops", "success": False}

        delegate = mock.Mock(side_effect=[
            as_future(exception=connection_error),
            as_future(failed_return_value),
            as_future(exception=connection_error),
            as_future(exception=connection_error),
            as_future(failed_return_value),
            as_future(success_return_value)
        ])
        es = None
        params = {
            # we try exactly as often as there are errors to also test the semantics of "retry".
            "retries": 5,
            "retry-wait-period": 0.01,
            "retry-on-timeout": True,
            "retry-on-error": True
        }
        retrier = runner.Retry(delegate)

        result = await retrier(es, params)
        self.assertEqual(success_return_value, result)

        delegate.assert_has_calls([
            # connection error
            mock.call(es, params),
            # application error
            mock.call(es, params),
            # connection error
            mock.call(es, params),
            # connection error
            mock.call(es, params),
            # application error
            mock.call(es, params),
            # success
            mock.call(es, params)
        ]) 
开发者ID:elastic,项目名称:rally,代码行数:43,代码来源:runner_test.py

示例13: init_elasticsearch

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def init_elasticsearch(uri):
    # init ElasticSearch
    es_conn = elasticsearch.Elasticsearch(uri)
    try:
        es_conn.info()
    except elasticsearch.ConnectionError:
        raise ElasticsearchConnectionError(uri)

    return es_conn 
开发者ID:MentatInnovations,项目名称:datastream.io,代码行数:11,代码来源:elastic.py

示例14: wait_until_up

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def wait_until_up(self):
        for i in xrange(1024):
            try:
                ret = self.client.cluster.health(wait_for_status='green', request_timeout=15 * 60)
                if ret.get('status') == 'green':
                    break
                sleep(10)
            except ConnectionError:
                pass 
开发者ID:StamusNetworks,项目名称:scirius,代码行数:11,代码来源:es_data.py

示例15: main_loop

# 需要导入模块: import elasticsearch [as 别名]
# 或者: from elasticsearch import ConnectionError [as 别名]
def main_loop(self, method, url, params, body, headers=None, ignore=(), timeout=None):
        for attempt in range(self.max_retries + 1):
            connection = self.get_connection()

            try:
                status, headers, data = yield from connection.perform_request(
                        method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
            except TransportError as e:
                if method == 'HEAD' and e.status_code == 404:
                    return False

                retry = False
                if isinstance(e, ConnectionTimeout):
                    retry = self.retry_on_timeout
                elif isinstance(e, ConnectionError):
                    retry = True
                elif e.status_code in self.retry_on_status:
                    retry = True

                if retry:
                    # only mark as dead if we are retrying
                    self.mark_dead(connection)
                    # raise exception on last retry
                    if attempt == self.max_retries:
                        raise
                else:
                    raise

            else:
                if method == 'HEAD':
                    return 200 <= status < 300

                # connection didn't fail, confirm it's live status
                self.connection_pool.mark_live(connection)
                if data:
                    data = self.deserializer.loads(data, headers.get('content-type'))
                return data 
开发者ID:elastic,项目名称:elasticsearch-py-async,代码行数:39,代码来源:transport.py


注:本文中的elasticsearch.ConnectionError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。