Authored by qinchao

docker node 自动发布

... ... @@ -73,7 +73,7 @@ public class DockerBuildCtrl {
public ModelAndView toBuildView(Model model,String project_id, String project_name,
String environment_name,String clusters_name,String clusters_text,
String operate_name, String branch_name, String rollbackImageStore,
String workid_name, String buildIds,String failMsg, HttpSession session) {
String workid_name, String buildIds,String failMsg, HttpSession session,String az2AutoSwitchOnlineCheck) {
List<Map<String,String>> buildInfoList=new ArrayList<>();
Map mapIds = new HashMap<>();
mapIds.put("ids",project_id);
... ... @@ -101,6 +101,12 @@ public class DockerBuildCtrl {
buildInfoList.add(map);
}
model.addAttribute("az2AutoSwitchOnlineCheck", StringUtils.isBlank(az2AutoSwitchOnlineCheck)?"":az2AutoSwitchOnlineCheck);
if(StringUtils.isNotBlank(az2AutoSwitchOnlineCheck)){
model.addAttribute("az2AutoSwitchOnlineCheck_project", project_name);
}else{
model.addAttribute("az2AutoSwitchOnlineCheck_project", "");
}
model.addAttribute("environment_name", environment_name);
model.addAttribute("clusters_name", clusters_name);
... ... @@ -117,6 +123,31 @@ public class DockerBuildCtrl {
}
/**
* 把node项目的az2区域切换到gray
*
* @return
*/
@RequestMapping(value = "/switchDcokerNodeAz2")
@ResponseBody
public BaseResponse switchDcokerNodeAz2(String project_name,String onlineOrGray) {
String projectType;
if("yohoblk-wap"==project_name){
projectType="blk";
}else if("yohobuywap-node"==project_name){
projectType="wap";
}else if("yohobuy-node"==project_name){
projectType="pc";
}else{
return new BaseResponse(201,"不支持参数:"+project_name);
}
Map map = new HashMap<>();
map.put("projectType",projectType);
map.put("onlineOrGray",onlineOrGray);
BaseResponse response=httpRestClient.defaultGet("/pch5DockerSwitch/switchDockerAz2", BaseResponse.class, map);
return response;
}
/**
* 获取所有项目
*
* @return
... ...
... ... @@ -84,6 +84,9 @@
<div>
<div class="form-inline" role="form"
style=" margin-top: 12px;margin-left: 25px;float: left;">
<!-- 用来判断az2是否需要切换到online-->
<input type="hidden" id="az2AutoSwitchOnlineCheck" readonly="readonly" value="${az2AutoSwitchOnlineCheck}"/>
<input type="hidden" id="az2AutoSwitchOnlineCheck_project" readonly="readonly" value="${az2AutoSwitchOnlineCheck_project}"/>
<div class="input-group" style="float: left;">
<span class="input-group-addon">操作:</span>
<input type="text" id="operate_name" name="operate_name" class="form-control"
... ... @@ -307,6 +310,50 @@
if(data.data!=null&&data.data.result==true){
clearInterval(intervalIndex);
writeToText(textareaId,"查询服务启动完成..........over!");
if("az2AutoSwitchOnlineCheck"==$("#az2AutoSwitchOnlineCheck").val()){
writeToText(textareaId,"gray环境发布master分支完成,开始关闭灰度!");
//自动切换到online
var dialog = $("<div>").appendTo($("body"));
dialog.dialog({
title: "关闭灰度",
backdrop: "static",
content: "gray环境发布master分支完成,开始关闭灰度,确定关闭?",
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
dialog.dialog("hide");
$.ajax({
type: "post",
url: contextPath+"/dockerBuild/switchDcokerNodeAz2",
data: {
project_name: $("#az2AutoSwitchOnlineCheck_project").val(),
onlineOrGray:"online"
},
dataType: "json",
success: function(resp){
if(resp.code==200){
writeToText(textareaId,"已关闭灰度!");
}else{
localAlert("错误","关闭灰度失败:"+resp.message);
}
},
error: function(){
localAlert("错误","关闭灰度环境异常");
}
});
}
}]
});
}
}else{
writeToText(textareaId,"............查询次数............"+count+"......当前状态---->"+data.data.resultMessage);
}
... ...
... ... @@ -232,6 +232,7 @@
<script src="<%=basePath%>js/select2.min.js"></script>
<script src="<%=basePath%>js/custom.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/layer/v311/layer.js" type="text/javascript"></script>
<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script type="text/javascript">
$("#li_project").addClass("active open");
... ... @@ -580,7 +581,7 @@
function deployOrRollback() {
var operate = $("input[name='operate']:checked").val();
if ("Deploy" == operate) {//发布
mirrorAndDeploy();
beginDeploy();
}else {
rollback();
}
... ... @@ -624,18 +625,17 @@
}
function mirrorAndDeploy() {
function mirrorAndDeploy(param) {
$("#confirmBtn").attr("disabled","disabled");
$("#cancelBtn").attr("disabled","disabled");
var param={};
param.operate_name=$("input[name='operate_name']").val();
param.project_id=$("input[name='project_id']").val();
param.project_name=$("input[name='project_name']").val();
param.environment_name=$("input[name='environment_name']").val();
param.branch_name=$("input[name='branch_name']").val();
param.workid_name=$("input[name='workid_name']").val();
param.clusters_name=$("input[name='clusters_name']").val();
param.clusters_text=$("input[name='clusters_text']").val();
var layerMirror=layer.open( {
type:3,
//area: ['800px', '500px'],
content:"镜像制作中",
time: 0 //不自动关闭
});
$.ajax({
url: contextPath + "dockerBuild/mirrorAndDeploy",
type: "post",
... ... @@ -648,6 +648,7 @@
param.failMsg=response.message;
GobalStandardPost( contextPath+ "dockerBuild/toBuildView",param);
}else{
layer.close(layerMirror);
//失败
if(response==null){
mirrorFail("制作镜像失败!");
... ... @@ -658,11 +659,90 @@
}
},
error: function (e) {
layer.close(layerMirror);
mirrorFail(e);
}
});
}
function beginDeploy(){
var param={};
param.operate_name=$("input[name='operate_name']").val();
param.project_id=$("input[name='project_id']").val();
param.project_name=$("input[name='project_name']").val();
param.environment_name=$("input[name='environment_name']").val();
param.branch_name=$("input[name='branch_name']").val();
param.workid_name=$("input[name='workid_name']").val();
param.clusters_name=$("input[name='clusters_name']").val();
param.clusters_text=$("input[name='clusters_text']").val();
//三个node项目发布灰度环境时,如果发master分支,自动加到online,如果非master分支,自动断开
param.az2AutoSwitchOnlineCheck="";
if(param.environment_name.indexOf("gray")>0 &&
("yohoblk-wap"==param.project_name||"yohobuywap-node"==param.project_name||"yohobuy-node"==param.project_name)){
$('#confirmSubmitDivId').modal('hide');
var dialog = $("<div>").appendTo($("body"));
var alertContent="发布开始前会自动启用az2-"+param.project_name+"灰度环境,确定发布?";
if("master"==param.branch_name){
alertContent="发布成功后会自动关闭az2-"+param.project_name+"灰度环境,确定发布?";
param.az2AutoSwitchOnlineCheck="az2AutoSwitchOnlineCheck";
}
dialog.dialog({
title: "你确定执行发布吗",
backdrop: "static",
content: alertContent,
buttons: [{
text: "否",
className: "btn-danger",
onclick: function () {
dialog.dialog("hide");
$('#confirmSubmitDivId').modal('show');
}
}, {
text: "是",
className: "btn-success",
onclick: function () {
dialog.dialog("hide");
var layerSwitch=layer.open( {
type:3,
//area: ['800px', '500px'],
content:" 切换中",
time: 0 //不自动关闭
});
$.ajax({
type: "post",
url: contextPath+"/dockerBuild/switchDcokerNodeAz2",
data: {
project_name: param.project_name,
onlineOrGray:"gray"
},
dataType: "json",
success: function(resp){
layer.close(layerSwitch);
if(resp.code==200){
mirrorAndDeploy(param);
}else{
localAlert("错误","az2切换灰度环境失败:"+resp.message);
}
},
error: function(){
layer.close(layerSwitch);
localAlert("错误","az2切换灰度环境异常");
}
});
}
}]
});
}else{
mirrorAndDeploy(param);
}
}
function mirrorFail(msg) {
console.log(msg);
$("#confirmBtn").removeAttr("disabled");
... ...