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


Python exceptions.TransportError方法代码示例

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


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

示例1: __init__

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def __init__(
        self, hosts=None, index="metrics", doc_type="metric", index_pattern="{index}-{date:%Y.%m.%d}", *args, **kwargs
    ):
        # Assign these in the backend as they are needed when writing metrics
        # to elasticsearch
        self.index = index
        self.doc_type = doc_type
        self.index_pattern = index_pattern

        # setup the client
        self.client = Elasticsearch(hosts=hosts, *args, **kwargs)

        # ensure the index is created
        try:
            self._setup_index()
        except TransportError as exc:
            logger.error('index setup error %r', exc)
        try:
            self._setup_mapping()
        except TransportError as exc:
            logger.error('mapping setup error %r', exc) 
开发者ID:kpn-digital,项目名称:py-timeexecution,代码行数:23,代码来源:elasticsearch.py

示例2: write

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def write(self, name, **data):
        """
        Write the metric to elasticsearch

        Args:
            name (str): The name of the metric to write
            data (dict): Additional data to store with the metric
        """

        data["name"] = name
        if not ("timestamp" in data):
            data["timestamp"] = datetime.utcnow()

        try:
            self.client.index(index=self.get_index(), doc_type=self.doc_type, id=None, body=data)
        except TransportError as exc:
            logger.warning('writing metric %r failure %r', data, exc) 
开发者ID:kpn-digital,项目名称:py-timeexecution,代码行数:19,代码来源:elasticsearch.py

示例3: bulk_write

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def bulk_write(self, metrics):
        """
        Write multiple metrics to elasticsearch in one request

        Args:
            metrics (list): data with mappings to send to elasticsearch
        """
        actions = []
        index = self.get_index()
        for metric in metrics:
            actions.append({'index': {'_index': index, '_type': self.doc_type}})
            actions.append(metric)
        try:
            self.client.bulk(actions)
        except TransportError as exc:
            logger.warning('bulk_write metrics %r failure %r', metrics, exc) 
开发者ID:kpn-digital,项目名称:py-timeexecution,代码行数:18,代码来源:elasticsearch.py

示例4: do_index_command

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def do_index_command(self, index: str, **options: Any) -> CommandReturnType:
        """Rebuild search index."""
        if options["interactive"]:
            logger.warning("This will permanently delete the index '%s'.", index)
            if not self._confirm_action():
                logger.warning(
                    "Aborting rebuild of index '%s' at user's request.", index
                )
                return None

        try:
            delete = delete_index(index)
        except TransportError:
            delete = {}
            logger.info("Index %s does not exist, cannot be deleted.", index)
        create = create_index(index)
        update = update_index(index)

        return {"delete": delete, "create": create, "update": update} 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:21,代码来源:rebuild_search_index.py

示例5: test_rebuild_search_index

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def test_rebuild_search_index(self, mock_update, mock_create, mock_delete):
        """Test the rebuild_search_index command."""
        cmd = rebuild_search_index.Command()
        result = cmd.do_index_command(
            "foo", interactive=False
        )  # True would hang the tests
        mock_delete.assert_called_once_with("foo")
        mock_create.assert_called_once_with("foo")
        mock_update.assert_called_once_with("foo")
        self.assertEqual(result["delete"], mock_delete.return_value)
        self.assertEqual(result["create"], mock_create.return_value)
        self.assertEqual(result["update"], mock_update.return_value)
        # check that the delete is handled if the index does not exist
        mock_delete.side_effect = TransportError("Index not found")
        result = cmd.do_index_command(
            "foo", interactive=False
        )  # True would hang the tests
        self.assertEqual(result["delete"], {}) 
开发者ID:yunojuno,项目名称:elasticsearch-django,代码行数:20,代码来源:test_commands.py

示例6: add_viewset

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def add_viewset(table):
    data_index = table.name
    record_data_index = "{}.".format(table.name)
    deleted_data_index = "{}..".format(table.name)

    def retrieve(self, request, *args, **kwargs):
        try:
            res = es.search(index=record_data_index, doc_type="record-data", body={"query": {"term": {"S-data-id": kwargs["pk"]}}}, sort="S-update-time:desc")
        except NotFoundError as exc:
            raise exceptions.NotFound("Document {} was not found in Type data of Index {}".format(kwargs["pk"], record_data_index))
        except TransportError as exc:
            return Response([])
        return Response(res["hits"])
    viewset = type(table.name, (mixins.RetrieveModelMixin, viewsets.GenericViewSet), dict(
        permission_classes=(permissions.IsAuthenticated, ), retrieve=retrieve))
    setattr(views, table.name, viewset)
    return viewset 
开发者ID:open-cmdb,项目名称:cmdb,代码行数:19,代码来源:initialize.py

示例7: add_transaction

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def add_transaction(self, tx):
        temp = {    '_type': 'doc',
                    '_op_type': 'update',
                    '_index': "btc-opreturn",
                    '_id': "%s-%s" % (tx['tx'], tx['n']),
                    'doc_as_upsert': True,
                    'doc': tx
                }

        self.transactions.append(temp)

        if len(self.transactions) > 200:
            try:
                self.es_handle.add_bulk_tx(self)
            except TransportError:
                import pdb; pdb.set_trace
            self.transactions = []
            self.current = -1 
开发者ID:joshbressers,项目名称:blockchain-elasticsearch,代码行数:20,代码来源:esbtc.py

示例8: execute

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def execute(self, ignore_cache=False, raise_on_error=True):
        """
        Execute the multi search request and return a list of search results.
        """
        if ignore_cache or not hasattr(self, '_response'):
            es = connections.get_connection(self._using)

            responses = es.msearch(
                index=self._index,
                body=self.to_dict(),
                **self._params
            )

            out = []
            for s, r in zip(self._searches, responses['responses']):
                if r.get('error', False):
                    if raise_on_error:
                        raise TransportError('N/A', r['error']['type'], r['error'])
                    r = None
                else:
                    r = Response(s, r)
                out.append(r)

            self._response = out

        return self._response 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:28,代码来源:search.py

示例9: take_snapshot

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def take_snapshot(options):
    esm = ElasticsearchSnapshotManager(options)
    sh = esm.sh

    snapshot = options.snapshot and options.snapshot or 'all_' + time.strftime('%Y%m%d%H')

    snapdef = {
        "include_global_state": True
    }

    if options.indices:
        snapdef['indices'] = ','.join(options.indices)

    try:
        sh.create(repository=options.repository, snapshot=snapshot, body=json.dumps(snapdef), wait_for_completion=options.wait, request_timeout=7200)

        # Housekeeping - delete old snapshots
        snapshots = sh.get(repository=options.repository, snapshot="_all", request_timeout=120)['snapshots']
        num_snaps = len(snapshots)
        if num_snaps > options.keep:
            up_to = num_snaps - options.keep
            logger.info('TOTAL: %d - Will delete 1 -> %d' % (num_snaps, up_to + 1))
            for snap in snapshots[0:up_to]:
                sh.delete(repository=options.repository, snapshot=snap['snapshot'], request_timeout=3600)
                logger.info('Deleted snapshot %s' % snap['snapshot'])
    except exceptions.TransportError as e:
        pass 
开发者ID:DomainGroupOSS,项目名称:elasticsearch-snapshots,代码行数:29,代码来源:es_backup.py

示例10: test_perform_request_exception

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def test_perform_request_exception(self):
        conn = es.ESHttpConnection()
        conn.pool = Mock()
        conn.pool.urlopen.side_effect = TransportError('N/A', '')
        with pytest.raises(JHTTPBadRequest):
            conn.perform_request('POST', 'http://localhost:9200') 
开发者ID:ramses-tech,项目名称:nefertari,代码行数:8,代码来源:test_elasticsearch.py

示例11: test_perform_request_no_index

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def test_perform_request_no_index(self, mock_log):
        mock_log.level = logging.DEBUG
        mock_log.debug.side_effect = TransportError(
            404, 'IndexMissingException')
        conn = es.ESHttpConnection()
        with pytest.raises(es.IndexNotFoundException):
            conn.perform_request('POST', 'http://localhost:9200') 
开发者ID:ramses-tech,项目名称:nefertari,代码行数:9,代码来源:test_elasticsearch.py

示例12: es_version

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def es_version(self):
        """
        Returns the reported version from the Elasticsearch server.
        """
        if self._es_version is None:
            for retry in range(3):
                try:
                    self._es_version = self.info()['version']['number']
                    break
                except TransportError:
                    if retry == 2:
                        raise
                    time.sleep(3)
        return self._es_version 
开发者ID:Yelp,项目名称:elastalert,代码行数:16,代码来源:__init__.py

示例13: create_new_index

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def create_new_index(group):
    """Create a new index for a specific Resource Type Group. Upon
       exit of this method, the index is still not ready to be used.
       The index still needs to have the settings/mappings set for
       each plugin (Document Type).
    """
    es_engine = searchlight.elasticsearch.get_api()

    kwargs = {}
    index_settings = _get_index_settings_from_config()
    if index_settings:
        kwargs = {'body': {'index': index_settings}}

    index_name = None
    while not index_name:
        # Use utcnow() to ensure that the name is unique.
        now = oslo_utils.timeutils.utcnow()
        index_name = (group + '-' + now.strftime(FORMAT))
        try:
            es_engine.indices.create(index=index_name, **kwargs)
        except es_exc.TransportError as e:
            if (e.error.startswith("IndexAlreadyExistsException") or
                    e.error.startswith("index_already_exists_exception")):
                # This index already exists! Try again.
                index_name = None
            else:
                raise

    return index_name 
开发者ID:openstack,项目名称:searchlight,代码行数:31,代码来源:utils.py

示例14: test_error_warning

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def test_error_warning(self, mocked_logger):

        transport_error = TransportError('mocked error')
        es_index_error_ctx = mock.patch(
            'time_execution.backends.elasticsearch.Elasticsearch.index', side_effect=transport_error
        )
        frozen_time_ctx = freeze_time('2016-07-13')

        with es_index_error_ctx, frozen_time_ctx:
            self.backend.write(name='test:metric', value=None)
            mocked_logger.warning.assert_called_once_with(
                'writing metric %r failure %r',
                {'timestamp': datetime(2016, 7, 13), 'value': None, 'name': 'test:metric'},
                transport_error,
            ) 
开发者ID:kpn-digital,项目名称:py-timeexecution,代码行数:17,代码来源:test_elasticsearch.py

示例15: test_bulk_write_error

# 需要导入模块: from elasticsearch import exceptions [as 别名]
# 或者: from elasticsearch.exceptions import TransportError [as 别名]
def test_bulk_write_error(self, mocked_logger):
        transport_error = TransportError('mocked error')
        es_index_error_ctx = mock.patch(
            'time_execution.backends.elasticsearch.Elasticsearch.bulk', side_effect=transport_error
        )
        metrics = [1, 2, 3]
        with es_index_error_ctx:
            self.backend.bulk_write(metrics)
            mocked_logger.warning.assert_called_once_with('bulk_write metrics %r failure %r', metrics, transport_error) 
开发者ID:kpn-digital,项目名称:py-timeexecution,代码行数:11,代码来源:test_elasticsearch.py


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