Exemplo n.º 1
0
def handle_tpcreator(owner_id, report_id, report_instance):
    """The method calls the TPCreator (see :ref:`guide_tpcreator`) for the given report instance,
    possibly creating new tiles from a master tile and altering dashboards'
    layouts. The signal :attr:`~mqe.signals.layout_modified` is issued for each
    modification."""
    layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(
        owner_id, report_id, [], 'tpcreator',
        mqeconfig.MAX_TPCREATORS_PER_REPORT)
    if not layout_rows:
        log.debug('No layout_by_report tpcreator rows')
        return

    log.info(
        'tpcreator is processing %s rows for owner_id=%s report_id=%s report_instance_id=%s',
        len(layout_rows), owner_id, report_id,
        report_instance.report_instance_id)
    for row in layout_rows:
        mods = [
            tpcreator_mod(report_instance, row),
            layouts.if_mod(lambda layout_mod: layout_mod.new_tiles,
                           layouts.repack_mod())
        ]
        lmr = layouts.apply_mods(mods,
                                 owner_id,
                                 row['dashboard_id'],
                                 for_layout_id=None,
                                 max_tries=MAX_TPCREATE_TRIES)
        if lmr and lmr.new_layout.layout_id != lmr.old_layout.layout_id:
            fire_signal(layout_modified,
                        reason='tpcreator',
                        layout_modification_result=lmr)
Exemplo n.º 2
0
    def test_promote_first_as_master_multiple_masters_one_apply_mods_run(self):
        rd = self.test_repack_dont_put_master_first()

        tile_config = {
            'tags': ['q1:10'],
            'series_spec_list': [
                dataseries.SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {
                'tpcreator_uispec': [{
                    'tag': 'q1:10',
                    'prefix': 'q1:'
                }],
            }
        }
        r2 = Report.insert(rd.owner_id, 'r2')
        master_tile2 = Tile.insert(rd.owner_id, r2.report_id, rd.dashboard_id,
                                   tile_config)
        layouts.place_tile(master_tile2)

        ri1 = r2.process_input('0', tags=['q1:8'],
                               handle_tpcreator=False).report_instance
        ri2 = r2.process_input('0', tags=['q1:12'],
                               handle_tpcreator=False).report_instance
        ri3 = r2.process_input('0', tags=['q1:6'],
                               handle_tpcreator=False).report_instance
        ri4 = rd.report.process_input('0',
                                      tags=['p1:2'],
                                      handle_tpcreator=False).report_instance

        layout_rows_tpcreator = c.dao.LayoutDAO.select_layout_by_report_multi(
            rd.owner_id, rd.report_id, [], 'tpcreator', 100)
        mods = [
            tpcreator.tpcreator_mod(ri1, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri2, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri3, layout_rows_tpcreator[0]),
            tpcreator.tpcreator_mod(ri4, layout_rows_tpcreator[0]),
            layouts.repack_mod(put_master_first=False),
            layouts.promote_first_as_master_mod(),
            layouts.if_mod(lambda layout_mod: layout_mod.tile_replacement,
                           layouts.repack_mod())
        ]
        layouts.apply_mods(mods, rd.owner_id, rd.dashboard_id, None)

        self.assertEqual([['p1:2'], ['p1:6'], ['p1:8'], ['p1:10'], ['p1:12'],
                          ['q1:6'], ['q1:8'], ['q1:10'], ['q1:12']],
                         [tile.tags for tile in rd.tiles_sorted_by_vo()])

        master1 = rd.get_tile_by_tags(['p1:2'])
        master2 = rd.get_tile_by_tags(['q1:6'])
        self.assertTrue(master1.is_master_tile())
        self.assertTrue(master2.is_master_tile())
        for tile in rd.tiles_sorted_by_vo():
            if tile.tags[0].startswith(
                    'p') and tile.tile_id != master1.tile_id:
                self.assertEqual(master1.tile_id, tile.get_master_tile_id())
            elif tile.tags[0].startswith(
                    'q') and tile.tile_id != master2.tile_id:
                self.assertEqual(master2.tile_id, tile.get_master_tile_id())
Exemplo n.º 3
0
def handle_tpcreator(owner_id, report_id, report_instance, make_first_master=False):
    """The method calls the TPCreator (see :ref:`guide_tpcreator`) for the given report instance,
    possibly creating new tiles from a master tile and altering dashboards'
    layouts. The signal :attr:`~mqe.signals.layout_modified` is issued for each
    modification.

    :param bool make_first_master: whether to promote the first tile wrt. ordering
        of tag values to a master tile. The default is ``False``, which means that
        a new master tile will not be promoted.

    """
    layout_rows = c.dao.LayoutDAO.select_layout_by_report_multi(owner_id, report_id, [], 'tpcreator',
                                                         mqeconfig.MAX_TPCREATORS_PER_REPORT)
    if not layout_rows:
        log.debug('No layout_by_report tpcreator rows')
        return

    log.info('tpcreator is processing %s rows for owner_id=%s report_id=%s report_instance_id=%s',
             len(layout_rows), owner_id, report_id, report_instance.report_instance_id)
    for row in layout_rows:
        mods = [tpcreator_mod(report_instance, row),
                # run the repacking only if tpcreator created a new tile
                layouts.if_mod(lambda layout_mod: layout_mod.new_tiles,
                               layouts.repack_mod(put_master_first=(not make_first_master)))]
        if make_first_master:
            mods.extend([
                # run the promote_first... mod only if tpcreator created a new tile
                layouts.if_mod(lambda layout_mod: layout_mod.new_tiles,
                               layouts.promote_first_as_master_mod()),
                # another repacking is needed if the promote_first... mod made replacements,
                # because the mod doesn't preserve ordering
                layouts.if_mod(lambda layout_mod: layout_mod.tile_replacement,
                               layouts.repack_mod()),
            ])

        lmr = layouts.apply_mods(mods, owner_id, row['dashboard_id'], for_layout_id=None,
                                 max_tries=MAX_TPCREATE_TRIES)
        if lmr and lmr.new_layout.layout_id != lmr.old_layout.layout_id:
            fire_signal(layout_modified, reason='tpcreator', layout_modification_result=lmr)