Exemplo n.º 1
0
def overview(req, service_name):
    cluster_id = req.GET.get('cluster')
    service = None

    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':

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

        response = req.zato.client.invoke('zato.service.get-by-name',
                                          input_dict)
        if response.has_data:
            service = Service()

            for name in ('id', 'name', 'is_active', 'impl_name', 'is_internal',
                         'usage', 'time_last', 'time_min_all_time',
                         'time_max_all_time', 'time_mean_all_time'):

                value = getattr(response.data, name)
                if name in ('is_active', 'is_internal'):
                    value = is_boolean(value)

                setattr(service, name, value)

            now = datetime.utcnow()
            start = now + relativedelta(minutes=-60)

            response = req.zato.client.invoke('zato.stats.get-by-service', {
                'service_id': service.id,
                'start': start,
                'stop': now
            })
            if response.has_data:
                for name in ('mean_trend', 'usage_trend', 'min_resp_time',
                             'max_resp_time', 'mean', 'usage', 'rate'):
                    value = getattr(response.data, name)
                    if not value or value == ZATO_NONE:
                        value = ''

                    setattr(service, 'time_{}_1h'.format(name), value)

            for channel_type in ('plain_http', 'soap', 'amqp', 'jms-wmq',
                                 'zmq'):
                channels = _get_channels(req.zato.client, req.zato.cluster,
                                         service.id, channel_type)
                getattr(service,
                        channel_type.replace('jms-', '') +
                        '_channels').extend(channels)

            for item in req.zato.client.invoke(
                    'zato.service.get-deployment-info-list',
                {'id': service.id}):
                service.deployment_info.append(
                    DeploymentInfo(item.server_name, item.details))

            # TODO: There needs to be a new service added zato.service.scheduler.job.get-by-service
            #       or .get-list should start accept a service name. Right now we pull all the
            #       jobs which is suboptimal.
            response = req.zato.client.invoke('zato.scheduler.job.get-list',
                                              {'cluster_id': cluster_id})
            if response.has_data:
                for item in response.data:
                    if item.service_name == service_name:
                        url = reverse('scheduler')
                        url += '?cluster={}'.format(cluster_id)
                        url += '&highlight={}'.format(item.id)
                        service.scheduler_jobs.append(
                            ExposedThrough(item.id, item.name, url))

    return_data = {
        'zato_clusters': req.zato.clusters,
        'service': service,
        'cluster_id': cluster_id,
        'search_form': req.zato.search_form,
        'create_form': create_form,
        'edit_form': edit_form,
    }

    return TemplateResponse(req, 'zato/service/overview.html', return_data)
Exemplo n.º 2
0
 def handle(self):
     return {
         'create_form': CreateForm(),
         'edit_form': EditForm(prefix='edit')
     }