EMsnap commented on a change in pull request #3219:
URL: https://github.com/apache/incubator-inlong/pull/3219#discussion_r829774691



##########
File path: 
inlong-tubemq/tubemq-manager/src/main/java/org/apache/inlong/tubemq/manager/controller/cluster/ClusterController.java
##########
@@ -185,4 +190,95 @@ String queryInfo(
         return masterService.queryMaster(url);
     }
 
+    public Map<String, Integer> getAllCount(long clusterId) {
+        int brokerSize = getBrokerSize(clusterId);
+        Map<String, Integer> mapCount = getTopicAndPartitionCount(clusterId);
+        int consumerGroupCount = gitConsumerGroupCount(clusterId);
+        int consumerCount = gitConsumerCount(clusterId);
+        Map<String, Integer> map = new HashMap<>();
+        map.put("brokerSize", brokerSize);
+        map.put("topicCount", mapCount.get("topicCount"));
+        map.put("partitionCount", mapCount.get("partitionCount"));
+        map.put("consumerGroupCount", consumerGroupCount);
+        map.put("consumerCount", consumerCount);
+        return map;
+    }
+
+    /**
+     * query borker size
+     * @param clusterId
+     * @return
+     */
+    public int getBrokerSize(long 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 Map<String, Integer> getTopicAndPartitionCount(long clusterId) {
+        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);
+        int count = 0;
+        for (Map map : list) {
+            Double totalRunNumPartCount = 
Double.valueOf(map.get("totalRunNumPartCount").toString());
+            count = count + (int)Math.ceil(totalRunNumPartCount);
+        }
+        Map<String, Integer> map = new HashMap<>();
+        map.put("topicCount", topicSize);
+        map.put("partitionCount", count);
+        return map;
+    }
+
+    /**
+     * query Consumer group count
+     * @param clusterId
+     * @return
+     */
+    public int gitConsumerGroupCount(long clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, 
TubeConst.QUERY_CONSUMER_GROUP_INFO);
+        int count = 0;
+        String groupData = masterService.queryMaster(queryUrl);
+        JsonObject jsonObject1 = gson.fromJson(groupData, JsonObject.class);
+        JsonElement data1 = jsonObject1.get("data");
+        JsonArray jsonElements1 = gson.fromJson(data1, JsonArray.class);
+        for (JsonElement jsonElement : jsonElements1) {
+            Map map1 = gson.fromJson(jsonElement, Map.class);
+            Double groupCount = 
Double.valueOf(map1.get("groupCount").toString());
+            count = count + (int)Math.ceil(groupCount);
+        }
+        return count;
+    }
+
+    /**
+     * query consumer count
+     * @param clusterId
+     * @return
+     */
+    public int gitConsumerCount(long clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, 
TubeConst.QUERY_CONSUMER_INFO);
+        String s = masterService.queryMaster(queryUrl);

Review comment:
       magic variable s




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to