예제 #1
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)
예제 #2
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)
예제 #3
0
파일: endpoint.py 프로젝트: ptzagk/zato
    def on_before_append_item(self, item):
        item.creation_time_utc = item.creation_time
        item.creation_time = from_utc_to_user(item.creation_time + '+00:00',
                                              self.req.zato.user_profile)
        item.name_slug = slugify(item.name)

        return item
예제 #4
0
    def handle(self):

        service_response = self.req.zato.client.invoke(
            'zato.pubsub.endpoint.get-endpoint-queue', {
                'cluster_id': self.req.zato.cluster_id,
                'id': self.input.sub_id,
            }).data.response

        return {
            'sub_id': self.input.sub_id,
            'name': service_response.name,
            'name_slug': slugify(service_response.name),
            'endpoint_id': service_response.endpoint_id,
            'ws_ext_client_id': service_response.ws_ext_client_id
        }
예제 #5
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
예제 #6
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')
예제 #7
0
def enrich_item(cluster_id, item):
    item.topic_patterns = item.topic_patterns or ''
    item.topic_patterns_html = '<br/>'.join(item.topic_patterns.splitlines())

    is_pub = 'pub' in item.role
    is_sub = 'sub' in item.role

    # Making a copy because it will be replaced with a concatenation of sec_type and security_id,
    # yet we still need it for the client string.
    security_id = item.security_id

    if item.security_id:
        item.security_id = '{}/{}'.format(item.sec_type, item.security_id)

    item.client_html = get_client_html(item, security_id, cluster_id)

    html_kwargs = {
        'cluster_id': cluster_id,
        'endpoint_id': item.id,
        'name_slug': slugify(item.name)
    }

    if is_pub:
        endpoint_topics_path = django_url_reverse('pubsub-endpoint-topics',
                                                  kwargs=html_kwargs)
        item.endpoint_topics_html = '<a href="{}">Topics</a>'.format(
            endpoint_topics_path)
    else:
        item.endpoint_topics_html = '<span class="form_hint">---</span>'

    if is_sub:
        endpoint_queues_path = django_url_reverse('pubsub-endpoint-queues',
                                                  kwargs=html_kwargs)
        item.endpoint_queues_html = '<a href="{}">Queues</a>'.format(
            endpoint_queues_path)
    else:
        item.endpoint_queues_html = '<span class="form_hint">---</span>'

    # This is also needed by the edit action so as not to construct it in JavaScript
    if item.is_internal:
        item.delete_html = '<span class="form_hint">Delete</span>'
    else:
        item.delete_html = """<a href="javascript:$.fn.zato.pubsub.endpoint.delete_('{}')">Delete</a>""".format(
            item.id)

    return item
예제 #8
0
 def post_process_return_data(self, return_data):
     return_data['name_slug'] = slugify(return_data['name'])
     return return_data
예제 #9
0
파일: message.py 프로젝트: henryw2019/zato
def get(req, cluster_id, object_type, object_id, msg_id):

    return_data = bunchify({
        'action': 'update',
    })

    return_data.cluster_id = cluster_id
    return_data.object_type = object_type
    return_data['{}_id'.format(object_type)] = object_id
    return_data.msg_id = msg_id

    if object_type == 'topic':
        object_service_name = 'zato.pubsub.topic.get'
        msg_service_name = 'zato.pubsub.message.get-from-topic'
    else:
        object_service_name = 'zato.pubsub.endpoint.get-endpoint-queue'
        msg_service_name = 'zato.pubsub.message.get-from-queue'

    object_service_response = req.zato.client.invoke(object_service_name, {
        'cluster_id': cluster_id,
        'id': object_id,
    }).data.response

    return_data.object_name = object_service_response.name

    if object_type == 'queue':
        return_data.ws_ext_client_id = object_service_response.ws_ext_client_id

    return_data.object_name_slug = slugify(return_data.object_name)

    try:
        msg_service_response = req.zato.client.invoke(msg_service_name, {
            'cluster_id': cluster_id,
            'msg_id': msg_id,
        }).data.response

    except Exception:
        return_data.has_msg = False

    else:
        return_data.has_msg = True
        return_data.update(msg_service_response)

        if object_type == 'topic':
            hook_pub_endpoint_id = return_data.endpoint_id
            hook_sub_endpoint_id = None
            return_data.object_id = return_data.pop('topic_id')
            return_data.pub_endpoint_html = get_endpoint_html(
                return_data, cluster_id)
        else:

            # If it's a queue, we still need to get metadata about the message's underlying publisher
            topic_msg_service_response = req.zato.client.invoke(
                'zato.pubsub.message.get-from-topic', {
                    'cluster_id': cluster_id,
                    'msg_id': msg_id,
                }).data.response

            return_data.topic_id = topic_msg_service_response.topic_id
            return_data.topic_name = topic_msg_service_response.topic_name
            return_data.pub_endpoint_id = topic_msg_service_response.endpoint_id
            return_data.pub_endpoint_name = topic_msg_service_response.endpoint_name
            return_data.pub_pattern_matched = topic_msg_service_response.pattern_matched
            return_data.pub_endpoint_html = get_endpoint_html(
                return_data, cluster_id, 'pub_endpoint_id',
                'pub_endpoint_name')
            return_data.sub_endpoint_html = get_endpoint_html(
                return_data, cluster_id)
            return_data.object_id = return_data.pop('queue_id')

            hook_pub_endpoint_id = return_data.pub_endpoint_id
            hook_sub_endpoint_id = return_data.endpoint_id

        hook_pub_service_response = req.zato.client.invoke(
            'zato.pubsub.hook.get-hook-service', {
                'cluster_id': cluster_id,
                'endpoint_id': hook_pub_endpoint_id,
                'hook_type': PUBSUB.HOOK_TYPE.PUB,
            }).data.response
        return_data.hook_pub_service_id = hook_pub_service_response.id
        return_data.hook_pub_service_name = hook_pub_service_response.name

        if hook_sub_endpoint_id:
            hook_sub_service_response = req.zato.client.invoke(
                'zato.pubsub.hook.get-hook-service', {
                    'cluster_id': cluster_id,
                    'endpoint_id': hook_sub_endpoint_id,
                    'hook_type': PUBSUB.HOOK_TYPE.SUB,
                }).data.response
            return_data.hook_sub_service_id = hook_sub_service_response.id
            return_data.hook_sub_service_name = hook_sub_service_response.name

        return_data.form = MsgForm(return_data)

        for name in ('pub_time', 'ext_pub_time', 'expiration_time',
                     'recv_time'):
            value = return_data.get(name)
            if value:
                return_data[name] = from_utc_to_user(value + '+00:00',
                                                     req.zato.user_profile)
                return_data[name + '_utc'] = value

    return TemplateResponse(req, 'zato/pubsub/message-details.html',
                            return_data)
예제 #10
0
파일: message.py 프로젝트: whaker/zato
def get(req, cluster_id, object_type, object_id, msg_id):

    return_data = bunchify({
        'action': 'update',
    })

    _has_gd = asbool(req.GET['has_gd'])
    _server_name = req.GET.get('server_name')
    _server_pid = req.GET.get('server_pid')

    _is_topic = object_type == 'topic'
    suffix = '-gd' if _has_gd else '-non-gd'

    input_dict = {
        'cluster_id': cluster_id,
        'msg_id': msg_id,
    }

    if not _has_gd:
        input_dict['server_name'] = _server_name
        input_dict['server_pid'] = _server_pid

    return_data.cluster_id = cluster_id
    return_data.object_type = object_type
    return_data['{}_id'.format(object_type)] = object_id
    return_data.msg_id = msg_id
    return_data.server_name = _server_name
    return_data.server_pid = _server_pid
    return_data.has_gd = _has_gd

    if _is_topic:
        object_service_name = 'zato.pubsub.topic.get'
        msg_service_name = 'zato.pubsub.message.get-from-topic' + suffix
    else:
        object_service_name = 'zato.pubsub.endpoint.get-endpoint-queue'
        msg_service_name = 'zato.pubsub.message.get-from-queue' + suffix
        input_dict['sub_key'] = req.GET['sub_key']

    object_service_response = req.zato.client.invoke(object_service_name, {
        'cluster_id': cluster_id,
        'id': object_id,
    }).data.response

    return_data.object_name = object_service_response.name

    if object_type == 'queue':
        return_data.ws_ext_client_id = object_service_response.ws_ext_client_id

    return_data.object_name_slug = slugify(return_data.object_name)

    try:
        msg_service_response = req.zato.client.invoke(msg_service_name,
                                                      input_dict).data.response
    except Exception:
        logger.warn(format_exc())
        return_data.has_msg = False
    else:
        if not msg_service_response['msg_id']:
            return_data.has_msg = False
        else:
            return_data.has_msg = True
            return_data.update(msg_service_response)

            return_data.pub_endpoint_html = get_endpoint_html(
                return_data, cluster_id, 'published_by_id',
                'published_by_name')
            return_data.sub_endpoint_html = get_endpoint_html(
                return_data, cluster_id, 'subscriber_id', 'subscriber_name')

            if _is_topic:
                hook_pub_endpoint_id = return_data.endpoint_id
                hook_sub_endpoint_id = None
                return_data.object_id = return_data.pop('topic_id')
                return_data.pub_endpoint_html = get_endpoint_html(
                    return_data, cluster_id)
            else:

                # If it's a GD queue, we still need to get metadata about the message's underlying publisher
                if _has_gd:
                    topic_msg_service_response = req.zato.client.invoke(
                        'zato.pubsub.message.get-from-topic' + suffix, {
                            'cluster_id': cluster_id,
                            'msg_id': msg_id,
                            'needs_sub_queue_check': False,
                        }).data.response

                    return_data.topic_id = topic_msg_service_response.topic_id
                    return_data.topic_name = topic_msg_service_response.topic_name
                    return_data.pub_endpoint_id = topic_msg_service_response.endpoint_id
                    return_data.pub_endpoint_name = topic_msg_service_response.endpoint_name
                    return_data.pub_pattern_matched = topic_msg_service_response.pub_pattern_matched
                    return_data.pub_endpoint_html = get_endpoint_html(
                        return_data, cluster_id, 'pub_endpoint_id',
                        'pub_endpoint_name')
                    return_data.sub_endpoint_html = get_endpoint_html(
                        return_data, cluster_id, 'subscriber_id',
                        'subscriber_name')
                    return_data.object_id = return_data.pop('queue_id')

                    hook_pub_endpoint_id = return_data.pub_endpoint_id
                    hook_sub_endpoint_id = return_data.subscriber_id

                    hook_pub_service_response = req.zato.client.invoke(
                        'zato.pubsub.hook.get-hook-service', {
                            'cluster_id': cluster_id,
                            'endpoint_id': hook_pub_endpoint_id,
                            'hook_type': PUBSUB.HOOK_TYPE.BEFORE_PUBLISH,
                        }).data.response
                    return_data.hook_pub_service_id = hook_pub_service_response.id
                    return_data.hook_pub_service_name = hook_pub_service_response.name

                    if hook_sub_endpoint_id:
                        hook_sub_service_response = req.zato.client.invoke(
                            'zato.pubsub.hook.get-hook-service', {
                                'cluster_id': cluster_id,
                                'endpoint_id': hook_sub_endpoint_id,
                                'hook_type': PUBSUB.HOOK_TYPE.BEFORE_DELIVERY,
                            }).data.response
                        return_data.hook_sub_service_id = hook_sub_service_response.id
                        return_data.hook_sub_service_name = hook_sub_service_response.name

            return_data.form = MsgForm(return_data)

            for name in ('pub_time', 'ext_pub_time', 'expiration_time',
                         'recv_time'):
                value = return_data.get(name)
                if value:
                    return_data[name] = from_utc_to_user(
                        value + '+00:00', req.zato.user_profile)
                    return_data[name + '_utc'] = value

    return TemplateResponse(req, 'zato/pubsub/message-details.html',
                            return_data)