def create_datasource_service(self, datasource): """Create a new DataService on this node. :param: datasource: datsource object. """ # get the driver info for the datasource ds_dict = self.make_datasource_dict(datasource) if not ds_dict['enabled']: LOG.info("datasource %s not enabled, skip loading", ds_dict['name']) return driver = self.loaded_drivers.get(ds_dict['driver']) if not driver: raise exception.DriverNotFound(id=ds_dict['driver']) if ds_dict['config'] is None: args = {'ds_id': ds_dict['id']} else: args = dict(ds_dict['config'], ds_id=ds_dict['id']) kwargs = {'name': ds_dict['name'], 'args': args} LOG.info("creating service %s with class %s and args %s", ds_dict['name'], driver.plugin, strutils.mask_password(kwargs, "****")) try: service = driver.plugin(**kwargs) except Exception: msg = ("Error loading instance of module '%s'") LOG.exception(msg, driver.plugin) raise exception.DataServiceError(msg % driver.plugin) return service
def delete_datasource(self, datasource, update_db=True): LOG.debug("Deleting %s datasource ", datasource['name']) datasource_id = datasource['id'] if update_db: # Note(thread-safety): blocking call result = datasources_db.delete_datasource_with_data(datasource_id) if not result: raise exception.DatasourceNotFound(id=datasource_id) # Note(thread-safety): blocking call try: self.synchronize_datasources() except Exception: msg = ('failed to synchronize_datasource after ' 'deleting datasource: %s' % datasource_id) LOG.exception(msg) raise exception.DataServiceError(msg)
def create_datasource_service(self, datasource): """Create a new DataService on this node. :param name is the name of the service. Must be unique across all services :param classPath is a string giving the path to the class name, e.g. congress.datasources.fake_datasource.FakeDataSource :param args is the list of arguments to give the DataService constructor :param type_ is the kind of service :param id_ is an optional parameter for specifying the uuid. """ # get the driver info for the datasource ds_dict = self.make_datasource_dict(datasource) if not ds_dict['enabled']: LOG.info("datasource %s not enabled, skip loading", ds_dict['name']) return driver_info = self.get_driver_info(ds_dict['driver']) # split class_path into module and class name class_path = driver_info['module'] pieces = class_path.split(".") module_name = ".".join(pieces[:-1]) class_name = pieces[-1] if ds_dict['config'] is None: args = {'ds_id': ds_dict['id']} else: args = dict(ds_dict['config'], ds_id=ds_dict['id']) kwargs = {'name': ds_dict['name'], 'args': args} LOG.info("creating service %s with class %s and args %s", ds_dict['name'], module_name, strutils.mask_password(kwargs, "****")) # import the module try: # Note(thread-safety): blocking call? module = importutils.import_module(module_name) service = getattr(module, class_name)(**kwargs) except Exception: msg = ("Error loading instance of module '%s'") LOG.exception(msg, class_path) raise exception.DataServiceError(msg % class_path) return service
def register_service(self, service): assert service.node is None if self.service_object(service.service_id): msg = ('Service %s already exsists on the node %s' % (service.service_id, self.node_id)) raise exception.DataServiceError(msg) access_policy = dispatcher.DefaultRPCAccessPolicy service.node = self self._services.append(service) service._target = self.service_rpc_target(service.service_id, server=self.node_id) service._rpc_server = messaging.get_rpc_server( self.transport, service._target, service.rpc_endpoints(), executor='eventlet', access_policy=access_policy) if self._running: service.start() LOG.debug('<%s> Service %s RPC Server listening on %s', self.node_id, service.service_id, service._target)
def delete_datasource(self, datasource, update_db=True): LOG.debug("Deleting %s datasource ", datasource['name']) datasource_id = datasource['id'] if update_db: # Note(thread-safety): blocking call result = datasources_db.delete_datasource_with_data(datasource_id) if not result: raise exception.DatasourceNotFound(id=datasource_id) # Note(thread-safety): blocking call try: self.synchronizer.sync_datasource(datasource['name']) # If local PE exists.. sync engine = self.node.service_object(api_base.ENGINE_SERVICE_ID) if engine: engine.synchronizer.sync_one_policy(datasource['name']) except Exception: msg = ('failed to synchronize_datasource after ' 'deleting datasource: %s' % datasource_id) LOG.exception(msg) raise exception.DataServiceError(msg)
def create_datasource_service(self, datasource): """Create a new DataService on this node. :param: name is the name of the service. Must be unique across all services :param: classPath is a string giving the path to the class name, e.g. congress.datasources.fake_datasource.FakeDataSource :param: args is the list of arguments to give the DataService constructor :param: type\_ is the kind of service :param: id\_ is an optional parameter for specifying the uuid. """ # get the driver info for the datasource ds_dict = self.make_datasource_dict(datasource) if not ds_dict['enabled']: LOG.info("datasource %s not enabled, skip loading", ds_dict['name']) return driver = self.loaded_drivers.get(ds_dict['driver']) if not driver: raise exception.DriverNotFound(id=ds_dict['driver']) if ds_dict['config'] is None: args = {'ds_id': ds_dict['id']} else: args = dict(ds_dict['config'], ds_id=ds_dict['id']) kwargs = {'name': ds_dict['name'], 'args': args} LOG.info("creating service %s with class %s and args %s", ds_dict['name'], driver.plugin, strutils.mask_password(kwargs, "****")) try: service = driver.plugin(**kwargs) except Exception: msg = ("Error loading instance of module '%s'") LOG.exception(msg, driver.plugin) raise exception.DataServiceError(msg % driver.plugin) return service