Search in sources :

Example 51 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-externals by apache.

the class ClusterServiceImpl method list.

@Override
public Map<String, Object> list() {
    try {
        Map<String, Object> resultMap = Maps.newHashMap();
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        logger.info("op=look_clusterInfo {}", JsonUtil.obj2String(clusterInfo));
        Map<String, Map<Long, Object>> /* brokerDetail */
        brokerServer = Maps.newHashMap();
        for (BrokerData brokerData : clusterInfo.getBrokerAddrTable().values()) {
            Map<Long, Object> brokerMasterSlaveMap = Maps.newHashMap();
            for (Map.Entry<Long, String> /* broker address */
            brokerAddr : brokerData.getBrokerAddrs().entrySet()) {
                KVTable kvTable = mqAdminExt.fetchBrokerRuntimeStats(brokerAddr.getValue());
                // KVTable kvTable = mqAdminExt.fetchBrokerRuntimeStats("127.0.0.1:10911");
                brokerMasterSlaveMap.put(brokerAddr.getKey(), kvTable.getTable());
            }
            brokerServer.put(brokerData.getBrokerName(), brokerMasterSlaveMap);
        }
        resultMap.put("clusterInfo", clusterInfo);
        resultMap.put("brokerServer", brokerServer);
        return resultMap;
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Map(java.util.Map)

Example 52 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-externals by apache.

the class DashboardCollectTask method collectTopic.

@Scheduled(cron = "30 0/1 * * * ?")
@MultiMQAdminCmdMethod(timeoutMillis = 5000)
public void collectTopic() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    Date date = new Date();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        TopicList topicList = mqAdminExt.fetchAllTopicList();
        Set<String> topicSet = topicList.getTopicList();
        for (String topic : topicSet) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic);
            GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
            double inTPS = 0;
            long inMsgCntToday = 0;
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        stopwatch.start();
                        log.info("start time: {}", stopwatch.toString());
                        BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                        stopwatch.stop();
                        log.info("stop time : {}", stopwatch.toString());
                        stopwatch.reset();
                        inTPS += bsd.getStatsMinute().getTps();
                        inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                    } catch (Exception e) {
                    // throw Throwables.propagate(e);
                    }
                }
            }
            if (groupList != null && !groupList.getGroupList().isEmpty()) {
                for (String group : groupList.getGroupList()) {
                    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                        if (masterAddr != null) {
                            try {
                                String statsKey = String.format("%s@%s", topic, group);
                                BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                                outTPS += bsd.getStatsMinute().getTps();
                                outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                            } catch (Exception e) {
                            // throw Throwables.propagate(e);
                            }
                        }
                    }
                }
            }
            List<String> list;
            try {
                list = dashboardCollectService.getTopicMap().get(topic);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
            if (null == list) {
                list = Lists.newArrayList();
            }
            list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday);
            dashboardCollectService.getTopicMap().put(topic, list);
        }
        log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Stopwatch(com.google.common.base.Stopwatch) Date(java.util.Date) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigDecimal(java.math.BigDecimal) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) ExecutionException(java.util.concurrent.ExecutionException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) Scheduled(org.springframework.scheduling.annotation.Scheduled) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 53 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method examineProducerConnectionInfo.

@Override
public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    ProducerConnection result = new ProducerConnection();
    List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
    BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
    String addr = null;
    if (brokerData != null) {
        addr = brokerData.selectBrokerAddr();
        if (StringUtils.isNotBlank(addr)) {
            result = this.mqClientInstance.getMQClientAPIImpl().getProducerConnectionList(addr, producerGroup, timeoutMillis);
        }
    }
    if (result.getConnectionSet().isEmpty()) {
        log.warn("the producer group not online. brokerAddr={}, group={}", addr, producerGroup);
        throw new MQClientException("Not found the producer group connection", null);
    }
    return result;
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ProducerConnection(org.apache.rocketmq.common.protocol.body.ProducerConnection) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 54 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method resetOffsetByTimestamp.

public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable = this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 55 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method getTopicClusterList.

@Override
public Set<String> getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException {
    Set<String> clusterSet = new HashSet<String>();
    ClusterInfo clusterInfo = examineBrokerClusterInfo();
    TopicRouteData topicRouteData = examineTopicRouteInfo(topic);
    BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);
    String brokerName = brokerData.getBrokerName();
    Iterator<Map.Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, Set<String>> next = it.next();
        if (next.getValue().contains(brokerName)) {
            clusterSet.add(next.getKey());
        }
    }
    return clusterSet;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) Entry(java.util.Map.Entry) Set(java.util.Set) HashSet(java.util.HashSet) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Aggregations

BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)106 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)65 HashMap (java.util.HashMap)41 ArrayList (java.util.ArrayList)29 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)29 HashSet (java.util.HashSet)27 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)23 Map (java.util.Map)22 MQClientException (org.apache.rocketmq.client.exception.MQClientException)21 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)21 List (java.util.List)20 Set (java.util.Set)20 Field (java.lang.reflect.Field)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)16 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)16 Entry (java.util.Map.Entry)14 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)14 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)14 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)14