예제 #1
0
def stats_data(req, stats_type):
    """ n and n_type will always be given. format may be None and will
    default to 'html'. Also, either start/stop or left_start/left_stop/shift
    will be present - if the latter, start and stop will be computed as left_start/left_stop
    shifted by the value pointed to by shift.
    """
    req_input = Bunch.fromkeys(
        ('utc_start', 'utc_stop', 'user_start', 'user_stop', 'n', 'n_type',
         'format', 'left-start', 'left-stop', 'right-start', 'right-stop',
         'shift', 'side', 'custom_range'))

    for name in req_input:
        req_input[name] = req.GET.get(name, '') or req.POST.get(name, '')

    # Now, this may look odd but for some reason UTC timestamps submitted
    # in the form of '2012-10-31T21:47:11.592868+00:00' get translated
    # by Django into '2012-10-31T21:47:11.592868+00:00' so the plus sign disappears.
    # We bring it back taking an advantage of the fact that ' 00:00' alone is never
    # a proper string of characters in a UTC timestamp.
    for name in ('utc_start', 'utc_stop'):
        req_input[name] = req_input[name].replace(' 00:00', '+00:00')
        req_input['orig_{}'.format(name)] = req_input[name]

    try:
        req_input.n = int(req_input.n)
    except ValueError:
        req_input.n = 0

    req_input.format = req_input.format or 'html'
    is_custom = False

    if req_input.shift:
        duration = skip_by_duration[req_input.shift]
        format = user_format[duration]

        shift_info = shift(parse(req_input.utc_start), req_input.user_start,
                           req.zato.user_profile, req_input.shift, duration,
                           format)

        for date_type in ('utc', 'user'):
            for direction in ('start', 'stop'):
                full_name = '{}_{}'.format(date_type, direction)
                req_input[full_name] = shift_info[full_name]

    elif req_input.custom_range:
        is_custom = True
        req_input['utc_start'] = utc.fromutc(
            from_user_to_utc(req_input.user_start,
                             req.zato.user_profile)).isoformat()
        req_input['utc_stop'] = utc.fromutc(
            from_user_to_utc(req_input.user_stop,
                             req.zato.user_profile)).isoformat()

        req_input['user_start'] = req_input.user_start
        req_input['user_stop'] = req_input.user_stop

    return globals()['_stats_data_{}'.format(
        req_input.format)](req.zato.user_profile, req_input, req.zato.client,
                           req.zato.cluster, stats_type, is_custom)
예제 #2
0
def maintenance_delete(req):
    start = from_user_to_utc(req.POST['start'], req.zato.user_profile)
    stop = from_user_to_utc(req.POST['stop'], req.zato.user_profile)

    req.zato.client.invoke('zato.stats.delete', {'start':start, 'stop':stop})

    msg = 'Submitted a request to delete statistics from [{}] to [{}]. Check the server logs for details.'.format(
        from_utc_to_user(start.isoformat() + '+00:00', req.zato.user_profile),
        from_utc_to_user(stop.isoformat() + '+00:00', req.zato.user_profile))

    messages.add_message(req, messages.INFO, msg, extra_tags='success')

    return redirect('{}?cluster={}'.format(reverse('stats-maintenance'), req.zato.cluster_id))
예제 #3
0
def stats_data(req, stats_type):
    """ n and n_type will always be given. format may be None and will
    default to 'html'. Also, either start/stop or left_start/left_stop/shift
    will be present - if the latter, start and stop will be computed as left_start/left_stop
    shifted by the value pointed to by shift.
    """
    req_input = Bunch.fromkeys(('utc_start', 'utc_stop', 'user_start', 'user_stop',
        'n', 'n_type', 'format', 'left-start', 'left-stop', 'right-start', 'right-stop',
        'shift', 'side', 'custom_range'))

    for name in req_input:
        req_input[name] = req.GET.get(name, '') or req.POST.get(name, '')

    # Now, this may look odd but for some reason UTC timestamps submitted
    # in the form of '2012-10-31T21:47:11.592868+00:00' get translated
    # by Django into '2012-10-31T21:47:11.592868+00:00' so the plus sign disappears.
    # We bring it back taking an advantage of the fact that ' 00:00' alone is never
    # a proper string of characters in a UTC timestamp.
    for name in('utc_start', 'utc_stop'):
        req_input[name] = req_input[name].replace(' 00:00', '+00:00')
        req_input['orig_{}'.format(name)] = req_input[name]

    try:
        req_input.n = int(req_input.n)
    except ValueError:
        req_input.n = 0

    req_input.format = req_input.format or 'html'
    is_custom = False

    if req_input.shift:
        duration = skip_by_duration[req_input.shift]
        format = user_format[duration]

        shift_info = shift(parse(req_input.utc_start), req_input.user_start, req.zato.user_profile, req_input.shift, duration, format)

        for date_type in('utc', 'user'):
            for direction in('start', 'stop'):
                full_name = '{}_{}'.format(date_type, direction)
                req_input[full_name] = shift_info[full_name]

    elif req_input.custom_range:
        is_custom = True
        req_input['utc_start'] = utc.fromutc(from_user_to_utc(req_input.user_start, req.zato.user_profile)).isoformat()
        req_input['utc_stop'] = utc.fromutc(from_user_to_utc(req_input.user_stop, req.zato.user_profile)).isoformat()

        req_input['user_start'] = req_input.user_start
        req_input['user_stop'] = req_input.user_stop

    return globals()['_stats_data_{}'.format(req_input.format)](req.zato.user_profile,
        req_input, req.zato.client, req.zato.cluster, stats_type, is_custom)
예제 #4
0
파일: stats.py 프로젝트: dangnammta/zato
def maintenance_delete(req):
    start = from_user_to_utc(req.POST['start'], req.zato.user_profile)
    stop = from_user_to_utc(req.POST['stop'], req.zato.user_profile)

    req.zato.client.invoke('zato.stats.delete', {'start': start, 'stop': stop})

    msg = 'Submitted a request to delete statistics from [{}] to [{}]. Check the server logs for details.'.format(
        from_utc_to_user(start.isoformat() + '+00:00', req.zato.user_profile),
        from_utc_to_user(stop.isoformat() + '+00:00', req.zato.user_profile))

    messages.add_message(req, messages.INFO, msg, extra_tags='success')

    return redirect('{}?cluster={}'.format(reverse('stats-maintenance'),
                                           req.zato.cluster_id))
예제 #5
0
def _get_create_edit_message(user_profile, cluster, params, form_prefix=""):
    """ A dictionary of core data which can be used by both 'edit' and 'create'
    actions, regardless of the job's type.
    """
    start_date = params.get(form_prefix + 'start_date', '')
    if start_date:
        start_date = from_user_to_utc(start_date, user_profile)

    return {
        'name': params[form_prefix + 'name'],
        'cluster_id': cluster.id,
        'id': params.get(form_prefix + 'id', ''),
        'is_active': bool(params.get(form_prefix + 'is_active')),
        'service': params.get(form_prefix + 'service', ''),
        'extra': params.get(form_prefix + 'extra', ''),
        'start_date': start_date.isoformat(),
    }
예제 #6
0
def _get_create_edit_message(user_profile, cluster, params, form_prefix=""):
    """ A dictionary of core data which can be used by both 'edit' and 'create'
    actions, regardless of the job's type.
    """
    start_date = params.get(form_prefix + 'start_date', '')
    if start_date:
        start_date = from_user_to_utc(start_date, user_profile)

    return {
        'name': params[form_prefix + 'name'],
        'cluster_id': cluster.id,
        'id': params.get(form_prefix + 'id', ''),
        'is_active': bool(params.get(form_prefix + 'is_active')),
        'service': params.get(form_prefix + 'service', ''),
        'extra': params.get(form_prefix + 'extra', ''),
        'start_date': start_date.isoformat(),
    }
예제 #7
0
 def on_after_set_input(self):
     for name in ('start', 'stop'):
         if self.input.get(name):
             self.input[name] = from_user_to_utc(self.input[name],
                                                 self.req.zato.user_profile)
예제 #8
0
 def on_after_set_input(self):
     for name in('start', 'stop'):
         if self.input.get(name):
             self.input[name] = from_user_to_utc(self.input[name], self.req.zato.user_profile)