示例#1
0
文件: scheduler.py 项目: dsuch/zato
def execute(req, job_id, cluster_id):
    """ Executes a scheduler's job.
    """
    try:
        invoke_admin_service(req.zato.cluster, 'zato:scheduler.job.execute', {'id':job_id})
    except Exception, e:
        msg = 'Could not execute the job. job_id:[{0}], cluster_id:[{1}], e:[{2}]'.format(job_id, cluster_id, format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#2
0
def delete(req, id, cluster_id):
    try:
        invoke_admin_service(
            req.zato.cluster,
            "zato:security.tech-account.delete",
            {"id": id, "zato_admin_tech_account_name": TECH_ACCOUNT_NAME},
        )
    except Exception, e:
        msg = "Could not delete the technical account, e:[{e}]".format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#3
0
文件: scheduler.py 项目: brtsz/zato
def _execute(server_address, params):
    """ Submits a request for an execution of a job.
    """
    logger.info('About to submit a request for an execution of a job, server_address=[%s], params=[%s]' % (server_address, params))

    zato_message = Element('{%s}zato_message' % zato_namespace)
    zato_message.job = Element('job')
    zato_message.job.name = params['name']
    invoke_admin_service(server_address, 'zato:scheduler.job.execute', etree.tostring(zato_message))

    logger.info('Successfully submitted a request, server_address=[%s], params=[%s]' % (server_address, params))
示例#4
0
文件: stats.py 项目: dsuch/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)
    
    invoke_admin_service(req.zato.cluster, '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, req.zato.user_profile), 
        from_utc_to_user(stop, 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
文件: __init__.py 项目: dsuch/zato
def change_password(req, service_name, field1='password1', field2='password2', success_msg='Password updated'):
    try:
        input_dict = {
            'id': req.POST.get('id'),
            'password1': req.POST.get(field1, ''),
            'password2': req.POST.get(field2, ''),
        }
        invoke_admin_service(req.zato.cluster, service_name, input_dict)

    except Exception, e:
        msg = 'Could not change the password, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#6
0
文件: __init__.py 项目: dsuch/zato
 def __call__(self, req, initial_input_dict={}, *args, **kwargs):
     try:
         super(Delete, self).__call__(req, *args, **kwargs)
         input_dict = {
             'id': self.req.zato.id,
             'cluster_id': self.cluster_id
         }
         input_dict.update(initial_input_dict)
         invoke_admin_service(self.req.zato.cluster, self.soap_action, input_dict)
         return HttpResponse()
     except Exception, e:
         msg = '{}, e:[{}]'.format(self.error_message, format_exc(e))
         logger.error(msg)
         return HttpResponseServerError(msg)
示例#7
0
文件: service.py 项目: dsuch/zato
def request_response_configure(req, service_name, cluster_id):
    try:
        input_dict = {
            'name': service_name,
            'cluster_id': req.zato.cluster_id,
            'sample_req_resp_freq': req.POST['sample_req_resp_freq']
        }
        invoke_admin_service(req.zato.cluster, 'zato:service.configure-request-response', input_dict)
        return HttpResponse('Saved successfully')

    except Exception, e:
        msg = 'Could not update the configuration, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#8
0
def edit(req):
    
    prefix = 'edit-'

    cluster_id = req.POST['cluster_id']
    tech_account_id = req.POST['id']
    name = req.POST[prefix + 'name']
    is_active = req.POST.get(prefix + 'is_active')
    is_active = True if is_active else False
    
    cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()

    try:
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        zato_message.data.tech_account_id = tech_account_id
        zato_message.data.name = name
        zato_message.data.is_active = is_active
        
        _, zato_message, soap_response = invoke_admin_service(cluster,
                        'zato:security.tech-account.edit', zato_message)
    
    except Exception, e:
        msg = "Could not update the technical account, e=[{e}]".format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#9
0
文件: amqp.py 项目: dsuch/zato
def _edit_create_response(cluster, verb, id, name, def_id):
    zato_message, soap_response  = invoke_admin_service(cluster, 'zato:definition.amqp.get-by-id', {'id':def_id})
    return_data = {'id': id,
                   'message': 'Successfully {0} the AMQP channel [{1}]'.format(verb, name),
                   'def_name': zato_message.response.item.name.text
                }
    return HttpResponse(dumps(return_data), mimetype='application/javascript')
示例#10
0
文件: scheduler.py 项目: brtsz/zato
def execute(req, job_id, cluster_id):
    """ Executes a scheduler's job.
    """
    try:
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.id = job_id

        invoke_admin_service(cluster, 'zato:scheduler.job.execute', zato_message)

    except Exception, e:
        msg = 'Could not execute the job. job_id=[{0}], cluster_id=[{1}], e=[{2}]'.format(
            job_id, cluster_id, format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#11
0
文件: amqp.py 项目: brtsz/zato
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        def_ids = _get_def_ids(cluster)
        create_form.set_def_id(def_ids)
        edit_form.set_def_id(def_ids)

        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster, 'zato:outgoing.amqp.get-list', zato_message)
        
        if zato_path('data.item_list.item').get_from(zato_message) is not None:
            
            for msg_item in zato_message.data.item_list.item:
                
                id = msg_item.id.text
                name = msg_item.name.text
                is_active = is_boolean(msg_item.is_active.text)
                delivery_mode = int(msg_item.delivery_mode.text)
                priority = msg_item.priority.text
                content_type = msg_item.content_type.text
                content_encoding = msg_item.content_encoding.text
                expiration = msg_item.expiration.text
                user_id = msg_item.user_id.text
                app_id = msg_item.app_id.text
                delivery_mode_text = delivery_friendly_name[delivery_mode]
                def_name = msg_item.def_name.text
                def_id = msg_item.def_id.text
                
                item =  OutgoingAMQP(id, name, is_active, delivery_mode, priority,
                    content_type, content_encoding, expiration, user_id, app_id,
                    def_id, delivery_mode_text, def_name)
                items.append(item)

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/outgoing/amqp.html', return_data,
                              context_instance=RequestContext(req))
示例#12
0
文件: service.py 项目: dsuch/zato
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)
示例#13
0
文件: http_soap.py 项目: brtsz/zato
def _get_security_list(cluster):
    zato_message = Element('{%s}zato_message' % zato_namespace)
    zato_message.data = Element('data')
    zato_message.data.cluster_id = cluster.id
    
    _, zato_message, _  = invoke_admin_service(cluster, 'zato:security.get-list', zato_message)
    return zato_message
示例#14
0
文件: translation.py 项目: dsuch/zato
def _get_systems(cluster):
    systems = []
    zato_message, _  = invoke_admin_service(cluster, 'zato:kvdb.data-dict.dictionary.get-system-list', {})
    if zato_path('response.item_list.item').get_from(zato_message) is not None:
        for item in zato_message.response.item_list.item:
            systems.append([item.name.text] * 2)
    return systems
示例#15
0
文件: service.py 项目: dsuch/zato
def _get_channels(cluster, id, channel_type):
    """ Returns a list of channels of a given type for the given service.
    """
    input_dict = {
        'id': id,
        'channel_type': channel_type
    }
    zato_message, soap_response  = invoke_admin_service(cluster, 'zato:service.get-channel-list', input_dict)

    response = []

    if zato_path('response.item_list.item').get_from(zato_message) is not None:
        for msg_item in zato_message.response.item_list.item:

            if channel_type in('plain_http', 'soap'):
                url = reverse('http-soap')
                url += '?connection=channel&transport={}'.format(channel_type)
                url += '&cluster={}'.format(cluster.id)
            else:
                url = reverse('channel-' + channel_type)
                url += '?cluster={}'.format(cluster.id)

            url += '&highlight={}'.format(msg_item.id.text)

            channel = Channel(msg_item.id.text, msg_item.name.text, url)
            response.append(channel)

    return response
示例#16
0
文件: service.py 项目: dsuch/zato
def last_stats(req, service_id, cluster_id):
    
    return_data = {
        'rate': '(error)',
        'mean': '(error)',
        'mean_trend': '(error)',
        }
    
    try:
        start, stop = last_hour_start_stop(datetime.utcnow())
        zato_message, _ = invoke_admin_service(req.zato.cluster, 
            'zato:stats.get-by-service', {'service_id': service_id, 'start':start, 'stop':stop})
        
        if zato_path('response.item').get_from(zato_message) is not None:
            item = zato_message.response.item
            for key in return_data:
                value = getattr(item, key).text or ''
                
                if value and key.endswith('trend') and value != ZATO_NONE:
                    value = [int(float(elem)) for elem in value.split(',')]

                if value == '0.0':
                    value = '<0.1'

                return_data[key] = value if value != ZATO_NONE else '0'

    except Exception, e:
        msg = 'Caught an exception while invoking zato:service.get-last-stats, e:[{}]'.format(format_exc(e))
        logger.error(msg)
示例#17
0
文件: service.py 项目: dsuch/zato
def source_info(req, service_name):

    service = Service(name=service_name)
    input_dict = {
        'cluster_id': req.zato.cluster_id,
        'name': service_name
    }

    zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.get-source-info', input_dict)

    if zato_path('response.item').get_from(zato_message) is not None:
        msg_item = zato_message.response.item
        service.id = msg_item.service_id.text

        source = msg_item.source.text.decode('base64') if msg_item.source else ''
        if source:
            source_html = highlight(source, PythonLexer(stripnl=False), HtmlFormatter(linenos='table'))

            service.source_info = SourceInfo()
            service.source_info.source = source
            service.source_info.source_html = source_html
            service.source_info.path = msg_item.source_path.text
            service.source_info.hash = msg_item.source_hash.text
            service.source_info.hash_method = msg_item.source_hash_method.text
            service.source_info.server_name = msg_item.server_name.text

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

    return TemplateResponse(req, 'zato/service/source-info.html', return_data)
示例#18
0
文件: jms_wmq.py 项目: brtsz/zato
def index(req):
    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')

    if cluster_id and req.method == 'GET':
        
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()
        
        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id
        
        _, zato_message, soap_response  = invoke_admin_service(cluster,
                'zato:definition.jms_wmq.get-list', zato_message)
        
        if zato_path('data.definition_list.definition').get_from(zato_message) is not None:
            
            for definition_elem in zato_message.data.definition_list.definition:

                id = definition_elem.id.text
                name = definition_elem.name.text
                host = definition_elem.host.text
                port = definition_elem.port.text
                queue_manager = definition_elem.queue_manager.text
                channel = definition_elem.channel.text
                cache_open_send_queues = is_boolean(definition_elem.cache_open_send_queues.text)
                cache_open_receive_queues = is_boolean(definition_elem.cache_open_receive_queues.text)
                use_shared_connections = is_boolean(definition_elem.use_shared_connections.text)
                ssl = is_boolean(definition_elem.ssl.text)
                ssl_cipher_spec = definition_elem.ssl_cipher_spec.text
                ssl_key_repository = definition_elem.ssl_key_repository.text
                needs_mcd = is_boolean(definition_elem.needs_mcd.text)
                max_chars_printed = definition_elem.max_chars_printed.text
                
                def_jms_wmq = ConnDefWMQ(id, name, host, port, queue_manager, channel,
                    cache_open_send_queues, cache_open_receive_queues, use_shared_connections, 
                    ssl, ssl_cipher_spec, ssl_key_repository, needs_mcd, max_chars_printed)
                
                items.append(def_jms_wmq)
                

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form':create_form,
        'edit_form':edit_form,
        }
    
    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [{0}]'.format(return_data))

    return render_to_response('zato/definition/jms_wmq.html', return_data,
                              context_instance=RequestContext(req))
示例#19
0
文件: wss.py 项目: dsuch/zato
def create(req):
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:security.wss.create', _get_edit_create_message(req.POST))
        return _edit_create_response(zato_message, 'created', req.POST['name'], req.POST['password_type'])
    except Exception, e:
        msg = "Could not create a WS-Security definition, e:[{e}]".format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#20
0
文件: jms_wmq.py 项目: dsuch/zato
def create(req):
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:channel.jms_wmq.create', _get_edit_create_message(req.POST))
        return _edit_create_response(req.zato.cluster, 'created', zato_message.response.item.id.text, req.POST['name'], req.POST['cluster_id'], req.POST['def_id'])
    except Exception, e:
        msg = 'Could not create a JMS WebSphere MQ channel, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#21
0
文件: http_soap.py 项目: dsuch/zato
def _delete_ping(req, id, cluster_id, service, error_template):
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, service, {'id': id})
        return zato_message
    except Exception, e:
        msg = error_template.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#22
0
文件: translation.py 项目: dsuch/zato
def _get_key_value_list(req, service_name, input_dict):
    return_data = []
    zato_message, _  = invoke_admin_service(req.zato.cluster, service_name, 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:
            return_data.append({'name':item.name.text})
    
    return HttpResponse(dumps(return_data), mimetype='application/javascript')
示例#23
0
文件: jms_wmq.py 项目: dsuch/zato
def edit(req):
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:channel.jms_wmq.edit', _get_edit_create_message(req.POST, 'edit-'))
        return _edit_create_response(req.zato.cluster, 'updated', req.POST['id'], req.POST['edit-name'], req.POST['cluster_id'], req.POST['edit-def_id'])
    except Exception, e:
        msg = 'Could not update the JMS WebSphere MQ channel, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#24
0
文件: http_soap.py 项目: dsuch/zato
def edit(req):
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:http_soap.edit', _get_edit_create_message(req.POST, 'edit-'))
        return _edit_create_response(zato_message.response.item.id.text, 'updated',
            req.POST['transport'], req.POST['connection'], req.POST['edit-name'])
    except Exception, e:
        msg = 'Could not perform the update, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#25
0
def get_by_id(req, tech_account_id, cluster_id):
    try:
        zato_message, soap_response = invoke_admin_service(
            req.zato.cluster, "zato:security.tech-account.get-by-id", {"tech_account_id": tech_account_id}
        )
    except Exception, e:
        msg = "Could not fetch the technical account, e:[{e}]".format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#26
0
文件: jms_wmq.py 项目: dsuch/zato
def _edit_create_response(cluster, verb, id, name, delivery_mode_text, cluster_id, def_id):
    zato_message, soap_response  = invoke_admin_service(cluster, 'zato:definition.jms_wmq.get-by-id', {'id':def_id, 'cluster_id':cluster_id})    
    return_data = {'id': id,
                   'message': 'Successfully {0} the outgoing JMS WebSphere MQ connection [{1}]'.format(verb, name),
                   'delivery_mode_text': delivery_mode_text,
                   'def_name': zato_message.response.item.name.text
                }
    
    return HttpResponse(dumps(return_data), mimetype='application/javascript')
示例#27
0
文件: wss.py 项目: brtsz/zato
def index(req):

    zato_clusters = req.odb.query(Cluster).order_by('name').all()
    choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET)
    cluster_id = req.GET.get('cluster')
    items = []
    
    create_form = CreateForm()
    edit_form = EditForm(prefix='edit')
    change_password_form = ChangePasswordForm()

    if cluster_id and req.method == 'GET':
        cluster = req.odb.query(Cluster).filter_by(id=cluster_id).first()

        zato_message = Element('{%s}zato_message' % zato_namespace)
        zato_message.data = Element('data')
        zato_message.data.cluster_id = cluster_id

        _ignored, zato_message, soap_response  = invoke_admin_service(cluster,
                'zato:security.wss.get-list', zato_message)

        if zato_path('data.definition_list.definition').get_from(zato_message) is not None:
            for definition_elem in zato_message.data.definition_list.definition:

                id = definition_elem.id.text
                name = definition_elem.name.text
                is_active = is_boolean(definition_elem.is_active.text)
                username = definition_elem.username.text
                password_type = ZATO_WSS_PASSWORD_TYPES[definition_elem.password_type.text]
                password_type_raw = definition_elem.password_type.text
                reject_empty_nonce_ts = definition_elem.reject_empty_nonce_ts
                reject_stale_username = definition_elem.reject_stale_username
                expiry_limit = definition_elem.expiry_limit
                nonce_freshness = definition_elem.nonce_freshness

                wss = WSSDefinition(id, name, is_active, username, None,
                        password_type, reject_empty_nonce_ts, reject_stale_username,
                        expiry_limit, nonce_freshness, password_type_raw=password_type_raw)

                items.append(wss)

    return_data = {'zato_clusters':zato_clusters,
        'cluster_id':cluster_id,
        'choose_cluster_form':choose_cluster_form,
        'items':items,
        'create_form': create_form,
        'edit_form': edit_form,
        'change_password_form': change_password_form
        }

    # TODO: Should really be done by a decorator.
    if logger.isEnabledFor(TRACE1):
        logger.log(TRACE1, 'Returning render_to_response [%s]' % return_data)

    return render_to_response('zato/security/wss.html', return_data,
                              context_instance=RequestContext(req))
示例#28
0
文件: wss.py 项目: dsuch/zato
def edit(req):
    """ Updates WS-S definitions's parameters (everything except for the password).
    """
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:security.wss.edit', _get_edit_create_message(req.POST, prefix='edit-'))
        return _edit_create_response(zato_message, 'updated', req.POST['edit-name'], req.POST['edit-password_type'])
    except Exception, e:
        msg = 'Could not update the WS-Security definition, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
示例#29
0
文件: cluster.py 项目: dsuch/zato
    def __call__(self, req, *args, **kwargs):
        zato_message, _ = invoke_admin_service(req.zato.cluster, "zato:cluster.server.get-by-id", {"id": req.zato.id})

        server = req.zato.odb.query(Server).filter_by(id=req.zato.id).one()

        client = get_lb_client(req.zato.cluster)  # Checks whether the server is known by LB
        if client.get_server_data_dict(server.name):
            client.add_remove_server("remove", zato_message.response.item.name.text)

        return super(ServerDelete, self).__call__(req, *args, **kwargs)
示例#30
0
文件: sql.py 项目: dsuch/zato
def ping(req, cluster_id, id):
    """ Pings a database and returns the time it took, in milliseconds.
    """
    try:
        zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:outgoing.sql.ping', {'id':id})
        response_time = zato_path('response.item.response_time', True).get_from(zato_message)
    except Exception, e:
        msg = 'Ping failed. e:[{}]'.format(format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)