You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/03/22 01:56:47 UTC

[GitHub] [incubator-inlong] healchow commented on a change in pull request #3273: [INLONG-3201][TubeMQ] Improve the cluster query function

healchow commented on a change in pull request #3273:
URL: https://github.com/apache/incubator-inlong/pull/3273#discussion_r831703511



##########
File path: inlong-tubemq/tubemq-manager/src/main/java/org/apache/inlong/tubemq/manager/controller/cluster/ClusterController.java
##########
@@ -185,4 +190,121 @@ String queryInfo(
         return masterService.queryMaster(url);
     }
 
+    /**
+     * get all count
+     * @param clusterId
+     * @return
+     */
+    public ClusterVo getAllCount(Integer clusterId) {
+        ClusterVo clusterVo = new ClusterVo();
+        int brokerSize = getBrokerSize(clusterId);
+        ClusterVo countVo = getTopicAndPartitionCount(clusterId);
+        int consumerGroupCount = getConsumerGroupCount(clusterId);
+        int consumerCount = getConsumerCount(clusterId);
+        int storeCount = getStoreCount(clusterId);
+        clusterVo.setBrokerCount(brokerSize);
+        clusterVo.setTopicCount(countVo.getTopicCount());
+        clusterVo.setPartitionCount(countVo.getPartitionCount());
+        clusterVo.setConsumerGroupCount(consumerGroupCount);
+        clusterVo.setConsumerCount(consumerCount);
+        clusterVo.setStoreCount(storeCount);
+        return clusterVo;
+    }
+
+    /**
+     * query borker size
+     * @param clusterId
+     * @return
+     */
+    public int getBrokerSize(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.BROKER_RUN_STATUS);
+        String s = masterService.queryMaster(queryUrl);
+        JsonObject jsonObject = gson.fromJson(s, JsonObject.class);
+        JsonElement count = jsonObject.get("count");
+        return gson.fromJson(count, int.class);
+    }
+
+    /**
+     * query topic and partition count
+     * @param clusterId
+     * @return
+     */
+    public ClusterVo getTopicAndPartitionCount(Integer clusterId) {
+        ClusterVo clusterVo = new ClusterVo();
+        String url = masterService.getQueryCountUrl(clusterId, TubeConst.TOPIC_CONFIG_INFO);
+        String s = masterService.queryMaster(url);
+        JsonObject jsonObject = gson.fromJson(s, JsonObject.class);
+        JsonElement data = jsonObject.get("data");
+        JsonElement dataCount = jsonObject.get("dataCount");
+        Integer topicSize = gson.fromJson(dataCount, Integer.class);
+        List<Map> list = gson.fromJson(data, List.class);

Review comment:
       Its recommended to use a Java POJO class to instead of a Map.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org