Exemplo n.º 1
0
def slow_response(req, service_name):

    items = []
    
    input_dict = {
        'name': service_name,
    }
    zato_message, soap_response = invoke_admin_service(req.zato.cluster, 
        'zato:service.slow-response.get-list', input_dict)
    
    if zato_path('response.item_list.item').get_from(zato_message) is not None:
        for _item in zato_message.response.item_list.item:
            item = SlowResponse()
            item.cid = _item.cid.text
            item.req_ts = from_utc_to_user(_item.req_ts.text+'+00:00', req.zato.user_profile)
            item.resp_ts = from_utc_to_user(_item.resp_ts.text+'+00:00', req.zato.user_profile)
            item.proc_time = _item.proc_time.text
            item.service_name = service_name
            
            items.append(item)
        
    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': _get_service(req, service_name),
        'items': items,
        }
        
    return TemplateResponse(req, 'zato/service/slow-response.html', return_data)
Exemplo n.º 2
0
def shift(utc_base_date, user_start, user_profile, shift_type, duration, format):
    """ Shifts the base date by the amount specified and returns resulting start
    and stop dates in UTC and user timezone.
    """
    if shift_type not in start_delta_kwargs:
        raise ValueError('Unknown shift_type:[{}]'.format(shift_type))

    _start_delta_kwargs = start_delta_kwargs[shift_type]

    # Special-case month duration because UTC '2012-09-30 22:00:00+00:00' (which is 2012-10-01 CEST)
    # minus one month happens to be '2012-08-30 22:00:00+00:00' instead of '2012-09-31 22:00:00+00:00'
    # so it's 2012-08-30 CEST instead of 2012-09-01. In other words, we would've jumped from Oct 2012 to Aug 2012 directly.

    if duration != 'month':
        utc_start = utc_base_date + relativedelta(**_start_delta_kwargs)
    else:
        user_start = datetime.strptime(user_start, user_profile.month_year_format_strptime)
        current_month_start = datetime(user_start.year, user_start.month, 1)
        prev_month_start = current_month_start + relativedelta(**_start_delta_kwargs)
        utc_start = from_local_to_utc(prev_month_start, user_profile.timezone)

    _stop_delta_kwargs = stop_delta_kwargs[duration]
    utc_stop = utc_start + relativedelta(**_stop_delta_kwargs)

    user_start = from_utc_to_user(utc_start, user_profile, format)
    user_stop = from_utc_to_user(utc_stop, user_profile, format)

    return DateInfo(utc_start.isoformat(), utc_stop.isoformat(), user_start, user_stop)
Exemplo n.º 3
0
def details(req, source_type, cluster_id, msg_id, topic_name):

    item = None
    pretty_print = asbool(req.GET.get('pretty_print'))

    input_dict = {
        'cluster_id': cluster_id,
        'msg_id': msg_id,
    }
    response = req.zato.client.invoke('zato.pubsub.message.get', input_dict)

    if response.has_data:
        item = Message()
        for name in('topic', 'producer', 'priority', 'mime_type', 'expiration', 'creation_time_utc', 'expire_at_utc', 'payload'):
            setattr(item, name, getattr(response.data, name, None))

        item.creation_time = from_utc_to_user(item.creation_time_utc+'+00:00', req.zato.user_profile)
        item.expire_at = from_utc_to_user(item.expire_at_utc+'+00:00', req.zato.user_profile)

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'item': item,
        'pretty_print': not pretty_print,
        'msg_id': msg_id,
        'topic_name': topic_name,
        'source_type': source_type,
        'sub_key': req.GET.get('sub_key')
        }

    return TemplateResponse(req, 'zato/pubsub/message/details.html', return_data)
Exemplo n.º 4
0
def _interval_based_job_def(user_profile, start_date, repeats, weeks, days, hours, minutes, seconds):

    buf = StringIO()

    if start_date:
        buf.write('Start on {0} at {1}.'.format(
            from_utc_to_user(start_date, user_profile, 'date'),
            from_utc_to_user(start_date, user_profile, 'time')))

    if not repeats:
        buf.write(' Repeat indefinitely.')
    else:
        if repeats == 1:
            buf.write(' Execute once.')
        elif repeats == 2:
            buf.write(' Repeat twice.')
        # .. my hand is itching to add 'repeats thrice.' here ;-)
        elif repeats > 2:
            buf.write(' Repeat ')
            buf.write(str(repeats))
            buf.write(' times.')

    interval = []
    buf.write(' Interval: ')
    for name, value in (('week',weeks), ('day',days),
                    ('hour',hours), ('minute',minutes),
                    ('second',seconds)):
        if value:
            value = int(value)
            interval.append('{0} {1}{2}'.format(value, name, 's' if value > 1 else ''))

    buf.write(', '.join(interval))
    buf.write('.')

    return buf.getvalue()
Exemplo n.º 5
0
def audit_log(req, **kwargs):
    out = kwargs
    out['req'] = req

    out.update(get_js_dt_format(req.zato.user_profile))

    for key in('batch_size', 'current_batch', 'start', 'stop', 'state', 'query'):
        value = req.GET.get(key)
        if value:
            out[key] = value

    out['form'] = AuditLogEntryList(initial=out)
    
    request = {
        'conn_id': out['conn_id'],
        'start': out.get('start', ''),
        'stop': out.get('stop'),
        'current_batch': out.get('current_batch', BATCH_DEFAULTS.PAGE_NO),
        'batch_size': out.get('batch_size', BATCH_DEFAULTS.SIZE),
        'query': out.get('query', ''),
    }

    out['items'] = []
    
    response = req.zato.client.invoke('zato.http-soap.get-audit-item-list', request)
    if response.ok:
        for item in response.data:
            item.req_time = from_utc_to_user(item.req_time_utc+'+00:00', req.zato.user_profile)
            item.resp_time = from_utc_to_user(item.resp_time_utc+'+00:00', req.zato.user_profile) if item.resp_time_utc else '(None)'
            out['items'].append(item)
        
    out.update(**req.zato.client.invoke('zato.http-soap.get-audit-batch-info', request).data)
    
    return TemplateResponse(req, 'zato/http_soap/audit/log.html', out)
Exemplo n.º 6
0
def _cron_style_job_def(user_profile, start_date, cron_definition):
    start_date = _get_start_date(start_date)

    buf = StringIO()
    buf.write('Start on {0} at {1}.'.format(
        from_utc_to_user(start_date, user_profile, 'date'),
        from_utc_to_user(start_date, user_profile, 'time')))
    buf.write('<br/>{0}'.format(cron_definition))

    return buf.getvalue()
Exemplo n.º 7
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))
Exemplo n.º 8
0
def slow_response_details(req, cid, service_name):

    item = None
    service = _get_service(req, service_name)
    pretty_print = asbool(req.GET.get('pretty_print'))
    
    input_dict = {
        'cid': cid,
        'name': service_name,
    }
    response = req.zato.client.invoke('zato.service.slow-response.get', input_dict)
    
    if response.has_data:
        cid = response.data.cid
        if cid != ZATO_NONE:
            item = SlowResponse()
            item.cid = response.data.cid
            item.req_ts = from_utc_to_user(response.data.req_ts+'+00:00', req.zato.user_profile)
            item.resp_ts = from_utc_to_user(response.data.resp_ts+'+00:00', req.zato.user_profile)
            item.proc_time = response.data.proc_time
            item.service_name = service_name
            item.threshold = service.slow_threshold
            
            for name in('req', 'resp'):
                value = getattr(response.data, name)
                if value:
                    #value = value.decode('base64')
                    if isinstance(value, dict):
                        value = dumps(value)
                        data_format = 'json'
                    else:
                        data_format = known_data_format(value)
                        
                    if data_format:
                        if pretty_print:
                            value = get_pretty_print(value, data_format)
                        attr_name = name + '_html'
                        setattr(item, attr_name, highlight(value, 
                             data_format_lexer[data_format](), HtmlFormatter(linenos='table')))

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
        'item': item,
        'pretty_print': not pretty_print,
        }
        
    return TemplateResponse(req, 'zato/service/slow-response-details.html', return_data)
Exemplo n.º 9
0
def slow_response_details(req, cid, service_name):

    item = None
    service = _get_service(req, service_name)
    pretty_print = asbool(req.GET.get("pretty_print"))

    input_dict = {"cid": cid, "name": service_name}
    response = req.zato.client.invoke("zato.service.slow-response.get", input_dict)

    if response.has_data:
        cid = response.data.cid
        if cid != ZATO_NONE:
            item = SlowResponse()
            item.cid = response.data.cid
            item.req_ts = from_utc_to_user(response.data.req_ts + "+00:00", req.zato.user_profile)
            item.resp_ts = from_utc_to_user(response.data.resp_ts + "+00:00", req.zato.user_profile)
            item.proc_time = response.data.proc_time
            item.service_name = service_name
            item.threshold = service.slow_threshold

            for name in ("req", "resp"):
                value = getattr(response.data, name)
                if value:
                    # value = value.decode('base64')
                    if isinstance(value, dict):
                        value = dumps(value)
                        data_format = "json"
                    else:
                        data_format = known_data_format(value)

                    if data_format:
                        if pretty_print:
                            value = get_pretty_print(value, data_format)
                        attr_name = name + "_html"
                        setattr(
                            item,
                            attr_name,
                            highlight(value, data_format_lexer[data_format](), HtmlFormatter(linenos="table")),
                        )

    return_data = {
        "cluster_id": req.zato.cluster_id,
        "service": service,
        "item": item,
        "pretty_print": not pretty_print,
    }

    return TemplateResponse(req, "zato/service/slow-response-details.html", return_data)
Exemplo n.º 10
0
def _common_edit_message(
    client, success_msg, id, name, host, up_status, up_mod_date, cluster_id, user_profile, fetch_lb_data=True
):
    """ Returns a common JSON message for both the actual 'edit' and 'add/remove to/from LB' actions.
    """
    return_data = {
        "id": id,
        "name": name,
        "host": host if host else "(unknown)",
        "up_status": up_status if up_status else "(unknown)",
        "up_mod_date": from_utc_to_user(up_mod_date + "+00:00", user_profile) if up_mod_date else "(unknown)",
        "cluster_id": cluster_id if cluster_id else "",
        "lb_state": "(unknown)",
        "lb_address": "(unknown)",
        "in_lb": "(unknown)",
        "message": success_msg.format(name),
    }

    if fetch_lb_data:
        lb_server_data = _get_server_data(client, name)

        return_data.update(
            {"lb_state": lb_server_data.state, "lb_address": lb_server_data.lb_address, "in_lb": lb_server_data.in_lb}
        )

    return HttpResponse(dumps(return_data), mimetype="application/javascript")
Exemplo n.º 11
0
def _common_edit_message(client, success_msg, id, name, host, up_status, up_mod_date, cluster_id, user_profile, fetch_lb_data=True):
    """ Returns a common JSON message for both the actual 'edit' and 'add/remove to/from LB' actions.
    """
    return_data = {
        'id': id,
        'name': name,

        'host': host if host else '(unknown)',
        'up_status': up_status if up_status else '(unknown)',
        'up_mod_date': from_utc_to_user(up_mod_date+'+00:00', user_profile) if up_mod_date else '(unknown)',
        'cluster_id': cluster_id if cluster_id else '',
        
        'lb_state': '(unknown)',
        'lb_address': '(unknown)',
        'in_lb': '(unknown)',
        'message': success_msg.format(name)
    }

    if fetch_lb_data:
        lb_server_data = _get_server_data(client, name)
        
        return_data.update({
            'lb_state': lb_server_data.state,
            'lb_address': lb_server_data.lb_address,
            'in_lb': lb_server_data.in_lb,
        })
    
    return HttpResponse(dumps(return_data), mimetype='application/javascript')
Exemplo n.º 12
0
    def __call__(self, req, initial_input_dict={}, initial_return_data={}, *args, **kwargs):

        edit_name = req.POST.get('edit-name')
        name = req.POST.get('name', edit_name)

        initial_return_data = {
            'current_depth': 0,
            'consumers_count': 0,
            'producers_count': 0,
            'last_pub_time': None,
            'cluster_id': req.zato.cluster_id,
            'name': name,
        }

        if edit_name:
            response = req.zato.client.invoke('zato.pubsub.topics.get-info', {
                'cluster_id': req.zato.cluster_id,
                'name': edit_name
            })

            if response.ok:
                initial_return_data.update(response.data)
                initial_return_data['last_pub_time'] = from_utc_to_user(
                    initial_return_data['last_pub_time'] + '+00:00', req.zato.user_profile)

        return super(_CreateEdit, self).__call__(
            req, initial_input_dict={}, initial_return_data=initial_return_data, *args, **kwargs)
Exemplo n.º 13
0
    def post_process_return_data(self, return_data):
        is_active = False
        for name in('is_active', 'edit-is_active'):
            if name in self.req.POST:
                is_active = True
                break

        return_data['is_active'] = is_active
        return_data['topic_name'] = self.req.POST['topic_name']
        return_data['message'] = 'Successfully {} consumer `{}`'.format(self.verb, return_data['name'])

        return_data['last_seen'] = None
        return_data['current_depth'] = 0

        client_id = self.req.POST.get('id')
        if client_id:
            response = self.req.zato.client.invoke('zato.pubsub.consumers.get-info', {'id': client_id})

            if response.ok:
                return_data['current_depth'] = response.data.current_depth
                return_data['in_flight_depth'] = response.data.in_flight_depth
                return_data['sub_key'] = response.data.sub_key
                if response.data.last_seen:
                    return_data['last_seen'] = from_utc_to_user(response.data.last_seen + '+00:00', self.req.zato.user_profile)

        return return_data
Exemplo n.º 14
0
 def test_shift_prev_week_by_day(self):
     now = parse('2012-03-21T00:39:19+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'today_prev_day_week', 'day', 'date')
     eq_(info.utc_start, '2012-03-14T00:39:19+00:00')
     eq_(info.utc_stop, '2012-03-15T00:39:19+00:00')
     eq_(info.user_start, '14-03-2012')
     eq_(info.user_stop, '15-03-2012')
     eq_(info.step, None)
Exemplo n.º 15
0
 def test_shift_prev_month_by_month(self):
     now = parse('2012-10-01T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile, 'month_year'), self.user_profile, 'this_month_prev_month', 'month', 'month_year')
     eq_(info.utc_start, '2012-08-31T22:00:00+00:00')
     eq_(info.utc_stop, '2012-09-30T22:00:00+00:00')
     eq_(info.user_start, '09-2012')
     eq_(info.user_stop, '10-2012')
     eq_(info.step, None)
Exemplo n.º 16
0
 def test_shift_prev_year_by_year(self):
     now = parse('2012-01-01T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'this_year_prev', 'year', 'year')
     eq_(info.utc_start, '2011-01-01T00:00:00+00:00')
     eq_(info.utc_stop, '2012-01-01T00:00:00+00:00')
     eq_(info.user_start, '2011')
     eq_(info.user_stop, '2012')
     eq_(info.step, None)
Exemplo n.º 17
0
 def test_shift_prev_day_by_day(self):
     now = parse_datetime('2012-03-21T00:39:19+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'today_prev_day', 'day', 'date')
     eq_(info.utc_start, '2012-03-20T00:39:19+00:00')
     eq_(info.utc_stop, '2012-03-21T00:39:19+00:00')
     eq_(info.user_start, '20-03-2012')
     eq_(info.user_stop, '21-03-2012')
     eq_(info.step, None)
Exemplo n.º 18
0
 def test_shift_prev_week_by_week(self):
     now = parse('2012-10-22T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'today_prev_day_week', 'week', 'date')
     eq_(info.utc_start, '2012-10-15T00:00:00+00:00')
     eq_(info.utc_stop, '2012-10-22T00:00:00+00:00')
     eq_(info.user_start, '15-10-2012')
     eq_(info.user_stop, '22-10-2012')
     eq_(info.step, None)
Exemplo n.º 19
0
def endpoint_queue_edit(req):

    sub_id = req.POST['id']
    cluster_id = req.POST['cluster_id']
    endpoint_type = req.POST['endpoint_type']

    # Always available
    request = {
        'id': sub_id,
        'cluster_id': cluster_id,
        'endpoint_type': endpoint_type
    }

    # Need form prefix
    for item in sorted(sub_attrs):
        if item not in ('id', 'cluster_id'):
            key = 'edit-{}'.format(item)
            value = req.POST.get(key)
            request[item] = value

    # Update subscription ..
    req.zato.client.invoke('zato.pubsub.endpoint.update-endpoint-queue', request)

    # .. and read it back - but this time it will include current data about depth.
    service = 'zato.pubsub.endpoint.get-endpoint-queue'
    request = bunchify({
        'id': sub_id,
        'cluster_id': cluster_id,
    })
    service_response = req.zato.client.invoke(service, request).data.response

    service_response.creation_time = from_utc_to_user(service_response.creation_time+'+00:00', req.zato.user_profile)

    if service_response.last_interaction_time:
        service_response.last_interaction_time = from_utc_to_user(
            service_response.last_interaction_time+'+00:00', req.zato.user_profile)

    response = {}
    response['id'] = sub_id
    response['message'] = 'Subscription updated successfully'
    response.update(**service_response)
    response.update(**request)
    response['name_slug'] = slugify(response['name'])

    return HttpResponse(dumps(response), content_type='application/javascript')
Exemplo n.º 20
0
def slow_response_details(req, cid, service_name):

    item = None
    service = _get_service(req, service_name)
    pretty_print = asbool(req.GET.get('pretty_print'))
    
    input_dict = {
        'cid': cid,
        'name': service_name,
    }
    zato_message, soap_response = invoke_admin_service(req.zato.cluster, 
        'zato:service.slow-response.get', input_dict)
    
    if zato_path('response.item').get_from(zato_message) is not None:
        _item = zato_message.response.item
        cid = _item.cid.text
        if cid != ZATO_NONE:
            item = SlowResponse()
            item.cid = _item.cid.text
            item.req_ts = from_utc_to_user(_item.req_ts.text+'+00:00', req.zato.user_profile)
            item.resp_ts = from_utc_to_user(_item.resp_ts.text+'+00:00', req.zato.user_profile)
            item.proc_time = _item.proc_time.text
            item.service_name = service_name
            item.threshold = service.slow_threshold
            
            for name in('req', 'resp'):
                value = getattr(_item, name)
                if value:
                    value = value.text.decode('base64')
                    data_format = known_data_format(value)
                    if data_format:
                        if pretty_print:
                            value = get_pretty_print(value, data_format)
                        attr_name = name + '_html'
                        setattr(item, attr_name, highlight(value, 
                             data_format_lexer[data_format](), HtmlFormatter(linenos='table')))

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
        'item': item,
        'pretty_print': not pretty_print,
        }
        
    return TemplateResponse(req, 'zato/service/slow-response-details.html', return_data)
Exemplo n.º 21
0
 def test_shift_prev_hour(self):
     with patch('zato.common.util._utcnow', self._utcnow):
         now = utcnow()
         info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'last_hour_prev', 'hour', 'date_time')
         eq_(info.utc_start, '2012-02-29T23:47:24.054903+00:00')
         eq_(info.utc_stop, '2012-03-01T00:47:24.054903+00:00')
         eq_(info.user_start, '01-03-2012 00:47:24')
         eq_(info.user_stop, '01-03-2012 01:47:24')
         eq_(info.step, None)
Exemplo n.º 22
0
def request_response(req, service_name):
    service = Service(name=service_name)
    pretty_print = asbool(req.GET.get('pretty_print'))

    input_dict = {'name': service_name, 'cluster_id': req.zato.cluster_id}

    service_response = req.zato.client.invoke(
        'zato.service.get-request-response', input_dict)
    if service_response.ok:
        request = b64decode(service_response.data.sample_req
                            if service_response.data.sample_req else '')
        request = request.decode('utf8')
        request_data_format = known_data_format(request)
        if request_data_format:
            if pretty_print:
                request = get_pretty_print(request, request_data_format)
            service.sample_req_html = highlight(
                request, data_format_lexer[request_data_format](),
                HtmlFormatter(linenos='table'))

        response = b64decode(service_response.data.sample_resp
                             if service_response.data.sample_resp else '')
        response = response.decode('utf8')
        response_data_format = known_data_format(response)
        if response_data_format:
            if pretty_print:
                response = get_pretty_print(response, response_data_format)
            service.sample_resp_html = highlight(
                response, data_format_lexer[response_data_format](),
                HtmlFormatter(linenos='table'))

        service.sample_req = request
        service.sample_resp = response

        ts = {}
        for name in ('req', 'resp'):
            full_name = 'sample_{}_ts'.format(name)
            value = getattr(service_response.data, full_name, '')
            if value:
                value = from_utc_to_user(value + '+00:00',
                                         req.zato.user_profile)
            ts[full_name] = value

        service.id = service_response.data.service_id
        service.sample_cid = service_response.data.sample_cid
        service.sample_req_ts = ts['sample_req_ts']
        service.sample_resp_ts = ts['sample_resp_ts']
        service.sample_req_resp_freq = service_response.data.sample_req_resp_freq

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
        'pretty_print': not pretty_print,
    }

    return TemplateResponse(req, 'zato/service/request-response.html',
                            return_data)
Exemplo n.º 23
0
 def test_shift_prev_week_by_week(self):
     now = parse('2012-10-22T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile),
                  self.user_profile, 'today_prev_day_week', 'week', 'date')
     eq_(info.utc_start, '2012-10-15T00:00:00+00:00')
     eq_(info.utc_stop, '2012-10-22T00:00:00+00:00')
     eq_(info.user_start, '15-10-2012')
     eq_(info.user_stop, '22-10-2012')
     eq_(info.step, None)
Exemplo n.º 24
0
 def test_shift_prev_day(self):
     with patch('zato.common.util._utcnow', self._utcnow):
         now = utcnow()
         info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'today_prev_day', 'hour', 'date_time')
         eq_(info.utc_start, '2012-02-29T00:47:24.054903+00:00')
         eq_(info.utc_stop, '2012-02-29T01:47:24.054903+00:00')
         eq_(info.user_start, '29-02-2012 01:47:24')
         eq_(info.user_stop, '29-02-2012 02:47:24')
         eq_(info.step, None)
Exemplo n.º 25
0
 def test_shift_prev_year_by_year(self):
     now = parse('2012-01-01T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile),
                  self.user_profile, 'this_year_prev', 'year', 'year')
     eq_(info.utc_start, '2011-01-01T00:00:00+00:00')
     eq_(info.utc_stop, '2012-01-01T00:00:00+00:00')
     eq_(info.user_start, '2011')
     eq_(info.user_stop, '2012')
     eq_(info.step, None)
Exemplo n.º 26
0
def slow_response(req, service_name):

    items = []
    input_dict = {"name": service_name}

    for _item in req.zato.client.invoke("zato.service.slow-response.get-list", input_dict):
        item = SlowResponse()
        item.cid = _item.cid
        item.req_ts = from_utc_to_user(_item.req_ts + "+00:00", req.zato.user_profile)
        item.resp_ts = from_utc_to_user(_item.resp_ts + "+00:00", req.zato.user_profile)
        item.proc_time = _item.proc_time
        item.service_name = service_name

        items.append(item)

    return_data = {"cluster_id": req.zato.cluster_id, "service": _get_service(req, service_name), "items": items}

    return TemplateResponse(req, "zato/service/slow-response.html", return_data)
Exemplo n.º 27
0
 def test_shift_prev_week(self):
     with patch('zato.common.util._utcnow', self._utcnow):
         now = utcnow()
         info = shift(now, from_utc_to_user(now, self.user_profile), self.user_profile, 'today_prev_day_week', 'hour', 'date_time')
         eq_(info.utc_start, '2012-02-23T00:47:24.054903+00:00')
         eq_(info.utc_stop, '2012-02-23T01:47:24.054903+00:00')
         eq_(info.user_start, '23-02-2012 01:47:24')
         eq_(info.user_stop, '23-02-2012 02:47:24')
         eq_(info.step, None)
Exemplo n.º 28
0
    def on_before_append_item(self, item):

        item.current_depth_gd = item.current_depth_gd or 0
        item.current_depth_non_gd = item.current_depth_non_gd or 0

        item.name_slug = slugify(item.name)

        item.creation_time_utc = item.creation_time
        item.creation_time = from_utc_to_user(item.creation_time + '+00:00',
                                              self.req.zato.user_profile)

        if item.last_interaction_time:
            item.last_interaction_time_utc = item.last_interaction_time
            item.last_interaction_time = from_utc_to_user(
                item.last_interaction_time + '+00:00',
                self.req.zato.user_profile)

        return item
Exemplo n.º 29
0
def _interval_based_job_def(user_profile, start_date, repeats, weeks, days, hours, minutes, seconds):

    buf = StringIO()

    if start_date:
        buf.write('Start on {0} at {1}.'.format(
            from_utc_to_user(start_date, user_profile, 'date'),
            from_utc_to_user(start_date, user_profile, 'time')))

    if not repeats:
        buf.write(' Repeat indefinitely.')
    else:
        if repeats == 1:
            buf.write(' Execute once.')
        elif repeats == 2:
            buf.write(' Repeat twice.')
        # .. thrice or more
        elif repeats > 2:
            buf.write(' Repeat ')
            if isinstance(repeats, int):
                repeats = str(repeats)
            else:
                repeats = repeats if isinstance(repeats, unicode) else repeats.decode('utf8')
            buf.write(repeats)
            buf.write(' times.')

    interval = []
    buf.write(' Interval: ')
    for name, value in (('week',weeks), ('day',days),
                    ('hour',hours), ('minute',minutes),
                    ('second',seconds)):
        if value:
            try:
                value = int(value)
            except ValueError:
                logger.warn('Cannot convert `%s` `%s` to an int, `%s` `%s` `%s` `%s` `%s` `%s` `%s`',
                    name, value, start_date, repeats, weeks, days, hours, minutes, seconds)
            else:
                interval.append('{0} {1}{2}'.format(value, name, 's' if value > 1 else ''))

    buf.write(', '.join(interval))
    buf.write('.')

    return buf.getvalue()
Exemplo n.º 30
0
    def handle_return_data(self, return_data):

        for item in return_data['items']:

            item.id = fs_safe_name('{}-{}'.format(item.name, item.pid))

            if item.last_gd_run:
                item.last_gd_run_utc = item.last_gd_run
                item.last_gd_run = from_utc_to_user(
                    item.last_gd_run_utc + '+00:00',
                    self.req.zato.user_profile)

            if item.last_task_run:
                item.last_task_run_utc = item.last_task_run
                item.last_task_run = from_utc_to_user(
                    item.last_task_run_utc + '+00:00',
                    self.req.zato.user_profile)

        return return_data
Exemplo n.º 31
0
 def test_shift_prev_month_by_month(self):
     now = parse('2012-10-01T00:00:00+00:00')
     info = shift(now, from_utc_to_user(now, self.user_profile,
                                        'month_year'), self.user_profile,
                  'this_month_prev_month', 'month', 'month_year')
     eq_(info.utc_start, '2012-08-31T22:00:00+00:00')
     eq_(info.utc_stop, '2012-09-30T22:00:00+00:00')
     eq_(info.user_start, '09-2012')
     eq_(info.user_stop, '10-2012')
     eq_(info.step, None)
Exemplo n.º 32
0
    def handle_return_data(self, return_data):

        for item in return_data['items']:

            item.id = fs_safe_name('{}-{}'.format(item.thread_id,
                                                  item.object_id))

            if item.last_gd_run:
                item.last_gd_run_utc = item.last_gd_run
                item.last_gd_run = from_utc_to_user(
                    item.last_gd_run_utc + '+00:00',
                    self.req.zato.user_profile)

            if item.last_delivery:
                item.last_delivery_utc = item.last_delivery
                item.last_delivery = from_utc_to_user(
                    item.last_delivery_utc + '+00:00',
                    self.req.zato.user_profile)

        return return_data
Exemplo n.º 33
0
    def on_before_append_item(self, item):
        if getattr(item, 'callback_list', None):
            item.callback_list = '\n'.join(item.callback_list.split(','))

        for name_utc in('last_updated_utc', 'last_used_utc'):
            value = getattr(item, name_utc, None)
            if value:
                name = name_utc.replace('_utc', '')
                setattr(item, name, from_utc_to_user(value + '+00:00', self.req.zato.user_profile))

        return item
Exemplo n.º 34
0
    def on_before_append_item(self, item, _to_user_dt=('expires_at', 'last_read', 'prev_read', 'last_write', 'prev_write')):

        item.key_escaped = item.key.encode('utf8') if isinstance(item.key, unicode) else item.key
        item.key_escaped = b64encode(item.key_escaped)

        for name in _to_user_dt:
            value = getattr(item, name)
            if value:
                setattr(item, name, from_utc_to_user(value, self.req.zato.user_profile))

        return item
Exemplo n.º 35
0
def request_response(req, service_name):
    service = Service(name=service_name)
    pretty_print = asbool(req.GET.get('pretty_print'))
    
    input_dict = {
        'name': service_name,
        'cluster_id': req.zato.cluster_id
    }
    zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.get-request-response', input_dict)

    if zato_path('response.item').get_from(zato_message) is not None:
        item = zato_message.response.item

        request = (item.sample_req.text if item.sample_req.text else '').decode('base64')
        request_data_format = known_data_format(request)
        if request_data_format:
            if pretty_print:
                request = get_pretty_print(request, request_data_format)
            service.sample_req_html = highlight(request, data_format_lexer[request_data_format](), 
                HtmlFormatter(linenos='table'))

        response = (item.sample_resp.text if item.sample_resp.text else '').decode('base64')
        response_data_format = known_data_format(response)
        if response_data_format:
            if pretty_print:
                response = get_pretty_print(response, response_data_format)
            service.sample_resp_html = highlight(response, data_format_lexer[response_data_format](), 
                HtmlFormatter(linenos='table'))

        service.sample_req = request
        service.sample_resp = response

        ts = {}
        for name in('req', 'resp'):
            full_name = 'sample_{}_ts'.format(name)
            value = getattr(item, full_name).text or ''
            if value:
                value = from_utc_to_user(value+'+00:00', req.zato.user_profile)
            ts[full_name] = value
                
        service.id = item.service_id.text
        service.sample_cid = item.sample_cid.text
        service.sample_req_ts = ts['sample_req_ts']
        service.sample_resp_ts = ts['sample_resp_ts']
        service.sample_req_resp_freq = item.sample_req_resp_freq.text

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
        'pretty_print': not pretty_print,
        }

    return TemplateResponse(req, 'zato/service/request-response.html', return_data)
Exemplo n.º 36
0
    def post_process_return_data(self, return_data):

        return_data['publishers_link'] = '<a href="{}">{}</a>'.format(
            django_url_reverse('pubsub-topic-publishers',
                               kwargs={
                                   'cluster_id': self.req.zato.cluster_id,
                                   'topic_id': return_data['id'],
                                   'name_slug': slugify(return_data['name'])
                               }), 'Publishers')

        return_data['subscribers_link'] = '<a href="{}">{}</a>'.format(
            django_url_reverse('pubsub-topic-subscribers',
                               kwargs={
                                   'cluster_id': self.req.zato.cluster_id,
                                   'topic_id': return_data['id'],
                                   'name_slug': slugify(return_data['name'])
                               }), 'Subscribers')

        item = self.req.zato.client.invoke('zato.pubsub.topic.get', {
            'cluster_id': self.req.zato.cluster_id,
            'id': return_data['id'],
        }).data.response

        return_data['has_gd'] = item.has_gd
        if item.get('last_pub_time'):
            return_data['last_pub_time'] = from_utc_to_user(
                item.last_pub_time + '+00:00', self.req.zato.user_profile)
        else:
            return_data['last_pub_time'] = None

        return_data['current_depth_link'] = """
            <a href="{}?cluster={}">{}</a>
            /
            <a href="{}?cluster={}">{}</a>
            """.format(

            # GD messages
            django_url_reverse('pubsub-topic-messages',
                               kwargs={
                                   'topic_id': return_data['id'],
                                   'name_slug': slugify(return_data['name'])
                               }),
            self.req.zato.cluster_id,
            item.current_depth_gd,

            # Non-GD messages
            django_url_reverse('pubsub-topic-in-ram-backlog',
                               kwargs={
                                   'topic_id': return_data['id'],
                                   'name_slug': slugify(return_data['name'])
                               }),
            self.req.zato.cluster_id,
            item.current_depth_gd)
Exemplo n.º 37
0
def audit_log(req, **kwargs):
    out = kwargs
    out['req'] = req

    out.update(get_js_dt_format(req.zato.user_profile))

    for key in ('batch_size', 'current_batch', 'start', 'stop', 'state',
                'query'):
        value = req.GET.get(key)
        if value:
            out[key] = value

    out['form'] = AuditLogEntryList(initial=out)

    request = {
        'conn_id': out['conn_id'],
        'start': out.get('start', ''),
        'stop': out.get('stop'),
        'current_batch': out.get('current_batch', BATCH_DEFAULTS.PAGE_NO),
        'batch_size': out.get('batch_size', BATCH_DEFAULTS.SIZE),
        'query': out.get('query', ''),
    }

    out['items'] = []

    response = req.zato.client.invoke('zato.http-soap.get-audit-item-list',
                                      request)
    if response.ok:
        for item in response.data:
            item.req_time = from_utc_to_user(item.req_time_utc + '+00:00',
                                             req.zato.user_profile)
            item.resp_time = from_utc_to_user(
                item.resp_time_utc + '+00:00',
                req.zato.user_profile) if item.resp_time_utc else '(None)'
            out['items'].append(item)

    out.update(**req.zato.client.invoke('zato.http-soap.get-audit-batch-info',
                                        request).data)

    return TemplateResponse(req, 'zato/http_soap/audit/log.html', out)
Exemplo n.º 38
0
def manage(req, cluster_id):
    """ GUI for managing HAProxy configuration.
    """
    cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
    client = get_lb_client(cluster)

    lb_start_time = from_utc_to_user(client.get_uptime_info(), req.zato.user_profile)
    lb_config = client.get_config()
    lb_work_config = client.get_work_config()
    lb_work_config['verify_fields'] = ', '.join(['%s=%s' % (k,v) for (k, v) in sorted(lb_work_config['verify_fields'].items())])
    
    form_data = {
        'global_log_host': lb_config['global_']['log']['host'],
        'global_log_port': lb_config['global_']['log']['port'],
        'global_log_level': lb_config['global_']['log']['level'],
        'global_log_facility': lb_config['global_']['log']['facility'],

        'timeout_connect': lb_config['defaults']['timeout_connect'],
        'timeout_client': lb_config['defaults']['timeout_client'],
        'timeout_server': lb_config['defaults']['timeout_server'],

        'http_plain_bind_address':lb_config['frontend']['front_http_plain']['bind']['address'],
        'http_plain_bind_port':lb_config['frontend']['front_http_plain']['bind']['port'],
        'http_plain_log_http_requests':lb_config['frontend']['front_http_plain']['log_http_requests'],
        'http_plain_maxconn':lb_config['frontend']['front_http_plain']['maxconn'],
        'http_plain_monitor_uri':lb_config['frontend']['front_http_plain']['monitor_uri'],
        }

    backends = {}
    for backend_type in lb_config['backend']:
        for name in lb_config['backend'][backend_type]:
            # Is it a server?
            if 'address' in lb_config['backend'][backend_type][name]:
                if not name in backends:
                    backends[name] = {}
                backends[name][backend_type] = {}
                backends[name][backend_type]['address'] = lb_config['backend'][backend_type][name]['address']
                backends[name][backend_type]['port'] = lb_config['backend'][backend_type][name]['port']
                backends[name][backend_type]['extra'] = lb_config['backend'][backend_type][name]['extra']

    backends = OrderedDict(sorted(backends.items(), key=lambda t: t[0]))
    form = ManageLoadBalancerForm(initial=form_data)
    haproxy_alive = _haproxy_alive(client)
    cluster.stats_uri, cluster.stats_port = _haproxy_stat_config(lb_config=lb_config)
    servers_state = client.get_servers_state()

    return_data = {'cluster':cluster, 'lb_start_time':lb_start_time,
                   'lb_config':lb_config, 'lb_work_config':lb_work_config,
                   'form':form, 'backends':backends, 'haproxy_alive':haproxy_alive,
                   'servers_state':servers_state}

    return TemplateResponse(req, 'zato/load_balancer/manage.html', return_data)
Exemplo n.º 39
0
    def on_before_append_item(self, item):
        item.id = item.pub_client_id.replace('.', '-')
        item.connection_time_utc = item.connection_time
        item.connection_time = from_utc_to_user(
            item.connection_time_utc + '+00:00', self.req.zato.user_profile)

        if item.ext_client_name:
            item.ext_client_name = [
                elem.strip() for elem in item.ext_client_name.split(';')
            ]
            item.ext_client_name = '\n'.join(item.ext_client_name)

        return item
Exemplo n.º 40
0
    def post_process_return_data(self, return_data):

        response = self.req.zato.client.invoke('zato.pubsub.endpoint.get-endpoint-summary', {
            'cluster_id': self.req.zato.cluster_id,
            'endpoint_id': self.input.endpoint_id,
        }).data

        if response['last_seen']:
            response['last_seen'] = from_utc_to_user(response['last_seen']+'+00:00', self.req.zato.user_profile)

        if response['last_deliv_time']:
            response['last_deliv_time'] = from_utc_to_user(response['last_deliv_time']+'+00:00', self.req.zato.user_profile)

        response['pubsub_endpoint_queues_link'] = \
            django_url_reverse('pubsub-endpoint-queues',
                    kwargs={
                        'cluster_id':self.req.zato.cluster_id,
                        'endpoint_id':response['id'],
                        'name_slug':slugify(response['endpoint_name'])}
                    ),

        return_data.update(response)
Exemplo n.º 41
0
def request_response(req, service_name):
    service = Service(name=service_name)
    pretty_print = asbool(req.GET.get('pretty_print'))

    input_dict = {
        'name': service_name,
        'cluster_id': req.zato.cluster_id
    }

    service_response = req.zato.client.invoke('zato.service.get-request-response', input_dict)
    if service_response.ok:
        request = (service_response.data.sample_req if service_response.data.sample_req else '').decode('base64')
        request_data_format = known_data_format(request)
        if request_data_format:
            if pretty_print:
                request = get_pretty_print(request, request_data_format)
            service.sample_req_html = highlight(request, data_format_lexer[request_data_format](),
                HtmlFormatter(linenos='table'))

        response = (service_response.data.sample_resp if service_response.data.sample_resp else '').decode('base64')
        response_data_format = known_data_format(response)
        if response_data_format:
            if pretty_print:
                response = get_pretty_print(response, response_data_format)
            service.sample_resp_html = highlight(response, data_format_lexer[response_data_format](),
                HtmlFormatter(linenos='table'))

        service.sample_req = request
        service.sample_resp = response

        ts = {}
        for name in('req', 'resp'):
            full_name = 'sample_{}_ts'.format(name)
            value = getattr(service_response.data, full_name, '')
            if value:
                value = from_utc_to_user(value+'+00:00', req.zato.user_profile)
            ts[full_name] = value

        service.id = service_response.data.service_id
        service.sample_cid = service_response.data.sample_cid
        service.sample_req_ts = ts['sample_req_ts']
        service.sample_resp_ts = ts['sample_resp_ts']
        service.sample_req_resp_freq = service_response.data.sample_req_resp_freq

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': service,
        'pretty_print': not pretty_print,
        }

    return TemplateResponse(req, 'zato/service/request-response.html', return_data)
Exemplo n.º 42
0
 def _update_item(server_name, lb_address, lb_state):
     for item in items:
         if item.name == server_name:
             item.in_lb = True
             item.lb_address = lb_address
             item.lb_state = lb_state
             
             if item.up_mod_date:
                 item.up_mod_date_user = from_utc_to_user(item.up_mod_date.replace(tzinfo=UTC).isoformat(), req.zato.user_profile)
                
             if item.up_status == SERVER_UP_STATUS.RUNNING:
                 item.may_be_deleted = False
             else:
                 item.may_be_deleted = True
Exemplo n.º 43
0
    def get_today(_user_profile, _format):
        """ user_start is today's midnight but it needs to be in user's TZ. user_stop is current time simply,
        in user's timezone again.
        """
        user_now = now(timezone(_user_profile.timezone)).replace(tzinfo=None)
        user_today_midnight = datetime(user_now.year, user_now.month, user_now.day)

        utc_start = from_local_to_utc(user_today_midnight, _user_profile.timezone)
        utc_stop = from_local_to_utc(user_now, _user_profile.timezone)

        user_start = from_utc_to_user(utc_start, _user_profile, _format)
        user_stop = None

        return utc_start, utc_stop, user_start, user_stop
Exemplo n.º 44
0
 def _update_item(server_name, lb_address, lb_state):
     for item in items:
         if item.name == server_name:
             item.in_lb = True
             item.lb_address = lb_address
             item.lb_state = lb_state
             
             if item.up_mod_date:
                 item.up_mod_date_user = from_utc_to_user(item.up_mod_date.replace(tzinfo=UTC).isoformat(), req.zato.user_profile)
                
             if item.up_status == SERVER_UP_STATUS.RUNNING:
                 item.may_be_deleted = False
             else:
                 item.may_be_deleted = True
Exemplo n.º 45
0
def servers(req):
    """ A view for server management.
    """
    items = req.zato.odb.query(Server).order_by(Server.name).all()

    for item in items:
        if item.up_mod_date:
            item.up_mod_date_user = from_utc_to_user(
                item.up_mod_date.replace(tzinfo=UTC).isoformat(),
                req.zato.user_profile)

    try:
        client = get_lb_client(req.zato.get('cluster'))
        server_data_dict = client.get_server_data_dict()
        bck_http_plain = client.get_config()['backend']['bck_http_plain']
        lb_client_invoked = True
    except Exception:
        logger.error(format_exc())
        lb_client_invoked = False

    if lb_client_invoked:

        def _update_item(server_name, lb_address, lb_state):
            for item in items:
                if item.name == server_name:
                    item.in_lb = True
                    item.lb_address = lb_address
                    item.lb_state = lb_state

                    if item.up_status == SERVER_UP_STATUS.RUNNING:
                        item.may_be_deleted = False
                    else:
                        item.may_be_deleted = True

        for server_name in bck_http_plain:
            lb_address = '{}:{}'.format(bck_http_plain[server_name]['address'],
                                        bck_http_plain[server_name]['port'])
            _update_item(server_name, lb_address,
                         server_data_dict[server_name]['state'])

    return_data = {
        'items': items,
        'search_form': req.zato.search_form,
        'zato_clusters': req.zato.clusters,
        'cluster': req.zato.get('cluster'),
        'edit_form': EditServerForm(prefix='edit')
    }

    return TemplateResponse(req, 'zato/cluster/servers.html', return_data)
Exemplo n.º 46
0
    def handle_return_data(self, return_data):

        for item in return_data['items']:

            item.id = fs_safe_name(item.py_object)

            if item.last_sync:
                item.last_sync_utc = item.last_sync
                item.last_sync = from_utc_to_user(
                    item.last_sync_utc + '+00:00', self.req.zato.user_profile)

            if item.last_sync_sk:
                item.last_sync_sk_utc = item.last_sync_sk
                item.last_sync_sk = from_utc_to_user(
                    item.last_sync_sk_utc + '+00:00',
                    self.req.zato.user_profile)

            if item.last_iter_run:
                item.last_iter_run_utc = item.last_iter_run
                item.last_iter_run = from_utc_to_user(
                    item.last_iter_run_utc + '+00:00',
                    self.req.zato.user_profile)

        return return_data
Exemplo n.º 47
0
def slow_response(req, service_name):

    items = []
    input_dict = {
        'name': service_name,
    }

    for _item in req.zato.client.invoke('zato.service.slow-response.get-list', input_dict):
        item = SlowResponse()
        item.cid = _item.cid
        item.req_ts = from_utc_to_user(_item.req_ts+'+00:00', req.zato.user_profile)
        item.resp_ts = from_utc_to_user(_item.resp_ts+'+00:00', req.zato.user_profile)
        item.proc_time = _item.proc_time
        item.service_name = service_name

        items.append(item)

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': _get_service(req, service_name),
        'items': items,
        }

    return TemplateResponse(req, 'zato/service/slow-response.html', return_data)
Exemplo n.º 48
0
def slow_response(req, service_name):

    items = []
    input_dict = {
        'name': service_name,
    }

    for _item in req.zato.client.invoke('zato.service.slow-response.get-list', input_dict):
        item = SlowResponse()
        item.cid = _item.cid
        item.req_ts = from_utc_to_user(_item.req_ts+'+00:00', req.zato.user_profile)
        item.resp_ts = from_utc_to_user(_item.resp_ts+'+00:00', req.zato.user_profile)
        item.proc_time = _item.proc_time
        item.service_name = service_name

        items.append(item)

    return_data = {
        'cluster_id': req.zato.cluster_id,
        'service': _get_service(req, service_name),
        'items': items,
        }

    return TemplateResponse(req, 'zato/service/slow-response.html', return_data)
Exemplo n.º 49
0
def _index(req, cluster_id, topic_name, source_name, source_type):
    items = []
    input_dict = {
        'cluster_id': cluster_id,
        'source_name':source_name,
        'source_type': source_type
    }

    for _item in req.zato.client.invoke('zato.pubsub.message.get-list', input_dict):
        _item = Message(**_item)
        _item.creation_time = from_utc_to_user(_item.creation_time_utc+'+00:00', req.zato.user_profile)
        _item.expire_at = from_utc_to_user(_item.expire_at_utc+'+00:00', req.zato.user_profile)
        _item.id = _item.msg_id
        items.append(_item)

    return_data = {
        'topic_name': topic_name,
        'cluster_id': req.zato.cluster_id,
        'items': items,
        'source_type': source_type,
        'source_name': source_name
        }

    return TemplateResponse(req, 'zato/pubsub/message/index.html', return_data)
Exemplo n.º 50
0
    def get_today(_user_profile, _format):
        """ user_start is today's midnight but it needs to be in user's TZ. user_stop is current time simply,
        in user's timezone again.
        """
        user_now = now(timezone(_user_profile.timezone)).replace(tzinfo=None)
        user_today_midnight = datetime(user_now.year, user_now.month,
                                       user_now.day)

        utc_start = from_local_to_utc(user_today_midnight,
                                      _user_profile.timezone)
        utc_stop = from_local_to_utc(user_now, _user_profile.timezone)

        user_start = from_utc_to_user(utc_start, _user_profile, _format)
        user_stop = None

        return utc_start, utc_stop, user_start, user_stop
Exemplo n.º 51
0
def _common_edit_message(client,
                         success_msg,
                         id,
                         name,
                         host,
                         up_status,
                         up_mod_date,
                         cluster_id,
                         user_profile,
                         fetch_lb_data=True):
    """ Returns a common JSON message for both the actual 'edit' and 'add/remove to/from LB' actions.
    """
    return_data = {
        'id':
        id,
        'name':
        name,
        'host':
        host if host else '(unknown)',
        'up_status':
        up_status if up_status else '(unknown)',
        'up_mod_date':
        from_utc_to_user(up_mod_date + '+00:00', user_profile)
        if up_mod_date else '(unknown)',
        'cluster_id':
        cluster_id if cluster_id else '',
        'lb_state':
        '(unknown)',
        'lb_address':
        '(unknown)',
        'in_lb':
        '(unknown)',
        'message':
        success_msg.format(name)
    }

    if fetch_lb_data:
        lb_server_data = _get_server_data(client, name)

        return_data.update({
            'lb_state': lb_server_data.state,
            'lb_address': lb_server_data.lb_address,
            'in_lb': lb_server_data.in_lb,
        })

    return HttpResponse(dumps(return_data),
                        content_type='application/javascript')
Exemplo n.º 52
0
def request_response(req, service_name):
    service = Service(name=service_name)
    pretty_print = asbool(req.GET.get("pretty_print"))

    input_dict = {"name": service_name, "cluster_id": req.zato.cluster_id}

    service_response = req.zato.client.invoke("zato.service.get-request-response", input_dict)
    if service_response.ok:
        request = (service_response.data.sample_req if service_response.data.sample_req else "").decode("base64")
        request_data_format = known_data_format(request)
        if request_data_format:
            if pretty_print:
                request = get_pretty_print(request, request_data_format)
            service.sample_req_html = highlight(
                request, data_format_lexer[request_data_format](), HtmlFormatter(linenos="table")
            )

        response = (service_response.data.sample_resp if service_response.data.sample_resp else "").decode("base64")
        response_data_format = known_data_format(response)
        if response_data_format:
            if pretty_print:
                response = get_pretty_print(response, response_data_format)
            service.sample_resp_html = highlight(
                response, data_format_lexer[response_data_format](), HtmlFormatter(linenos="table")
            )

        service.sample_req = request
        service.sample_resp = response

        ts = {}
        for name in ("req", "resp"):
            full_name = "sample_{}_ts".format(name)
            value = getattr(service_response.data, full_name, "")
            if value:
                value = from_utc_to_user(value + "+00:00", req.zato.user_profile)
            ts[full_name] = value

        service.id = service_response.data.service_id
        service.sample_cid = service_response.data.sample_cid
        service.sample_req_ts = ts["sample_req_ts"]
        service.sample_resp_ts = ts["sample_resp_ts"]
        service.sample_req_resp_freq = service_response.data.sample_req_resp_freq

    return_data = {"cluster_id": req.zato.cluster_id, "service": service, "pretty_print": not pretty_print}

    return TemplateResponse(req, "zato/service/request-response.html", return_data)
Exemplo n.º 53
0
def servers(req):
    """ A view for server management.
    """
    items = req.zato.odb.query(Server).order_by(Server.name).all()

    for item in items:
        if item.up_mod_date:
            item.up_mod_date_user = from_utc_to_user(
                item.up_mod_date.replace(tzinfo=UTC).isoformat(),
                req.zato.user_profile)

    try:
        client = get_lb_client(req.zato.get('cluster'))
        server_data_dict = client.get_server_data_dict()
        bck_http_plain = client.get_config()['backend']['bck_http_plain']
        lb_client_invoked = True
    except Exception, e:
        logger.error(format_exc(e))
        lb_client_invoked = False
Exemplo n.º 54
0
    def handle(self):
        
        out = {}
        service = 'zato.pattern.delivery.get-history-list'
        req = {'task_id': self.input['task_id']}
        response = self.req.zato.client.invoke(service, req)
        
        if self.item:
            out['has_item'] = True
            out['show_resubmit_button'] = self.item.state in([DELIVERY_STATE.IN_DOUBT, DELIVERY_STATE.CONFIRMED, DELIVERY_STATE.FAILED])
            out['show_update_button'] = not out['show_resubmit_button']
        else:
            out['has_item'] = False

        if response.ok:
            for item in response.data:
                item.entry_time = from_utc_to_user(item.entry_time + '+00:00', self.req.zato.user_profile)
            out['history'] = response.data
        else:
            logger.warn(response.details)
            
        return out
Exemplo n.º 55
0
    def handle_return_data(self, return_data):

        # Get task metadata from a relevant service
        response = self.req.zato.client.invoke(
            'zato.pubsub.task.delivery.get-delivery-task', {
                'server_name': self.input.server_name,
                'server_pid': self.input.server_pid,
                'python_id': self.input.python_id,
            })
        return_data['task'] = response.data

        # Handle the list of results now
        for item in return_data['items']:

            item.id = item.msg_id

            if item.recv_time:
                item.recv_time_utc = item.recv_time
                item.recv_time = from_utc_to_user(
                    item.recv_time_utc + '+00:00', self.req.zato.user_profile)

        return return_data
Exemplo n.º 56
0
    def __call__(self,
                 req,
                 initial_input_dict={},
                 initial_return_data={},
                 *args,
                 **kwargs):

        edit_name = req.POST.get('edit-name')
        name = req.POST.get('name', edit_name)

        initial_return_data = {
            'current_depth': 0,
            'consumers_count': 0,
            'producers_count': 0,
            'last_pub_time': None,
            'cluster_id': req.zato.cluster_id,
            'name': name,
        }

        if edit_name:
            response = req.zato.client.invoke('zato.pubsub.topics.get-info', {
                'cluster_id': req.zato.cluster_id,
                'name': edit_name
            })

            if response.ok:
                initial_return_data.update(response.data)
                if initial_return_data['last_pub_time']:
                    initial_return_data['last_pub_time'] = from_utc_to_user(
                        initial_return_data['last_pub_time'] + '+00:00',
                        req.zato.user_profile)

        return super(_CreateEdit,
                     self).__call__(req,
                                    initial_input_dict={},
                                    initial_return_data=initial_return_data,
                                    *args,
                                    **kwargs)
Exemplo n.º 57
0
 def on_before_append_item(self, item):
     item.recv_time = from_utc_to_user(item.recv_time + '+00:00',
                                       self.req.zato.user_profile)
     return item
Exemplo n.º 58
0
 def on_before_append_item(self, item):
     item.pub_time = from_utc_to_user(item.pub_time + '+00:00',
                                      self.req.zato.user_profile)
     item.endpoint_html = get_endpoint_html(item, self.req.zato.cluster_id)
     return item