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


Python exceptions.KazooException方法代码示例

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


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

示例1: _exc_wrapper

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def _exc_wrapper(self):
        """Exception context-manager which wraps kazoo exceptions.

        This is used to capture and wrap any kazoo specific exceptions and
        then group them into corresponding taskflow exceptions (not doing
        that would expose the underlying kazoo exception model).
        """
        try:
            yield
        except self._client.handler.timeout_exception:
            exc.raise_with_cause(exc.StorageFailure,
                                 "Storage backend timeout")
        except k_exc.SessionExpiredError:
            exc.raise_with_cause(exc.StorageFailure,
                                 "Storage backend session has expired")
        except k_exc.NoNodeError:
            exc.raise_with_cause(exc.NotFound,
                                 "Storage backend node not found")
        except k_exc.NodeExistsError:
            exc.raise_with_cause(exc.Duplicate,
                                 "Storage backend duplicate node")
        except (k_exc.KazooException, k_exc.ZookeeperError):
            exc.raise_with_cause(exc.StorageFailure,
                                 "Storage backend internal error") 
开发者ID:openstack,项目名称:taskflow,代码行数:26,代码来源:impl_zookeeper.py

示例2: _wrap

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def _wrap(self, job_uuid, job_path,
              fail_msg_tpl="Failure: %s", ensure_known=True):
        if job_path:
            fail_msg_tpl += " (%s)" % (job_path)
        if ensure_known:
            if not job_path:
                raise ValueError("Unable to check if %r is a known path"
                                 % (job_path))
            if job_path not in self._known_jobs:
                fail_msg_tpl += ", unknown job"
                raise excp.NotFound(fail_msg_tpl % (job_uuid))
        try:
            yield
        except self._client.handler.timeout_exception:
            fail_msg_tpl += ", operation timed out"
            excp.raise_with_cause(excp.JobFailure, fail_msg_tpl % (job_uuid))
        except k_exceptions.SessionExpiredError:
            fail_msg_tpl += ", session expired"
            excp.raise_with_cause(excp.JobFailure, fail_msg_tpl % (job_uuid))
        except k_exceptions.NoNodeError:
            fail_msg_tpl += ", unknown job"
            excp.raise_with_cause(excp.NotFound, fail_msg_tpl % (job_uuid))
        except k_exceptions.KazooException:
            fail_msg_tpl += ", internal error"
            excp.raise_with_cause(excp.JobFailure, fail_msg_tpl % (job_uuid)) 
开发者ID:openstack,项目名称:taskflow,代码行数:27,代码来源:impl_zookeeper.py

示例3: ping

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def ping(self):
        '''
        Simple command to test if the zookeeper session is able to connect
        at this very moment
        '''
        try:
            # dummy ping to ensure we are still connected
            self.zoo_client.server_version()
            return True
        except KazooException:
            return False 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:13,代码来源:zookeeper_watcher.py

示例4: test_ping

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def test_ping(self):
        self.zoo_watcher.zoo_client.server_version = MagicMock()
        self.assertTrue(self.zoo_watcher.ping())
        self.zoo_watcher.zoo_client.server_version = MagicMock(side_effect=KazooException)
        self.assertFalse(self.zoo_watcher.ping()) 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:7,代码来源:test_zookeeper_watcher.py

示例5: close_zk

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def close_zk(zk):
    if not isinstance(zk, KazooClient):
        raise TypeError('expect KazooClient or KazooClientExt, but got {t}'.format(t=type(zk)))

    try:
        zk.stop()

    except KazooException as e:
        logger.exception(repr(e) + ' while stop zk client')

    try:
        zk.close()

    except Exception as e:
        logger.exception(repr(e) + ' while close zk client') 
开发者ID:bsc-s2,项目名称:pykit,代码行数:17,代码来源:zkutil.py

示例6: set_topic_retention

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def set_topic_retention(topic, zk):
    try:
        zdata, zstat = zk.get("/config/topics/{0}".format(topic.name))
        tdata = json_loads(zdata)
        topic.retention = int(tdata['config']['retention.ms'])
    except (KeyError, ValueError, KazooException):
        # If we can't get the config override for any reason, just stick with whatever the default is
        pass 
开发者ID:linkedin,项目名称:kafka-tools,代码行数:10,代码来源:cluster.py

示例7: dump_scheduler_state

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def dump_scheduler_state(self, state):
    if not isinstance(state, Scheduler):
      raise TypeError("'state' should be an instance of Scheduler")

    path = self._get_scheduler_state_path()
    self._client.retry(self._client.ensure_path, posixpath.dirname(path))

    content = cPickle.dumps(state)
    try:
      self._client.retry(self._create_or_set, path, content)
    except KazooException as e:
      raise self.Error('Failed to persist Scheduler: %s' % e) 
开发者ID:apache,项目名称:incubator-retired-cotton,代码行数:14,代码来源:zk_state.py

示例8: load_scheduler_state

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def load_scheduler_state(self):
    path = self._get_scheduler_state_path()

    try:
      content = self._client.get(path)[0]
      state = cPickle.loads(content)
      if not isinstance(state, Scheduler):
        raise self.Error("Invalid state object. Expect Scheduler, got %s" % type(state))
      return state
    except NoNodeError:
      log.info('No scheduler state found on path %s' % path)
      return None
    except (KazooException, PickleError, ValueError) as e:
      raise self.Error('Failed to recover Scheduler: %s' % e) 
开发者ID:apache,项目名称:incubator-retired-cotton,代码行数:16,代码来源:zk_state.py

示例9: load_cluster_state

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def load_cluster_state(self, cluster_name):
    path = self._get_cluster_state_path(cluster_name)

    try:
      content = self._client.get(path)[0]
      state = cPickle.loads(content)
      if not isinstance(state, MySQLCluster):
        raise self.Error("Invalid state object. Expect MySQLCluster, got %s" % type(state))
      return state
    except NoNodeError:
      log.info('No cluster state found on path %s' % path)
      return None
    except (KazooException, PickleError, ValueError) as e:
      raise self.Error('Failed to recover MySQLCluster: %s' % e) 
开发者ID:apache,项目名称:incubator-retired-cotton,代码行数:16,代码来源:zk_state.py

示例10: remove_cluster_state

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def remove_cluster_state(self, cluster_name):
    path = self._get_cluster_state_path(cluster_name)
    try:
      self._client.retry(self._client.delete, path, recursive=True)
    except KazooException as e:
      raise self.Error("Failed to remove MySQLCluster: %s" % e)

  # --- Helper methods. --- 
开发者ID:apache,项目名称:incubator-retired-cotton,代码行数:10,代码来源:zk_state.py

示例11: checked_commit

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def checked_commit(txn):
    """Commits a kazoo transcation and validates the result.

    NOTE(harlowja): Until https://github.com/python-zk/kazoo/pull/224 is fixed
    or a similar pull request is merged we have to workaround the transaction
    failing silently.
    """
    if not txn.operations:
        return []
    results = txn.commit()
    failures = []
    for op, result in compat_zip(txn.operations, results):
        if isinstance(result, k_exc.KazooException):
            failures.append((op, result))
    if len(results) < len(txn.operations):
        raise KazooTransactionException(
            "Transaction returned %s results, this is less than"
            " the number of expected transaction operations %s"
            % (len(results), len(txn.operations)), failures)
    if len(results) > len(txn.operations):
        raise KazooTransactionException(
            "Transaction returned %s results, this is greater than"
            " the number of expected transaction operations %s"
            % (len(results), len(txn.operations)), failures)
    if failures:
        raise KazooTransactionException(
            "Transaction with %s operations failed: %s"
            % (len(txn.operations),
               prettify_failures(failures, limit=1)), failures)
    return results 
开发者ID:openstack,项目名称:taskflow,代码行数:32,代码来源:kazoo_utils.py

示例12: close

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def close(self):
        self._validated = False
        if not self._owned:
            return
        try:
            k_utils.finalize_client(self._client)
        except (k_exc.KazooException, k_exc.ZookeeperError):
            exc.raise_with_cause(exc.StorageFailure,
                                 "Unable to finalize client") 
开发者ID:openstack,项目名称:taskflow,代码行数:11,代码来源:impl_zookeeper.py

示例13: _get_node_attr

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def _get_node_attr(self, path, attr_name, trans_func=None):
        try:
            _data, node_stat = self._client.get(path)
            attr = getattr(node_stat, attr_name)
            if trans_func is not None:
                return trans_func(attr)
            else:
                return attr
        except k_exceptions.NoNodeError:
            excp.raise_with_cause(
                excp.NotFound,
                "Can not fetch the %r attribute of job %s (%s),"
                " path %s not found" % (attr_name, self.uuid,
                                        self.path, path))
        except self._client.handler.timeout_exception:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the %r attribute of job %s (%s),"
                " operation timed out" % (attr_name, self.uuid, self.path))
        except k_exceptions.SessionExpiredError:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the %r attribute of job %s (%s),"
                " session expired" % (attr_name, self.uuid, self.path))
        except (AttributeError, k_exceptions.KazooException):
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the %r attribute of job %s (%s),"
                " internal error" % (attr_name, self.uuid, self.path)) 
开发者ID:openstack,项目名称:taskflow,代码行数:31,代码来源:impl_zookeeper.py

示例14: state

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def state(self):
        owner = self.board.find_owner(self)
        job_data = {}
        try:
            raw_data, _data_stat = self._client.get(self.path)
            job_data = misc.decode_json(raw_data)
        except k_exceptions.NoNodeError:
            pass
        except k_exceptions.SessionExpiredError:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " session expired" % (self.uuid))
        except self._client.handler.timeout_exception:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " operation timed out" % (self.uuid))
        except k_exceptions.KazooException:
            excp.raise_with_cause(
                excp.JobFailure,
                "Can not fetch the state of %s,"
                " internal error" % (self.uuid))
        if not job_data:
            # No data this job has been completed (the owner that we might have
            # fetched will not be able to be fetched again, since the job node
            # is a parent node of the owner/lock node).
            return states.COMPLETE
        if not owner:
            # No owner, but data, still work to be done.
            return states.UNCLAIMED
        return states.CLAIMED 
开发者ID:openstack,项目名称:taskflow,代码行数:34,代码来源:impl_zookeeper.py

示例15: register_entity

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import KazooException [as 别名]
def register_entity(self, entity):
        entity_type = entity.kind
        if entity_type == c_base.Conductor.ENTITY_KIND:
            entity_path = k_paths.join(self.entity_path, entity_type)
            try:
                self._client.ensure_path(entity_path)
                self._client.create(k_paths.join(entity_path, entity.name),
                                    value=misc.binary_encode(
                                        jsonutils.dumps(entity.to_dict())),
                                    ephemeral=True)
            except k_exceptions.NodeExistsError:
                pass
            except self._client.handler.timeout_exception:
                excp.raise_with_cause(
                    excp.JobFailure,
                    "Can not register entity %s under %s, operation"
                    " timed out" % (entity.name, entity_path))
            except k_exceptions.SessionExpiredError:
                excp.raise_with_cause(
                    excp.JobFailure,
                    "Can not register entity %s under %s, session"
                    " expired" % (entity.name, entity_path))
            except k_exceptions.KazooException:
                excp.raise_with_cause(
                    excp.JobFailure,
                    "Can not register entity %s under %s, internal"
                    " error" % (entity.name, entity_path))
        else:
            raise excp.NotImplementedError(
                "Not implemented for other entity type '%s'" % entity_type) 
开发者ID:openstack,项目名称:taskflow,代码行数:32,代码来源:impl_zookeeper.py


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