Ejemplo n.º 1
0
 def _get_groups_handler(async_result, timeout):
     try:
         group_ids = async_result.get(block=True, timeout=timeout)
     except exceptions.NoNodeError:
         raise coordination.ToozError("tooz namespace has not been created")
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
     else:
         return set(g.encode('ascii') for g in group_ids)
Ejemplo n.º 2
0
 def _create_group_handler(async_result, timeout, group_id):
     try:
         async_result.get(block=True, timeout=timeout)
     except exceptions.NodeExistsError:
         raise coordination.GroupAlreadyExist(group_id)
     except exceptions.NoNodeError:
         raise coordination.ToozError("tooz namespace has not been created")
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
Ejemplo n.º 3
0
 def submit(self, cb, *args, **kwargs):
     if not self.started:
         raise coordination.ToozError("%s driver asynchronous executor"
                                      " has not been started" %
                                      self.driver_name)
     try:
         return self.executor.submit(cb, *args, **kwargs)
     except RuntimeError:
         raise coordination.ToozError("%s driver asynchronous executor has"
                                      " been shutdown" % self.driver_name)
Ejemplo n.º 4
0
 def _leave_group_handler(async_result, timeout, group_id, member_id):
     try:
         async_result.get(block=True, timeout=timeout)
     except exceptions.NoNodeError:
         raise coordination.MemberNotJoined(group_id, member_id)
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
Ejemplo n.º 5
0
 def _join_group_handler(async_result, timeout, group_id, member_id):
     try:
         async_result.get(block=True, timeout=timeout)
     except exceptions.NodeExistsError:
         raise coordination.MemberAlreadyExist(group_id, member_id)
     except exceptions.NoNodeError:
         raise coordination.GroupNotCreated(group_id)
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
Ejemplo n.º 6
0
 def _get_members_handler(async_result, timeout, group_id):
     try:
         members_ids = async_result.get(block=True, timeout=timeout)
     except exceptions.NoNodeError:
         raise coordination.GroupNotCreated(group_id)
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
     else:
         return set(m.encode('ascii') for m in members_ids)
Ejemplo n.º 7
0
 def _get_member_capabilities_handler(async_result, timeout, group_id,
                                      member_id):
     try:
         capabilities = async_result.get(block=True, timeout=timeout)[0]
     except exceptions.NoNodeError:
         raise coordination.MemberNotJoined(group_id, member_id)
     except exceptions.ZookeeperError as e:
         raise coordination.ToozError(str(e))
     else:
         return capabilities
Ejemplo n.º 8
0
 def _delete_group(script):
     keys = [
         self._encode_group_id(group_id),
         self._groups,
     ]
     args = [
         self._encode_group_id(group_id, apply_namespace=False),
     ]
     result = int(script(keys=keys, args=args))
     if result in (-1, -2):
         raise coordination.GroupNotCreated(group_id)
     if result == -3:
         raise coordination.GroupNotEmpty(group_id)
     if result == -4:
         raise coordination.ToozError("Unable to remove '%s' key"
                                      " from set located at '%s'" %
                                      (args[0], keys[-1]))
     if result != 1:
         raise coordination.ToozError(
             "Internal error, unable"
             " to complete group '%s' removal" % (group_id))
Ejemplo n.º 9
0
 def build(cls, driver_name, options):
     default_executor_fact = cls.KIND_TO_FACTORY[cls.DEFAULT_KIND]
     if 'executor' in options:
         executor_kind = options['executor']
         try:
             default_executor_fact = cls.KIND_TO_FACTORY[executor_kind]
         except KeyError:
             executors_known = sorted(list(cls.KIND_TO_FACTORY))
             raise coordination.ToozError("Unknown executor"
                                          " '%s' provided, accepted values"
                                          " are %s" %
                                          (executor_kind, executors_known))
     return cls(driver_name, default_executor_fact)
Ejemplo n.º 10
0
    def start(self):
        try:
            self._coord.start(timeout=self.timeout)
        except self._coord.handler.timeout_exception as e:
            raise coordination.ToozConnectionError("operation error: %s" % (e))

        try:
            self._coord.ensure_path(self.paths_join("/", self._TOOZ_NAMESPACE))
        except exceptions.KazooException as e:
            raise coordination.ToozError("operation error: %s" % (e))

        self._group_members = collections.defaultdict(set)
        self._watchers = six.moves.queue.Queue()
        self._leader_locks = {}
Ejemplo n.º 11
0
Archivo: ipc.py Proyecto: csfreak/tooz
 def _write_group_list(self, group_list):
     data = msgpack.dumps(list(group_list))
     if len(data) >= self._SEGMENT_SIZE - 2:
         raise coordination.ToozError("Group list is too big")
     self._group_list.write(struct.pack('H', len(data)))
     self._group_list.write(data, offset=2)
Ejemplo n.º 12
0
 def _get_script(self, script_key):
     try:
         return self._scripts[script_key]
     except KeyError:
         raise coordination.ToozError("Redis driver has not been started")
Ejemplo n.º 13
0
 def _submit(self, cb, *args, **kwargs):
     if not self._started:
         raise coordination.ToozError("Redis driver has not been started")
     return self._executor.submit(cb, *args, **kwargs)