Ejemplo n.º 1
0
    def __init__(self, inventory_router_url, jobs_collection,
                 tasks_collection):
        registration_service_bind_address = rpc_configuration.get(
            'backend', {}).get('service_url', 'tcp://0.0.0.0:9002')
        service_info = rpc_configuration.get('info', {})
        super(BackEndService, self).__init__(registration_service_bind_address)

        self.inventory_router_url = inventory_router_url
        self.inventory_client = AsyncInventoryClient(inventory_router_url)
        self.jobs_collection = jobs_collection
        self.tasks_collection = tasks_collection

        self.controller = BackendController(service_info,
                                            self.inventory_client,
                                            self.jobs_collection,
                                            self.tasks_collection)

        self.dispatcher = AsyncDispatcher(self.controller)
Ejemplo n.º 2
0
def rpc_backend_service():
    """
    Entry point

    :return:
    """

    configure_logging()
    db_configuration = rpc_configuration.get('db', {})

    # Create the event loop
    loop = zmq.asyncio.ZMQEventLoop()
    loop.set_debug(False)
    asyncio.set_event_loop(loop)

    # Ready the DB
    connection = get_connection(
        server_or_servers=db_configuration.get('rpc_mongo_servers',
                                               'localhost'),
        replica_set=db_configuration.get('replica_set'))

    jobs_collection = get_jobs_collection(connection)
    tasks_collection = get_tasks_collection(connection)

    jobs_collection.create_index('ttl_time_completed', expireAfterSeconds=3600)
    tasks_collection.create_index('ttl_time_completed',
                                  expireAfterSeconds=3600)

    # Inject the monitor loop
    monitor = Monitor(jobs_collection, tasks_collection, loop=loop)
    asyncio.ensure_future(monitor.loop(), loop=loop)

    # Create a backend instance
    inventory_router = rpc_configuration['inventory']['inventory_router']
    server = BackEndService(inventory_router, jobs_collection,
                            tasks_collection)
    server.reacquire()

    # Inject ping loop
    asyncio.ensure_future(ping_loop(server.context, 30, 10, 2500, 5, .42, loop,
                                    inventory_router),
                          loop=loop)

    try:
        loop.run_until_complete(server.start())
    except KeyboardInterrupt:
        log.info('Sending kill signals')
        monitor.kill()
        stop_ping()
    finally:
        log.debug('Cleaning up...')
        pending = asyncio.Task.all_tasks()
        loop.run_until_complete(asyncio.gather(*pending))
Ejemplo n.º 3
0
    def __init__(self, inventory_client, jobs_collection, tasks_collection):
        """

        :param jobs_collection: motor mongodb collection
        :param tasks_collection: motor mongodb collection
        """
        service_bind_address = rpc_configuration.get('frontend', {}).get(
            'service_url', 'tcp://0.0.0.0:9001')
        super(FrontEndService, self).__init__(service_bind_address)

        self.inventory_client = inventory_client
        self.jobs_collection = jobs_collection
        self.tasks_collection = tasks_collection

        self.controller = FrontEndController(inventory_client, jobs_collection,
                                             tasks_collection)

        self.dispatcher = AsyncDispatcher(self.controller)
Ejemplo n.º 4
0
def rpc_frontend_service():
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s : %(levelname)s - %(name)s - %(message)s')

    db_configuration = rpc_configuration.get('db', {})

    # Create the event loop
    loop = zmq.asyncio.ZMQEventLoop()
    loop.set_debug(True)
    asyncio.set_event_loop(loop)

    # Ready the DB
    connection = get_connection(
        server_or_servers=db_configuration.get('rpc_mongo_servers',
                                               'localhost'),
        replica_set=db_configuration.get('replica_set'))

    jobs_collection = get_jobs_collection(connection)
    tasks_collection = get_tasks_collection(connection)

    jobs_collection.create_index('ttl_time_completed', expireAfterSeconds=3600)
    tasks_collection.create_index('ttl_time_completed',
                                  expireAfterSeconds=3600)

    inventory_router = rpc_configuration['inventory']['inventory_router']

    server = FrontEndService(inventory_router, jobs_collection,
                             tasks_collection)

    # Start main loop
    try:
        loop.run_until_complete(server.start())
    except KeyboardInterrupt:
        pass
    finally:
        server.socket.close(0)
        server.context.destroy()
Ejemplo n.º 5
0
    socket.send(msgpack.packb(_payload))

    if not socket.poll(timeout):
        log.debug('Ping timeout: %s' % zurl)
        socket.close()
        return False

    reply = socket.recv()
    log.debug("%s : %s" % (zurl, msgpack.unpackb(reply, encoding='utf-8')))
    socket.close()
    return True


if __name__ == '__main__':
    from mercury.rpc.db import ActiveInventoryDBController
    from mercury.rpc.configuration import rpc_configuration
    from mercury.common.mongo import get_collection

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s : %(levelname)s - %(name)s - %(message)s')
    logging.getLogger('mercury.rpc.ping').setLevel(logging.DEBUG)
    db_configuration = rpc_configuration.get('db', {})
    collection = get_collection(
        db_configuration.get('rpc_mongo_db', 'test'),
        db_configuration.get('rpc_mongo_collection', 'rpc'),
        server_or_servers=db_configuration.get('rpc_mongo_servers',
                                               'localhost'),
        replica_set=db_configuration.get('replica_set'))
    _db_controller = ActiveInventoryDBController(collection=collection)