mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
支持预发布、灰度发布
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
<zookeeper.version>3.4.12</zookeeper.version>
|
||||
<curator-recipes.version>4.0.1</curator-recipes.version>
|
||||
<okhttp.version>3.11.0</okhttp.version>
|
||||
<easyopen.version>1.16.2</easyopen.version>
|
||||
<fastmybatis.version>1.8.0</fastmybatis.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -37,13 +39,13 @@
|
||||
<dependency>
|
||||
<groupId>net.oschina.durcframework</groupId>
|
||||
<artifactId>easyopen-spring-boot-starter</artifactId>
|
||||
<version>1.16.2</version>
|
||||
<version>${easyopen.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.oschina.durcframework</groupId>
|
||||
<artifactId>fastmybatis-spring-boot-starter</artifactId>
|
||||
<version>1.7.2</version>
|
||||
<version>${fastmybatis.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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<RouteServiceInfo> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
@@ -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";
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
@@ -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<ConfigGrayUserkey, Long> {
|
||||
}
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -88,11 +88,11 @@
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
const regexIP = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
||||
const ipValidator = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请输入IP'))
|
||||
} else {
|
||||
const regexIP = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
||||
if (!regexIP.test(value)) {
|
||||
callback(new Error('IP格式不正确'))
|
||||
}
|
||||
|
@@ -73,21 +73,151 @@
|
||||
<el-button v-if="scope.row.parentId > 0 && scope.row.metadata.env" type="text" size="mini" @click="onEnvOnline(scope.row)">上线</el-button>
|
||||
<el-button v-if="scope.row.parentId > 0 && !scope.row.metadata.env" type="text" size="mini" @click="onEnvPre(scope.row)">预发布</el-button>
|
||||
<el-button v-if="scope.row.parentId > 0 && !scope.row.metadata.env" type="text" size="mini" @click="onEnvGray(scope.row)">灰度发布</el-button>
|
||||
<el-button v-if="scope.row.parentId > 0 && scope.row.metadata.env === 'gray'" type="text" size="mini" @click="onUpdateUserkey(scope.row)">灰度设置</el-button>
|
||||
<el-button v-if="scope.row.parentId > 0 && scope.row.status === 'UP'" type="text" size="mini" @click="onDisable(scope.row)">禁用</el-button>
|
||||
<el-button v-if="scope.row.parentId > 0 && scope.row.status === 'OUT_OF_SERVICE'" type="text" size="mini" @click="onEnable(scope.row)">启用</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- dialog -->
|
||||
<el-dialog
|
||||
title="灰度设置"
|
||||
:visible.sync="grayDialogVisible"
|
||||
:close-on-click-modal="false"
|
||||
@close="resetForm('grayForm')"
|
||||
>
|
||||
<el-form
|
||||
ref="grayForm"
|
||||
:model="grayForm"
|
||||
:rules="grayFormRules"
|
||||
size="mini"
|
||||
>
|
||||
<el-form-item label="服务器实例">
|
||||
{{ grayForm.serviceId + ' (' + grayForm.ipPort + ')' }}
|
||||
</el-form-item>
|
||||
<el-tabs v-model="tabsActiveName" type="card">
|
||||
<el-tab-pane label="灰度用户" name="first">
|
||||
<el-alert
|
||||
title="可以是appId,或userId,多个用英文逗号隔开"
|
||||
type="info"
|
||||
:closable="false"
|
||||
style="margin-bottom: 20px;"
|
||||
/>
|
||||
<el-form-item prop="userKeyContent">
|
||||
<el-input
|
||||
v-model="grayForm.userKeyContent"
|
||||
placeholder="可以是appId,或userId,多个用英文逗号隔开"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="接口配置" name="second">
|
||||
<el-form-item>
|
||||
<el-button type="text" @click="addNameVersion">新增灰度接口</el-button>
|
||||
</el-form-item>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr
|
||||
v-for="(grayRouteConfig, index) in grayForm.grayRouteConfigList"
|
||||
:key="grayRouteConfig.key"
|
||||
>
|
||||
<td>
|
||||
<el-form-item
|
||||
:key="grayRouteConfig.key"
|
||||
:prop="'grayRouteConfigList.' + index + '.oldRouteId'"
|
||||
:rules="{required: true, message: '不能为空', trigger: ['blur', 'change']}"
|
||||
>
|
||||
老接口:
|
||||
<el-select
|
||||
v-model="grayRouteConfig.oldRouteId"
|
||||
style="margin-right: 10px;"
|
||||
@change="onChangeOldRoute(grayRouteConfig)"
|
||||
>
|
||||
<el-option
|
||||
v-for="route in routeList"
|
||||
:key="route.id"
|
||||
:label="route.name + '(' + route.version + ')'"
|
||||
:value="route.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</td>
|
||||
<td>
|
||||
<el-form-item
|
||||
:key="grayRouteConfig.key + 1"
|
||||
:prop="'grayRouteConfigList.' + index + '.newVersion'"
|
||||
:rules="{required: true, message: '不能为空', trigger: ['blur', 'change']}"
|
||||
>
|
||||
灰度接口:
|
||||
<el-select
|
||||
v-model="grayRouteConfig.newVersion"
|
||||
no-data-text="无数据"
|
||||
>
|
||||
<el-option
|
||||
v-for="routeNew in getGraySelectData(grayRouteConfig.oldRouteId)"
|
||||
:key="routeNew.id"
|
||||
:label="routeNew.name + '(' + routeNew.version + ')'"
|
||||
:value="routeNew.version"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</td>
|
||||
<td style="vertical-align: baseline;">
|
||||
<el-button v-if="index > 0" type="text" @click.prevent="removeNameVersion(grayRouteConfig)">删除</el-button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="grayDialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="onAddUserKey">确 定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
const regex = /^\w+(,\w+)*$/
|
||||
const userKeyContentValidator = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('不能为空'))
|
||||
} else {
|
||||
if (!regex.test(value)) {
|
||||
callback(new Error('格式不正确'))
|
||||
}
|
||||
callback()
|
||||
}
|
||||
}
|
||||
return {
|
||||
searchFormData: {
|
||||
serviceId: ''
|
||||
},
|
||||
grayDialogVisible: false,
|
||||
grayForm: {
|
||||
serviceId: '',
|
||||
instanceId: '',
|
||||
ipPort: '',
|
||||
userKeyContent: '',
|
||||
onlyUpdateGrayUserkey: false,
|
||||
grayRouteConfigList: [{
|
||||
oldRouteId: '',
|
||||
newVersion: '',
|
||||
key: Date.now()
|
||||
}]
|
||||
},
|
||||
tabsActiveName: 'first',
|
||||
routeList: [],
|
||||
selectNameVersion: [],
|
||||
grayFormRules: {
|
||||
userKeyContent: [
|
||||
{ required: true, message: '不能为空', trigger: 'blur' },
|
||||
{ validator: userKeyContentValidator, trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
tableData: []
|
||||
}
|
||||
},
|
||||
@@ -100,6 +230,18 @@ export default {
|
||||
this.tableData = this.buildTreeData(resp.data)
|
||||
})
|
||||
},
|
||||
loadRouteList: function(serviceId) {
|
||||
if (this.routeList.length === 0) {
|
||||
this.post('route.list/1.2', { serviceId: serviceId.toLowerCase() }, function(resp) {
|
||||
this.routeList = resp.data
|
||||
})
|
||||
}
|
||||
},
|
||||
getGraySelectData: function(oldRouteId) {
|
||||
return this.routeList.filter(routeNew => {
|
||||
return oldRouteId !== routeNew.id && oldRouteId.indexOf(routeNew.name) > -1
|
||||
})
|
||||
},
|
||||
buildTreeData: function(data) {
|
||||
data.forEach(ele => {
|
||||
const parentId = ele.parentId
|
||||
@@ -159,13 +301,82 @@ export default {
|
||||
})
|
||||
},
|
||||
onEnvGray: function(row) {
|
||||
this.confirm('确定要灰度发布【' + row.serviceId + '】吗?', function(done) {
|
||||
this.post('service.instance.env.gray', row, function() {
|
||||
this.tip('灰度发布发成功')
|
||||
done()
|
||||
this.grayForm.onlyUpdateGrayUserkey = false
|
||||
this.openGrayDialog(row)
|
||||
},
|
||||
onUpdateUserkey: function(row) {
|
||||
this.grayForm.onlyUpdateGrayUserkey = true
|
||||
this.openGrayDialog(row)
|
||||
},
|
||||
openGrayDialog: function(row) {
|
||||
const serviceId = row.serviceId
|
||||
this.loadRouteList(serviceId)
|
||||
this.post('service.instance.gray.userkey.get', { instanceId: row.instanceId }, function(resp) {
|
||||
this.grayDialogVisible = true
|
||||
const data = resp.data
|
||||
Object.assign(this.grayForm, {
|
||||
serviceId: serviceId,
|
||||
instanceId: row.instanceId,
|
||||
ipPort: row.ipPort,
|
||||
userKeyContent: data.userKeyContent || '',
|
||||
grayRouteConfigList: this.createGrayRouteConfigList(data.nameVersionContent)
|
||||
})
|
||||
})
|
||||
},
|
||||
createGrayRouteConfigList: function(nameVersionContent) {
|
||||
if (!nameVersionContent) {
|
||||
return [{
|
||||
oldRouteId: '',
|
||||
newVersion: '',
|
||||
key: Date.now()
|
||||
}]
|
||||
}
|
||||
const list = []
|
||||
const arr = nameVersionContent.split(',')
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
const el = arr[i]
|
||||
const elArr = el.split('=')
|
||||
list.push({
|
||||
oldRouteId: elArr[0],
|
||||
newVersion: elArr[1],
|
||||
key: Date.now()
|
||||
})
|
||||
}
|
||||
return list
|
||||
},
|
||||
onAddUserKey: function() {
|
||||
this.$refs.grayForm.validate((valid) => {
|
||||
if (valid) {
|
||||
const nameVersionContents = []
|
||||
const grayRouteConfigList = this.grayForm.grayRouteConfigList
|
||||
for (let i = 0; i < grayRouteConfigList.length; i++) {
|
||||
const config = grayRouteConfigList[i]
|
||||
nameVersionContents.push(config.oldRouteId + '=' + config.newVersion)
|
||||
}
|
||||
this.grayForm.nameVersionContent = nameVersionContents.join(',')
|
||||
this.post('service.instance.env.gray', this.grayForm, function() {
|
||||
this.grayDialogVisible = false
|
||||
this.tip('灰度发布发成功')
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
onChangeOldRoute: function(config) {
|
||||
config.newVersion = ''
|
||||
},
|
||||
addNameVersion: function() {
|
||||
this.grayForm.grayRouteConfigList.push({
|
||||
oldRouteId: '',
|
||||
newVersion: '',
|
||||
key: Date.now()
|
||||
})
|
||||
},
|
||||
removeNameVersion: function(item) {
|
||||
const index = this.grayForm.grayRouteConfigList.indexOf(item)
|
||||
if (index !== -1) {
|
||||
this.grayForm.grayRouteConfigList.splice(index, 1)
|
||||
}
|
||||
},
|
||||
renderServiceName: function(row) {
|
||||
let instanceCount = ''
|
||||
if (row.children && row.children.length > 0) {
|
||||
@@ -175,14 +386,6 @@ export default {
|
||||
instanceCount = ` (${onlineCount}/${row.children.length})`
|
||||
}
|
||||
return row.serviceId + instanceCount
|
||||
},
|
||||
renderMetadata: function(row) {
|
||||
const metadata = row.metadata
|
||||
const html = []
|
||||
for (const key in metadata) {
|
||||
html.push(key + '=' + metadata[key])
|
||||
}
|
||||
return html.join('<br />')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user