From 202267b686a874f513f1730f9bfb687b2e4e9c99 Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 2 Aug 2019 20:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A2=84=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E3=80=81=E7=81=B0=E5=BA=A6=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/docs/files/10110_预发布灰度发布.md | 31 +++ sop-1.14.0.sql | 12 + sop-admin/sop-admin-server/pom.xml | 6 +- .../SopAdminServerApplication.java | 4 + .../gitee/sop/adminserver/api/isv/IsvApi.java | 3 +- .../api/service/IPBlacklistApi.java | 12 +- .../adminserver/api/service/ServiceApi.java | 65 ++++- .../param/ServiceInstanceGrayParam.java | 26 ++ .../service/param/ServiceInstanceParam.java | 27 +++ .../api/service/param/ServiceSearchParam.java | 5 +- .../sop/adminserver/bean/ChannelMsg.java | 5 +- .../adminserver/bean/UserKeyDefinition.java | 12 + .../adminserver/bean/ZookeeperContext.java | 4 + .../adminserver/common/ChannelOperation.java | 60 +++++ .../adminserver/entity/ConfigGrayUserkey.java | 42 ++++ .../mapper/ConfigGrayUserkeyMapper.java | 12 + .../service/RouteConfigService.java | 7 +- .../service/RoutePermissionService.java | 5 +- .../main/resources/application-dev.properties | 4 - .../src/views/service/ipBlacklist.vue | 2 +- .../src/views/service/serviceList.vue | 227 +++++++++++++++++- .../sop/gatewaycommon/bean/SpringContext.java | 30 +++ .../gatewaycommon/bean/UserKeyDefinition.java | 12 + .../manager/ZookeeperContext.java | 4 + .../gatewaycommon/param/BaseParamBuilder.java | 8 +- .../sop/gatewaycommon/param/ParamNames.java | 2 + .../sop/gatewaycommon/util/RequestUtil.java | 10 +- .../configuration/BaseZuulConfiguration.java | 8 + .../zuul/param/ZuulParamBuilder.java | 9 +- .../sop/servercommon/bean/ParamNames.java | 2 + .../mapping/ApiMappingRequestCondition.java | 4 + .../gitee/sop/servercommon/util/OpenUtil.java | 5 +- .../sop/gateway/entity/ConfigGrayUserkey.java | 42 ++++ .../EnvironmentServerChooser.java | 116 +++++++++ .../PreEnvironmentServerChooser.java | 55 ----- .../loadbalancer/ServiceGrayConfig.java | 33 +++ .../loadbalancer/SopPropertiesFactory.java | 4 +- .../sop/gateway/manager/UserKeyManager.java | 132 ++++++++++ .../mapper/ConfigGrayUserkeyMapper.java | 11 + sop.sql | 12 + 40 files changed, 947 insertions(+), 123 deletions(-) create mode 100644 doc/docs/files/10110_预发布灰度发布.md create mode 100644 sop-1.14.0.sql create mode 100644 sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceGrayParam.java create mode 100644 sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/UserKeyDefinition.java create mode 100644 sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/ChannelOperation.java create mode 100644 sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigGrayUserkey.java create mode 100644 sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/ConfigGrayUserkeyMapper.java create mode 100644 sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SpringContext.java create mode 100644 sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/UserKeyDefinition.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/entity/ConfigGrayUserkey.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/EnvironmentServerChooser.java delete mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/PreEnvironmentServerChooser.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/loadbalancer/ServiceGrayConfig.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/manager/UserKeyManager.java create mode 100644 sop-gateway/src/main/java/com/gitee/sop/gateway/mapper/ConfigGrayUserkeyMapper.java diff --git a/doc/docs/files/10110_预发布灰度发布.md b/doc/docs/files/10110_预发布灰度发布.md new file mode 100644 index 00000000..6a19915d --- /dev/null +++ b/doc/docs/files/10110_预发布灰度发布.md @@ -0,0 +1,31 @@ +# 预发布灰度发布 + +从1.14.0开始支持预发布、灰度发布,可登陆`SOP-Admin`,然后选择`服务列表`进行操作。 + +## 使用预发布 + +假设网关工程在阿里云负载均衡有两台服务器,域名分别为: + +|域名|说明| +|:---- |:---- | +|open1.domain.com |网关服务器1 | +|openpre.domain.com | 网关服务器2,作为预发布请求入口| + +线上域名为`open.domain.com`,请求网关`http://open.domain.com/api`会负载均衡到这两台服务器 + +在网关工程打开`com.gitee.sop.gateway.loadbalancer.EnvironmentServerChooser`类,修改`PRE_DOMAIN`变量 + +```java +/** + * 预发布机器域名 + */ +private static final String PRE_DOMAIN = "openpre.domain.com"; +``` + +网关工程打包发布到阿里云 + +登录SOP-Admin,在服务列表中点击预发布,然后接口的请求地址变成:`http://openpre.domain.com/api` + +## 使用灰度发布 + +灰度发布可允许指定的用户进行访问,其它用户则走正常流程。 diff --git a/sop-1.14.0.sql b/sop-1.14.0.sql new file mode 100644 index 00000000..d84dadbb --- /dev/null +++ b/sop-1.14.0.sql @@ -0,0 +1,12 @@ +use sop; + +CREATE TABLE `config_gray_userkey` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `instance_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'serviceId', + `user_key_content` text COMMENT '用户key,多个用引文逗号隔开', + `name_version_content` text COMMENT '需要灰度的接口,goods.get=1.2,order.list=1.2', + `gmt_create` datetime DEFAULT CURRENT_TIMESTAMP, + `gmt_modified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_instanceid` (`instance_id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='灰度发布用户key'; \ No newline at end of file diff --git a/sop-admin/sop-admin-server/pom.xml b/sop-admin/sop-admin-server/pom.xml index ff05f7e3..8e5bb49c 100644 --- a/sop-admin/sop-admin-server/pom.xml +++ b/sop-admin/sop-admin-server/pom.xml @@ -24,6 +24,8 @@ 3.4.12 4.0.1 3.11.0 + 1.16.2 + 1.8.0 @@ -37,13 +39,13 @@ net.oschina.durcframework easyopen-spring-boot-starter - 1.16.2 + ${easyopen.version} net.oschina.durcframework fastmybatis-spring-boot-starter - 1.7.2 + ${fastmybatis.version} mysql diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java index e388660d..dc6f561e 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java @@ -1,12 +1,16 @@ package com.gitee.sop.adminserver; +import com.gitee.fastmybatis.core.FastmybatisConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.util.Arrays; + @SpringBootApplication public class SopAdminServerApplication { public static void main(String[] args) { + FastmybatisConfig.defaultIgnoreUpdateColumns = Arrays.asList("gmt_create", "gmt_modified"); SpringApplication.run(SopAdminServerApplication.class, args); } } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/IsvApi.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/IsvApi.java index 273c3553..bd4b6d25 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/IsvApi.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/IsvApi.java @@ -26,6 +26,7 @@ import com.gitee.sop.adminserver.api.isv.result.RoleVO; import com.gitee.sop.adminserver.bean.ChannelMsg; import com.gitee.sop.adminserver.bean.ZookeeperContext; import com.gitee.sop.adminserver.common.BizException; +import com.gitee.sop.adminserver.common.ChannelOperation; import com.gitee.sop.adminserver.common.IdGen; import com.gitee.sop.adminserver.common.RSATool; import com.gitee.sop.adminserver.common.ZookeeperPathNotExistException; @@ -229,7 +230,7 @@ public class IsvApi { if (isvDetail == null) { return; } - ChannelMsg channelMsg = new ChannelMsg("update", isvDetail); + ChannelMsg channelMsg = new ChannelMsg(ChannelOperation.ISV_INFO_UPDATE, isvDetail); String path = ZookeeperContext.getIsvInfoChannelPath(); String data = JSON.toJSONString(channelMsg); try { diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/IPBlacklistApi.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/IPBlacklistApi.java index 284140cc..4bb78936 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/IPBlacklistApi.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/IPBlacklistApi.java @@ -16,6 +16,7 @@ import com.gitee.sop.adminserver.api.service.result.ConfigIpBlacklistVO; import com.gitee.sop.adminserver.bean.ChannelMsg; import com.gitee.sop.adminserver.bean.ZookeeperContext; import com.gitee.sop.adminserver.common.BizException; +import com.gitee.sop.adminserver.common.ChannelOperation; import com.gitee.sop.adminserver.entity.ConfigIpBlacklist; import com.gitee.sop.adminserver.mapper.ConfigIpBlacklistMapper; import lombok.extern.slf4j.Slf4j; @@ -51,7 +52,7 @@ public class IPBlacklistApi { CopyUtil.copyPropertiesIgnoreNull(form, rec); configIpBlacklistMapper.saveIgnoreNull(rec); try { - this.sendIpBlacklistMsg(rec, BlacklistMsgType.ADD); + this.sendIpBlacklistMsg(rec, ChannelOperation.BLACKLIST_ADD); } catch (Exception e) { log.error("推送IP黑名单失败, rec:{}",rec, e); throw new BizException("推送IP黑名单失败"); @@ -75,19 +76,18 @@ public class IPBlacklistApi { } configIpBlacklistMapper.deleteById(id); try { - this.sendIpBlacklistMsg(rec, BlacklistMsgType.DELETE); + this.sendIpBlacklistMsg(rec, ChannelOperation.BLACKLIST_DELETE); } catch (Exception e) { log.error("推送IP黑名单失败, rec:{}",rec, e); throw new BizException("推送IP黑名单失败"); } } - public void sendIpBlacklistMsg(ConfigIpBlacklist configIpBlacklist, BlacklistMsgType blacklistMsgType) throws Exception { - String configData = JSON.toJSONString(configIpBlacklist); - ChannelMsg channelMsg = new ChannelMsg(blacklistMsgType.name().toLowerCase(), configData); + public void sendIpBlacklistMsg(ConfigIpBlacklist configIpBlacklist, ChannelOperation channelOperation) throws Exception { + ChannelMsg channelMsg = new ChannelMsg(channelOperation, configIpBlacklist); String jsonData = JSON.toJSONString(channelMsg); String path = ZookeeperContext.getIpBlacklistChannelPath(); - log.info("消息推送--IP黑名单设置({}), path:{}, data:{}",blacklistMsgType.name(), path, jsonData); + log.info("消息推送--IP黑名单设置({}), path:{}, data:{}",channelOperation.getOperation(), path, jsonData); ZookeeperContext.createOrUpdateData(path, jsonData); } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/ServiceApi.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/ServiceApi.java index fa3d4b0a..aa4e6b9c 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/ServiceApi.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/ServiceApi.java @@ -6,16 +6,23 @@ import com.gitee.easyopen.annotation.ApiService; import com.gitee.easyopen.doc.annotation.ApiDoc; import com.gitee.easyopen.doc.annotation.ApiDocMethod; import com.gitee.sop.adminserver.api.service.param.ServiceAddParam; +import com.gitee.sop.adminserver.api.service.param.ServiceInstanceGrayParam; +import com.gitee.sop.adminserver.api.service.param.ServiceInstanceParam; import com.gitee.sop.adminserver.api.service.param.ServiceSearchParam; import com.gitee.sop.adminserver.api.service.result.RouteServiceInfo; import com.gitee.sop.adminserver.api.service.result.ServiceInfoVo; import com.gitee.sop.adminserver.api.service.result.ServiceInstanceVO; +import com.gitee.sop.adminserver.bean.ChannelMsg; import com.gitee.sop.adminserver.bean.MetadataEnum; import com.gitee.sop.adminserver.bean.ServiceRouteInfo; +import com.gitee.sop.adminserver.bean.UserKeyDefinition; import com.gitee.sop.adminserver.bean.ZookeeperContext; import com.gitee.sop.adminserver.common.BizException; +import com.gitee.sop.adminserver.common.ChannelOperation; import com.gitee.sop.adminserver.common.ZookeeperPathExistException; import com.gitee.sop.adminserver.common.ZookeeperPathNotExistException; +import com.gitee.sop.adminserver.entity.ConfigGrayUserkey; +import com.gitee.sop.adminserver.mapper.ConfigGrayUserkeyMapper; import com.gitee.sop.registryapi.bean.ServiceInfo; import com.gitee.sop.registryapi.bean.ServiceInstance; import com.gitee.sop.registryapi.service.RegistryService; @@ -45,6 +52,9 @@ public class ServiceApi { @Autowired private RegistryService registryService; + @Autowired + private ConfigGrayUserkeyMapper configGrayUserkeyMapper; + @Api(name = "zookeeper.service.list") @ApiDocMethod(description = "zk中的服务列表", elementClass = RouteServiceInfo.class) List listServiceInfo(ServiceSearchParam param) { @@ -157,9 +167,9 @@ public class ServiceApi { @Api(name = "service.instance.offline") @ApiDocMethod(description = "服务禁用") - void serviceOffline(ServiceInstance param) { + void serviceOffline(ServiceInstanceParam param) { try { - registryService.offlineInstance(param); + registryService.offlineInstance(param.buildServiceInstance()); } catch (Exception e) { log.error("服务禁用失败,param:{}", param, e); throw new BizException("服务禁用失败,请查看日志"); @@ -168,9 +178,9 @@ public class ServiceApi { @Api(name = "service.instance.online") @ApiDocMethod(description = "服务启用") - void serviceOnline(ServiceInstance param) throws IOException { + void serviceOnline(ServiceInstanceParam param) throws IOException { try { - registryService.onlineInstance(param); + registryService.onlineInstance(param.buildServiceInstance()); } catch (Exception e) { log.error("服务启用失败,param:{}", param, e); throw new BizException("服务启用失败,请查看日志"); @@ -179,10 +189,10 @@ public class ServiceApi { @Api(name = "service.instance.env.pre") @ApiDocMethod(description = "预发布") - void serviceEnvPre(ServiceInstance param) throws IOException { + void serviceEnvPre(ServiceInstanceParam param) throws IOException { try { MetadataEnum envPre = MetadataEnum.ENV_PRE; - registryService.setMetadata(param, envPre.getKey(), envPre.getValue()); + registryService.setMetadata(param.buildServiceInstance(), envPre.getKey(), envPre.getValue()); } catch (Exception e) { log.error("预发布失败,param:{}", param, e); throw new BizException("预发布失败,请查看日志"); @@ -191,10 +201,31 @@ public class ServiceApi { @Api(name = "service.instance.env.gray") @ApiDocMethod(description = "灰度发布") - void serviceEnvGray(ServiceInstance param) throws IOException { + void serviceEnvGray(ServiceInstanceGrayParam param) throws IOException { try { - MetadataEnum envPre = MetadataEnum.ENV_GRAY; - registryService.setMetadata(param, envPre.getKey(), envPre.getValue()); + Boolean onlyUpdateGrayUserkey = param.getOnlyUpdateGrayUserkey(); + if (onlyUpdateGrayUserkey == null || !onlyUpdateGrayUserkey) { + MetadataEnum envPre = MetadataEnum.ENV_GRAY; + registryService.setMetadata(param.buildServiceInstance(), envPre.getKey(), envPre.getValue()); + } + + String instanceId = param.getInstanceId(); + String userKeyContent = param.getUserKeyContent(); + String nameVersionContent = param.getNameVersionContent(); + + ConfigGrayUserkey configGrayUserkey = configGrayUserkeyMapper.getByColumn("instance_id", instanceId); + if (configGrayUserkey == null) { + configGrayUserkey = new ConfigGrayUserkey(); + configGrayUserkey.setInstanceId(instanceId); + configGrayUserkey.setUserKeyContent(userKeyContent); + configGrayUserkey.setNameVersionContent(nameVersionContent); + configGrayUserkeyMapper.save(configGrayUserkey); + } else { + configGrayUserkey.setUserKeyContent(userKeyContent); + configGrayUserkey.setNameVersionContent(nameVersionContent); + configGrayUserkeyMapper.update(configGrayUserkey); + } + this.sendUserKeyMsg(instanceId, ChannelOperation.GRAY_USER_KEY_SET); } catch (Exception e) { log.error("灰度发布失败,param:{}", param, e); throw new BizException("灰度发布失败,请查看日志"); @@ -207,10 +238,26 @@ public class ServiceApi { try { MetadataEnum envPre = MetadataEnum.ENV_ONLINE; registryService.setMetadata(param, envPre.getKey(), envPre.getValue()); + this.sendUserKeyMsg(param.getServiceId(), ChannelOperation.GRAY_USER_KEY_CLEAR); } catch (Exception e) { log.error("上线失败,param:{}", param, e); throw new BizException("上线失败,请查看日志"); } } + @Api(name = "service.instance.gray.userkey.get") + ConfigGrayUserkey getGrayUserkey(ServiceSearchParam param) { + return configGrayUserkeyMapper.getByColumn("instance_id", param.getInstanceId()); + } + + private void sendUserKeyMsg(String serviceId, ChannelOperation channelOperation) { + UserKeyDefinition userKeyDefinition = new UserKeyDefinition(); + userKeyDefinition.setServiceId(serviceId); + ChannelMsg channelMsg = new ChannelMsg(channelOperation, userKeyDefinition); + String jsonData = JSON.toJSONString(channelMsg); + String path = ZookeeperContext.getUserKeyChannelPath(); + log.info("消息推送--灰度发布({}), path:{}, data:{}",channelOperation.getOperation(), path, jsonData); + ZookeeperContext.createOrUpdateData(path, jsonData); + } + } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceGrayParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceGrayParam.java new file mode 100644 index 00000000..7fbc377d --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceGrayParam.java @@ -0,0 +1,26 @@ +package com.gitee.sop.adminserver.api.service.param; + +import com.gitee.easyopen.doc.annotation.ApiDocField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; + +/** + * @author tanghc + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class ServiceInstanceGrayParam extends ServiceInstanceParam { + + @ApiDocField(description = "灰度发布用户,多个用英文逗号隔开") + @NotBlank(message = "灰度发布用户不能为空") + private String userKeyContent; + + @ApiDocField(description = "灰度发布接口名版本号如:order.get1.0=1.2,多个用英文逗号隔开") + @NotBlank(message = "灰度发布接口名版本号不能为空") + private String nameVersionContent; + + @ApiDocField(description = "是否仅更新灰度用户") + private Boolean onlyUpdateGrayUserkey; +} diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceParam.java index 7dfe26fc..ad550de5 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceParam.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceInstanceParam.java @@ -1,6 +1,8 @@ package com.gitee.sop.adminserver.api.service.param; import com.gitee.easyopen.doc.annotation.ApiDocField; +import com.gitee.easyopen.util.CopyUtil; +import com.gitee.sop.registryapi.bean.ServiceInstance; import lombok.Data; import javax.validation.constraints.NotBlank; @@ -17,4 +19,29 @@ public class ServiceInstanceParam { @ApiDocField(description = "instanceId") @NotBlank(message = "instanceId不能为空") private String instanceId; + + /** + * ip + */ + @ApiDocField(description = "ip") + private String ip; + + /** + * port + */ + @ApiDocField(description = "port") + private int port; + + /** + * 服务状态,UP:已上线,OUT_OF_SERVICE:已下线 + */ + @ApiDocField(description = "status") + private String status; + + + public ServiceInstance buildServiceInstance() { + ServiceInstance serviceInstance = new ServiceInstance(); + CopyUtil.copyPropertiesIgnoreNull(this, serviceInstance); + return serviceInstance; + } } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceSearchParam.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceSearchParam.java index 34535ad6..217482a8 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceSearchParam.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/param/ServiceSearchParam.java @@ -4,8 +4,6 @@ import com.gitee.easyopen.doc.annotation.ApiDocField; import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotBlank; - /** * @author tanghc */ @@ -15,4 +13,7 @@ public class ServiceSearchParam { @ApiDocField(description = "服务名serviceId") private String serviceId; + + @ApiDocField(description = "instanceId") + private String instanceId; } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ChannelMsg.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ChannelMsg.java index dabbe29b..558107c4 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ChannelMsg.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ChannelMsg.java @@ -1,5 +1,6 @@ package com.gitee.sop.adminserver.bean; +import com.gitee.sop.adminserver.common.ChannelOperation; import lombok.Data; /** @@ -8,8 +9,8 @@ import lombok.Data; @Data public class ChannelMsg { - public ChannelMsg(String operation, Object data) { - this.operation = operation; + public ChannelMsg(ChannelOperation channelOperation, Object data) { + this.operation = channelOperation.getOperation(); this.data = data; } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/UserKeyDefinition.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/UserKeyDefinition.java new file mode 100644 index 00000000..9fe32449 --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/UserKeyDefinition.java @@ -0,0 +1,12 @@ +package com.gitee.sop.adminserver.bean; + +import lombok.Data; + +/** + * @author tanghc + */ +@Data +public class UserKeyDefinition { + private String serviceId; + private String data; +} diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java index 50547a75..285433f0 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java @@ -89,6 +89,10 @@ public class ZookeeperContext { return serviceIdPath + "/" + routeId; } + public static String getUserKeyChannelPath() { + return SOP_MSG_CHANNEL_PATH + "/userkey"; + } + public static String getIsvInfoChannelPath() { return SOP_MSG_CHANNEL_PATH + "/isvinfo"; } diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/ChannelOperation.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/ChannelOperation.java new file mode 100644 index 00000000..741ae0b8 --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/common/ChannelOperation.java @@ -0,0 +1,60 @@ +package com.gitee.sop.adminserver.common; + +/** + * @author tanghc + */ +public enum ChannelOperation { + /** + * 限流推送路由配置-修改 + */ + LIMIT_CONFIG_UPDATE("update"), + + /** + * 路由信息更新 + */ + ROUTE_CONFIG_UPDATE("update"), + + /** + * isv信息修改 + */ + ISV_INFO_UPDATE("update"), + + /** + * 黑名单消息类型:添加 + */ + BLACKLIST_ADD("add"), + /** + * 黑名单消息类型:删除 + */ + BLACKLIST_DELETE("delete"), + + /** + * 路由权限配置更新 + */ + ROUTE_PERMISSION_UPDATE("update"), + /** + * 路由权限加载 + */ + ROUTE_PERMISSION_RELOAD("reload"), + + /** + * 灰度发布用户key设置 + */ + GRAY_USER_KEY_SET("set"), + /** + * 灰度发布用户key清除 + */ + GRAY_USER_KEY_CLEAR("clear"), + + ; + + private String operation; + + ChannelOperation(String operation) { + this.operation = operation; + } + + public String getOperation() { + return operation; + } +} diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigGrayUserkey.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigGrayUserkey.java new file mode 100644 index 00000000..1bd13466 --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigGrayUserkey.java @@ -0,0 +1,42 @@ +package com.gitee.sop.adminserver.entity; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + + +/** + * 表名:config_gray_userkey + * 备注:灰度发布用户key + * + * @author tanghc + */ +@Table(name = "config_gray_userkey") +@Data +public class ConfigGrayUserkey { + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + /** 数据库字段:id */ + private Long id; + + /** instanceId, 数据库字段:instance_id */ + private String instanceId; + + /** 用户key,多个用引文逗号隔开, 数据库字段:user_key_content */ + private String userKeyContent; + + /** 需要灰度的接口,goods.get=1.2,order.list=1.2, 数据库字段:name_version_content */ + private String nameVersionContent; + + /** 数据库字段:gmt_create */ + private Date gmtCreate; + + /** 数据库字段:gmt_modified */ + private Date gmtModified; +} diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/ConfigGrayUserkeyMapper.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/ConfigGrayUserkeyMapper.java new file mode 100644 index 00000000..7af34e0d --- /dev/null +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/ConfigGrayUserkeyMapper.java @@ -0,0 +1,12 @@ +package com.gitee.sop.adminserver.mapper; + +import com.gitee.fastmybatis.core.mapper.CrudMapper; + +import com.gitee.sop.adminserver.entity.ConfigGrayUserkey; + + +/** + * @author tanghc + */ +public interface ConfigGrayUserkeyMapper extends CrudMapper { +} diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RouteConfigService.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RouteConfigService.java index 0b09a09b..d1dd2ceb 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RouteConfigService.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RouteConfigService.java @@ -5,6 +5,7 @@ import com.gitee.sop.adminserver.bean.ChannelMsg; import com.gitee.sop.adminserver.bean.ConfigLimitDto; import com.gitee.sop.adminserver.bean.RouteConfigDto; import com.gitee.sop.adminserver.bean.ZookeeperContext; +import com.gitee.sop.adminserver.common.ChannelOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -21,8 +22,7 @@ public class RouteConfigService { * @throws Exception */ public void sendRouteConfigMsg(RouteConfigDto routeConfigDto) { - String configData = JSON.toJSONString(routeConfigDto); - ChannelMsg channelMsg = new ChannelMsg("update", configData); + ChannelMsg channelMsg = new ChannelMsg(ChannelOperation.ROUTE_CONFIG_UPDATE, routeConfigDto); String jsonData = JSON.toJSONString(channelMsg); String path = ZookeeperContext.getRouteConfigChannelPath(); log.info("消息推送--路由配置(update), path:{}, data:{}", path, jsonData); @@ -35,8 +35,7 @@ public class RouteConfigService { * @throws Exception */ public void sendLimitConfigMsg(ConfigLimitDto routeConfigDto) throws Exception { - String configData = JSON.toJSONString(routeConfigDto); - ChannelMsg channelMsg = new ChannelMsg("update", configData); + ChannelMsg channelMsg = new ChannelMsg(ChannelOperation.LIMIT_CONFIG_UPDATE, routeConfigDto); String jsonData = JSON.toJSONString(channelMsg); String path = ZookeeperContext.getLimitConfigChannelPath(); log.info("消息推送--限流配置(update), path:{}, data:{}", path, jsonData); diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java index 3a352bbd..3595d88f 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java @@ -7,6 +7,7 @@ import com.gitee.sop.adminserver.bean.ChannelMsg; import com.gitee.sop.adminserver.bean.IsvRoutePermission; import com.gitee.sop.adminserver.bean.SopAdminConstants; import com.gitee.sop.adminserver.bean.ZookeeperContext; +import com.gitee.sop.adminserver.common.ChannelOperation; import com.gitee.sop.adminserver.entity.PermIsvRole; import com.gitee.sop.adminserver.entity.PermRolePermission; import com.gitee.sop.adminserver.mapper.IsvInfoMapper; @@ -68,7 +69,7 @@ public class RoutePermissionService { isvRoutePermission.setAppKey(appKey); isvRoutePermission.setRouteIdList(routeIdList); isvRoutePermission.setRouteIdListMd5(roleCodeListMd5); - ChannelMsg channelMsg = new ChannelMsg("update", isvRoutePermission); + ChannelMsg channelMsg = new ChannelMsg(ChannelOperation.ROUTE_PERMISSION_UPDATE, isvRoutePermission); String jsonData = JSON.toJSONString(channelMsg); String path = ZookeeperContext.getIsvRoutePermissionChannelPath(); log.info("消息推送--路由权限(update), path:{}, data:{}", path, jsonData); @@ -105,7 +106,7 @@ public class RoutePermissionService { }); IsvRoutePermission isvRoutePermission = new IsvRoutePermission(); isvRoutePermission.setListenPath(listenPath); - ChannelMsg channelMsg = new ChannelMsg("reload", isvRoutePermission); + ChannelMsg channelMsg = new ChannelMsg(ChannelOperation.ROUTE_PERMISSION_RELOAD, isvRoutePermission); String jsonData = JSON.toJSONString(channelMsg); String path = ZookeeperContext.getIsvRoutePermissionChannelPath(); log.info("消息推送--路由权限(reload), path:{}, data:{}", path, jsonData); diff --git a/sop-admin/sop-admin-server/src/main/resources/application-dev.properties b/sop-admin/sop-admin-server/src/main/resources/application-dev.properties index 72f173cd..de57a517 100644 --- a/sop-admin/sop-admin-server/src/main/resources/application-dev.properties +++ b/sop-admin/sop-admin-server/src/main/resources/application-dev.properties @@ -44,9 +44,5 @@ registry.name=eureka logging.level.com.gitee=debug -# 不用改 -mybatis.fill.com.gitee.fastmybatis.core.support.DateFillInsert=gmt_create -mybatis.fill.com.gitee.fastmybatis.core.support.DateFillUpdate=gmt_modified - # 不用改,如果要改,请全局替换修改 zuul.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC diff --git a/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue b/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue index e7e79a25..c6ce5592 100644 --- a/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue +++ b/sop-admin/sop-admin-vue/src/views/service/ipBlacklist.vue @@ -88,11 +88,11 @@