...
|
...
|
@@ -3,141 +3,427 @@ $(function() { |
|
|
refreshAutosSalingTable();
|
|
|
});
|
|
|
|
|
|
// 刷新表格数据
|
|
|
//根据类型获取需要显示的列
|
|
|
function getColumns(){
|
|
|
var columns = [
|
|
|
{
|
|
|
title : "索引",
|
|
|
width : "50px",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
return (rowIndex + 1);
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "组名",
|
|
|
field : "scalingGroupName",
|
|
|
width : "25%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "IP",
|
|
|
field : "ip",
|
|
|
width : "25%",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
var instances = rowData.scalingInstancess;
|
|
|
if(instances == null || instances.length == 0){
|
|
|
return;
|
|
|
}
|
|
|
var ips = "";
|
|
|
for(var index = 0;index < instances.length;index++){
|
|
|
var protectedB = instances[index].protectedFrom;
|
|
|
var message = "";
|
|
|
if(protectedB != null && protectedB != undefined){
|
|
|
if("TRUE" == protectedB.toUpperCase()){
|
|
|
message = "免于缩减";
|
|
|
}
|
|
|
}
|
|
|
if(message != ""){
|
|
|
ips += "<font color='#FF0000'>" + instances[index].ip + ":" + message + "</font><br>";
|
|
|
}else{
|
|
|
ips += instances[index].ip + "<br>";
|
|
|
}
|
|
|
}
|
|
|
return ips;
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "期望容量",
|
|
|
field : "desiredCapacity",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "最少实例数",
|
|
|
field : "minSize",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "最多实例数",
|
|
|
field : "maxSize",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "操作",
|
|
|
width : "100px",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
var div = $("<div>");
|
|
|
$("<button onclick=\"changeServer(\'"
|
|
|
+ rowData.scalingGroupId + "\',\'"
|
|
|
+ rowData.scalingGroupName + "\',\'"
|
|
|
+ rowData.protectedFromCount + "\',\'"
|
|
|
+ rowData.desiredCapacity + "\',\'"
|
|
|
+ rowData.minSize + "\',\'"
|
|
|
+ rowData.maxSize + "\')\">").addClass(
|
|
|
"btn btn-xs btn-success").html("扩充或缩减")
|
|
|
.appendTo(div);
|
|
|
return div;
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
} ];
|
|
|
return columns;
|
|
|
}
|
|
|
|
|
|
//刷新表格数据
|
|
|
function refreshAutosSalingTable() {
|
|
|
var columns = getColumns();
|
|
|
$("#autoscalingTable").table(
|
|
|
{
|
|
|
columnAutoWidth : false,
|
|
|
url : contextPath + "awsapi/autoscalingconfig",
|
|
|
url : contextPath + "autoScalingTool/autoscalingconfig?cloudType=" + $("#cloudType").val(),
|
|
|
striped : true,
|
|
|
title : "Auto Scaling 组集合",
|
|
|
loadFilter : function(data) {
|
|
|
return defaultLoadFilter(data);
|
|
|
},
|
|
|
columns : [
|
|
|
{
|
|
|
title : "索引",
|
|
|
width : "50px",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
return (rowIndex + 1);
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "组名",
|
|
|
field : "autoScalingGroupName",
|
|
|
width : "25%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "IP",
|
|
|
field : "ip",
|
|
|
width : "25%",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
var awsInstances = rowData.awsInstancess;
|
|
|
if(awsInstances == null || awsInstances.length == 0){
|
|
|
return;
|
|
|
}
|
|
|
var ips = "";
|
|
|
for(var index = 0;index < awsInstances.length;index++){
|
|
|
var protectedB = awsInstances[index].protectedFrom;
|
|
|
var message = "";
|
|
|
if(protectedB != null && protectedB != undefined){
|
|
|
if("TRUE" == protectedB.toUpperCase()){
|
|
|
message = "免于缩减";
|
|
|
}
|
|
|
}
|
|
|
if(message != ""){
|
|
|
ips += "<font color='#FF0000'>" + awsInstances[index].ip + ":" + message + "</font><br>";
|
|
|
}else{
|
|
|
ips += awsInstances[index].ip + "<br>";
|
|
|
}
|
|
|
}
|
|
|
return ips;
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "目前服务器台数",
|
|
|
field : "desiredCapacity",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "最少服务器台数",
|
|
|
field : "minSize",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "最多服务器台数",
|
|
|
field : "maxSize",
|
|
|
width : "10%",
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
title : "操作",
|
|
|
width : "100px",
|
|
|
formatter : function(value, rowData, rowIndex) {
|
|
|
var div = $("<div>");
|
|
|
$("<button onclick=\"changeServer(\'"
|
|
|
+ rowData.autoScalingGroupName + "\',\'"
|
|
|
+ rowData.protectedFromCount + "\',\'"
|
|
|
+ rowData.minSize + "\',\'"
|
|
|
+ rowData.maxSize + "\')\">").addClass(
|
|
|
"btn btn-xs btn-success").html("扩充或缩减")
|
|
|
.appendTo(div);
|
|
|
return div;
|
|
|
},
|
|
|
styler : function(value, rowData, rowIndex){
|
|
|
return {
|
|
|
"vertical-align" : "middle"
|
|
|
};
|
|
|
}
|
|
|
} ]
|
|
|
columns : columns
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function changeServer(groupName, protectedFromCount, minSize, maxSize){
|
|
|
//修改前原始数据,用于判断是否需要调用修改接口
|
|
|
var scalingGroupName;
|
|
|
var souScalingGroupId;
|
|
|
var souProtectedFromCount;
|
|
|
var souDesiredCapacity;
|
|
|
var souMinSize;
|
|
|
var souMaxSize;
|
|
|
//修改伸缩组
|
|
|
function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapacity, minSize, maxSize){
|
|
|
scalingGroupName = groupName;
|
|
|
souScalingGroupId = scalingGroupId;
|
|
|
souProtectedFromCount = protectedFromCount;
|
|
|
souDesiredCapacity = desiredCapacity;
|
|
|
souMinSize = minSize;
|
|
|
souMaxSize = maxSize;
|
|
|
|
|
|
$("#myModalLabel").text("");
|
|
|
$("#protectedFromCount").val("");
|
|
|
$("#minSize").val("");
|
|
|
$("#maxSize").val("");
|
|
|
$("#desiredCapacity").val("");
|
|
|
|
|
|
$("#myModalLabel").text(groupName + " : 扩充或缩减");
|
|
|
$("#protectedFromCount").val(protectedFromCount);
|
|
|
$("#minSize").val(minSize);
|
|
|
$("#maxSize").val(maxSize);
|
|
|
$("#desiredCapacity").val(desiredCapacity);
|
|
|
$("#myModal").modal('show');
|
|
|
}
|
|
|
|
|
|
function changeOk(){
|
|
|
//异常处理
|
|
|
if(souScalingGroupId == "" || souScalingGroupId == undefined
|
|
|
|| souProtectedFromCount == "" || souProtectedFromCount == undefined
|
|
|
|| souMinSize == "" || souMinSize == undefined
|
|
|
|| souMaxSize == "" || souMaxSize == undefined
|
|
|
|| souDesiredCapacity == "" || souDesiredCapacity == undefined){
|
|
|
alert("异常,请重新点击 扩充或缩减 开始");
|
|
|
return;
|
|
|
}
|
|
|
//受保护的实例数
|
|
|
var protectedFromCount = $("#protectedFromCount").val();
|
|
|
//最少实例数,大于等于受保护的实例数
|
|
|
var minSize = $("#minSize").val();
|
|
|
//最多实例数
|
|
|
var maxSize = $("#maxSize").val();
|
|
|
//期望实例数,大于等于最小实例数 小于等于最多实例数
|
|
|
var desiredCapacity = $("#desiredCapacity").val();
|
|
|
alert("待续......");
|
|
|
if((protectedFromCount == souProtectedFromCount) && (minSize == souMinSize)
|
|
|
&& (maxSize == souMaxSize)
|
|
|
&& (desiredCapacity == souDesiredCapacity)){
|
|
|
alert("数据未做修改!");
|
|
|
$("#myModal").modal('hide');
|
|
|
return;
|
|
|
}
|
|
|
if(minSize < protectedFromCount){
|
|
|
alert("期望调整的最小实例数 小于 受保护的实例数!");
|
|
|
return;
|
|
|
}else if(maxSize < minSize){
|
|
|
alert("期望调整的最大实例数 小于 最小实例数!");
|
|
|
return;
|
|
|
}else if((desiredCapacity < minSize) || (desiredCapacity > maxSize)){
|
|
|
alert("期望调整的容量必须在最小和最大实例数之间,最大<=容量>=最小!");
|
|
|
return;
|
|
|
}
|
|
|
var showMessage;
|
|
|
if(desiredCapacity == souDesiredCapacity){
|
|
|
//基础信息修改,不涉及到缩容或者扩容
|
|
|
showMessage = "";
|
|
|
}else{
|
|
|
if(desiredCapacity < souDesiredCapacity){
|
|
|
showMessage = "缩容";
|
|
|
}else if(desiredCapacity > souDesiredCapacity){
|
|
|
showMessage = "扩容";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(confirm("是否确定要执行!")){
|
|
|
$("#myModal").modal('hide');
|
|
|
var parms = {};
|
|
|
if(2 != $("#cloudType").val()){
|
|
|
alert("暂时只提供腾讯云的操作!");
|
|
|
return;
|
|
|
}else{
|
|
|
var qCloudParms = {};
|
|
|
parms.cloudType = parseInt($("#cloudType").val());
|
|
|
qCloudParms.scalingGroupId = souScalingGroupId;
|
|
|
qCloudParms.minSize = parseInt(minSize);
|
|
|
qCloudParms.maxSize = parseInt(maxSize);
|
|
|
qCloudParms.desiredCapacity = parseInt(desiredCapacity);
|
|
|
parms.qCloudParms = qCloudParms;
|
|
|
}
|
|
|
$.ajax({
|
|
|
url: '/autoScalingTool/modifyScalingGroup?cloudType=' + parseInt($("#cloudType").val()),
|
|
|
type: 'POST',
|
|
|
data: qCloudParms,
|
|
|
dataType: 'json',
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
alert('修改伸缩组失败:'+data.message);
|
|
|
}else{
|
|
|
if(showMessage == "" || showMessage == undefined){
|
|
|
alert("修改基础信息成功!");
|
|
|
clear_Sour();
|
|
|
return;
|
|
|
}
|
|
|
$("#myModalMessageLabel").text(scalingGroupName + ":正在 " + showMessage);
|
|
|
$("#myModalMessage").modal('show');
|
|
|
$("#myModalMessage").unbind("keyup");
|
|
|
$(".modal-backdrop").unbind("click");
|
|
|
//清空
|
|
|
$("#resultScalingMessage").html("");
|
|
|
$("#closeButton").attr("disabled","disabled");
|
|
|
refCloudMessage(showMessage, Math.abs(souDesiredCapacity - desiredCapacity));
|
|
|
}
|
|
|
},
|
|
|
error: function (data) {
|
|
|
alert('系统异常');
|
|
|
clear_Sour();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function clear_Sour(){
|
|
|
//清空
|
|
|
souProtectedFromCount = "";
|
|
|
souDesiredCapacity = "";
|
|
|
souMinSize = "";
|
|
|
souMaxSize = "";
|
|
|
}
|
|
|
|
|
|
//腾讯云:修改伸缩组后的下一个流程是查询伸缩活动
|
|
|
function refCloudMessage(showMessage, serverCount){
|
|
|
var timestamp = Date.parse(new Date());
|
|
|
var count = 0;
|
|
|
writeToText("开始..........");
|
|
|
var intervalIndex = setInterval(function() {
|
|
|
$.ajax({
|
|
|
url: '/autoScalingTool/describeScalingActivity?scalingGroupId=' + souScalingGroupId + '&startTime=' + timestamp,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
clearInterval(intervalIndex);
|
|
|
}else{
|
|
|
var returnJson = data.data[0];
|
|
|
if(showMessage == "缩容"){
|
|
|
if(returnJson.msg != "success"){
|
|
|
if(count == 0){
|
|
|
writeToText(returnJson.desciption);
|
|
|
}else{
|
|
|
writeToText("......");
|
|
|
}
|
|
|
}else{
|
|
|
writeToText("第 1 步:" + showMessage + " 成功!");
|
|
|
$("#closeButton").removeAttr("disabled");
|
|
|
clearInterval(intervalIndex);
|
|
|
|
|
|
|
|
|
unDeploy();
|
|
|
writeToText("结束..........");
|
|
|
return;
|
|
|
}
|
|
|
}else{
|
|
|
if(returnJson.succInsList == undefined || returnJson.succInsList.length != 2){
|
|
|
if(count == 0){
|
|
|
writeToText(returnJson.desciption);
|
|
|
}else{
|
|
|
writeToText("......");
|
|
|
}
|
|
|
}else{
|
|
|
writeToText("第 1 步:" + showMessage + " 成功!");
|
|
|
writeToText("...")
|
|
|
clearInterval(intervalIndex);
|
|
|
//扩容成功后执行
|
|
|
deploy(returnJson.succInsList);
|
|
|
writeToText("结束..........");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
count += 1;
|
|
|
},
|
|
|
error: function (data) {
|
|
|
alert('系统异常');
|
|
|
}
|
|
|
});
|
|
|
}, 5000);
|
|
|
}
|
|
|
|
|
|
//写入消息
|
|
|
function writeToText(msg){
|
|
|
var d = $("#resultScalingMessage").val();
|
|
|
$("#resultScalingMessage").html(d + "
" + msg);
|
|
|
var scrollTop = $("#resultScalingMessage")[0].scrollHeight;
|
|
|
$("#resultScalingMessage").scrollTop(scrollTop);
|
|
|
}
|
|
|
|
|
|
//1:扩容成功后执行
|
|
|
function deploy(instanceIds){
|
|
|
if(instanceIds == undefined){
|
|
|
//发布完之后,显示关闭按钮
|
|
|
$("#closeButton").removeAttr("disabled");
|
|
|
return;
|
|
|
}
|
|
|
var instanceIdStr = "";
|
|
|
for (var i = 0; i < instanceIds.length; i ++) {
|
|
|
if(i == instanceIds.length - 1){
|
|
|
instanceIdStr += instanceIds[i];
|
|
|
}else{
|
|
|
instanceIdStr += instanceIds[i] + ",";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
writeToText("实例ID为:" + instanceIdStr);
|
|
|
writeToText("正在通过实例ID获取实例的内网ip:请稍后...");
|
|
|
var ips = getIpByInstanceIds(instanceIdStr);
|
|
|
writeToText("第 2 步:获取内网成功!")
|
|
|
if(ips == undefined){
|
|
|
writeToText("系统异常,执行失败....");
|
|
|
deployLaster();
|
|
|
return;
|
|
|
}
|
|
|
writeToText("正在发布系统,请稍后...");
|
|
|
deployProject(ips);
|
|
|
writeToText("第 3 步:系统部署成功!");
|
|
|
deployLaster();
|
|
|
}
|
|
|
|
|
|
//发布成功和失败都执行
|
|
|
function deployLaster(){
|
|
|
//发布完之后,显示关闭按钮
|
|
|
$("#closeButton").removeAttr("disabled");
|
|
|
//成功后清空
|
|
|
clear_Sour();
|
|
|
}
|
|
|
|
|
|
//2:根据实例id获取内网ip地址
|
|
|
function getIpByInstanceIds(instanceIds){
|
|
|
var returnIps;
|
|
|
$.ajax({
|
|
|
url: '/autoScalingTool/getQcloudDescribeInstances?ids=' + instanceIds,
|
|
|
type: 'POST',
|
|
|
dataType: 'json',
|
|
|
async:false,
|
|
|
success: function (data) {
|
|
|
if (!data || data.code != 200) {
|
|
|
alert(data.message);
|
|
|
}else{
|
|
|
//组装内网ip
|
|
|
var dataJson = data.data;
|
|
|
if(dataJson == undefined){
|
|
|
writeToText("系统异常,执行失败....");
|
|
|
//发布完之后,显示关闭按钮
|
|
|
$("#closeButton").removeAttr("disabled");
|
|
|
return;
|
|
|
}
|
|
|
//展现
|
|
|
var ips = "";
|
|
|
for(var i = 0;i < dataJson.length;i++){
|
|
|
if(i == dataJson.length - 1){
|
|
|
ips += dataJson[i].lanIp;
|
|
|
}else{
|
|
|
ips += dataJson[i].lanIp + ",";
|
|
|
}
|
|
|
writeToText("实例id:" + dataJson[i].unInstanceId + " - ip:" + dataJson[i].lanIp);
|
|
|
}
|
|
|
returnIps = ips;
|
|
|
}
|
|
|
},
|
|
|
error: function (data) {
|
|
|
writeToText('系统异常!');
|
|
|
deployLaster();
|
|
|
}
|
|
|
});
|
|
|
return returnIps;
|
|
|
}
|
|
|
|
|
|
//3:根据ip发布项目
|
|
|
function deployProject(ips){
|
|
|
|
|
|
}
|
|
|
|
|
|
//缩容成功后执行
|
|
|
function unDeploy(){
|
|
|
|
|
|
//发布完之后,显示关闭按钮
|
|
|
$("#closeButton").removeAttr("disabled");
|
|
|
|
|
|
//成功后清空
|
|
|
clear_Sour();
|
|
|
}
|
|
|
|
|
|
function changeByCloudType(){
|
|
|
refreshAutosSalingTable();
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|