Skip to content

Commit 21dc2ac

Browse files
1294566108yuanziwei
andauthored
Support dashboard v4-v5 switch And query for v5 topic (#198)
* Support dashboard v4-v5 switch And query for v5 topic * Modify tag name --------- Co-authored-by: yuanziwei <[email protected]>
1 parent 823bce2 commit 21dc2ac

File tree

11 files changed

+202
-14
lines changed

11 files changed

+202
-14
lines changed

src/main/java/org/apache/rocketmq/dashboard/controller/TopicController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public Object list(@RequestParam(value = "skipSysProcess", required = false) boo
5656
return topicService.fetchAllTopicList(skipSysProcess, skipRetryAndDlq);
5757
}
5858

59+
@RequestMapping(value = "/list.queryTopicType", method = RequestMethod.GET)
60+
@ResponseBody
61+
public Object listTopicType() {
62+
return topicService.examineAllTopicType();
63+
}
64+
5965
@RequestMapping(value = "/stats.query", method = RequestMethod.GET)
6066
@ResponseBody
6167
public Object stats(@RequestParam String topic) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.rocketmq.dashboard.model.request;
18+
19+
import java.util.List;
20+
21+
public class TopicTypeList {
22+
private List<String> topicNameList;
23+
private List<String> messageTypeList;
24+
25+
public List<String> getTopicNameList() {
26+
return topicNameList;
27+
}
28+
29+
public void setTopicNameList(List<String> topicNameList) {
30+
this.topicNameList = topicNameList;
31+
}
32+
33+
public List<String> getMessageTypeList() {
34+
return messageTypeList;
35+
}
36+
37+
public void setMessageTypeList(List<String> messageTypeList) {
38+
this.messageTypeList = messageTypeList;
39+
}
40+
41+
public TopicTypeList(List<String> topicNameList, List<String> messageTypeList) {
42+
this.topicNameList = topicNameList;
43+
this.messageTypeList = messageTypeList;
44+
}
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.rocketmq.dashboard.model.request;
18+
19+
public class TopicTypeMeta {
20+
private String topicName;
21+
private String messageType;
22+
23+
public String getTopicName() {
24+
return topicName;
25+
}
26+
27+
public void setTopicName(String topicName) {
28+
this.topicName = topicName;
29+
}
30+
31+
public String getMessageType() {
32+
return messageType;
33+
}
34+
35+
public void setMessageType(String messageType) {
36+
this.messageType = messageType;
37+
}
38+
}

src/main/java/org/apache/rocketmq/dashboard/service/TopicService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.rocketmq.client.producer.SendResult;
2121
import org.apache.rocketmq.common.TopicConfig;
22+
import org.apache.rocketmq.dashboard.model.request.TopicTypeList;
2223
import org.apache.rocketmq.remoting.protocol.admin.TopicStatsTable;
2324
import org.apache.rocketmq.remoting.protocol.body.GroupList;
2425
import org.apache.rocketmq.remoting.protocol.body.TopicList;
@@ -31,6 +32,8 @@
3132
public interface TopicService {
3233
TopicList fetchAllTopicList(boolean skipSysProcess, boolean skipRetryAndDlq);
3334

35+
TopicTypeList examineAllTopicType();
36+
3437
TopicStatsTable stats(String topic);
3538

3639
TopicRouteData route(String topic);

src/main/java/org/apache/rocketmq/dashboard/service/impl/TopicServiceImpl.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.apache.rocketmq.dashboard.config.RMQConfigure;
4141
import org.apache.rocketmq.dashboard.model.request.SendTopicMessageRequest;
4242
import org.apache.rocketmq.dashboard.model.request.TopicConfigInfo;
43+
import org.apache.rocketmq.dashboard.model.request.TopicTypeList;
44+
import org.apache.rocketmq.dashboard.model.request.TopicTypeMeta;
4345
import org.apache.rocketmq.dashboard.service.AbstractCommonService;
4446
import org.apache.rocketmq.dashboard.service.TopicService;
4547
import org.apache.rocketmq.remoting.RPCHook;
@@ -54,7 +56,9 @@
5456
import org.springframework.beans.BeanUtils;
5557
import org.springframework.beans.factory.annotation.Autowired;
5658
import org.springframework.stereotype.Service;
59+
import org.springframework.util.CollectionUtils;
5760

61+
import java.util.ArrayList;
5862
import java.util.Arrays;
5963
import java.util.HashSet;
6064
import java.util.List;
@@ -99,6 +103,41 @@ public TopicList fetchAllTopicList(boolean skipSysProcess, boolean skipRetryAndD
99103
}
100104
}
101105

106+
@Override
107+
public TopicTypeList examineAllTopicType() {
108+
ArrayList<TopicTypeMeta> topicTypes = new ArrayList<>();
109+
ArrayList<String> names = new ArrayList<>();
110+
ArrayList<String> messageTypes = new ArrayList<>();
111+
TopicList topicList = fetchAllTopicList(false, false);
112+
checkTopicType(topicList, topicTypes);
113+
topicTypes.sort((t1, t2) -> t1.getTopicName().compareTo(t2.getTopicName()));
114+
for (TopicTypeMeta topicTypeMeta : topicTypes) {
115+
names.add(topicTypeMeta.getTopicName());
116+
messageTypes.add(topicTypeMeta.getMessageType());
117+
}
118+
return new TopicTypeList(names, messageTypes);
119+
}
120+
121+
private void checkTopicType(TopicList topicList, ArrayList<TopicTypeMeta> topicTypes) {
122+
for (String topicName : topicList.getTopicList()) {
123+
TopicTypeMeta topicType = new TopicTypeMeta();
124+
topicType.setTopicName(topicName);
125+
if (topicName.startsWith("%R")) {
126+
topicType.setMessageType("RETRY");
127+
} else if (topicName.startsWith("%D")) {
128+
topicType.setMessageType("DELAY");
129+
} else if (topicName.startsWith("%S")) {
130+
topicType.setMessageType("SYSTEM");
131+
} else {
132+
List<TopicConfigInfo> topicConfigInfos = examineTopicConfig(topicName);
133+
if (!CollectionUtils.isEmpty(topicConfigInfos)) {
134+
topicType.setMessageType(topicConfigInfos.get(0).getMessageType());
135+
}
136+
}
137+
topicTypes.add(topicType);
138+
}
139+
}
140+
102141
@Override
103142
public TopicStatsTable stats(String topic) {
104143
try {

src/main/resources/static/src/controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515
* limitations under the License.
1616
*/
1717
app.controller('AppCtrl', ['$scope','$window','$translate','$http','Notification', function ($scope,$window,$translate, $http, Notification) {
18+
$scope.rmqVersion = localStorage.getItem("isV5") === "true" ? true : false;
19+
1820
$scope.changeTranslate = function(langKey){
1921
$translate.use(langKey);
2022
}
2123

24+
$scope.changeRMQVersion = function (version) {
25+
$scope.rmqVersion = version === 5;
26+
localStorage.setItem("isV5", $scope.rmqVersion);
27+
}
28+
2229
$scope.logout = function(){
2330
$http({
2431
method: "POST",

src/main/resources/static/src/i18n/en.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ var en = {
5454
"RESET_CUS_OFFSET": "Reset Consumer Offset",
5555
"DELETE": "Delete",
5656
"CHANGE_LANG": "ChangeLanguage",
57+
"CHANGE_VERSION": "ChangeVersion",
5758
"BROKER": "Broker",
5859
"NORMAL": "NORMAL",
5960
"RETRY": "RETRY",
61+
"FIFO": "FIFO",
62+
"TRANSACTION": "TRANSACTION",
6063
"DLQ": "DLQ",
6164
"QUANTITY":"Quantity",
6265
"TYPE":"Type",

src/main/resources/static/src/i18n/zh.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ var zh = {
5555
"SKIP_MESSAGE_ACCUMULATE":"跳过堆积",
5656
"DELETE": "删除",
5757
"CHANGE_LANG": "更换语言",
58+
"CHANGE_VERSION": "更换版本",
5859
"BROKER": "Broker",
5960
"NORMAL": "普通",
6061
"RETRY": "重试",
62+
"FIFO": "顺序",
63+
"TRANSACTION": "事务",
6164
"DLQ": "死信",
6265
"QUANTITY":"数量",
6366
"TYPE":"类型",

src/main/resources/static/src/topic.js

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,30 @@ module.controller('topicController', ['$scope', 'ngDialog', '$http', 'Notificati
4545
}
4646
};
4747
$scope.filterNormal = true
48+
$scope.filterDelay = false
49+
$scope.filterFifo = false
50+
$scope.filterTransaction = false
4851
$scope.filterRetry = false
4952
$scope.filterDLQ = false
5053
$scope.filterSystem = false
5154
$scope.allTopicList = [];
55+
$scope.allTopicNameList = [];
56+
$scope.allMessageTypeList = [];
5257
$scope.topicShowList = [];
5358
$scope.userRole = $window.sessionStorage.getItem("userrole");
54-
$scope.writeOperationEnabled = $scope.userRole == null ? true : ($scope.userRole == 1 ? true : false);
59+
$scope.writeOperationEnabled = $scope.userRole == null ? true : ($scope.userRole == 1 ? true : false);
5560

5661
$scope.refreshTopicList = function () {
5762
$http({
5863
method: "GET",
59-
url: "topic/list.query"
64+
url: "topic/list.queryTopicType"
6065
}).success(function (resp) {
6166
if (resp.status == 0) {
62-
$scope.allTopicList = resp.data.topicList.sort();
63-
console.log($scope.allTopicList);
67+
$scope.allTopicNameList = resp.data.topicNameList;
68+
$scope.allMessageTypeList = resp.data.messageTypeList;
69+
console.log($scope.allTopicNameList);
6470
console.log(JSON.stringify(resp));
65-
$scope.showTopicList(1, $scope.allTopicList.length);
71+
$scope.showTopicList(1, $scope.allTopicNameList.length);
6672

6773
} else {
6874
Notification.error({message: resp.errMsg, delay: 5000});
@@ -79,6 +85,15 @@ module.controller('topicController', ['$scope', 'ngDialog', '$http', 'Notificati
7985
$scope.$watch('filterNormal', function () {
8086
$scope.filterList(1);
8187
});
88+
$scope.$watch('filterFifo', function () {
89+
$scope.filterList(1);
90+
});
91+
$scope.$watch('filterTransaction', function () {
92+
$scope.filterList(1);
93+
});
94+
$scope.$watch('filterDelay', function () {
95+
$scope.filterList(1);
96+
});
8297
$scope.$watch('filterRetry', function () {
8398
$scope.filterList(1);
8499
});
@@ -92,21 +107,21 @@ module.controller('topicController', ['$scope', 'ngDialog', '$http', 'Notificati
92107
var lowExceptStr = $scope.filterStr.toLowerCase();
93108
var canShowList = [];
94109

95-
$scope.allTopicList.forEach(function (element) {
96-
if ($scope.filterByType(element)) {
97-
if (element.toLowerCase().indexOf(lowExceptStr) != -1) {
98-
canShowList.push(element);
110+
for (let i = 0; i < $scope.allTopicNameList.length; ++i) {
111+
if ($scope.filterByType($scope.allTopicNameList[i], $scope.allMessageTypeList[i])) {
112+
if ($scope.allTopicNameList[i].toLowerCase().indexOf(lowExceptStr) != -1) {
113+
canShowList.push($scope.allTopicNameList[i]);
99114
}
100115
}
101-
});
116+
}
102117
$scope.paginationConf.totalItems = canShowList.length;
103118
var perPage = $scope.paginationConf.itemsPerPage;
104119
var from = (currentPage - 1) * perPage;
105120
var to = (from + perPage) > canShowList.length ? canShowList.length : from + perPage;
106121
$scope.topicShowList = canShowList.slice(from, to);
107122
};
108123

109-
$scope.filterByType = function (str) {
124+
$scope.filterByType = function (str, type) {
110125
if ($scope.filterRetry) {
111126
if (str.startsWith("%R")) {
112127
return true
@@ -123,7 +138,22 @@ module.controller('topicController', ['$scope', 'ngDialog', '$http', 'Notificati
123138
}
124139
}
125140
if ($scope.filterNormal) {
126-
if (str.startsWith("%") == false) {
141+
if (type.includes("NORMAL")) {
142+
return true
143+
}
144+
}
145+
if ($scope.filterDelay) {
146+
if (type.includes("DELAY")) {
147+
return true
148+
}
149+
}
150+
if ($scope.filterFifo) {
151+
if (type.includes("FIFO")) {
152+
return true
153+
}
154+
}
155+
if ($scope.filterTransaction) {
156+
if (type.includes("TRANSACTION")) {
127157
return true
128158
}
129159
}
@@ -138,10 +168,10 @@ module.controller('topicController', ['$scope', 'ngDialog', '$http', 'Notificati
138168
var perPage = $scope.paginationConf.itemsPerPage;
139169
var from = (currentPage - 1) * perPage;
140170
var to = (from + perPage) > totalItem ? totalItem : from + perPage;
141-
console.log($scope.allTopicList);
171+
console.log($scope.allTopicNameList);
142172
console.log(from)
143173
console.log(to)
144-
$scope.topicShowList = $scope.allTopicList.slice(from, to);
174+
$scope.topicShowList = $scope.allTopicNameList.slice(from, to);
145175
$scope.paginationConf.totalItems = totalItem;
146176
console.log($scope.topicShowList)
147177
console.log($scope.paginationConf.totalItems)

src/main/resources/static/view/layout/_header.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
<li><a href="javascript:void(0)" ng-click="changeTranslate('zh')">Simplified Chinese</a></li>
4848
</ul>
4949
</li>
50+
<li class="dropdown">
51+
<a href="bootstrap-elements.html" data-target="#" class="dropdown-toggle" data-toggle="dropdown">{{'CHANGE_VERSION' | translate}}
52+
<b class="caret"></b></a>
53+
<ul class="dropdown-menu">
54+
<li><a href="javascript:void(0)" ng-click="changeRMQVersion(5)">RocketMQ 5.x</a></li>
55+
<li><a href="javascript:void(0)" ng-click="changeRMQVersion(4)">RocketMQ 4.x</a></li>
56+
</ul>
57+
</li>
5058
<li class="dropdown" ng-show="username != ''">
5159
<a href="bootstrap-elements.html" data-target="#" class="dropdown-toggle" data-toggle="dropdown">{{username}}
5260
<b class="caret"></b></a>

0 commit comments

Comments
 (0)