mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
支持预发布、灰度发布
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
<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>
|
||||
<fastmybatis.version>1.8.1</fastmybatis.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@@ -1,16 +1,12 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ 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.StatusEnum;
|
||||
import com.gitee.sop.adminserver.common.ZookeeperPathExistException;
|
||||
import com.gitee.sop.adminserver.common.ZookeeperPathNotExistException;
|
||||
import com.gitee.sop.adminserver.entity.ConfigGrayUserkey;
|
||||
@@ -49,6 +50,7 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public class ServiceApi {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RegistryService registryService;
|
||||
|
||||
@@ -219,10 +221,12 @@ public class ServiceApi {
|
||||
configGrayUserkey.setInstanceId(instanceId);
|
||||
configGrayUserkey.setUserKeyContent(userKeyContent);
|
||||
configGrayUserkey.setNameVersionContent(nameVersionContent);
|
||||
configGrayUserkey.setStatus(StatusEnum.STATUS_ENABLE.getStatus());
|
||||
configGrayUserkeyMapper.save(configGrayUserkey);
|
||||
} else {
|
||||
configGrayUserkey.setUserKeyContent(userKeyContent);
|
||||
configGrayUserkey.setNameVersionContent(nameVersionContent);
|
||||
configGrayUserkey.setStatus(StatusEnum.STATUS_ENABLE.getStatus());
|
||||
configGrayUserkeyMapper.update(configGrayUserkey);
|
||||
}
|
||||
this.sendUserKeyMsg(instanceId, ChannelOperation.GRAY_USER_KEY_SET);
|
||||
@@ -238,7 +242,13 @@ 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);
|
||||
|
||||
ConfigGrayUserkey configGrayUserkey = configGrayUserkeyMapper.getByColumn("instance_id", param.getInstanceId());
|
||||
if (configGrayUserkey != null && configGrayUserkey.getStatus() == StatusEnum.STATUS_ENABLE.getStatus()) {
|
||||
configGrayUserkey.setStatus(StatusEnum.STATUS_DISABLE.getStatus());
|
||||
configGrayUserkeyMapper.update(configGrayUserkey);
|
||||
}
|
||||
this.sendUserKeyMsg(param.getInstanceId(), ChannelOperation.GRAY_USER_KEY_CLEAR);
|
||||
} catch (Exception e) {
|
||||
log.error("上线失败,param:{}", param, e);
|
||||
throw new BizException("上线失败,请查看日志");
|
||||
@@ -250,9 +260,9 @@ public class ServiceApi {
|
||||
return configGrayUserkeyMapper.getByColumn("instance_id", param.getInstanceId());
|
||||
}
|
||||
|
||||
private void sendUserKeyMsg(String serviceId, ChannelOperation channelOperation) {
|
||||
private void sendUserKeyMsg(String instanceId, ChannelOperation channelOperation) {
|
||||
UserKeyDefinition userKeyDefinition = new UserKeyDefinition();
|
||||
userKeyDefinition.setServiceId(serviceId);
|
||||
userKeyDefinition.setInstanceId(instanceId);
|
||||
ChannelMsg channelMsg = new ChannelMsg(channelOperation, userKeyDefinition);
|
||||
String jsonData = JSON.toJSONString(channelMsg);
|
||||
String path = ZookeeperContext.getUserKeyChannelPath();
|
||||
|
@@ -7,6 +7,6 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class UserKeyDefinition {
|
||||
private String serviceId;
|
||||
private String instanceId;
|
||||
private String data;
|
||||
}
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package com.gitee.sop.adminserver.common;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 通用状态枚举
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@Getter
|
||||
public enum StatusEnum {
|
||||
/**
|
||||
* 启用
|
||||
*/
|
||||
STATUS_ENABLE((byte)1),
|
||||
/**
|
||||
* 禁用
|
||||
*/
|
||||
STATUS_DISABLE((byte)0),
|
||||
;
|
||||
private byte status;
|
||||
|
||||
StatusEnum(byte status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
@@ -34,6 +34,9 @@ public class ConfigGrayUserkey {
|
||||
/** 需要灰度的接口,goods.get=1.2,order.list=1.2, 数据库字段:name_version_content */
|
||||
private String nameVersionContent;
|
||||
|
||||
/** 0:禁用,1:启用, 数据库字段:status */
|
||||
private Byte status;
|
||||
|
||||
/** 数据库字段:gmt_create */
|
||||
private Date gmtCreate;
|
||||
|
||||
|
@@ -44,5 +44,9 @@ registry.name=eureka
|
||||
|
||||
logging.level.com.gitee=debug
|
||||
|
||||
# 不用改
|
||||
mybatis.ignore-update-columns[0]=gmt_create
|
||||
mybatis.ignore-update-columns[1]=gmt_modified
|
||||
|
||||
# 不用改,如果要改,请全局替换修改
|
||||
zuul.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC
|
||||
|
@@ -163,7 +163,7 @@
|
||||
</el-form-item>
|
||||
</td>
|
||||
<td style="vertical-align: baseline;">
|
||||
<el-button v-if="index > 0" type="text" @click.prevent="removeNameVersion(grayRouteConfig)">删除</el-button>
|
||||
<el-button v-show="grayForm.grayRouteConfigList.length > 1" type="text" @click.prevent="removeNameVersion(grayRouteConfig)">删除</el-button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -203,11 +203,7 @@ export default {
|
||||
ipPort: '',
|
||||
userKeyContent: '',
|
||||
onlyUpdateGrayUserkey: false,
|
||||
grayRouteConfigList: [{
|
||||
oldRouteId: '',
|
||||
newVersion: '',
|
||||
key: Date.now()
|
||||
}]
|
||||
grayRouteConfigList: []
|
||||
},
|
||||
tabsActiveName: 'first',
|
||||
routeList: [],
|
||||
|
Reference in New Issue
Block a user