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 06:29:59 UTC

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

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



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

Review comment:
       pls make a name that's readable

##########
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);
+        int partitionCount = 0;
+        for (Map map : list) {
+            Double totalRunNumPartCount = Double.valueOf(map.get("totalRunNumPartCount").toString());
+            partitionCount = partitionCount + (int)Math.ceil(totalRunNumPartCount);
+        }
+        clusterVo.setTopicCount(topicSize);
+        clusterVo.setPartitionCount(partitionCount);
+        return clusterVo;
+    }
+
+    /**
+     * query Consumer group count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerGroupCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_GROUP_INFO);
+        int consumerGroupCount = 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());
+            consumerGroupCount = consumerGroupCount + (int)Math.ceil(groupCount);
+        }
+        return consumerGroupCount;
+    }
+
+    /**
+     * query consumer count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_INFO);
+        String queryMaster = masterService.queryMaster(queryUrl);
+        JsonObject jsonObject = gson.fromJson(queryMaster, JsonObject.class);
+        JsonElement data = jsonObject.get("data");
+        JsonArray jsonData = gson.fromJson(data, JsonArray.class);
+        int consumerCount = 0;
+        for (JsonElement jsonDatum : jsonData) {
+            Map map1 = gson.fromJson(jsonDatum, Map.class);

Review comment:
       invalid variable name

##########
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);
+        int partitionCount = 0;
+        for (Map map : list) {
+            Double totalRunNumPartCount = Double.valueOf(map.get("totalRunNumPartCount").toString());
+            partitionCount = partitionCount + (int)Math.ceil(totalRunNumPartCount);
+        }
+        clusterVo.setTopicCount(topicSize);
+        clusterVo.setPartitionCount(partitionCount);
+        return clusterVo;
+    }
+
+    /**
+     * query Consumer group count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerGroupCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_GROUP_INFO);
+        int consumerGroupCount = 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());
+            consumerGroupCount = consumerGroupCount + (int)Math.ceil(groupCount);
+        }
+        return consumerGroupCount;
+    }
+
+    /**
+     * query consumer count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_INFO);
+        String queryMaster = masterService.queryMaster(queryUrl);
+        JsonObject jsonObject = gson.fromJson(queryMaster, JsonObject.class);
+        JsonElement data = jsonObject.get("data");
+        JsonArray jsonData = gson.fromJson(data, JsonArray.class);
+        int consumerCount = 0;
+        for (JsonElement jsonDatum : jsonData) {
+            Map map1 = gson.fromJson(jsonDatum, Map.class);
+            Double groupCount = Double.valueOf(map1.get("consumerNum").toString());
+            consumerCount = (int)Math.ceil(groupCount);
+        }
+        return consumerCount;
+    }
+
+    /**
+     * query store count
+     * @param clusterId
+     * @return
+     */
+    public int getStoreCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.TOPIC_VIEW);
+        JsonObject jsonObject = gson.fromJson(masterService.queryMaster(queryUrl), JsonObject.class);
+        JsonElement getData = jsonObject.get("data");
+        JsonArray jsonData = gson.fromJson(getData, JsonArray.class);
+        int storeCount = 0;
+        for (JsonElement jsonDatum : jsonData) {
+            Map map1 = gson.fromJson(jsonDatum, Map.class);

Review comment:
       DITTO

##########
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);
+        int partitionCount = 0;
+        for (Map map : list) {
+            Double totalRunNumPartCount = Double.valueOf(map.get("totalRunNumPartCount").toString());
+            partitionCount = partitionCount + (int)Math.ceil(totalRunNumPartCount);
+        }
+        clusterVo.setTopicCount(topicSize);
+        clusterVo.setPartitionCount(partitionCount);
+        return clusterVo;
+    }
+
+    /**
+     * query Consumer group count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerGroupCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_GROUP_INFO);
+        int consumerGroupCount = 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());
+            consumerGroupCount = consumerGroupCount + (int)Math.ceil(groupCount);
+        }
+        return consumerGroupCount;
+    }
+
+    /**
+     * query consumer count
+     * @param clusterId
+     * @return
+     */
+    public int getConsumerCount(Integer clusterId) {
+        String queryUrl = masterService.getQueryCountUrl(clusterId, TubeConst.QUERY_CONSUMER_INFO);
+        String queryMaster = masterService.queryMaster(queryUrl);
+        JsonObject jsonObject = gson.fromJson(queryMaster, JsonObject.class);
+        JsonElement data = jsonObject.get("data");
+        JsonArray jsonData = gson.fromJson(data, JsonArray.class);
+        int consumerCount = 0;
+        for (JsonElement jsonDatum : jsonData) {
+            Map map1 = gson.fromJson(jsonDatum, Map.class);

Review comment:
       create a pojo for 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