def align_server(index, port, shm=False, clean=False): if shm: server = yield from rpc.serve_rpc( BwaServe(index, clean=clean), bind='tcp://127.0.0.1:{}'.format(port)) else: server = yield from rpc.serve_rpc( BwapyServe(index[0]), bind='tcp://127.0.0.1:{}'.format(port)) return server
def align_server(index, port, shm=False, clean=False, opts=''): if shm: server = yield from rpc.serve_rpc( BwaServe(index, clean=clean, bwa_opts=opts), bind='tcp://127.0.0.1:{}'.format(port) ) else: server = yield from rpc.serve_rpc( BwapyServe(index[0], bwa_opts=opts), bind='tcp://127.0.0.1:{}'.format(port) ) return server
def align_server(index, port, aligner, opts=''): bind = 'tcp://127.0.0.1:{}'.format(port) if aligner == 'minimap': server = yield from rpc.serve_rpc(MiniMapServe(index[0], map_opts=opts), bind=bind) elif aligner == 'bwa': server = yield from rpc.serve_rpc(BwapyServe(index[0], bwa_opts=opts), bind=bind) else: raise ValueError("Unknown aligner '{}'.".format(aligner)) return server
def get_frontserver(engine_callback, config, socket, b2fsocket, loop=None): """A helper function that is used internally to create a running server for the front part of Xbus :param engine_callback: the engine constructor we will "yield from" to get a real dbengine :param config: the application configuration instance :class:`configparser.ConfigParser` it MUST contain a `redis` section and two keys: 'host' and 'port' :param socket: a string representing the socket address on which we will spawn our 0mq listener :param b2fsocket: a string representing the socket address on which the front server will listen so that the backend will be able to register itself :param loop: the event loop this server must use :return: a future that is waiting for a wait_closed() call before being fired back. """ dbengine = yield from engine_callback(config) broker = XbusBrokerFront(dbengine, loop=loop) redis_host = config.get('redis', 'host') redis_port = config.getint('redis', 'port') yield from broker.prepare_redis(redis_host, redis_port) frontzmqserver = yield from rpc.serve_rpc(broker, bind=socket, loop=loop) # prepare the socket we use to communicate between front and backend front2back = XbusBrokerFront2Back(broker) front_from_back_zqm = yield from rpc.serve_rpc( front2back, bind=b2fsocket, loop=loop, ) coroutines = [ frontzmqserver.wait_closed(), front_from_back_zqm.wait_closed() ] # wait for all coroutines to complete yield from asyncio.gather(*coroutines)
def get_front_broker(self, uid, password, profile_id): """a helper function to call from inside a test to setup your login :param uid: role id you want to assume during tests :param password: the password you want to use in your test :param profile_id: the profile id your login must be attached to :return: a zmqserver future you can yield from. Don't forget to close() it when you are done with it """ # no dbengine for the broker :) broker = XbusBrokerFront(None) # new token always returns the same testable uuid... broker.new_token = Mock( return_value=self.token ) self.login_info = (uid, gen_password(password), profile_id) broker.find_emitter_by_login = self.get_mock_emitter broker.save_key = self.mock_save_key zmqserver = yield from rpc.serve_rpc( broker, bind=self.front_socket, loop=self.loop ) #yield from zmqserver.wait_closed() self.loop.set_exception_handler(self.error_handler) return zmqserver
def start(self): self.client = yield from rpc.connect_rpc(connect=self.back_url, loop=self.loop) self.token = yield from self.client.call.login(self.login, self.password) res = yield from self.client.call.register_node(self.token, self.url) server = yield from rpc.serve_rpc(self, bind=self.url, loop=self.loop) return server
def go(): pub = yield from rpc.connect_pubsub(bind="tcp://*:6882") pub.transport.setsockopt(zmq.SNDHWM, 128) w = Wlm(pub=pub) serv = yield from rpc.serve_rpc(w, bind="tcp://*:6881") serv.transport.setsockopt(zmq.SNDHWM, 128) w.cbc = wlm.CallbackProc(w.cb) # keep from being gc-ed if wlm.lib.Instantiate(wlm.cInstCheckForWLM, 1, 0, 0): wlm.lib.Instantiate(wlm.cInstNotification, wlm.cNotifyInstallCallback, w.cbc, 0) logger.info("listening")
def initialize_zmq(): """ Setup and initialize the ZeroMQ DEALER/ROUTER connectivity. """ address = setup_zeromq(config, logger) handler = Handler(executor, config, logger, loader, store, transformer, lock) logger.info('Binding ZeroMQ librarian service at \'{}\'.' .format(address)) service = yield from rpc.serve_rpc(handler, bind=address, log_exceptions=True) return service
def replay_server(fast5, channels, port, good_class, time_warp=1): """Create an RPC server to replay data from a .fast5 file. :param fast5: input .fast5 file for simulation. :param channels: list of channels to simulate. :param port: port on which to listen for clients. :param good_class: read classification name of desirable reads. :returns: instance of :class:`ReplayFast5`. """ server = yield from rpc.serve_rpc( ReplayFast5(fast5, channels, good_class=good_class, time_warp=time_warp), bind='tcp://127.0.0.1:{}'.format(port), translation_table=translation_table, ) return server
def initialize_zmq(): """ Setup and initialize the ZeroMQ PUSH/PULL connectivity. """ engine, events = setup_zeromq(config, logger) logger.info('Binding ZeroMQ engine service at \'{}\'.'.format(engine)) logger.info('Connecting to ZeroMQ events service at \'{}\'.' .format(','.join(events))) events = yield from rpc.connect_pipeline(connect=events) handler = Handler(config, logger, events, store, lock) engine = yield from rpc.serve_rpc(handler, connect=engine, log_exceptions=True) return engine, events
def initialize_zmq(): """ Setup and initialize the ZeroMQ connectivity. """ broker, engine = setup_zeromq(config, logger) logger.info('Binding ZeroMQ broker service at \'{}\'.' .format(broker)) logger.info('Connecting to ZeroMQ engine at \'{}\'.' .format(','.join(engine))) engine = yield from rpc.connect_rpc(bind=engine) broker_handler = BrokerHandler(config, logger, engine, directory) broker = yield from rpc.serve_rpc(broker_handler, bind=broker, log_exceptions=True) return broker, engine
def get_mock_frontbroker(self, **attrs): """Create a mock front-end broker, using the given arguments to override the object's methods and attributes with dummy values. The given values will be converted whenever necessary: _ to a mock function returning the new value, if the overridden value is callable and the new value isn't ; _ then to a coroutine, if the overridden value is also a coroutine and the new value isn't. :param attrs: a dictionary which maps overridden attributes to their new value. :return: a zmqserver future you can yield from. Don't forget to close() it when you are done with it """ broker = XbusBrokerFront(None, loop=self.loop) print(dir(broker)) for attr, value in attrs.items(): old_value = getattr(broker, attr) if old_value: if hasattr(old_value, '__call__'): if not hasattr(value, '__call__'): value = Mock(return_value=value) if asyncio.iscoroutinefunction(old_value) is True: if asyncio.iscoroutinefunction(value) is not True: value = asyncio.coroutine(value) setattr(broker, attr, value) zmqserver = yield from rpc.serve_rpc( broker, bind=self.front_socket, loop=self.loop ) self.loop.set_exception_handler(self.error_handler) return zmqserver
def get_backserver(engine_callback, config, socket, b2fsocket, loop=None): """A helper function that is used internally to create a running server for the back part of Xbus :param engine_callback: the engine constructor we will be to "yield from" to get a real dbengine :param config: the application configuration instance :class:`configparser.ConfigParser` it MUST contain a section redis and two keys: 'host' and 'port' :param socket: a string representing the socker address on which we will spawn our 0mq listener :param socket: the event loop the server must run with :return: a future that is waiting for a closed() call before being fired back. """ dbengine = yield from engine_callback(config) broker_back = XbusBrokerBack(dbengine, b2fsocket, socket, loop=loop) redis_host = config.get('redis', 'host') redis_port = config.getint('redis', 'port') yield from broker_back.prepare_redis(redis_host, redis_port) yield from broker_back.register_on_front() zmqserver = yield from rpc.serve_rpc( broker_back, bind=socket, loop=loop, ) yield from zmqserver.wait_closed()