def launch_simple_architecture(config, supervisor):
    # Pusher
    pusher_generator = PusherGenerator()
    pusher_info = pusher_generator.generate(config)
    pusher_cls, pusher_start_message = pusher_info['test_pusher']

    pusher = supervisor.launch(pusher_cls, pusher_start_message)

    # Dispatcher
    route_table = RouteTable()
    route_table.dispatch_rule(
        HWPCReport,
        HWPCDispatchRule(getattr(HWPCDepthLevel, 'SOCKET'), primary=True))
    dispatcher_start_message = DispatcherStartMessage(
        'system', 'dispatcher', DummyFormulaActor,
        DummyFormulaValues({'test_pusher': pusher}, 0), route_table, 'cpu')

    dispatcher = supervisor.launch(DispatcherActor, dispatcher_start_message)

    # Puller
    report_filter = Filter()
    report_filter.filter(filter_rule, dispatcher)
    puller_generator = PullerGenerator(report_filter, [])
    puller_info = puller_generator.generate(config)
    puller_cls, puller_start_message = puller_info['test_puller']
    puller = supervisor.launch(puller_cls, puller_start_message)
    def run(self):
        config = {
            'verbose': True,
            'stream': True,
            'output': {
                'test_pusher': {
                    'type': 'mongodb',
                    'model': 'PowerReport',
                    'uri': MONGO_URI,
                    'db': MONGO_DATABASE_NAME,
                    'collection': MONGO_OUTPUT_COLLECTION_NAME
                }
            },
            'input': {
                'test_puller': {
                    'type': 'mongodb',
                    'model': 'HWPCReport',
                    'uri': MONGO_URI,
                    'db': MONGO_DATABASE_NAME,
                    'collection': MONGO_INPUT_COLLECTION_NAME
                }
            }
        }
        supervisor = Supervisor(config['verbose'])

        def term_handler(_, __):
            supervisor.shutdown()
            exit(0)

        signal.signal(signal.SIGTERM, term_handler)
        signal.signal(signal.SIGINT, term_handler)
        # Pusher
        pusher_generator = PusherGenerator()
        pusher_info = pusher_generator.generate(config)
        pusher_cls, pusher_start_message = pusher_info['test_pusher']

        pusher = supervisor.launch(pusher_cls, pusher_start_message)
        # Dispatcher
        route_table = RouteTable()
        route_table.dispatch_rule(
            HWPCReport,
            HWPCDispatchRule(getattr(HWPCDepthLevel, 'SOCKET'), primary=True))
        dispatcher_start_message = DispatcherStartMessage(
            'system', 'dispatcher', DummyFormulaActor,
            DummyFormulaValues({'test_pusher': pusher}, 0), route_table, 'cpu')

        dispatcher = supervisor.launch(DispatcherActor,
                                       dispatcher_start_message)
        # Puller
        report_filter = Filter()
        report_filter.filter(filter_rule, dispatcher)
        puller_generator = PullerGenerator(report_filter, [])
        puller_info = puller_generator.generate(config)
        puller_cls, puller_start_message = puller_info['test_puller']
        puller = supervisor.launch(puller_cls, puller_start_message)
        supervisor.monitor()
Exemplo n.º 3
0
def test_generate_puller_from_simple_config():
    """
    generate mongodb puller from this config :
    { 'verbose': True, 'stream': True, 'input': {'toto': {'model': 'HWPCReport', 'type': 'mongodb', 'uri': 'titi', 'db': 'tata',
                                             'collection': 'tutu'}}}

    Test if :
      - function return a dict containing one element, its key is 'toto'
      - puller type is PullerActor
      - puller name is toto
      - puller database type is MongoDB
      - database uri is titi
      - database db is tata
      - database collection is tutu

    """
    args = {
        'verbose': True,
        'stream': True,
        'input': {
            'toto': {
                'model': 'HWPCReport',
                'type': 'mongodb',
                'uri': 'titi',
                'db': 'tata',
                'collection': 'tutu'
            }
        }
    }
    generator = PullerGenerator(None, [])
    result = generator.generate(args)

    assert len(result) == 1
    assert 'toto' in result
    puller_cls, start_message = result['toto']
    assert puller_cls == PullerActor
    assert isinstance(start_message, PullerStartMessage)
    assert start_message.name == 'toto'

    db = start_message.database

    assert isinstance(db, MongoDB)
    assert db.uri == 'titi'
    assert db.db_name == 'tata'
    assert db.collection_name == 'tutu'
Exemplo n.º 4
0
def test_remove_mongodb_factory_and_generate_puller_from_a_config_with_mongodb_input_must_call_sys_exit_(
        mocked_sys_exit):
    args = {
        'verbose': True,
        'stream': True,
        'input': {
            'toto': {
                'model': 'HWPCReport',
                'type': 'mongodb',
                'uri': 'titi',
                'db': 'tata',
                'collection': 'tutu'
            }
        }
    }
    generator = PullerGenerator(None, [])
    generator.remove_db_factory('mongodb')
    with pytest.raises(PowerAPIException):
        result = generator.generate(args)
Exemplo n.º 5
0
def test_generate_puller_from_empty_config_dict_call_sys_exit(mocked_sys_exit):
    args = {}
    generator = PullerGenerator(None, [])

    with pytest.raises(PowerAPIException):
        generator.generate(args)
Exemplo n.º 6
0
def test_generate_two_pusher():
    """
    generate two mongodb puller from this config :
    { 'verbose': True, 'stream': True, 'input': {'toto': {'model': 'HWPCReport', 'type': 'mongodb', 'uri': 'titi', 'db': 'tata',
                                             'collection': 'tutu'},
                                                             'titi': {'model': 'HWPCReport', 'type': 'mongodb', 'uri': 'titi', 'db': 'tata',
                                             'collection': 'huhu'}}}

    Test if :
      - function return a dict containing two actor, their key are 'toto' and 'titi'
      - pullers type are PullerActor
      - pullers name are toto and titi
      - pullers database type are MongoDB
      - databases uri are titi
      - databases db are tata
      - databases collection are tutu and huhu

    """
    args = {
        'verbose': True,
        'stream': True,
        'input': {
            'toto': {
                'model': 'HWPCReport',
                'type': 'mongodb',
                'uri': 'titi',
                'db': 'tata',
                'collection': 'tutu'
            },
            'titi': {
                'model': 'HWPCReport',
                'type': 'mongodb',
                'uri': 'titi',
                'db': 'tata',
                'collection': 'huhu'
            }
        }
    }
    generator = PullerGenerator(None, [])
    result = generator.generate(args)

    assert len(result) == 2
    assert 'toto' in result
    puller1_cls, start_message1 = result['toto']
    assert puller1_cls == PullerActor
    assert start_message1.name == 'toto'

    db = start_message1.database

    assert isinstance(db, MongoDB)
    assert db.uri == 'titi'
    assert db.db_name == 'tata'
    assert db.collection_name == 'tutu'

    assert 'titi' in result
    puller2_cls, start_message2 = result['titi']
    assert puller2_cls == PullerActor
    assert start_message2.name == 'titi'

    db = start_message2.database

    assert isinstance(db, MongoDB)
    assert db.uri == 'titi'
    assert db.db_name == 'tata'
    assert db.collection_name == 'huhu'