Authored by qinchao

pch5 az2 自动切换环境准备

... ... @@ -14,6 +14,16 @@ public class BuildProcessHistory {
private String environment;
private String operate;
/**
* 1 '正在进行';
* 2 '成功';
* 3 '取消发布';
* 3 '取消发布';
* 4 '失败';
* '其他';
}
*/
private int currentStatus;
private int status;
private String user;
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.mysql.mapper;
import com.model.BuildProcessHistory;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -14,4 +15,7 @@ public interface BuildHistoryMapper {
List<BuildProcessHistory> selectByCodition(PageBean page);
//取最近的一次成功发布记录
BuildProcessHistory selectLatestSuccessProjectRecord(@Param("currentProject") String currentProject, @Param("environment") String environment);
}
... ...
... ... @@ -19,6 +19,10 @@
</resultMap>
<sql id="Base_Column_List" >
id,status,localid,currentStatus,environment,operate,user,project_order,branch,currentProject,rollbackfile,tag, workid,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') AS createTime
</sql>
<select id="selectCountByCodition" resultType="java.lang.Integer">
select
count(1)
... ... @@ -55,4 +59,16 @@
limit #{startIndex},#{pageSize}
</select>
<select id="selectLatestSuccessProjectRecord" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from build_process_history
where currentStatus=2 and currentProject= #{currentProject}
<if test="environment != null &amp;&amp; environment != ''" >
and environment like concat(#{environment},'%')
</if>
order by create_time desc,id desc
limit 1
</select>
</mapper>
\ No newline at end of file
... ...
package com.monitor.switchs;
import com.model.BuildProcessHistory;
import com.model.HostInfo;
import com.monitor.cmdb.service.IHostInfoService;
import com.monitor.model.page.PageResponse;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.BuildHistoryMapper;
import com.yoho.ops.cmdb.models.Host;
import com.yoho.ops.cmdb.models.LoadBalance;
import com.yoho.ops.cmdb.qcloud.lb.QcloudLoadBalance;
... ... @@ -31,6 +34,11 @@ import java.util.stream.Collectors;
public class Pch5SwitchCtrl {
private final static Logger logger = LoggerFactory.getLogger("switchLogger");
@Autowired
private BuildHistoryMapper buildHistoryMapper;
private final String[] PROJECTS_IN_AZ={"YOHOBUY-WAP-NODE","YOHOBUY-PC-NODE","YOHOBLK-WAP"};
//Pch5的负载均衡器,传统型,生产
private final String ELB_PCH5_ID="lb-ceg44td5";
private final String ELB_BLK_ID="lb-2wfrxx7p";
... ... @@ -93,6 +101,45 @@ public class Pch5SwitchCtrl {
return response;
}
@RequestMapping(value = "/queryAz2InGray")
@ResponseBody
public BaseResponse<Boolean> queryAz2InGray() {
boolean az2InGray=false;
List<HostInfo> ls=hostInfoService.getHostInfosByTagList(Arrays.asList(const_tags_for_nginx_node_az2.split(",")));
if(ls!=null){
for(HostInfo hostInfo:ls){
if(hostInfo.getTags()!=null&&hostInfo.getTags().indexOf("灰度")>=0){
az2InGray=true;
break;
}
}
}
return new BaseResponse(az2InGray);
}
/**
* 最近发布记录(success)
*
*/
@RequestMapping(value = "/getAzProjectLatestReleaseHistory")
@ResponseBody
public BaseResponse getAzProjectLatestReleaseHistory() {
List<BuildProcessHistory> ls=new ArrayList();
for(String proj:PROJECTS_IN_AZ){
BuildProcessHistory history=buildHistoryMapper.selectLatestSuccessProjectRecord(proj,"az2");
if(history!=null){
ls.add(history);
}
}
BaseResponse rtn=new BaseResponse();
PageResponse<BuildProcessHistory> pi=new PageResponse();
pi.setTotal(ls.size());
pi.setRows(ls);
pi.setCurrentPage(1);
rtn.setData(pi);
return rtn;
}
/**
* 检查
* @param az1_host_cmdb
... ... @@ -207,15 +254,7 @@ public class Pch5SwitchCtrl {
//检查是否启用了灰度
//如果az2机器不再生产环境下,且host为gray,则是灰度
//TODO 检查是否灰度
List<HostInfo> ls=hostInfoService.getHostInfosByTagList(Arrays.asList(const_tags_for_nginx_node_az2.split(",")));
if(ls!=null){
for(HostInfo hostInfo:ls){
if(hostInfo.getTags()!=null&&hostInfo.getTags().indexOf("灰度")>=0){
az2InGray=true;
break;
}
}
}
az2InGray=this.queryAz2InGray().getData();
}
if(i==0){
... ...