Authored by jimi.ji

提交响应的发布

... ... @@ -440,4 +440,5 @@ public class HttpUriContants {
public static final String GET_DOCERK_INFO_BY_ID = "/dockerProject/getDockerInfoById";
public static final String DEL_DOCKER_INFO_BYID = "/dockerProject/delDockerInfoById";
public static final String DOCKER_DEPLOY_ROLLBACK_BY_IMAGE="/dockerProject/deployByImageStore";
public static final String DOCKER_DEPLOY_JENKINS_DEPLOY="/dockerProject/jenkinsDeploy";
}
\ No newline at end of file
... ...
... ... @@ -28,6 +28,7 @@ public class ProjectEnvironment {
dockerProjectTypeMap.put("ci","核心系统ci");
dockerProjectTypeMap.put("ops","ops");
dockerProjectTypeMap.put("erp","erp");
dockerProjectTypeMap.put("jenkins-deploy","jenkins-deploy");
projectDeployTypeMap.put("git","git分支");
projectDeployTypeMap.put("image","镜像文件");
... ... @@ -45,11 +46,27 @@ public class ProjectEnvironment {
public static List<String> getDockerEnvironments(String projectName){
if(projectName!=null&&projectName.contains("yoho-shop-manage")){
if(projectName!=null&&projectName.contains("yohobuywap-node")){
//该项目没有灰度
return Arrays.asList("yoho-online");
return dockerEnvironments;
}
return dockerEnvironments;
if(projectName!=null&&projectName.contains("yohobuy-node")){
//该项目没有灰度
return dockerEnvironments;
}
if(projectName!=null&&projectName.contains("ufo-app-web")){
//该项目没有灰度
return dockerEnvironments;
}
if(projectName!=null&&projectName.contains("yoho-app-web")){
//该项目没有灰度
return dockerEnvironments;
}
if(projectName!=null&&projectName.contains("ultrainBlockApi")){
//该项目没有灰度
return dockerEnvironments;
}
return Arrays.asList("yoho-online");
}
public static Map<String,String> getDockerProjectTypeMap(){
... ...
... ... @@ -151,6 +151,38 @@ public class DockerBuildCtrl {
return new ModelAndView("project/docker_build");
}
@RequestMapping("/toBuildViewNew")
public ModelAndView toBuildViewNew(Model model,String project_id,String environment_name, String image_file_name,
String branch_name,String workid_name, String buildId, HttpSession session) {
List<Map<String,String>> buildInfoList=new ArrayList<>();
Map mapIds = new HashMap<>();
mapIds.put("ids",project_id);
BaseResponse response=httpRestClient.defaultGet("/dockerProject/getDockerProjectMapByIds", BaseResponse.class, mapIds);
Map projectMap=JSON.parseObject((String)response.getData(),Map.class);
Map map=new HashMap();
map.put("projectId",project_id);
map.put("buildId",buildId);
map.put("projectInfo",projectMap.get(Integer.parseInt(project_id)));
buildInfoList.add(map);
model.addAttribute("environment_name", environment_name);
model.addAttribute("clusters_name","");
model.addAttribute("clusters_text", "");
model.addAttribute("operate_name", "DEPLOY");
model.addAttribute("branch_name", branch_name);
model.addAttribute("project_deploy_type", "");
model.addAttribute("image_file_name", image_file_name);
model.addAttribute("workid_name", workid_name);
model.addAttribute("rollbackfile_name", "");
model.addAttribute("buildIds", buildId);
model.addAttribute("failMsg", "");
model.addAttribute("buildInfoList",JSONArray.toJSON(buildInfoList));
return new ModelAndView("project/docker_build");
}
/**
* 把node项目的az2区域切换到gray
* @env 发布环境 ,拦截器记录操作日志用
... ... @@ -276,6 +308,26 @@ public class DockerBuildCtrl {
*
* @return
*/
@RequestMapping(value = "/jenkinsDeploy")
@ResponseBody
public BaseResponse jenkinsDeploy(String project_id,String workid_name,
String environment_name,String image_file_name,String branch_name) {
Map<String, String> map = new HashMap<>();
map.put("projectId", project_id);
map.put("environment", environment_name);
map.put("rollbackImageStore", image_file_name);
map.put("branchName", branch_name);
map.put("workId", workid_name);
return httpRestClient.defaultGet(HttpUriContants.DOCKER_DEPLOY_JENKINS_DEPLOY, BaseResponse.class, map);
}
/**
* deploy项目
*
* @return
*/
@RequestMapping(value = "/mirrorAndDeploy")
@ResponseBody
public BaseResponse mirrorAndDeploy(String project_id, String project_name,
... ... @@ -311,7 +363,7 @@ public class DockerBuildCtrl {
dockerJenkinsReq.setBranch(branch_name);
dockerJenkinsReq.setReleaseWorkId(workid_name);
if("deploy".equalsIgnoreCase(operate_name)){
return httpRestClient.defaultPost("/dockerProject/mirrorAndDeploy",dockerJenkinsReq,BaseResponse.class);
return httpRestClient.defaultPost("/dockerProject/mirrorAndDeploy",dockerJenkinsReq,BaseResponse.class);
}
BaseResponse rtnBaseResponse=new BaseResponse(201);
rtnBaseResponse.setMessage("暂不支持的操作:"+operate_name);
... ...
... ... @@ -151,7 +151,7 @@ public class OuterIntfCtrl {
public BaseResponse updateJenkinsStatus(String ticketID,String jobID,String status) {
Map<String,String> map=new HashMap<>();
map.put("ticketID",ticketID);
map.put("jobID",jobID);
map.put("jobID",jobID.replace(",","/"));
map.put("status",status);
return httpClient.defaultGet("/dockerProject/updateJenkinsStatus",BaseResponse.class,map);
}
... ...
... ... @@ -159,7 +159,7 @@
<c:forEach items="${buildInfoList }" var="buildInfo">
<div style="float: left;height: 600px;">
<hr>
<div>当前项目:<input type="text" id="currentProject_${buildInfo.projectId}" value="${buildInfo.projectName}" readonly="readonly">
<div>当前项目:<input type="text" id="currentProject_${buildInfo.projectId}" value="${buildInfo.projectInfo.projectName}" readonly="readonly">
</div>
<%--<div style="height: 50px" class="alert alert-warning" id="task-info-div_${dockerProject.id}">
</div>--%>
... ... @@ -184,51 +184,72 @@
<script>
var buildInfoList = '${buildInfoList}';
<%--$(function () {--%>
<%--console.log("project_deploy_type is "+"${project_deploy_type}");--%>
<%--if("${operate_name}".toUpperCase()=="DEPLOY"&&"git"=="${project_deploy_type}"){--%>
<%--if(buildInfoList!=null&&buildInfoList.length>0){--%>
<%--var buildInfoListJson=JSON.parse(buildInfoList);--%>
<%--//docek发布--%>
<%--for(var i=0;i<buildInfoListJson.length;i++){--%>
<%--buildDocker(buildInfoListJson[i]);--%>
<%--}--%>
<%--}--%>
<%--}else{--%>
<%--//回滚或者镜像发布--%>
<%--if(buildInfoList!=null&&buildInfoList.length>0){--%>
<%--var buildInfoListJson=JSON.parse(buildInfoList);--%>
<%--//docek回滚--%>
<%--for(var i=0;i<buildInfoListJson.length;i++){--%>
<%--rollbackDocker(buildInfoListJson[i]);--%>
<%--}--%>
<%--}--%>
<%--}--%>
<%--});--%>
$(function () {
console.log("project_deploy_type is "+"${project_deploy_type}");
if("${operate_name}".toUpperCase()=="DEPLOY"&&"git"=="${project_deploy_type}"){
if(buildInfoList!=null&&buildInfoList.length>0){
var buildInfoListJson=JSON.parse(buildInfoList);
//docek发布
for(var i=0;i<buildInfoListJson.length;i++){
buildDocker(buildInfoListJson[i]);
}
}
}else{
//回滚或者镜像发布
if(buildInfoList!=null&&buildInfoList.length>0){
var buildInfoListJson=JSON.parse(buildInfoList);
//docek回滚
for(var i=0;i<buildInfoListJson.length;i++){
rollbackDocker(buildInfoListJson[i]);
}
if(buildInfoList!=null&&buildInfoList.length>0){
var buildInfoListJson=JSON.parse(buildInfoList);
//docek回滚
for(var i=0;i<buildInfoListJson.length;i++){
jenkinsSearchDocker(buildInfoListJson[i]);
}
}
});
function rollbackDocker(buildInfo){
function jenkinsSearchDocker(buildInfo){
var textareaId=buildInfo.projectId;
writeToText(textareaId,"开始查询腾讯云发布结果,请等待..........");
//开始查询腾讯云deploy状态,延迟60秒再开始查询
writeToText(textareaId,"开始查询是否完成..........");
setTimeout(function(){
builderDocker_queryServiceStatus(buildInfo,textareaId);
builderDocker_queryJenkinsStatus(buildInfo,textareaId);
}, 30000);
}
// function rollbackDocker(buildInfo){
// var textareaId=buildInfo.projectId;
// writeToText(textareaId,"开始查询腾讯云发布结果,请等待..........");
// //开始查询腾讯云deploy状态,延迟60秒再开始查询
// setTimeout(function(){
// builderDocker_queryServiceStatus(buildInfo,textareaId);
// }, 30000);
// }
function buildDocker(buildInfo){
//镜像的制作状态
console.log(buildInfo);
var textareaId=buildInfo.projectId;
builderDocker_queryJenkinsStatus(buildInfo,textareaId);
// builderDocker_queryJenkinsStatus(buildInfo,textareaId);
}
function builderDocker_queryJenkinsStatus(buildInfo,textareaId) {
var buildId=buildInfo.buildId;
var url = contextPath + 'dockerBuild/queryJenkinsStatus';
writeToText(textareaId,"镜像制作信息:"+buildId);
writeToText(textareaId,"开始查询镜像制作是否完成..........");
writeToText(textareaId,"开始查询jenkins任务完成情况:"+buildId);
var count = 0;
var errorTimes = 0;
var intervalIndex = setInterval(function() {
... ... @@ -245,26 +266,26 @@
errorTimes++;
if(errorTimes>5){
clearInterval(intervalIndex);
writeToText(textareaId,"发生错误data is null or data code !=200,查询镜像制作程序终止..........");
writeToText(textareaId,"发生错误data is null or data code !=200,查询jenkins程序终止..........");
writeToText(textareaId,"data is "+data);
responseError(data);
}else{
writeToText(textareaId,"发生错误data is null or data code !=200,继续获取数据,请耐心等待, errorTimes =."+errorTimes);
writeToText(textareaId,"发生错误data is null or data code !=200,查询jenkins程序终止, errorTimes =."+errorTimes);
writeToText(textareaId,"data is "+data);
}
}else{
if("SUCCESS"==data.data){
clearInterval(intervalIndex);
writeToText(textareaId,"镜像制作完成..........");
writeToText(textareaId,"开始查询腾讯云发布结果,请等待..........");
writeToText(textareaId,"jenkins发布完成且成功..........");
writeToText(textareaId,"构建的jenkinsJOB为:http://jenkins.yohops.com/job/"+data.message);
//开始查询腾讯云deploy状态,延迟60秒再开始查询
setTimeout(function(){
builderDocker_queryServiceStatus(buildInfo,textareaId);
}, 30000);
// setTimeout(function(){
// builderDocker_queryServiceStatus(buildInfo,textareaId);
// }, 30000);
}else if("FAILURE"==data.data){
clearInterval(intervalIndex);
writeToText(textareaId,"镜像制作失败.........");
writeToText(textareaId,"终止");
writeToText(textareaId,"jenkins发布完成但失败,失败原因麻烦查看如下的jenkins_job");
writeToText(textareaId,"构建的jenkinsJOB为:http://jenkins.yohops.com/job/"+data.message);
}else{
writeToText(textareaId,"............查询次数............"+count);
}
... ...
... ... @@ -645,28 +645,40 @@
//打开提交的确认界面
function comfirmSubmit() {
//判断是否为jenkins-deploy,若是则直接部署
// var projectTypes =$("input[name='projectTypes']:checked").val()
// if("jenkins-deploy"==projectTypes){
// var param_jenkins={};
// param_jenkins.project_id=$('input[name="project1"]:checked').val();
// param_jenkins.environment_name=$("input[name='environments']:checked").val();
// param_jenkins.image_file_name=$("#imagesList").val();
// useJenkinsDeploy(param_jenkins);
// return;
// }
var operate = $("input[name='operate']:checked").val();
var environment = $("input[name='environments']:checked").val();
var projectDeployType = $("#projectDeployType").val();
//获取集群
//获取集群,基本上从后台读取了
var clustersName=new Array();
var clustersText=new Array();
if("yoho-online"==environment){
$('input[name="dockerOnlineClusterId"]:checked').each(function () {
clustersName.push($(this).val());//向数组中添加元素
clustersText.push($(this).next().text());
});
}else{
$('input[name="dockerGrayClusterId"]:checked').each(function () {
clustersName.push($(this).val());//向数组中添加元素
clustersText.push($(this).next().text());
});
}
if (clustersName.length == 0) {
alert("请选择发布集群");
if (""==environment) {
alert("请选择发布环境");
return;
}
// if("yoho-online"==environment){
// $('input[name="dockerOnlineClusterId"]:checked').each(function () {
// clustersName.push($(this).val());//向数组中添加元素
// clustersText.push($(this).next().text());
// });
// }else{
// $('input[name="dockerGrayClusterId"]:checked').each(function () {
// clustersName.push($(this).val());//向数组中添加元素
// clustersText.push($(this).next().text());
// });
// }
var projects = new Array();
var projectNames = new Array();
if ("Deploy" == operate) {//发布
... ... @@ -685,8 +697,8 @@
var branch = $("input[name='branch']").val();
var imageFile=$("#imagesList").val();
var uploadCDN = $("#uploadCDN").val();
var cdnBranch = $("#cdnBranch").val();
// var uploadCDN = $("#uploadCDN").val();
// var cdnBranch = $("#cdnBranch").val();
if(projectDeployType=="image"){
$("#comfirm_deploy_content_div_image").show();
branch="";
... ... @@ -694,12 +706,12 @@
alert("请填写镜像文件");
return;
}
if(uploadCDN==1){
if(!cdnBranch){
alert("请填写上传CDN分支");
return;
}
}
// if(uploadCDN==1){
// if(!cdnBranch){
// alert("请填写上传CDN分支");
// return;
// }
// }
}else if(projectDeployType=="git"){
$("#comfirm_deploy_content_div_git").show();
if (!branch) {
... ... @@ -764,12 +776,43 @@
function deployOrRollback() {
var operate = $("input[name='operate']:checked").val();
if ("Deploy" == operate) {//发布
beginDeploy();
// beginDeploy();
useJenkinsDeploy();
}else {
rollback();
}
}
function useJenkinsDeploy() {
var param={};
param.project_id=$("input[name='project_id']").val();
param.environment_name=$("input[name='environment_name']").val();
param.image_file_name=$("input[name='image_file_name']").val();
param.branch_name=$("input[name='branch_name']").val();
param.workid_name=$("input[name='workid_name']").val();
// param.operate_name=$("input[name='operate_name']").val();
// param.project_name=$("input[name='project_name']").val();
// param.project_deploy_type=$("input[name='project_deploy_type']").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();
$.ajax({
url: contextPath + "dockerBuild/jenkinsDeploy",
type: "post",
dataType: "json",
data: param ,
success: function (response) {
if(response!=null&&(response.code==200)){
param.buildId=response.data;
GobalStandardPost( contextPath+ "dockerBuild/toBuildViewNew",param);
}else{
mirrorFail(response.message);
}
}
});
}
function rollback(){
$("#confirmBtn").attr("disabled","disabled");
$("#cancelBtn").attr("disabled","disabled");
... ... @@ -790,6 +833,7 @@
data: param ,
success: function (response) {
if(response!=null&&(response.code==200)){
param.buildIds=response.data;
GobalStandardPost( contextPath+ "dockerBuild/toBuildView",param);
}else{
//失败
... ... @@ -860,8 +904,8 @@
param.workid_name=$("input[name='workid_name']").val();
param.clusters_name=$("input[name='clusters_name']").val();
param.clusters_text=$("input[name='clusters_text']").val();
param.uploadCDN = $("#uploadCDN").val();
param.cdnBranch = $("#cdnBranch").val();
// param.uploadCDN = $("#uploadCDN").val();
// param.cdnBranch = $("#cdnBranch").val();
console.log(param);
//三个node项目发布灰度环境时,自动启用灰度,发布online环境时,自动关闭灰度
param.az2AutoSwitchOnlineCheck="";
... ...