Authored by zhaoqi

降级服务后台接口

... ... @@ -12,6 +12,8 @@ public class DegradeConfig {
private String configName;
private String configShowName;
private String configDesc;
private Integer level;
... ...
... ... @@ -13,6 +13,8 @@ public class DegradeInfoReq extends PageRequest {
private String configName;
private String configShowName;
private Integer level;
private String switchOn;
... ...
... ... @@ -4,13 +4,14 @@
<resultMap id="BaseResultMap" type="com.monitor.model.domain.DegradeConfig" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="config_name" property="configName" jdbcType="VARCHAR" />
<result column="config_show_name" property="configShowName" jdbcType="VARCHAR" />
<result column="switch_on" property="switchOn" jdbcType="CHAR" />
<result column="config_desc" property="configDesc" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="TINYINT" />
<result column="img_url" property="imgUrl" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, config_name, switch_on, config_desc, level, img_url
id, config_name, config_show_name, switch_on, config_desc, level, img_url
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -23,9 +24,6 @@
<include refid="Base_Column_List" />
from degrade_info
where 1=1
<if test="configName != null &amp;&amp; configName !='' " >
and config_name = #{configName}
</if>
<if test="switchOn != null &amp;&amp; switchOn != '' " >
and switch_on = #{switchOn}
</if>
... ... @@ -38,10 +36,10 @@
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.monitor.model.domain.DegradeConfig" >
insert into degrade_info (id, config_name, switch_on,
insert into degrade_info (id, config_name, config_show_name, switch_on,
config_desc, level, img_url
)
values (#{id,jdbcType=INTEGER}, #{configName,jdbcType=VARCHAR}, #{switchOn,jdbcType=CHAR},
values (#{id,jdbcType=INTEGER}, #{configName,jdbcType=VARCHAR}, #{configShowName,jdbcType=VARCHAR}, #{switchOn,jdbcType=CHAR},
#{configDesc,jdbcType=VARCHAR}, #{level,jdbcType=TINYINT}, #{imgUrl,jdbcType=VARCHAR}
)
</insert>
... ... @@ -51,6 +49,9 @@
<if test="configName != null" >
config_name,
</if>
<if test="configShowName != null" >
config_show_name,
</if>
<if test="switchOn != null" >
switch_on,
</if>
... ... @@ -68,6 +69,9 @@
<if test="configName != null" >
#{configName,jdbcType=VARCHAR},
</if>
<if test="configShowName != null" >
#{configShowName,jdbcType=VARCHAR},
</if>
<if test="switchOn != null" >
#{switchOn,jdbcType=CHAR},
</if>
... ... @@ -85,6 +89,9 @@
<update id="updateByPrimaryKeySelective" parameterType="com.monitor.model.domain.DegradeConfig" >
update degrade_info
<set >
<if test="configShowName != null" >
config_show_name = #{configShowName,jdbcType=VARCHAR},
</if>
<if test="switchOn != null" >
switch_on = #{switchOn,jdbcType=CHAR},
</if>
... ... @@ -103,6 +110,7 @@
<update id="updateByPrimaryKey" parameterType="com.monitor.model.domain.DegradeConfig" >
update degrade_info
set config_name = #{configName,jdbcType=VARCHAR},
config_show_name = #{configShowName,jdbcType=VARCHAR},
switch_on = #{switchOn,jdbcType=CHAR},
config_desc = #{configDesc,jdbcType=VARCHAR},
level = #{level,jdbcType=TINYINT},
... ...
... ... @@ -16,6 +16,8 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by zhaoqi on 2016/8/26 0026.
... ... @@ -36,7 +38,7 @@ public class DegradeServiceImpl implements DegradeService {
private static String QQ = "zookeeper_qq";
// 测试用
// private static String TEST = "zookeeper_205";
private static String TEST = "zookeeper_205";
@Override
public PageResponse<DegradeConfig> getDegradeConfigList(DegradeInfoReq req) {
... ... @@ -75,17 +77,17 @@ public class DegradeServiceImpl implements DegradeService {
zkTreeAllReq.setZkPath(ZK_PATH+"/"+req.getConfigName());
zkTreeAllReq.setZkValue(req.getSwitchOn().equals("Y")?"true":"false");
if ("all".equals(req.getCloudType())) {
zkTreeAllReq.setIp("zookeeper_aws");
zkMoitorService.editZkMonitorDetail(zkTreeAllReq);
zkTreeAllReq.setIp("zookeeper_qq");
zkMoitorService.editZkMonitorDetail(zkTreeAllReq);
return ;
}
// if ("all".equals(req.getCloudType())) {
// zkTreeAllReq.setIp("zookeeper_aws");
// zkMoitorService.editZkMonitorDetail(zkTreeAllReq);
//
// zkTreeAllReq.setIp("zookeeper_qq");
// zkMoitorService.editZkMonitorDetail(zkTreeAllReq);
// return ;
// }
zkTreeAllReq.setIp(req.getCloudType());
// test
// zkTreeAllReq.setIp(TEST);
zkTreeAllReq.setIp(TEST);
zkMoitorService.editZkMonitorDetail(zkTreeAllReq);
}
... ... @@ -105,6 +107,7 @@ public class DegradeServiceImpl implements DegradeService {
config.setSwitchOn("true".equals(configZk.getZkValue())?"Y":"N");
for (DegradeConfig configDb : configListDb) {
if (configZk.getZkName().equals(configDb.getConfigName())) {
config.setConfigShowName(configDb.getConfigShowName());
config.setConfigDesc(configDb.getConfigDesc());
config.setImgUrl(configDb.getImgUrl());
config.setId(configDb.getId());
... ... @@ -114,6 +117,7 @@ public class DegradeServiceImpl implements DegradeService {
}
degradeConfigList.add(config);
}
// 进行过滤
degradeConfigList = dealFilter(req,degradeConfigList);
result.setRows(getPageRows(degradeConfigList,req));
result.setCurrentPage(req.getCurrentPage());
... ... @@ -130,8 +134,13 @@ public class DegradeServiceImpl implements DegradeService {
continue;
}
}
if (StringUtils.isNotBlank(req.getConfigShowName())) {
if (!findByRegex(req.getConfigShowName(),degradeConfig.getConfigShowName())) {
continue;
}
}
if (StringUtils.isNotBlank(req.getConfigName())) {
if (!degradeConfig.getConfigName().equals(req.getConfigName())) {
if (!findByRegex(req.getConfigName(),degradeConfig.getConfigName())) {
continue;
}
}
... ... @@ -149,6 +158,17 @@ public class DegradeServiceImpl implements DegradeService {
return afterFilter;
}
private boolean findByRegex(String p, String to) {
if (StringUtils.isBlank(to)) {
return false;
}
p = p.replaceAll("\\.","\\\\.");
String regex = ".*"+p+".*";
Pattern showNamePattern = Pattern.compile(regex);
Matcher matcher = showNamePattern.matcher(to);
return matcher.find();
}
private List<DegradeConfig> getPageRows(List<DegradeConfig> degradeConfigList, DegradeInfoReq req) {
int start = req.getPageSize()*(req.getCurrentPage()-1);
int end = start+req.getPageSize() > degradeConfigList.size() ? degradeConfigList.size() : start+req.getPageSize() ;
... ... @@ -168,7 +188,7 @@ public class DegradeServiceImpl implements DegradeService {
cloudType = AWS;
}
// test
// cloudType = TEST;
cloudType = TEST;
return zkMoitorService.getAllChildren(cloudType,ZK_PATH);
}
}
... ...