當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。