...
|
...
|
@@ -147,19 +147,99 @@ |
|
|
</script>
|
|
|
<script>
|
|
|
var dockerProjects = '${docker_project_list}';
|
|
|
var myArray;
|
|
|
var removeArray = new Array();
|
|
|
|
|
|
function buildDocker(dockerProject){
|
|
|
//发起创建镜像的请求
|
|
|
// builderDocker_createMirror(dockerProject);
|
|
|
builderDocker_createMirror(dockerProject);
|
|
|
|
|
|
//轮询镜像是否成功
|
|
|
alert("轮询开始");
|
|
|
//开始deploy
|
|
|
}
|
|
|
|
|
|
//发布是否成功查询
|
|
|
function builderDocker_queryServiceStatus(dockerProject){
|
|
|
var url = contextPath + 'dockerBuild/queryDockerServerStatus';
|
|
|
writeToText(dockerProject.id,"开始查询服务启动..........");
|
|
|
var count = 0;
|
|
|
var errorTimes = 0;
|
|
|
var intervalIndex = setInterval(function() {
|
|
|
$.ajax({
|
|
|
url: url,
|
|
|
type: 'POST',
|
|
|
data:getDockerRequestParam(dockerProject),
|
|
|
dataType: 'json',
|
|
|
timeout : 0,
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
errorTimes++;
|
|
|
if(errorTimes>5){
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"发生错误data is null or data code !=200,查询服务启动程序终止..........");
|
|
|
writeToText(dockerProject.id,"data is "+data);
|
|
|
responseError(data);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"发生错误data is null or data code !=200,查询服务启动,继续获取数据,请耐心等待, errorTimes =."+errorTimes);
|
|
|
writeToText(dockerProject.id,"data is "+data);
|
|
|
}
|
|
|
}else{
|
|
|
if(data.data!=null&&((data.data).toUpperCase()=="NORMAL")){
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"查询服务启动完成..........over!");
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"............查询次数............"+count+"......当前状态---->"+data.data);
|
|
|
}
|
|
|
}
|
|
|
count += 1;
|
|
|
},
|
|
|
error: function (e) {
|
|
|
errorTimes++;
|
|
|
if(errorTimes>5){
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"发生错误error,查询服务启动程序终止..........");
|
|
|
writeToText(dockerProject.id,"error is "+e);
|
|
|
requestError(dockerProject.id,url);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"发生错误error,查询服务启动,继续获取数据,请耐心等待,errorTimes =."+errorTimes);
|
|
|
writeToText(dockerProject.id,"error is "+e);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}, 10000);
|
|
|
}
|
|
|
|
|
|
function getDockerRequestParam(dockerProject){
|
|
|
var frontParam={};
|
|
|
frontParam.serviceName=dockerProject.dockerProjectName;
|
|
|
if($("#environment_name").val().indexOf("GRAY")>=0){
|
|
|
frontParam.clusterId=dockerProject.dockerGrayClusterId;
|
|
|
frontParam.namespace =dockerProject.dockerGrayNameSpace;
|
|
|
}else{
|
|
|
frontParam.clusterId=dockerProject.dockerOnlineClusterId;
|
|
|
frontParam.namespace =dockerProject.dockerOnlineNameSpace;
|
|
|
}
|
|
|
return frontParam;
|
|
|
}
|
|
|
|
|
|
function builderDocker_deploy(dockerProject){
|
|
|
writeToText(dockerProject.id,"开始docker发布....");
|
|
|
var url= contextPath + 'dockerBuild/deployMirror';
|
|
|
$.ajax({
|
|
|
url: url,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
data:getDockerRequestParam(dockerProject),
|
|
|
async: false,
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
writeToText(dockerProject.id,"....docker发布请求失败!");
|
|
|
responseError(dockerProject.id,data);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"....docker发布请求成功");
|
|
|
builderDocker_queryServiceStatus(dockerProject);
|
|
|
}
|
|
|
},
|
|
|
error: function (e) {
|
|
|
writeToText(dockerProject.id,"....docker发布请求失败,发生异常!");
|
|
|
requestError(dockerProject.id,url);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function builderDocker_createMirror(dockerProject){
|
...
|
...
|
@@ -170,6 +250,7 @@ alert("轮询开始"); |
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
data:{
|
|
|
projectType:dockerProject.projectType,
|
|
|
appNames:dockerProject.projectName,
|
|
|
nodeEnv:$("#environment_name").val(),
|
|
|
branch:$("#branch_name").val(),
|
...
|
...
|
@@ -179,18 +260,74 @@ alert("轮询开始"); |
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
writeToText(dockerProject.id,"....jenkins制作镜像请求失败!");
|
|
|
responseError(data);
|
|
|
responseError(dockerProject.id,data);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"....jenkins制作镜像请求成功");
|
|
|
writeToText(dockerProject.id,"....jenkins制作镜像请求成功,buildId is "+data.data);
|
|
|
|
|
|
builderDocker_queryJenkinsStatus(data.data,dockerProject);
|
|
|
}
|
|
|
},
|
|
|
error: function (e) {
|
|
|
writeToText(dockerProject.id,"....jenkins制作镜像请求失败,发生异常!");
|
|
|
requestError(url);
|
|
|
requestError(dockerProject.id,url);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function builderDocker_queryJenkinsStatus(buildId,dockerProject) {
|
|
|
var url = contextPath + 'dockerBuild/queryJenkinsStatus';
|
|
|
writeToText(dockerProject.id,"开始查询镜像制作是否完成..........");
|
|
|
var count = 0;
|
|
|
var errorTimes = 0;
|
|
|
var intervalIndex = setInterval(function() {
|
|
|
$.ajax({
|
|
|
url: url,
|
|
|
type: 'POST',
|
|
|
data:{
|
|
|
buildId:buildId
|
|
|
},
|
|
|
dataType: 'json',
|
|
|
timeout : 0,
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
errorTimes++;
|
|
|
if(errorTimes>5){
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"发生错误data is null or data code !=200,查询镜像制作程序终止..........");
|
|
|
writeToText(dockerProject.id,"data is "+data);
|
|
|
responseError(data);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"发生错误data is null or data code !=200,继续获取数据,请耐心等待, errorTimes =."+errorTimes);
|
|
|
writeToText(dockerProject.id,"data is "+data);
|
|
|
}
|
|
|
}else{
|
|
|
if(!("SUCCESS"==data.data)){
|
|
|
writeToText(dockerProject.id,"............查询次数............"+count);
|
|
|
}else{
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"镜像制作完成..........");
|
|
|
//开始deploy
|
|
|
builderDocker_deploy(dockerProject);
|
|
|
}
|
|
|
}
|
|
|
count += 1;
|
|
|
},
|
|
|
error: function (e) {
|
|
|
errorTimes++;
|
|
|
if(errorTimes>5){
|
|
|
clearInterval(intervalIndex);
|
|
|
writeToText(dockerProject.id,"发生错误error,查询镜像制作程序终止..........");
|
|
|
writeToText(dockerProject.id,"error is "+e);
|
|
|
requestError(dockerProject.id,url);
|
|
|
}else{
|
|
|
writeToText(dockerProject.id,"发生错误error,继续获取数据,请耐心等待,errorTimes =."+errorTimes);
|
|
|
writeToText(dockerProject.id,"error is "+e);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}, 10000);
|
|
|
}
|
|
|
|
|
|
//写入消息
|
|
|
function writeToText(id,msg){
|
|
|
var d = $("#resultArea_"+id).val();
|
...
|
...
|
@@ -199,8 +336,12 @@ alert("轮询开始"); |
|
|
$("#resultArea_"+id).scrollTop(scrollTop);
|
|
|
}
|
|
|
|
|
|
//请求接口异常
|
|
|
function requestError(id,api){
|
|
|
writeToText(id,'系统异常:' + api);
|
|
|
}
|
|
|
|
|
|
$(function () {
|
|
|
console.log(dockerProjects);
|
|
|
if(dockerProjects!=null&&dockerProjects.length>0){
|
|
|
console.log(dockerProjects);
|
|
|
var dockerProjectsJson=JSON.parse(dockerProjects);
|
...
|
...
|
@@ -210,165 +351,9 @@ alert("轮询开始"); |
|
|
buildDocker(dockerProjectsJson[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return ;
|
|
|
|
|
|
var messageListHidden = $("#messageListHidden").val();
|
|
|
myArray = messageListHidden.split(",");
|
|
|
|
|
|
var interval = setInterval(function () {//查后台,展示数据
|
|
|
$.each(myArray, function (idx, val) {
|
|
|
if(jQuery.inArray(val, removeArray) != -1){
|
|
|
return;
|
|
|
}
|
|
|
if(val == ""){
|
|
|
return;
|
|
|
}
|
|
|
var cproject = $("#currentProject_"+val).val();
|
|
|
$.ajax({
|
|
|
url: contextPath + 'project/getbuildmsg?messageid=' + val+"&project="+cproject,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
success: function (data3) {
|
|
|
var obj2 = eval("(" + data3 + ")");
|
|
|
var messagedata = obj2.data;
|
|
|
|
|
|
var currproject = messagedata.currentProject;
|
|
|
if (currproject != cproject) {
|
|
|
$("#currentProject_"+val).val(currproject);//更换当前的项目
|
|
|
$("#resultArea_" + val).val("")
|
|
|
}
|
|
|
|
|
|
if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) {
|
|
|
var d = $("#resultArea_" + val).val();
|
|
|
$("#resultArea_"+ val).val(d + messagedata.message);
|
|
|
var scrollTop = $("#resultArea_" + val)[0].scrollHeight;
|
|
|
$("#resultArea_" + val).scrollTop(scrollTop);
|
|
|
}
|
|
|
|
|
|
//code为2 ,则结束
|
|
|
var code = obj2.code;
|
|
|
var message = obj2.message;
|
|
|
//只有状态2,3,4才表示系统部署成功与否
|
|
|
if (code == 2 || code == 3 || code == 4) {
|
|
|
document.getElementById("task-info-div_" + val).innerHTML = "<strong>'" + message + "'</strong>";
|
|
|
removeArray.push(val);
|
|
|
$("#cancel-btn_"+val).hide();
|
|
|
}
|
|
|
|
|
|
},
|
|
|
error: function (e) {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}, 3000);
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 取消
|
|
|
*/
|
|
|
function cancelBuild(messageid) {
|
|
|
|
|
|
var jsondata = {"id": messageid};
|
|
|
$.ajax({
|
|
|
url: contextPath + 'project/cancelBuild',
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
data: jsondata,
|
|
|
success: function (data) {
|
|
|
},
|
|
|
error: function (e) {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//做停止用
|
|
|
var setIntervalIndex;
|
|
|
//调用30次后停止调用
|
|
|
var setIntervalCount = 0;
|
|
|
|
|
|
/**
|
|
|
* 集成测试
|
|
|
*/
|
|
|
function testexecute(){
|
|
|
$("#testingdiv").hide();
|
|
|
setIntervalCount = 0;
|
|
|
var value;
|
|
|
var envi = $("#environment_name").val();
|
|
|
if(envi == "aws"){
|
|
|
value = 6;
|
|
|
}else if(envi == "qcloud"){
|
|
|
value = 7;
|
|
|
}else{
|
|
|
value = 5;
|
|
|
}
|
|
|
if(setIntervalIndex != null && setIntervalIndex != undefined){
|
|
|
clearInterval(setIntervalIndex);
|
|
|
setIntervalIndex = null;
|
|
|
}
|
|
|
$.ajax({
|
|
|
url: contextPath + 'project/testexecute?env=' + value,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
success: function (returnVal) {
|
|
|
$("#btnTest").attr('disabled',true);//设置disabled属性为true,按钮不可用
|
|
|
if(returnVal == null || returnVal.data == null || returnVal.data == ""){
|
|
|
alert("http://qmc.yohops.com:9999/autoTask/executeApiAutoTask,参数env="+value+",post请求失败!");
|
|
|
$("#btnTest").removeAttr("disabled"); //移除disabled属性
|
|
|
return;
|
|
|
}
|
|
|
var json = returnVal.data;
|
|
|
//获取到id
|
|
|
var id = json.id;
|
|
|
setIntervalIndex = setInterval(function(){testget(id);}, 1000 * 60);
|
|
|
},
|
|
|
error: function (e) {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 集成测试
|
|
|
*/
|
|
|
function testget(id){
|
|
|
if(id == null || id == undefined){
|
|
|
return;
|
|
|
}
|
|
|
$.ajax({
|
|
|
url: contextPath + 'project/testget?id=' + id,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
success: function (returnVal) {
|
|
|
if(returnVal == null || returnVal.data == null || returnVal.data == ""){
|
|
|
setIntervalCount = setIntervalCount + 1;
|
|
|
if(setIntervalCount >= 30){
|
|
|
$("#btnTest").removeAttr("disabled"); //移除disabled属性
|
|
|
clearInterval(setIntervalIndex);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
var message = returnVal.message;
|
|
|
var code = returnVal.code;
|
|
|
|
|
|
$("#testingdiv").show();
|
|
|
$("#testingresult").val("id:" + id + ";message:" + message + ";code:"+code);
|
|
|
$("#btnTest").removeAttr("disabled"); //移除disabled属性
|
|
|
clearInterval(setIntervalIndex);
|
|
|
},
|
|
|
error: function (e) {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
|
document.onkeydown = function()
|
|
|
{
|
|
|
if(event.keyCode==116 || event.keyCode==8 || (event.ctrlKey && event.keyCode==82) || event.keyCode == 13) {
|
|
|
event.keyCode=0;
|
|
|
event.returnValue = false;
|
|
|
}
|
|
|
}
|
|
|
document.oncontextmenu = function() {event.returnValue = false;}
|
|
|
|
|
|
</script> |
|
|
\ No newline at end of file |
...
|
...
|
|