Skip to content

Commit 4587f06

Browse files
committed
【Doe_V1.1.0】增加接口version和group支持
1 parent 0339811 commit 4587f06

File tree

11 files changed

+105
-19
lines changed

11 files changed

+105
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- 修复grid序号问题
55
- 修复spring 版本过低问题
66
- 增加注册中心管理页面
7+
- 增加接口version和group支持
78
- provider 修改为starter方式
89
- 增加守护程序,停止、重启、发布
910
* 需要python2 环境支持

mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/crontroller/DubboController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public ResultDTO<Object> doListMethods(@NotNull ConnectDTO dto) {
139139
@RequestMapping("/doListProviders")
140140
public ResultDTO<Object> doListProviders(@NotNull ConnectDTO dto) {
141141

142-
log.info("DubboController.doListProviders({})", dto.getServiceName());
142+
log.info("DubboController.doListProviders({} {} {})", dto.getServiceName(), dto.getVersion(), dto.getGroup());
143143

144144
ResultDTO<Object> resultDTO = new ResultDTO<>();
145145

mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/dto/ConnectDTO.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,12 @@ public class ConnectDTO extends BaseDTO {
4646
* timeout of waiting for result.
4747
*/
4848
private int timeout;
49-
49+
/**
50+
* interface version number, eg: 1.0.0
51+
*/
52+
private String version;
53+
/**
54+
* the group of interface, eg: mmcgroup
55+
*/
56+
private String group;
5057
}

mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/handler/CuratorHandler.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
import com.alibaba.dubbo.common.Constants;
1313
import com.alibaba.dubbo.common.URL;
14+
import com.alibaba.dubbo.common.utils.StringUtils;
1415
import com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry;
1516
import com.alibaba.dubbo.remoting.zookeeper.ZookeeperClient;
1617
import com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
1718
import com.mmc.dubbo.doe.cache.MethodCaches;
1819
import com.mmc.dubbo.doe.cache.UrlCaches;
20+
import com.mmc.dubbo.doe.dto.ConnectDTO;
1921
import com.mmc.dubbo.doe.dto.MethodModelDTO;
22+
import com.mmc.dubbo.doe.exception.DoeException;
2023
import com.mmc.dubbo.doe.model.ServiceModel;
2124
import com.mmc.dubbo.doe.model.UrlModel;
2225

@@ -71,14 +74,29 @@ public List<ServiceModel> getInterfaces() {
7174
return ret;
7275
}
7376

74-
public List<UrlModel> getProviders(String interfaceName) {
77+
public List<UrlModel> getProviders(ConnectDTO dto) {
78+
79+
if (null == dto) {
80+
throw new DoeException("dto can't be null.");
81+
}
82+
if (StringUtils.isEmpty(dto.getServiceName())) {
83+
throw new DoeException("service name can't be null.");
84+
}
7585

7686
Map<String, String> map = new HashMap<>();
77-
map.put(Constants.INTERFACE_KEY, interfaceName);
87+
map.put(Constants.INTERFACE_KEY, dto.getServiceName());
88+
89+
if (StringUtils.isNotEmpty(dto.getVersion())) {
90+
map.put(Constants.VERSION_KEY, dto.getVersion());
91+
}
92+
if (StringUtils.isNotEmpty(dto.getGroup())) {
93+
map.put(Constants.GROUP_KEY, dto.getGroup());
94+
}
95+
7896
URL url = new URL(protocol, host, port, map);
7997
List<URL> list = registry.lookup(url);
8098

81-
return UrlCaches.cache(interfaceName, list);
99+
return UrlCaches.cache(dto.getServiceName(), list);
82100
}
83101

84102
public List<MethodModelDTO> getMethods(String interfaceName) throws ClassNotFoundException {

mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/service/impl/ConnectServiceImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ public List<UrlModelDTO> listProviders(@NotNull ConnectDTO connect) throws NoSuc
9898
throw new DoeException("the cache is validate, please reconnect to zk againt.");
9999
}
100100

101-
// TODO add service version support
102-
List<UrlModel> providers = client.getProviders(connect.getServiceName());
101+
List<UrlModel> providers = client.getProviders(connect);
103102

104103
// throw fast json error if you don't convert simple pojo
105104
// I have no idea why the UrlModel object will throw stack over flow exception.

mmc-dubbo-doe/src/main/java/com/mmc/dubbo/doe/util/ParamUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public static HashMap<String,String> getAttachmentFromUrl(URL url) throws Except
4040

4141
HashMap<String, String> map = new HashMap<String, String>();
4242
map.put(Constants.PATH_KEY, interfaceName);
43+
map.put(Constants.VERSION_KEY, url.getParameter(Constants.VERSION_KEY));
44+
map.put(Constants.GROUP_KEY, url.getParameter(Constants.GROUP_KEY));
4345
/**
4446
* doesn't necessary to set these params.
4547
*

mmc-dubbo-doe/src/main/resources/templates/pages/v3/normalCnt.html

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ <h5 class="lighter">注册中心</h5>
6363
</button>
6464
</span>
6565
</div>
66+
<span class="smaller-20 lighter blue">如有需要,请先设置group和version,再连接zk.</span>
6667
</div>
6768
</div>
6869
</form>
@@ -115,10 +116,32 @@ <h4>提供者地址</h4>
115116
</div>
116117

117118
<div class="col-xs-12 col-sm-4">
118-
<button class="btn btn-app btn-pink btn-sm" onclick="doListMethods();">
119-
<i class="icon-share-alt bigger-200"></i>
120-
拉取方法
121-
</button>
119+
<div class="col-xs-5">
120+
<form class="form-horizontal">
121+
<div class="control-group">
122+
<label class="control-label" for="txtVersion">接口版本</label>
123+
124+
<div class="controls">
125+
<input type="text" id="txtVersion" placeholder="" />
126+
</div>
127+
</div>
128+
129+
<div class="control-group">
130+
<label class="control-label" for="txtGroup">接口分组</label>
131+
132+
<div class="controls">
133+
<input type="text" id="txtGroup" placeholder="" />
134+
</div>
135+
</div>
136+
</form>
137+
</div>
138+
<div class="col-xs-5">
139+
<button class="btn btn-app btn-pink btn-sm" onclick="doListMethods();">
140+
<i class="icon-share-alt bigger-200"></i>
141+
拉取方法
142+
</button>
143+
144+
</div>
122145
</div>
123146
</div>
124147

@@ -290,6 +313,8 @@ <h4>响应结果</h4>
290313
var providerKey = $("#cboProviders").val();
291314
var methodKey = $("input[name='rdMethodKey']:checked").val();
292315
var json = paramEditor.getValue();
316+
var version = $("#txtVersion").val();
317+
var group = $("#txtGroup").val();
293318

294319
if (null == providerKey || providerKey.length <= 0) {
295320
return;
@@ -298,7 +323,7 @@ <h4>响应结果</h4>
298323
return;
299324
}
300325

301-
var params = {"providerKey": providerKey, "json": json, "methodKey": methodKey};
326+
var params = {"providerKey": providerKey, "json": json, "methodKey": methodKey, "version": version, "group": group};
302327
Nora.Ajax("/doe/dubbo/doSend", params, function (data) {
303328

304329
if (data.success && null != data.data && data.data.length > 0) {
@@ -386,8 +411,10 @@ <h4>响应结果</h4>
386411
function doListProviders(serviceName) {
387412

388413
var conn = $("#txtConnect").val();// 这就是selected的值
414+
var version = $("#txtVersion").val();
415+
var group = $("#txtGroup").val();
389416

390-
var params = {"conn": conn, "serviceName": serviceName};
417+
var params = {"conn": conn, "serviceName": serviceName, "version": version, "group": group};
391418
var cboProvider = $("#cboProviders");
392419
Nora.Ajax("/doe/dubbo/doListProviders", params, function (data) {
393420

mmc-dubbo-doe/src/test/java/com/mmc/dubbo/doe/test/TestCuratorHandler.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package com.mmc.dubbo.doe.test;
1111

12+
import com.mmc.dubbo.doe.dto.ConnectDTO;
1213
import com.mmc.dubbo.doe.handler.CuratorHandler;
1314
import com.mmc.dubbo.doe.dto.MethodModelDTO;
1415
import com.mmc.dubbo.doe.model.ServiceModel;
@@ -53,7 +54,17 @@ public void testGetInterfaces() {
5354
public void testGetProviders() {
5455

5556
String interfaceName = "com.mmc.dubbo.api.user.UserService";
56-
List<UrlModel> list = client.getProviders(interfaceName);
57+
58+
ConnectDTO dto = new ConnectDTO();
59+
dto.setServiceName(interfaceName);
60+
61+
List<UrlModel> list = client.getProviders(dto);
62+
Assert.assertTrue(list.size() <= 1);
63+
64+
dto.setVersion("2.0.0");
65+
dto.setGroup("mmcgroup");
66+
list = client.getProviders(dto);
67+
Assert.assertTrue(list.size() == 0);
5768

5869
System.out.println("----------------------------------------------------------------");
5970
list.forEach(l -> {

mmc-dubbo-doe/src/test/java/com/mmc/dubbo/doe/test/TestDemo.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.mmc.dubbo.api.user.UserFact;
1818
import com.mmc.dubbo.doe.client.DoeClient;
1919
import com.mmc.dubbo.doe.context.ResponseDispatcher;
20+
import com.mmc.dubbo.doe.dto.ConnectDTO;
2021
import com.mmc.dubbo.doe.handler.CuratorHandler;
2122
import com.mmc.dubbo.doe.model.UrlModel;
2223
import com.mmc.dubbo.doe.util.ParamUtil;
@@ -47,7 +48,9 @@ public void testDemo() throws Exception {
4748

4849
CuratorHandler curatorHandler = new CuratorHandler(protocol, host, port);
4950
curatorHandler.doConnect();
50-
List<UrlModel> urls = curatorHandler.getProviders(interfaceName);
51+
ConnectDTO conn = new ConnectDTO();
52+
conn.setServiceName(interfaceName);
53+
List<UrlModel> urls = curatorHandler.getProviders(conn);
5154

5255
URL url = urls.get(0).getUrl();
5356
url = url.addParameter(Constants.CODEC_KEY, protocol); // 非常重要,必须要设置编码器协议类型

mmc-dubbo-provider/src/main/java/com/mmc/dubbo/provider/user/UserFeedbackServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @author Joey
1717
* @date 2018/5/8 20:31
1818
*/
19-
@com.alibaba.dubbo.config.annotation.Service
19+
@com.alibaba.dubbo.config.annotation.Service(version = "2.0.0", group = "mmcgroup")
2020
public class UserFeedbackServiceImpl implements UserService {
2121

2222
/**
@@ -32,7 +32,7 @@ public UserFact getCurrentById(long id) {
3232

3333
UserFact user = new UserFact();
3434
user.setId(id);
35-
user.setName("SUCCESS");
35+
user.setName("mmcgroup");
3636

3737
return user;
3838
}

0 commit comments

Comments
 (0)