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()
Esempio 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'
Esempio 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)
Esempio n. 5
0
def run_rapl(args) -> None:
    """
    Run PowerAPI with the SmartWatts formula.
    :param args: CLI arguments namespace
    :param logger: Logger to use for the actors
    """
    fconf = args

    logging.info('RAPL-Formula version %s using PowerAPI version %s', rapl_formula_version, powerapi_version)

    if not fconf['enable-cpu-formula'] and not fconf['enable-dram-formula']:
        logging.error('You need to enable at least one formula')
        return

    route_table = RouteTable()
    route_table.dispatch_rule(HWPCReport, HWPCDispatchRule(HWPCDepthLevel.SOCKET, primary=True))

    report_filter = Filter()

    report_modifier_list = ReportModifierGenerator().generate(fconf)

    supervisor = Supervisor(args['verbose'])

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

    signal.signal(signal.SIGTERM, term_handler)
    signal.signal(signal.SIGINT, term_handler)
    try:
        logging.info('Starting RAPL-formula actors...')

        power_pushers = {}
        pushers_info = PusherGenerator().generate(args)
        for pusher_name in pushers_info:
            pusher_cls, pusher_start_message = pushers_info[pusher_name]
            power_pushers[pusher_name] = supervisor.launch(
                pusher_cls, pusher_start_message
            )

        logging.info('CPU formula is %s' % ('DISABLED' if not fconf['enable-cpu-formula'] else 'ENABLED'))
        if fconf['enable-cpu-formula']:
            logging.info('CPU formula parameters: RAPL_REF=%s' % (fconf['cpu-rapl-ref-event']))
            setup_cpu_formula_actor(supervisor, fconf, route_table, report_filter, power_pushers)

            logging.info('DRAM formula is %s' % ('DISABLED' if not fconf['enable-dram-formula'] else 'ENABLED'))
        if fconf['enable-dram-formula']:
            logging.info('DRAM formula parameters: RAPL_REF=%s' % (fconf['dram-rapl-ref-event']))
            setup_dram_formula_actor(supervisor, fconf, route_table, report_filter, power_pushers)

        pullers_info = PullerGenerator(report_filter, report_modifier_list).generate(args)
        for puller_name in pullers_info:
            puller_cls, puller_start_message = pullers_info[puller_name]
            supervisor.launch(puller_cls, puller_start_message)
    except InitializationException as exn:
        logging.error('Actor initialization error: ' + exn.msg)
        supervisor.shutdown()
        sys.exit(-1)

    logging.info('RAPL-formula is now running...')
    supervisor.monitor()
    logging.info('RAPL-formula is shutting down...')
Esempio n. 6
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)
Esempio n. 7
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'