Esempio n. 1
0
def _ViewLayout(request, layout_name, extra_context=None):
    """Get a monitor layout according to `layout_name`."""
    layout = loader.LayoutLoader().GetLayoutByModuleName(layout_name)
    if layout is None:
        return http.HttpResponseRedirect(urlresolvers.reverse('home'))
    layout.Initialize()
    configs = _LoadConfigs()
    configs['scenarios'] = layout.Scenario()
    context = _PrepareContext(configs)
    client_id = _CreateAndAddClientIdToContext(context)
    # Initialize the layout.
    layout.Export(layout_memory.GetMemory(client_id, True))
    # Add polling URL.
    context['periodic_url'] = '/dashboard/periodic/layout/%s/%s' % (
        client_id, layout_name)
    context['layout_name'] = layout_name
    context['content_width'] = settings.CSS_GRID_COLUMNS
    context['order_horizontally'] = layout.OrderHorizontally()
    context['default_font_size'] = layout.DefaultFontSize()
    context['sim_mode'] = settings.POPULATE_MESSAGES_FROM_SIM

    if extra_context:
        context.update(extra_context)

    template_name = 'monitor.html'
    return shortcuts.render(request,
                            template_name,
                            context,
                            context_instance=template.RequestContext(request))
Esempio n. 2
0
def main():
  print '---------------------------'
  print 'Layouts in the web monitor:'
  print '---------------------------'
  layout_loader = loader.LayoutLoader()
  module_names = layout_loader.ModuleNames()
  for module_name in sorted(module_names):
    print '{:>16}:     {:60}'.format(
        module_name, layout_loader.GetLayoutByModuleName(module_name).Name())
Esempio n. 3
0
 def _RunLayouts(self):
     num_messages = 10
     messages = test_util.SynthesizeMessages()
     for layout_name in self._layout_names:
         layout = loader.LayoutLoader().GetLayoutByModuleName(layout_name)
         layout.Initialize()
         for _ in range(num_messages):
             json.dumps(layout.Filter(messages).Json())
             assert not layout.ErrorReport()
Esempio n. 4
0
def Home(request):
    """Get the response for the home page."""

    layout_names = loader.LayoutLoader().Names()
    layout_names.sort()
    all_layouts = [{
        'name':
        layout,
        'url':
        urlresolvers.reverse('view_aio_layout',
                             args=[loader.LayoutLoader().ModuleName(layout)])
    } for layout in layout_names]
    context = {
        'layouts': all_layouts,
        'canvas_cols': settings.CSS_GRID_COLUMNS,
    }
    _CreateAndAddClientIdToContext(context)

    template_name = 'home.html'
    return shortcuts.render(request,
                            template_name,
                            context,
                            context_instance=template.RequestContext(request))
Esempio n. 5
0
def PeriodicDataPoll(request, client_id, layout_name):
    """Compute realtime data and respond to periodic polling from a client layout.

  Args:
    request: An HttpRequest from the client.
    client_id: The ID of the client's browser tab.
    layout_name: Name of the layout associated with the client.

  Returns:
    An HttpResponse in the format of a serialized JSON object.
  """
    aggregated_message = _GetMessage(request, client_id)
    if not aggregated_message:
        aggregated_message = struct_tree.StructTree({},
                                                    fail_silently=True,
                                                    readonly=True)
    layout = loader.LayoutLoader().GetLayoutByModuleName(layout_name)
    tab_memory = layout_memory.GetMemory(client_id, False)
    if tab_memory is not None:
        # Load the persistent memory.
        layout.Import(tab_memory)
    else:
        layout.Initialize()
        tab_memory = layout_memory.GetMemory(client_id, True)

    # Start the AIO receiver in case the server has restarted.
    _TryToEnforceAioReceiver(client_id)

    try:
        data = layout.Filter(aggregated_message)
    except Exception:  # pylint: disable=broad-except
        # layout.Filter may introduce any kind of exception.
        logging.error('PeriodicDataPoll encountered an error:\n%s',
                      debug_util.FormatTraceback())

        layout.Export(tab_memory)
        return http.HttpResponse('{}')

    # Save the persistent memory.
    layout.Export(tab_memory)
    resp = data.Json()
    if settings.DEBUG:
        resp['__message__'] = '\n-----------------------------\n'.join(
            'Error in indicator "%s":\n%s' % (k, v)
            for k, v in layout.ErrorReport())
    resp_str = json.dumps(resp)
    layout.ClearErrors()
    return http.HttpResponse(resp_str)
Esempio n. 6
0
 def setUp(self):
     self._layout_names = loader.LayoutLoader().ModuleNames()
Esempio n. 7
0
def ViewLogStructure(request, paths, template_name='log_structure.html'):
    """View structure of an HDF5 log at given log path.

  Args:
    request: An HttpRequest from the client.
    paths: Paths to the local log files.
    template_name: The HTML template used to render the layout.

  Returns:
    An HttpResponse that renders the log structure.
  """

    # `context` includes variables used to render the HTML.
    context = {
        'graph_width': 6000,
        'graph_height': 6000,
        'frame_width': 200,
        'frame_height': 540,
        'canvas_cols': 12,
    }

    log_paths = []
    for path in paths.split(';'):
        path = path.strip()
        if not path:
            continue
        path_template = string.Template(path)
        log_path = path_template.substitute(os.environ)
        basename = os.path.basename(log_path)
        if basename.startswith('(') and basename.endswith(')'):
            dirname = os.path.dirname(log_path)
            regex_pattern = re.compile(basename[1:-1] + '$')
            filenames = os.listdir(dirname)
            matched_files = [f for f in filenames if regex_pattern.match(f)]
            log_paths += [os.path.join(dirname, f) for f in matched_files]
        else:
            log_paths.append(log_path)

    if not log_paths:
        context['errors'] = 'Cannot find log data'
    else:
        # Use the first log to index fields.
        log_data = struct_tree.StructTree(log_paths[0],
                                          fail_silently=True,
                                          readonly=True)
        log_skeleton = log_data.Skeleton(depth=1)
        d3_data = struct_tree.DictToD3Tree(log_skeleton, '/')
        d3_data['expand_url'] = urlresolvers.reverse('browse_log', args=[''])
        request.session['log_paths'] = log_paths
        context['skeleton'] = json.dumps(d3_data)

    order_horizontally = True
    configs = _LoadConfigs()
    scenarios = layout_base.AssembleLayout(
        [
            ('Signals', [
                widgets.DictLinesWidget(
                    'series', None, interactive=True, use_markers=True),
            ]),
        ],
        desired_view_cols=1,
        order_horizontally=order_horizontally)
    layout_names = loader.LayoutLoader().ModuleNames()
    layout_names.sort()
    configs['scenarios'] = scenarios
    context.update(_PrepareContext(configs))
    context['layout_names'] = layout_names
    context['content_width'] = settings.CSS_GRID_COLUMNS - 2
    context['order_horizontally'] = order_horizontally
    _CreateAndAddClientIdToContext(context)
    return shortcuts.render(request,
                            template_name,
                            context,
                            context_instance=template.RequestContext(request))