Authored by qinchao

aws伸缩

... ... @@ -298,7 +298,7 @@ public class AutoScalingCtrl {
*/
@RequestMapping("/updateIpToGit")
@ResponseBody
public BaseResponse<?> updateIpToGit(int cloudType, String projectName, String scalingGroupId,String oldInstanceIps,String upDownFlag){
public BaseResponse<?> updateIpToGit(int cloudType, String projectName, String scalingGroupId,String oldInstanceIps,String newInstanceIps,String upDownFlag){
String cloudTypeStr="";
if(1==cloudType){
cloudTypeStr="aws";
... ... @@ -307,17 +307,17 @@ public class AutoScalingCtrl {
}
//获取新的伸缩实例ip
BaseResponse newInstanceIpsResponse=this.getIpsByScalingGroupId(cloudType,projectName,scalingGroupId);
/*BaseResponse newInstanceIpsResponse=this.getIpsByScalingGroupId(cloudType,projectName,scalingGroupId);
if(newInstanceIpsResponse==null||newInstanceIpsResponse.getCode()!=200){
newInstanceIpsResponse.setMessage("获取伸缩组新的实例ip失败!");
return newInstanceIpsResponse;
}
}*/
String projectNameArray[]= AutoScalingGroupProjectConstant.getProjectNames(cloudTypeStr,projectName).split(",");
StringBuilder sb=new StringBuilder();
for(String project:projectNameArray){
String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_IP_TO_GIT+"?cloudType=%s&projectName=%s&scalingGroupId=%s",cloudType,project, scalingGroupId);
String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_IP_TO_GIT+"?cloudType=%d&projectName=%s&scalingGroupId=%s",cloudType,project, scalingGroupId);
BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
if(responseTmp==null||responseTmp.getCode()!=200){
responseTmp.setMessage(responseTmp.getMessage()+"**********project:"+project);
... ... @@ -328,10 +328,16 @@ public class AutoScalingCtrl {
}
if("gateway".equals(projectName)){
List<String> newInstanceIps=(List<String>)newInstanceIpsResponse.getData();
//List<String> newInstanceIps=(List<String>)newInstanceIpsResponse.getData();
List<String> newInstanceIpList=null;
if(StringUtils.isNotBlank(newInstanceIps)){
newInstanceIpList=Arrays.asList(newInstanceIps.split(","));
}else{
newInstanceIpList=new ArrayList<String>();
}
if("up".equals(upDownFlag)){
List<String> oldIps= Arrays.asList(oldInstanceIps.split(","));
for(String strIP:newInstanceIps){
for(String strIP:newInstanceIpList){
if(!oldIps.contains(strIP)&&StringUtils.isNotBlank(strIP)){
String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","add",cloudTypeStr, strIP);
BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
... ... @@ -342,7 +348,7 @@ public class AutoScalingCtrl {
}else if("down".equals(upDownFlag)){
List<String> oldIps= Arrays.asList(oldInstanceIps.split(","));
for(String strIP:oldIps){
if(!newInstanceIps.contains(strIP)){
if(!newInstanceIpList.contains(strIP)){
String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","del",cloudTypeStr, strIP);
BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
sb.append("gateway upstream del "+strIP);
... ...
... ... @@ -758,4 +758,81 @@ function deploy_bak(instanceIds){
//3.1:发布项目的同时获取发布的消息,由于定时器是异步行为,故下一步骤智能在内部进行
deployProjectGetMsg(messageId,ips);
}
}
\ No newline at end of file
}
function refCloudMessage_bak2(cloudType,showMessage, serverChangeCount,desiredCapacity){
var url = contextPath + 'autoScalingTool/describeScalingActivity?cloudType='+cloudType+'&scalingGroupName='+scalingGroupName ;
writeToText("开始..........");
var count = 0;
var intervalIndex = setInterval(function() {
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
success: function (data) {
if (!data || data.code != 200) {
responseError(data);
}else{
var checkPassFlag=true;
var actualServerInstNum = -1;
if(data.data.length==0){
actualServerInstNum=0;
}else{
var dataJson = data.data[0];
if(dataJson==null){
checkPassFlag=false;
}
if(dataJson.scalingInstancess==null||dataJson.scalingInstancess==undefined){
actualServerInstNum=0;
}else{
actualServerInstNum=dataJson.scalingInstancess.length;
}
}
//计算变化主机的ip
var changedIps="";
if(actualServerInstNum != desiredCapacity){
checkPassFlag=false;
}else{
for(var tmp=0;tmp<dataJson.scalingInstancess.length;tmp++){
var tmpInstIp=dataJson.scalingInstancess[tmp].ip;
if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){
checkPassFlag=false;
break;
}
if(souInstanceIps.indexOf(tmpInstIp) < 0){
if(changedIps.length>0){
changedIps += ",";
}
writeToText("扩容机器实例ID为:" + dataJson.scalingInstancess[tmp].id+",IP为:"+tmpInstIp);
changedIps += tmpInstIp;
}
}
}
if(!checkPassFlag){
writeToText("............"+count);
}else{
writeToText("第 1 步:" + showMessage + " 成功!");
writeToText("...");
clearInterval(intervalIndex);
if(showMessage == "缩容"){
unDeploy(showMessage);
writeToText("结束..........");
return;
}else{
writeToText("内网ip合计:"+changedIps);
//扩容成功后执行
deploy(changedIps);
}
}
}
count += 1;
},
error: function (e) {
requestError(url);
}
});
}, 10000);
}
... ...
... ... @@ -207,6 +207,7 @@ var souMaxSize;
var souBranch;
//原实例ip
var souInstanceIps;
var newInstanceIps;
//修改伸缩组
function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapacity, minSize, maxSize){
scalingGroupName = groupName;
... ... @@ -217,6 +218,7 @@ function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapa
souMinSize = minSize;
souMaxSize = maxSize;
souInstanceIps="";
newInstanceIps="";
$("#myModalLabel").text("");
$("#protectedFromCount").val("");
... ... @@ -346,6 +348,7 @@ function clear_Sour(){
souMinSize = "";
souMaxSize = "";
souInstanceIps ="";
newInstanceIps="";
}
//腾讯云:修改伸缩组后的下一个流程是查询伸缩活动
... ... @@ -365,6 +368,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
//计算变化主机的ip
var checkPassFlag=true;
var changedIps="";
newInstanceIps="";
if(data.data.length != desiredCapacity){
checkPassFlag=false;
}else{
... ... @@ -372,8 +376,13 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
var tmpInstIp=data.data[tmp];
if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){
checkPassFlag=false;
newInstanceIps="";
break;
}
if(newInstanceIps.length>0){
newInstanceIps += ",";
}
newInstanceIps += tmpInstIp;
if(souInstanceIps.indexOf(tmpInstIp) < 0){
if(changedIps.length>0){
changedIps += ",";
... ... @@ -395,8 +404,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
writeToText("结束..........");
return;
}else{
writeToText("内网ip合计:"+changedIps);
writeToText("新扩容的内网ip合计:"+changedIps);
//扩容成功后执行
deploy(changedIps);
}
... ... @@ -411,89 +419,8 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
}, 10000);
}
function refCloudMessage_bak2(cloudType,showMessage, serverChangeCount,desiredCapacity){
var url = contextPath + 'autoScalingTool/describeScalingActivity?cloudType='+cloudType+'&scalingGroupName='+scalingGroupName ;
writeToText("开始..........");
var count = 0;
var intervalIndex = setInterval(function() {
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
success: function (data) {
if (!data || data.code != 200) {
responseError(data);
}else{
var checkPassFlag=true;
var actualServerInstNum = -1;
if(data.data.length==0){
actualServerInstNum=0;
}else{
var dataJson = data.data[0];
if(dataJson==null){
checkPassFlag=false;
}
if(dataJson.scalingInstancess==null||dataJson.scalingInstancess==undefined){
actualServerInstNum=0;
}else{
actualServerInstNum=dataJson.scalingInstancess.length;
}
}
//计算变化主机的ip
var changedIps="";
if(actualServerInstNum != desiredCapacity){
checkPassFlag=false;
}else{
for(var tmp=0;tmp<dataJson.scalingInstancess.length;tmp++){
var tmpInstIp=dataJson.scalingInstancess[tmp].ip;
if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){
checkPassFlag=false;
break;
}
if(souInstanceIps.indexOf(tmpInstIp) < 0){
if(changedIps.length>0){
changedIps += ",";
}
writeToText("扩容机器实例ID为:" + dataJson.scalingInstancess[tmp].id+",IP为:"+tmpInstIp);
changedIps += tmpInstIp;
}
}
}
if(!checkPassFlag){
writeToText("............"+count);
}else{
writeToText("第 1 步:" + showMessage + " 成功!");
writeToText("...");
clearInterval(intervalIndex);
if(showMessage == "缩容"){
unDeploy(showMessage);
writeToText("结束..........");
return;
}else{
writeToText("内网ip合计:"+changedIps);
//扩容成功后执行
deploy(changedIps);
}
}
}
count += 1;
},
error: function (e) {
requestError(url);
}
});
}, 10000);
}
//写入消息
function writeToText(msg){
var d = $("#resultScalingMessage").val();
$("#resultScalingMessage").html(d + "&#13" + msg);
var scrollTop = $("#resultScalingMessage")[0].scrollHeight;
$("#resultScalingMessage").scrollTop(scrollTop);
}
//1:扩容成功后执行
function deploy(ips){
writeToText("第 2 步:获取内网成功!");
... ... @@ -636,26 +563,6 @@ function deployProject(ips){
//3.1:发布项目的同时获取发布的消息
function deployProjectGetMsg(msgId, ips){
/*$.ajax({
url: contextPath + 'autoScalingTool/getDeployProjectNames?scalingGroupName='+scalingGroupName + '&environment=qcloud',
type: 'POST',
dataType: 'json',
async: false,
success: function (data) {
if (!data || data.code != 200) {
responseError(data);
}else{
var allProjects = data.data.split(",");
for(var testi= 0;testi<allProjects.length;testi++){
}
}
},
error: function (e) {
requestError(url);
}
});*/
var intervalIndexMsg = setInterval(function() {
var url = contextPath + 'autoScalingTool/getBuildMsgAfterDeploy?messageid=' + msgId+"&project="+scalingGroupName;
$.ajax({
... ... @@ -682,29 +589,7 @@ function deployProjectGetMsg(msgId, ips){
}else{
writeToText(".......");
}
}
/* var obj2 = eval("(" + data3 + ")");
var messagedata = obj2.data;
if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) {
writeToText(messagedata.message);
}
//code为2 ,则结束
var code = obj2.code;
//只有状态2,3,4才表示系统部署成功与否
if (code == 2 || code == 3 || code == 4) {
writeToText("第 3 步:系统部署成功!");
clearInterval(intervalIndexMsg);
writeToText(">>>第 4 步:正在进行集成测试,请稍后...");
//4:集成测试
//integrationTest(ips);
writeToText(">>>集成测试暂时不需要,忽略...");
writeToText(">>>更新到git,请稍后...");
//5:更新git文件
editToGit();
}*/
},
error: function (e) {
requestError(url);
... ... @@ -765,14 +650,14 @@ function editToGit(showMessage){
paramFront.projectName=scalingGroupName;
paramFront.scalingGroupId=souScalingGroupId;
paramFront.oldInstanceIps=souInstanceIps;
paramFront.newInstanceIps=newInstanceIps;
paramFront.upDownFlag=upDownFlag;
// var url = contextPath+'autoScalingTool/updateIpToGit?
// cloudType='+$("#cloudType").val()+'&projectName='+scalingGroupName+'&scalingGroupId=' + souScalingGroupId+"&oldInstanceIps="+souInstanceIps +"&upDownFlag="+upDownFlag;
var url=contextPath+'autoScalingTool/updateIpToGit';
$.ajax({
url: url,
type: 'POST',
data: paramFront,
timeout:0,
dataType: 'json',
async: false,
success: function (data) {
... ... @@ -812,6 +697,14 @@ function unDeploy(showMessage){
clear_Sour();
}
//写入消息
function writeToText(msg){
var d = $("#resultScalingMessage").val();
$("#resultScalingMessage").html(d + "&#13" + msg);
var scrollTop = $("#resultScalingMessage")[0].scrollHeight;
$("#resultScalingMessage").scrollTop(scrollTop);
}
//请求接口异常
function requestError(api){
writeToText('系统异常:' + api);
... ...