Esempio n. 1
0
    def __init__(self, database_servers, replica_set, database, collection):
        connection = get_connection(server_or_servers=database_servers,
                                    replica_set=replica_set)
        self.collection = get_collection(database,
                                         collection,
                                         connection=connection)
        self.db = InventoryDBController(self.collection)

        super(InventoryController, self).__init__()
Esempio n. 2
0
 def connection(self):
     if not self.__connection:
         if self.use_asyncio:
             self.__connection = asyncio_mongo.get_connection(
                 self.servers, self.replica_name
             )
         else:
             self.__connection = common_mongo.get_connection(
                 self.servers, self.replica_name)
     return self.__connection
Esempio n. 3
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))
Esempio n. 4
0
    def __init__(self, inventory_configuration):
        self.inventory_configuration = inventory_configuration
        self.db_configuration = self.inventory_configuration.get(
            'inventory', {}).get('db', {})
        log.debug('DB Configuration: %s' % self.db_configuration)

        db_name = self.db_configuration.get('name')
        if not db_name:
            log.warning('DB name is not specified, using test')
            db_name = 'test'

        connection = get_connection(
            server_or_servers=self.db_configuration.get(
                'servers', ['localhost']),
            replica_set=self.db_configuration.get('replica_set'))
        self.collection = get_collection(
            db_name,  # Perhaps we should raise an exception
            self.db_configuration.get('collection', 'inventory'),
            connection=connection)
        self.db = InventoryDBController(self.collection)

        super(InventoryController, self).__init__()
Esempio n. 5
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()