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/18 08:12:27 UTC

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

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



##########
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) {

Review comment:
       getConsumer

##########
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);

Review comment:
       don't use number as variable name




-- 
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