def load_storage_driver(conf, cache, storage_type=None, control_mode=False): """Loads a storage driver and returns it. The driver's initializer will be passed conf and cache as its positional args. :param conf: Configuration instance to use for loading the driver. Must include a 'drivers' group. :param cache: Cache instance that the driver can (optionally) use to reduce latency for some operations. :param storage_type: The storage_type to load. If None, then the `drivers` option will be used. :param control_mode: (Default False). Determines which driver type to load; if False, the data driver is loaded. If True, the control driver is loaded. """ mode = 'control' if control_mode else 'data' driver_type = 'zaqar.{0}.storage'.format(mode) storage_type = storage_type or conf['drivers'].storage try: mgr = driver.DriverManager(driver_type, storage_type, invoke_on_load=True, invoke_args=[conf, cache]) return mgr.driver except Exception as exc: LOG.exception(exc) raise errors.InvalidDriver(exc)
def load_storage_impl(uri, control_mode=False, default_store=None): """Loads a storage driver implementation and returns it. :param uri: The connection uri to parse and load a driver for. :param control_mode: (Default False). Determines which driver type to load; if False, the data driver is loaded. If True, the control driver is loaded. :param default_store: The default store to load if no scheme is parsed. """ mode = 'control' if control_mode else 'data' driver_type = 'zaqar.{0}.storage'.format(mode) storage_type = six.moves.urllib_parse.urlparse(uri).scheme or default_store try: mgr = driver.DriverManager(driver_type, storage_type, invoke_on_load=False) return mgr.driver except Exception as exc: LOG.exception(exc) raise errors.InvalidDriver(exc)
def transport(self): transport_name = self.driver_conf.transport LOG.debug(u'Loading transport driver: %s', transport_name) if transport_name == consts.TRANSPORT_WEBSOCKET: args = [self.conf, self.api, self.cache] else: args = [ self.conf, self.storage, self.cache, self.control, ] try: mgr = driver.DriverManager('zaqar.transport', transport_name, invoke_on_load=True, invoke_args=args) return mgr.driver except RuntimeError as exc: LOG.exception(exc) LOG.error(_LE(u'Failed to load transport driver zaqar.transport.' u'%(driver)s with args %(args)s'), {'driver': transport_name, 'args': args}) raise errors.InvalidDriver(exc)
def transport(self): transport_name = self.driver_conf.transport LOG.debug(u'Loading transport driver: %s', transport_name) # FIXME(vkmc): Find a better way to init args if transport_name == 'websocket': args = [self.conf, self.api, self.cache] else: args = [ self.conf, self.storage, self.cache, self.control, ] try: mgr = driver.DriverManager('zaqar.transport', transport_name, invoke_on_load=True, invoke_args=args) return mgr.driver except RuntimeError as exc: LOG.exception(exc) LOG.error( u'Failed to load transport driver zaqar.transport.' u'%(driver)s with args %(args)s', { 'driver': transport_name, 'args': args }) raise errors.InvalidDriver(exc)
def cache(self): LOG.debug(u'Loading proxy cache driver') try: oslo_cache.register_config(self.conf) return oslo_cache.get_cache(self.conf) except RuntimeError as exc: LOG.exception(exc) raise errors.InvalidDriver(exc)
def load_storage_driver(conf, cache, storage_type=None, control_mode=False, control_driver=None): """Loads a storage driver and returns it. The driver's initializer will be passed conf and cache as its positional args. :param conf: Configuration instance to use for loading the driver. Must include a 'drivers' group. :param cache: Cache instance that the driver can (optionally) use to reduce latency for some operations. :param storage_type: The storage_type to load. If None, then the `drivers` option will be used. :param control_mode: (Default False). Determines which driver type to load; if False, the data driver is loaded. If True, the control driver is loaded. :param control_driver: (Default None). The control driver instance to pass to the storage driver. Needed to access the queue controller, mainly. """ if control_mode: mode = 'control' storage_type = storage_type or conf['drivers'].management_store else: mode = 'data' storage_type = storage_type or conf['drivers'].message_store driver_type = 'zaqar.{0}.storage'.format(mode) _invoke_args = [conf, cache] if control_driver is not None: _invoke_args.append(control_driver) try: mgr = driver.DriverManager(driver_type, storage_type, invoke_on_load=True, invoke_args=_invoke_args) if conf.profiler.enabled: if ((mode == "control" and conf.profiler.trace_management_store) or (mode == "data" and conf.profiler.trace_message_store)): trace_name = '{0}_{1}_driver'.format(storage_type, mode) return profiler.trace_cls(trace_name, trace_private=True)(mgr.driver) else: return mgr.driver except Exception as exc: LOG.error( _LE('Failed to load "{}" driver for "{}"').format( driver_type, storage_type)) LOG.exception(exc) raise errors.InvalidDriver(exc)
def transport(self): transport_name = self.driver_conf.transport LOG.debug(u'Loading transport driver: %s', transport_name) args = [ self.conf, self.storage, self.cache, self.control, ] try: mgr = driver.DriverManager('zaqar.queues.transport', transport_name, invoke_on_load=True, invoke_args=args) return mgr.driver except RuntimeError as exc: LOG.exception(exc) raise errors.InvalidDriver(exc)