Beispiel #1
0
def get_consumer_group_by_tag(env, event_id):
    topic = request.args.get('topic')
    tag = request.args.get('tag')
    if not topic or not tag:
        log.warning(u'topic or tag is none')
        return response_params_error()
    return jsonify(console.get_consumergroup_by_tag(env, event_id, topic, tag))
Beispiel #2
0
def get_msg_by_key(env, event_id):
    topic = request.args.get('topic')
    msgKey = request.args.get('msgKey')
    if not topic or not msgKey:
        log.warning(u'topic or msgKey is none')
        return response_params_error()
    return jsonify(console.get_msg_by_msgkey(env, event_id, topic, msgKey))
Beispiel #3
0
def get_msg_by_id(env, event_id):
    topic = request.args.get('topic')
    msgId = request.args.get('msgId')
    if not topic or not msgId:
        log.warning(u'topic or msgId is none')
        return response_params_error()
    return jsonify(console.get_msg_by_msgid(env, event_id, topic, msgId))
Beispiel #4
0
def get_consumergroup_client_connection(env, event_id):
    consumerGroup = request.args.get('consumerGroup')
    if not consumerGroup:
        log.warning(u'consumerGroup is none')
        return response_params_error()
    # return jsonify(console.get_consumergroup_connection(env, event_id, consumerGroup))
    res = console.get_consumergroup_connection(env, event_id, consumerGroup)
    res_data = []
    if res['status']:
        consumerclient_info = res['data']
        if not consumerclient_info:
            return jsonify({
                'status': False,
                'data': 'null',
                'errMsg': 'rocketmq consle response empty data'
            })
        consumer_from_where = consumerclient_info['consumeFromWhere']
        consumer_type = consumerclient_info['consumeType']
        message_model = consumerclient_info['messageModel']
        connection_info = consumerclient_info['connectionSet']
        for info in connection_info:
            res_dict = {}
            res_dict['consumer_from_where'] = consumer_from_where
            res_dict['consumer_type'] = consumer_type
            res_dict['message_model'] = message_model
            res_dict['client_addr'] = info['clientAddr']
            res_dict['client_id'] = info['clientId']
            res_dict['language'] = info['language']
            res_dict['version'] = info['version']
            res_dict['version_desc'] = info['versionDesc']
            res_data.append(res_dict)
        return jsonify({'status': True, 'data': res_data, 'errMsg': 'null'})
    else:
        return jsonify(res)
Beispiel #5
0
def get_producergroup_client_connection(env, event_id):
    topic = request.args.get('topic')
    producerGroup = request.args.get('producerGroup')
    if not topic or not producerGroup:
        log.warning(u'topic or producerGroup is none')
        return response_params_error()
    # return jsonify(console.get_producergroup_connection(env, event_id, topic, producerGroup))
    res = console.get_producergroup_connection(env, event_id, topic,
                                               producerGroup)
    res_data = []
    if res['status']:
        producerclient_info = res['data']['connectionSet']
        if not producerclient_info:
            return jsonify({
                'status': False,
                'data': 'null',
                'errMsg': 'rocketmq consle response empty data'
            })
        for info in producerclient_info:
            res_dict = {}
            res_dict['client_addr'] = info['clientAddr']
            res_dict['client_id'] = info['clientId']
            res_dict['language'] = info['language']
            res_dict['version'] = info['version']
            res_dict['version_desc'] = info['versionDesc']
            res_data.append(res_dict)
        return jsonify({'status': True, 'data': res_data, 'errMsg': 'null'})
    else:
        return jsonify(res)
Beispiel #6
0
 def inner():
     event_id = generate_event_id()
     log.info(u'http request path:{}, params:{}, event:{}'.format(
         request.path, request.args.to_dict(), event_id))
     env = request.args.get('env')
     if not env:
         if request.path in [
                 '/', '/topic_route', '/topic_status',
                 '/topic_consumergroup', '/consumergroup_status',
                 '/consumergroup_connection', '/producergroup_connection',
                 '/consumergroup_tag', '/message_key', '/message_id'
         ]:
             return func()
         else:
             log.warning(u'env is none')
             return response_params_error()
     return func(env, event_id)
Beispiel #7
0
def get_topic_status(env, event_id):
    topic = request.args.get('topic')
    if not topic:
        log.warning(u'topic is none')
        return response_params_error()
    res = console.get_topic_status(env, event_id, topic)
    if res['status']:
        res_data = []
        offset_info = res['data']['offsetTable']
        for info in offset_info:
            offset_data = offset_info[info]
            info = re.split(',| |=|\[|\]', info)
            offset_data['topic'] = info[3]
            offset_data['brokerName'] = info[6]
            offset_data['queueId'] = info[9]
            res_data.append(offset_data)
        return jsonify({'status': True, 'data': res_data, 'errMsg': 'null'})
    else:
        return jsonify(res)
    def get_consumergroup_by_tag(self, env, event_id, topic, tag):
        """查询指定topic中匹配到指定tag的订阅组"""

        match_consumergroup = []

        # 获取topic所有订阅组
        response = self.get_topic_consumer_status(env, event_id, topic)
        if not response['status']:
            log.warning(
                u'get all consumergroup of topic:{} failed, event:{}'.format(
                    topic, event_id))
            return {
                'status': False,
                'data': None,
                'errMsg': response['errMsg']
            }
        consumergroup_list = response['data'].keys()

        # 遍历订阅组,获取订阅组的客户端链接信息,从中过滤指定的topic和tag
        for consumergroup in consumergroup_list:
            response = self.get_consumergroup_connection(
                env, event_id, consumergroup)
            # if not response['status'] or not response['data']:
            #     log.warning(u'get consumergroup {} connection failed, event: {}'.format(consumergroup, event_id))
            #     return {'status': True, 'data': match_consumergroup, 'errMsg': 'null'}
            #     #continue
            if not response['status']:
                log.warning(
                    u'get consumergroup {} connection failed, errMsg:{}, event:{}'
                    .format(consumergroup, response['errMsg'], event_id))
                continue
            consumergroup_SubExpression_info = response['data'][
                'subscriptionTable']
            for _key in consumergroup_SubExpression_info:
                if consumergroup_SubExpression_info[_key]['topic'] == topic:
                    subString = consumergroup_SubExpression_info[topic][
                        'subString'].replace('||', '')
                    subString = subString.split()
                    if tag in subString:
                        match_consumergroup.append(consumergroup)
        return {'status': True, 'data': match_consumergroup, 'errMsg': 'null'}
Beispiel #9
0
def get_topic_consumer_status(env, event_id):
    topic = request.args.get('topic')
    if not topic:
        log.warning(u'topic is none')
        return response_params_error()
    # return jsonify(console.get_topic_consumer_status(env, event_id, topic))
    res = console.get_topic_consumer_status(env, event_id, topic)
    if res['status']:
        res_data = []
        consumergroup_info = res['data']
        if not consumergroup_info:
            return jsonify({
                'status': False,
                'data': 'null',
                'errMsg': 'rocketmq consle response empty data'
            })
        for info in consumergroup_info:
            consumergroup_name = info
            topic = consumergroup_info[info]['topic']
            queuestation_info = consumergroup_info[info]['queueStatInfoList']
            diff_total = consumergroup_info[info]['diffTotal']
            for _info in queuestation_info:
                res_dict = {}
                res_dict['consumer_group'] = consumergroup_name
                res_dict['broker_name'] = _info['brokerName']
                res_dict['topic'] = topic
                res_dict['queueId'] = _info['queueId']
                res_dict['broker_offset'] = _info['brokerOffset']
                res_dict['consumer_offset'] = _info['consumerOffset']
                res_dict['diff_offset'] = _info['brokerOffset'] - _info[
                    'consumerOffset']
                res_dict['diff_total'] = diff_total
                res_dict['consumer_client'] = _info['clientInfo']
                res_dict['last_update_timestamp'] = _info['lastTimestamp']
                res_data.append(res_dict)
        return jsonify({'status': True, 'data': res_data, 'errMsg': 'null'})
    else:
        return jsonify(res)
Beispiel #10
0
def get_topic_config(env, event_id):
    topic = request.args.get('topic')
    if not topic:
        log.warning(u'topic is none')
        return response_params_error()
    return jsonify(console.get_topic_config(env, event_id, topic))
Beispiel #11
0
def get_broker_config(env, event_id):
    brokerAddr = request.args.get('brokerAddr')
    if not brokerAddr:
        log.warning(u'brokerAddr is none')
        return response_params_error()
    return jsonify(console.get_broker_config(env, event_id, brokerAddr))