def submit(self, cb, *args, **kwargs): if not self.started: raise tooz.ToozError("%s driver asynchronous executor" " has not been started" % self.driver_name) try: return self.executor.submit(cb, *args, **kwargs) except RuntimeError: raise tooz.ToozError("%s driver asynchronous executor has" " been shutdown" % self.driver_name)
def stop(self): """Stop the service engine. If needed, the connection to servers is closed and the client will disappear from all joined groups. """ if not self._started: raise tooz.ToozError( "Can not stop a driver which has not been started") if self.heart.is_alive(): self.heart.stop() self.heart.wait() # Some of the drivers modify joined_groups when being called to leave # so clone it so that we aren't modifying something while iterating. joined_groups = self._joined_groups.copy() leaving = [self.leave_group(group) for group in joined_groups] for fut in leaving: try: fut.get() except tooz.ToozError: # Whatever happens, ignore. Maybe we got booted out/never # existed in the first place, or something is down, but we just # want to call _stop after whatever happens to not leak any # connection. pass self._stop() self._started = False
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 tooz.ToozError("Unable to remove '%s' key" " from set located at '%s'" % (args[0], keys[-1])) if result != 1: raise tooz.ToozError("Internal error, unable" " to complete group '%s' removal" % (group_id))
def test_init_host_with_coordinator_failed(self, mock_endpoint, mock_get_coord, mock_del_host): CONF.set_override('standalone', False) mock_get_coord.side_effect = (tooz.ToozError('Reaching coordination ' 'backend failed.'), None) self.assertRaises(tooz.ToozError, self.manager.init_host) self.mock_db_init.assert_called_once_with() self.mock_validate_processing_hooks.assert_not_called() self.mock_filter.init_filter.assert_not_called() self.assertIsNone(self.manager._periodics_worker) mock_get_coord.assert_called_once_with(prefix='conductor') mock_del_host.assert_called_once_with(self.manager)
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 tooz.ToozError("Unknown executor" " '%s' provided, accepted values" " are %s" % (executor_kind, executors_known)) return cls(driver_name, default_executor_fact)
def start(self, start_heart=False): """Start the service engine. If needed, the establishment of a connection to the servers is initiated. """ if self._started: raise tooz.ToozError( "Can not start a driver which has not been stopped") self._start() if self.requires_beating and start_heart: self.heart.start() self._started = True # Tracks which group are joined self._joined_groups = set()
def _do_delete_group(): try: entries = os.listdir(group_dir) except EnvironmentError as e: if e.errno == errno.ENOENT: raise coordination.GroupNotCreated(group_id) else: raise else: if len(entries) > 1: raise coordination.GroupNotEmpty(group_id) elif len(entries) == 1 and entries != ['.metadata']: raise tooz.ToozError( "Unexpected path '%s' found in" " group directory '%s' (expected to only find" " a '.metadata' path)" % (entries[0], group_dir)) else: try: shutil.rmtree(group_dir) except EnvironmentError as e: if e.errno != errno.ENOENT: raise
def _get_script(self, script_key): try: return self._scripts[script_key] except KeyError: raise tooz.ToozError("Redis driver has not been started")
def _submit(self, cb, *args, **kwargs): if not self._started: raise tooz.ToozError("Redis driver has not been started") return self._executor.submit(cb, *args, **kwargs)
def _write_group_list(self, group_list): data = msgpack.dumps(list(group_list)) if len(data) >= self._SEGMENT_SIZE - 2: raise tooz.ToozError("Group list is too big") self._group_list.write(struct.pack('H', len(data))) self._group_list.write(data, offset=2)