def test_zato_path(self): xml = etree.fromstring( """<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://zato.io/ns/20130518"> <soap:Body> <zato_channel_amqp_edit_response xmlns="https://zato.io/ns/20130518"> <zato_env> <cid>K08984532360785332835581231451</cid> <result>ZATO_OK</result> </zato_env> <item> <id>1</id> <name>crm.account</name> </item> </zato_channel_amqp_edit_response> </soap:Body> </soap:Envelope>""") request = soap_body_xpath(xml)[0].getchildren()[0] zato_path('item', True).get_from(request) path = uuid4().hex try: zato_path(path, True).get_from(request) except ParsingException: pass else: raise AssertionError( 'Expected an ParsingException with path:[{}]'.format(path))
def test_zato_path(self): xml = etree.fromstring("""<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://zato.io/ns/20130518"> <soap:Body> <zato_channel_amqp_edit_response xmlns="https://zato.io/ns/20130518"> <zato_env> <cid>K08984532360785332835581231451</cid> <result>ZATO_OK</result> </zato_env> <item> <id>1</id> <name>crm.account</name> </item> </zato_channel_amqp_edit_response> </soap:Body> </soap:Envelope>""") request = soap_body_xpath(xml)[0].getchildren()[0] zato_path('item', True).get_from(request) path = uuid4().hex try: zato_path(path, True).get_from(request) except ParsingException: pass else: raise AssertionError('Expected an ParsingException with path:[{}]'.format(path))
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
def __call__(self, req, *args, **kwargs): """ Handles the request, taking care of common things and delegating control to the subclass for fetching this view-specific data. """ try: super(Index, self).__call__(req, *args, **kwargs) del self.items[:] self.item = None return_data = {'cluster_id':self.cluster_id} output_repeated = getattr(self.SimpleIO, 'output_repeated', False) zato_path_needed = 'response.item_list.item' if output_repeated else 'response.item' if self.soap_action and self.cluster_id: zato_message = self.invoke_admin_service() if zato_message is not None and zato_path(zato_path_needed).get_from(zato_message) is not None: if output_repeated: self._handle_item_list(zato_message.response.item_list) else: self._handle_item(zato_message.response.item) return_data['items'] = self.items return_data['item'] = self.item return_data['zato_clusters'] = req.zato.clusters return_data['choose_cluster_form'] = req.zato.choose_cluster_form view_specific = self.handle() if view_specific: return_data.update(view_specific) return TemplateResponse(req, self.template, return_data) except Exception, e: return HttpResponseServerError(format_exc(e))
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)
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)
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)
def _get_interval_based_start_date(payload): start_date = zato_path('data.job.start_date', True).get_from(payload) if start_date: # Were optional date & time provided in a correct format? strptime(str(start_date), scheduler_date_time_format) return str(start_date)
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
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))
def _parse_extra_params(payload): """ Turns a query string with extra parameters into a dictionary. """ extra_dict = {} # Extra parameters are not mandatory. if zato_path("pool.extra_list").get_from(payload) is not None: for extra_elem in payload.pool.extra_list.extra: extra_elem_dict = parse_qs(unicode(extra_elem), True) param_name, param_value = extra_elem_dict.items()[0] param_name = str(param_name) param_value = param_value[0] if not param_value: msg = "Extra parameter [%s] has no value" % param_name logger.error(msg) raise ZatoException(msg) if param_name in extra_dict: msg = "Extra parameter [%s] specified more than once" % param_name logger.error(msg) raise ZatoException(msg) extra_dict[param_name] = param_value logger.debug("Returning extra parameters [%s]" % extra_dict) return extra_dict
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))
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')
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))
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)
def ping(req): """ Pings a database and returns the time it took, in milliseconds. """ try: result, zato_message_response, soap_response = _ping_delete(req, "zato:pool.sql.ping") response_time = zato_path("data.response_time").get_from(zato_message_response) except Exception, e: msg = "Ping failed. server_id=[%s], pool_name=[%s], e=[%s]" % (req.GET.get("server"), req.GET.get("pool_name"), format_exc()) logger.error(msg) return HttpResponseServerError(msg)
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 _, zato_message, soap_response = invoke_admin_service(cluster, 'zato:definition.amqp.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 vhost = definition_elem.vhost.text username = definition_elem.username.text frame_max = definition_elem.frame_max.text heartbeat = definition_elem.heartbeat.text def_amqp = ConnDefAMQP(id, name, 'amqp', host, port, vhost, username, None, frame_max, heartbeat) items.append(def_amqp) 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 [{0}]'.format(return_data)) return render_to_response('zato/definition/amqp.html', return_data, context_instance=RequestContext(req))
def _translate(): result = {} zato_message, _ = invoke_admin_service(req.zato.cluster, 'zato:kvdb.data-dict.translation.translate', post_data) if zato_path('response.item').get_from(zato_message) is not None: for name in('value2', 'repr', 'hex', 'sha1', 'sha256'): value = getattr(zato_message.response.item, name, None) if value and value.text != ZATO_NONE: result[name] = value.text return result
def _get_def_ids(cluster): out = {} zato_message, soap_response = invoke_admin_service(cluster, 'zato:definition.jms_wmq.get-list', {'cluster_id':cluster.id}) if zato_path('response.item_list.item').get_from(zato_message) is not None: for definition_elem in zato_message.response.item_list.item: id = definition_elem.id.text name = definition_elem.name.text out[id] = name return out
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)
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:channel.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) queue = msg_item.queue.text consumer_tag_prefix = msg_item.consumer_tag_prefix.text def_name = msg_item.def_name.text def_id = msg_item.def_id.text service_name = msg_item.service_name.text item = ChannelAMQP(id, name, is_active, queue, consumer_tag_prefix, def_id, def_name, service_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/channel/amqp.html", return_data, context_instance=RequestContext(req))
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:channel.jms_wmq.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) queue = msg_item.queue.text def_name = msg_item.def_name.text def_id = msg_item.def_id.text service_name = msg_item.service_name.text item = ChannelWMQ(id, name, is_active, queue, def_id, def_name, service_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/channel/jms_wmq.html', return_data, context_instance=RequestContext(req))
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 _, zato_message, soap_response = invoke_admin_service(cluster, "zato:outgoing.ftp.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) host = msg_item.host.text if msg_item.host else "" user = msg_item.user.text if msg_item.user else "" acct = msg_item.acct.text if msg_item.acct else "" timeout = msg_item.timeout.text if msg_item.timeout else "" port = msg_item.port.text if msg_item.port else "" dircache = is_boolean(msg_item.dircache.text) item = OutgoingFTP(id, name, is_active, host, user, None, acct, timeout, port, dircache) 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, "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 [{0}]".format(return_data)) return render_to_response("zato/outgoing/ftp.html", return_data, context_instance=RequestContext(req))
def index(req): """ Lists all the SQL connections. """ items = [] create_form = CreateForm() edit_form = EditForm(prefix='edit') change_password_form = ChangePasswordForm() if req.zato.cluster_id and req.method == 'GET': zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:outgoing.sql.get-list', {'cluster_id': req.zato.cluster_id}) if zato_path('response.item_list.item').get_from(zato_message) is not None: for msg_item in zato_message.response.item_list.item: id = msg_item.id.text name = msg_item.name.text is_active = is_boolean(msg_item.is_active.text) engine = msg_item.engine.text if msg_item.engine else '' host = msg_item.host.text if msg_item.host else '' port = msg_item.port.text if msg_item.port else '' db_name = msg_item.db_name.text if msg_item.db_name else '' username = msg_item.username.text if msg_item.username else '' pool_size = msg_item.pool_size.text if msg_item.pool_size else '' extra = msg_item.extra.text if msg_item.extra else '' item = SQLConnectionPool() item.id = id item.name = name item.is_active = is_active item.engine = engine item.engine_text = odb_engine_friendly_name[engine] item.host = host item.port = port item.db_name = db_name item.username = username item.pool_size = pool_size item.extra = extra items.append(item) return_data = {'zato_clusters':req.zato.clusters, 'cluster_id':req.zato.cluster_id, 'choose_cluster_form':req.zato.choose_cluster_form, 'items':items, 'create_form':create_form, 'edit_form':edit_form, 'change_password_form': change_password_form } return TemplateResponse(req, 'zato/outgoing/sql.html', return_data)
def _get_def_ids(cluster): out = {} 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.amqp.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 out[id] = name return out
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 _, zato_message, soap_response = invoke_admin_service(cluster, 'zato:security.tech-account.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) account = TechnicalAccount(id, name, is_active=is_active) items.append(account) 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 [{0}]'.format(return_data)) return render_to_response('zato/security/tech-account.html', return_data, context_instance=RequestContext(req))
def get_params(self, request_params, path_prefix='', default_value=ZATO_NO_DEFAULT_VALUE, use_text=True, is_required=True): """ Gets all requested parameters from a message. Will raise ParsingException if any is missing. """ params = {} if not isinstance(self.payload, basestring): for param in request_params: if isinstance(param, ForceType): param_name = param.name else: param_name = param if self.is_xml: try: elem = zato_path('{}.{}'.format(path_prefix, param_name), is_required).get_from(self.payload) except ParsingException, e: msg = 'Caught an exception while parsing, payload:[<![CDATA[{}]]>], e:[{}]'.format( etree.tostring(self.payload), format_exc(e)) raise ParsingException(self.cid, msg) if elem is not None: if use_text: value = elem.text # We are interested in the text the elem contains .. else: return elem # .. or in the elem itself. else: value = default_value else: value = self.payload.get(param_name) # Use a default value if an element is empty and we're allowed to # substitute its (empty) value with the default one. if default_value != ZATO_NO_DEFAULT_VALUE and not value: value = default_value else: if value is not None: value = unicode(value) try: if not isinstance(param, AsIs): params[param_name] = self.convert(param, param_name, value, self.has_simple_io_config) else: params[param_name] = value except Exception, e: msg = 'Caught an exception, param:[{}], param_name:[{}], value:[{}], self.has_simple_io_config:[{}], e:[{}]'.format( param, param_name, value, self.has_simple_io_config, format_exc(e)) self.logger.error(msg) raise Exception(msg)
def _get_service(req, name): """ Returns a service details by its name. """ service = Service(name=name) input_dict = { 'name': name, 'cluster_id': req.zato.cluster_id } zato_message, soap_response = invoke_admin_service(req.zato.cluster, 'zato:service.get-by-name', input_dict) if zato_path('response.item').get_from(zato_message) is not None: for name in('id', 'slow_threshold'): setattr(service, name, getattr(zato_message.response.item, name).text) return service
def details(req, service_id): zato_clusters = req.odb.query(Cluster).order_by('name').all() choose_cluster_form = ChooseClusterForm(zato_clusters, req.GET) cluster_id = req.GET.get('cluster') service = None 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.id = service_id zato_message.data.cluster_id = cluster_id _, zato_message, soap_response = invoke_admin_service(cluster, 'zato:service.get-by-id', zato_message) if zato_path('data.item').get_from(zato_message) is not None: msg_item = zato_message.data.item id = msg_item.id.text name = msg_item.name.text is_active = is_boolean(msg_item.is_active.text) impl_name = msg_item.impl_name.text is_internal = is_boolean(msg_item.is_internal.text) usage_count = msg_item.usage_count.text service = Service(id, name, is_active, impl_name, is_internal, None, usage_count) return_data = {'zato_clusters':zato_clusters, 'service': service, 'cluster_id':cluster_id, 'choose_cluster_form':choose_cluster_form, '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/service/details.html', return_data, context_instance=RequestContext(req))
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)
def _get_params(payload, request_params, path_prefix="", default_value=ZATO_NO_DEFAULT_VALUE, force_type=None, force_type_params=[], use_text=True): """ Gets all requested parameters from a message. Will raise an exception if any is missing. """ params = {} for param in request_params: elem = zato_path(path_prefix + param, True).get_from(payload) if use_text: value = elem.text # We are interested in the text the elem contains .. else: return elem # .. or in the elem itself. # Use a default value if an element is empty and we're allowed to # substitute its (empty) value with the default one. if default_value != ZATO_NO_DEFAULT_VALUE and not value: value = default_value else: if value is not None: value = unicode(value) # Should the value be of a specific type? if force_type and param in force_type_params: if force_type == bool: # TODO: Those should be stored in the app context if value.lower() in("0", "false"): value = False elif value.lower() in("1", "true"): value = True else: msg = "Don't know how to convert param [%s], value [%s], into a bool." % ( param, value) logger.error(msg) raise ZatoException(msg) else: value = force_type(value) params[param] = value return params