How to use the kazoo.exceptions.KazooException function in kazoo

To help you get started, we’ve selected a few kazoo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / taskflow / taskflow / persistence / backends / impl_zookeeper.py View on Github external
"""
        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")
github apache / incubator-retired-slider / slider-agent / src / main / python / kazoo / recipe / watchers.py View on Github external
def __call__(self, func):
        """Callable version for use as a decorator

        :param func: Function to call initially and every time the
                     data changes. `func` will be called with a
                     tuple, the value of the node and a
                     :class:`~kazoo.client.ZnodeStat` instance.
        :type func: callable

        """
        if self._used:
            raise KazooException(
                "A function has already been associated with this "
                "DataWatch instance.")

        self._func = func

        self._used = True
        self._client.add_listener(self._session_watcher)
        self._get_data()
        return func
github istresearch / scrapy-cluster / utils / scutils / zookeeper_watcher.py View on Github external
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
github twitter-archive / commons / src / python / twitter / common / zookeeper / group / kazoo_group.py View on Github external
def exists_completion(result):
      try:
        stat = result.get()
      except self.DISCONNECT_EXCEPTIONS:
        self._once(KazooState.CONNECTED, wait_exists)
        return
      except ke.NoNodeError:
        wait_exists()
        return
      except ke.KazooException as e:
        log.warning('Unexpected exists_completion result: (%s)%s' % (type(e), e))
        return

      if stat:
        do_monitor()
github Morgan-Stanley / treadmill / lib / python / treadmill / zkwatchers.py View on Github external
def __call__(self, func):
        """Callable version for use as a decorator"""
        if self._used:
            raise kazoo.exceptions.KazooException(
                'A function has already been associated with this '
                'ExistingDataWatch instance.')

        self._func = func

        self._used = True
        self._client.add_listener(self._session_watcher)
        self._get_data()
        return func
github python-zk / kazoo / kazoo / exceptions.py View on Github external
"""Kazoo Exceptions"""
from collections import defaultdict


class KazooException(Exception):
    """Base Kazoo exception that all other kazoo library exceptions
    inherit from"""


class ZookeeperError(KazooException):
    """Base Zookeeper exception for errors originating from the
    Zookeeper server"""


class CancelledError(KazooException):
    """Raised when a process is cancelled by another thread"""


class ConfigurationError(KazooException):
    """Raised if the configuration arguments to an object are
    invalid"""


class ZookeeperStoppedError(KazooException):
    """Raised when the kazoo client stopped (and thus not connected)"""


class ConnectionDropped(KazooException):
    """Internal error for jumping out of loops"""
github AppScale / appscale / APIServer / appscale / api_server / app_identity.py View on Github external
pass
            else:
                valid_certs.append(cert)

        if valid_certs:
            return valid_certs

        # If there are no valid certificates, try to generate a a new one.
        if self._key is None:
            raise UnknownError('A private key is not configured')

        new_cert = PublicCertificate.from_key(self._key, self.project_id)
        try:
            self._zk_client.create('{}/cert'.format(self._certs_node),
                                   new_cert.to_json(), sequence=True)
        except KazooException:
            raise UnknownError('Unable to create new certificate')

        return [new_cert]
github python-zk / kazoo / kazoo / exceptions.py View on Github external
class ZookeeperStoppedError(KazooException):
    """Raised when the kazoo client stopped (and thus not connected)"""


class ConnectionDropped(KazooException):
    """Internal error for jumping out of loops"""


class LockTimeout(KazooException):
    """Raised if failed to acquire a lock.

    .. versionadded:: 1.1
    """


class WriterNotClosedException(KazooException):
    """Raised if the writer is unable to stop closing when requested.

    .. versionadded:: 1.2
    """


class SASLException(KazooException):
    """Raised if SASL encountered a (local) error.

    .. versionadded:: 2.7.0
    """


def _invalid_error_code():
    raise RuntimeError('Invalid error code')
github AppScale / appscale / AppDB / appscale / datastore / zkappscale / entity_lock.py View on Github external
def _best_effort_cleanup(self):
    """ Attempt to delete nodes that this lock has created. """
    try:
      nodes = self._find_nodes()
      self._delete_nodes(nodes)
    except KazooException:
      pass
github apache / incubator-retired-slider / slider-agent / src / main / python / kazoo / recipe / partitioner.py View on Github external
def _release_locks(self):
        """Attempt to completely remove all the locks"""
        self._acquire_event.clear()
        for lock in self._locks[:]:
            try:
                lock.release()
            except KazooException:  # pragma: nocover
                # We proceed to remove as many as possible, and leave
                # the ones we couldn't remove
                pass
            else:
                self._locks.remove(lock)