Authored by qinchao

aws伸缩

@@ -298,7 +298,7 @@ public class AutoScalingCtrl { @@ -298,7 +298,7 @@ public class AutoScalingCtrl {
298 */ 298 */
299 @RequestMapping("/updateIpToGit") 299 @RequestMapping("/updateIpToGit")
300 @ResponseBody 300 @ResponseBody
301 - public BaseResponse<?> updateIpToGit(int cloudType, String projectName, String scalingGroupId,String oldInstanceIps,String upDownFlag){ 301 + public BaseResponse<?> updateIpToGit(int cloudType, String projectName, String scalingGroupId,String oldInstanceIps,String newInstanceIps,String upDownFlag){
302 String cloudTypeStr=""; 302 String cloudTypeStr="";
303 if(1==cloudType){ 303 if(1==cloudType){
304 cloudTypeStr="aws"; 304 cloudTypeStr="aws";
@@ -307,17 +307,17 @@ public class AutoScalingCtrl { @@ -307,17 +307,17 @@ public class AutoScalingCtrl {
307 } 307 }
308 308
309 //获取新的伸缩实例ip 309 //获取新的伸缩实例ip
310 - BaseResponse newInstanceIpsResponse=this.getIpsByScalingGroupId(cloudType,projectName,scalingGroupId); 310 + /*BaseResponse newInstanceIpsResponse=this.getIpsByScalingGroupId(cloudType,projectName,scalingGroupId);
311 if(newInstanceIpsResponse==null||newInstanceIpsResponse.getCode()!=200){ 311 if(newInstanceIpsResponse==null||newInstanceIpsResponse.getCode()!=200){
312 newInstanceIpsResponse.setMessage("获取伸缩组新的实例ip失败!"); 312 newInstanceIpsResponse.setMessage("获取伸缩组新的实例ip失败!");
313 return newInstanceIpsResponse; 313 return newInstanceIpsResponse;
314 - } 314 + }*/
315 315
316 316
317 String projectNameArray[]= AutoScalingGroupProjectConstant.getProjectNames(cloudTypeStr,projectName).split(","); 317 String projectNameArray[]= AutoScalingGroupProjectConstant.getProjectNames(cloudTypeStr,projectName).split(",");
318 StringBuilder sb=new StringBuilder(); 318 StringBuilder sb=new StringBuilder();
319 for(String project:projectNameArray){ 319 for(String project:projectNameArray){
320 - String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_IP_TO_GIT+"?cloudType=%s&projectName=%s&scalingGroupId=%s",cloudType,project, scalingGroupId); 320 + String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_IP_TO_GIT+"?cloudType=%d&projectName=%s&scalingGroupId=%s",cloudType,project, scalingGroupId);
321 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class); 321 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
322 if(responseTmp==null||responseTmp.getCode()!=200){ 322 if(responseTmp==null||responseTmp.getCode()!=200){
323 responseTmp.setMessage(responseTmp.getMessage()+"**********project:"+project); 323 responseTmp.setMessage(responseTmp.getMessage()+"**********project:"+project);
@@ -328,10 +328,16 @@ public class AutoScalingCtrl { @@ -328,10 +328,16 @@ public class AutoScalingCtrl {
328 } 328 }
329 329
330 if("gateway".equals(projectName)){ 330 if("gateway".equals(projectName)){
331 - List<String> newInstanceIps=(List<String>)newInstanceIpsResponse.getData(); 331 + //List<String> newInstanceIps=(List<String>)newInstanceIpsResponse.getData();
  332 + List<String> newInstanceIpList=null;
  333 + if(StringUtils.isNotBlank(newInstanceIps)){
  334 + newInstanceIpList=Arrays.asList(newInstanceIps.split(","));
  335 + }else{
  336 + newInstanceIpList=new ArrayList<String>();
  337 + }
332 if("up".equals(upDownFlag)){ 338 if("up".equals(upDownFlag)){
333 List<String> oldIps= Arrays.asList(oldInstanceIps.split(",")); 339 List<String> oldIps= Arrays.asList(oldInstanceIps.split(","));
334 - for(String strIP:newInstanceIps){ 340 + for(String strIP:newInstanceIpList){
335 if(!oldIps.contains(strIP)&&StringUtils.isNotBlank(strIP)){ 341 if(!oldIps.contains(strIP)&&StringUtils.isNotBlank(strIP)){
336 String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","add",cloudTypeStr, strIP); 342 String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","add",cloudTypeStr, strIP);
337 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class); 343 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
@@ -342,7 +348,7 @@ public class AutoScalingCtrl { @@ -342,7 +348,7 @@ public class AutoScalingCtrl {
342 }else if("down".equals(upDownFlag)){ 348 }else if("down".equals(upDownFlag)){
343 List<String> oldIps= Arrays.asList(oldInstanceIps.split(",")); 349 List<String> oldIps= Arrays.asList(oldInstanceIps.split(","));
344 for(String strIP:oldIps){ 350 for(String strIP:oldIps){
345 - if(!newInstanceIps.contains(strIP)){ 351 + if(!newInstanceIpList.contains(strIP)){
346 String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","del",cloudTypeStr, strIP); 352 String url = String.format(HttpUriContants.GET_CLOUD_UPDATE_GATEWAY_CHANGE_UPSTREAM+"?operate=%s&cloudTypeStr=%s&ip=%s","del",cloudTypeStr, strIP);
347 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class); 353 BaseResponse<?> responseTmp = httpClient.defaultPost(url, null, BaseResponse.class);
348 sb.append("gateway upstream del "+strIP); 354 sb.append("gateway upstream del "+strIP);
@@ -758,4 +758,81 @@ function deploy_bak(instanceIds){ @@ -758,4 +758,81 @@ function deploy_bak(instanceIds){
758 //3.1:发布项目的同时获取发布的消息,由于定时器是异步行为,故下一步骤智能在内部进行 758 //3.1:发布项目的同时获取发布的消息,由于定时器是异步行为,故下一步骤智能在内部进行
759 deployProjectGetMsg(messageId,ips); 759 deployProjectGetMsg(messageId,ips);
760 } 760 }
761 -}  
  761 +}
  762 +
  763 +
  764 +function refCloudMessage_bak2(cloudType,showMessage, serverChangeCount,desiredCapacity){
  765 + var url = contextPath + 'autoScalingTool/describeScalingActivity?cloudType='+cloudType+'&scalingGroupName='+scalingGroupName ;
  766 + writeToText("开始..........");
  767 + var count = 0;
  768 + var intervalIndex = setInterval(function() {
  769 + $.ajax({
  770 + url: url,
  771 + type: 'POST',
  772 + dataType: 'json',
  773 + success: function (data) {
  774 + if (!data || data.code != 200) {
  775 + responseError(data);
  776 + }else{
  777 + var checkPassFlag=true;
  778 + var actualServerInstNum = -1;
  779 + if(data.data.length==0){
  780 + actualServerInstNum=0;
  781 + }else{
  782 + var dataJson = data.data[0];
  783 + if(dataJson==null){
  784 + checkPassFlag=false;
  785 + }
  786 + if(dataJson.scalingInstancess==null||dataJson.scalingInstancess==undefined){
  787 + actualServerInstNum=0;
  788 + }else{
  789 + actualServerInstNum=dataJson.scalingInstancess.length;
  790 + }
  791 + }
  792 + //计算变化主机的ip
  793 + var changedIps="";
  794 + if(actualServerInstNum != desiredCapacity){
  795 + checkPassFlag=false;
  796 + }else{
  797 + for(var tmp=0;tmp<dataJson.scalingInstancess.length;tmp++){
  798 + var tmpInstIp=dataJson.scalingInstancess[tmp].ip;
  799 + if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){
  800 + checkPassFlag=false;
  801 + break;
  802 + }
  803 + if(souInstanceIps.indexOf(tmpInstIp) < 0){
  804 + if(changedIps.length>0){
  805 + changedIps += ",";
  806 + }
  807 + writeToText("扩容机器实例ID为:" + dataJson.scalingInstancess[tmp].id+",IP为:"+tmpInstIp);
  808 + changedIps += tmpInstIp;
  809 + }
  810 + }
  811 + }
  812 + if(!checkPassFlag){
  813 + writeToText("............"+count);
  814 + }else{
  815 + writeToText("第 1 步:" + showMessage + " 成功!");
  816 + writeToText("...");
  817 + clearInterval(intervalIndex);
  818 +
  819 + if(showMessage == "缩容"){
  820 + unDeploy(showMessage);
  821 + writeToText("结束..........");
  822 + return;
  823 + }else{
  824 +
  825 + writeToText("内网ip合计:"+changedIps);
  826 + //扩容成功后执行
  827 + deploy(changedIps);
  828 + }
  829 + }
  830 + }
  831 + count += 1;
  832 + },
  833 + error: function (e) {
  834 + requestError(url);
  835 + }
  836 + });
  837 + }, 10000);
  838 +}
@@ -207,6 +207,7 @@ var souMaxSize; @@ -207,6 +207,7 @@ var souMaxSize;
207 var souBranch; 207 var souBranch;
208 //原实例ip 208 //原实例ip
209 var souInstanceIps; 209 var souInstanceIps;
  210 +var newInstanceIps;
210 //修改伸缩组 211 //修改伸缩组
211 function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapacity, minSize, maxSize){ 212 function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapacity, minSize, maxSize){
212 scalingGroupName = groupName; 213 scalingGroupName = groupName;
@@ -217,6 +218,7 @@ function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapa @@ -217,6 +218,7 @@ function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapa
217 souMinSize = minSize; 218 souMinSize = minSize;
218 souMaxSize = maxSize; 219 souMaxSize = maxSize;
219 souInstanceIps=""; 220 souInstanceIps="";
  221 + newInstanceIps="";
220 222
221 $("#myModalLabel").text(""); 223 $("#myModalLabel").text("");
222 $("#protectedFromCount").val(""); 224 $("#protectedFromCount").val("");
@@ -346,6 +348,7 @@ function clear_Sour(){ @@ -346,6 +348,7 @@ function clear_Sour(){
346 souMinSize = ""; 348 souMinSize = "";
347 souMaxSize = ""; 349 souMaxSize = "";
348 souInstanceIps =""; 350 souInstanceIps ="";
  351 + newInstanceIps="";
349 } 352 }
350 353
351 //腾讯云:修改伸缩组后的下一个流程是查询伸缩活动 354 //腾讯云:修改伸缩组后的下一个流程是查询伸缩活动
@@ -365,6 +368,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit @@ -365,6 +368,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
365 //计算变化主机的ip 368 //计算变化主机的ip
366 var checkPassFlag=true; 369 var checkPassFlag=true;
367 var changedIps=""; 370 var changedIps="";
  371 + newInstanceIps="";
368 if(data.data.length != desiredCapacity){ 372 if(data.data.length != desiredCapacity){
369 checkPassFlag=false; 373 checkPassFlag=false;
370 }else{ 374 }else{
@@ -372,8 +376,13 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit @@ -372,8 +376,13 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
372 var tmpInstIp=data.data[tmp]; 376 var tmpInstIp=data.data[tmp];
373 if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){ 377 if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){
374 checkPassFlag=false; 378 checkPassFlag=false;
  379 + newInstanceIps="";
375 break; 380 break;
376 } 381 }
  382 + if(newInstanceIps.length>0){
  383 + newInstanceIps += ",";
  384 + }
  385 + newInstanceIps += tmpInstIp;
377 if(souInstanceIps.indexOf(tmpInstIp) < 0){ 386 if(souInstanceIps.indexOf(tmpInstIp) < 0){
378 if(changedIps.length>0){ 387 if(changedIps.length>0){
379 changedIps += ","; 388 changedIps += ",";
@@ -395,8 +404,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit @@ -395,8 +404,7 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
395 writeToText("结束.........."); 404 writeToText("结束..........");
396 return; 405 return;
397 }else{ 406 }else{
398 -  
399 - writeToText("内网ip合计:"+changedIps); 407 + writeToText("新扩容的内网ip合计:"+changedIps);
400 //扩容成功后执行 408 //扩容成功后执行
401 deploy(changedIps); 409 deploy(changedIps);
402 } 410 }
@@ -411,89 +419,8 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit @@ -411,89 +419,8 @@ function refCloudMessage(cloudType,showMessage, serverChangeCount,desiredCapacit
411 }, 10000); 419 }, 10000);
412 } 420 }
413 421
414 -function refCloudMessage_bak2(cloudType,showMessage, serverChangeCount,desiredCapacity){  
415 - var url = contextPath + 'autoScalingTool/describeScalingActivity?cloudType='+cloudType+'&scalingGroupName='+scalingGroupName ;  
416 - writeToText("开始..........");  
417 - var count = 0;  
418 - var intervalIndex = setInterval(function() {  
419 - $.ajax({  
420 - url: url,  
421 - type: 'POST',  
422 - dataType: 'json',  
423 - success: function (data) {  
424 - if (!data || data.code != 200) {  
425 - responseError(data);  
426 - }else{  
427 - var checkPassFlag=true;  
428 - var actualServerInstNum = -1;  
429 - if(data.data.length==0){  
430 - actualServerInstNum=0;  
431 - }else{  
432 - var dataJson = data.data[0];  
433 - if(dataJson==null){  
434 - checkPassFlag=false;  
435 - }  
436 - if(dataJson.scalingInstancess==null||dataJson.scalingInstancess==undefined){  
437 - actualServerInstNum=0;  
438 - }else{  
439 - actualServerInstNum=dataJson.scalingInstancess.length;  
440 - }  
441 - }  
442 - //计算变化主机的ip  
443 - var changedIps="";  
444 - if(actualServerInstNum != desiredCapacity){  
445 - checkPassFlag=false;  
446 - }else{  
447 - for(var tmp=0;tmp<dataJson.scalingInstancess.length;tmp++){  
448 - var tmpInstIp=dataJson.scalingInstancess[tmp].ip;  
449 - if(tmpInstIp==null||tmpInstIp==""||tmpInstIp==undefined){  
450 - checkPassFlag=false;  
451 - break;  
452 - }  
453 - if(souInstanceIps.indexOf(tmpInstIp) < 0){  
454 - if(changedIps.length>0){  
455 - changedIps += ",";  
456 - }  
457 - writeToText("扩容机器实例ID为:" + dataJson.scalingInstancess[tmp].id+",IP为:"+tmpInstIp);  
458 - changedIps += tmpInstIp;  
459 - }  
460 - }  
461 - }  
462 - if(!checkPassFlag){  
463 - writeToText("............"+count);  
464 - }else{  
465 - writeToText("第 1 步:" + showMessage + " 成功!");  
466 - writeToText("...");  
467 - clearInterval(intervalIndex);  
468 422
469 - if(showMessage == "缩容"){  
470 - unDeploy(showMessage);  
471 - writeToText("结束..........");  
472 - return;  
473 - }else{  
474 423
475 - writeToText("内网ip合计:"+changedIps);  
476 - //扩容成功后执行  
477 - deploy(changedIps);  
478 - }  
479 - }  
480 - }  
481 - count += 1;  
482 - },  
483 - error: function (e) {  
484 - requestError(url);  
485 - }  
486 - });  
487 - }, 10000);  
488 -}  
489 -  
490 -//写入消息  
491 -function writeToText(msg){  
492 - var d = $("#resultScalingMessage").val();  
493 - $("#resultScalingMessage").html(d + "&#13" + msg);  
494 - var scrollTop = $("#resultScalingMessage")[0].scrollHeight;  
495 - $("#resultScalingMessage").scrollTop(scrollTop);  
496 -}  
497 //1:扩容成功后执行 424 //1:扩容成功后执行
498 function deploy(ips){ 425 function deploy(ips){
499 writeToText("第 2 步:获取内网成功!"); 426 writeToText("第 2 步:获取内网成功!");
@@ -636,26 +563,6 @@ function deployProject(ips){ @@ -636,26 +563,6 @@ function deployProject(ips){
636 563
637 //3.1:发布项目的同时获取发布的消息 564 //3.1:发布项目的同时获取发布的消息
638 function deployProjectGetMsg(msgId, ips){ 565 function deployProjectGetMsg(msgId, ips){
639 - /*$.ajax({  
640 - url: contextPath + 'autoScalingTool/getDeployProjectNames?scalingGroupName='+scalingGroupName + '&environment=qcloud',  
641 - type: 'POST',  
642 - dataType: 'json',  
643 - async: false,  
644 - success: function (data) {  
645 - if (!data || data.code != 200) {  
646 - responseError(data);  
647 - }else{  
648 - var allProjects = data.data.split(",");  
649 - for(var testi= 0;testi<allProjects.length;testi++){  
650 -  
651 - }  
652 - }  
653 - },  
654 - error: function (e) {  
655 - requestError(url);  
656 - }  
657 - });*/  
658 -  
659 var intervalIndexMsg = setInterval(function() { 566 var intervalIndexMsg = setInterval(function() {
660 var url = contextPath + 'autoScalingTool/getBuildMsgAfterDeploy?messageid=' + msgId+"&project="+scalingGroupName; 567 var url = contextPath + 'autoScalingTool/getBuildMsgAfterDeploy?messageid=' + msgId+"&project="+scalingGroupName;
661 $.ajax({ 568 $.ajax({
@@ -682,29 +589,7 @@ function deployProjectGetMsg(msgId, ips){ @@ -682,29 +589,7 @@ function deployProjectGetMsg(msgId, ips){
682 }else{ 589 }else{
683 writeToText("......."); 590 writeToText(".......");
684 } 591 }
685 -  
686 - }  
687 - /* var obj2 = eval("(" + data3 + ")");  
688 - var messagedata = obj2.data;  
689 - if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) {  
690 - writeToText(messagedata.message);  
691 } 592 }
692 - //code为2 ,则结束  
693 - var code = obj2.code;  
694 - //只有状态2,3,4才表示系统部署成功与否  
695 - if (code == 2 || code == 3 || code == 4) {  
696 - writeToText("第 3 步:系统部署成功!");  
697 - clearInterval(intervalIndexMsg);  
698 -  
699 - writeToText(">>>第 4 步:正在进行集成测试,请稍后...");  
700 - //4:集成测试  
701 - //integrationTest(ips);  
702 - writeToText(">>>集成测试暂时不需要,忽略...");  
703 -  
704 - writeToText(">>>更新到git,请稍后...");  
705 - //5:更新git文件  
706 - editToGit();  
707 - }*/  
708 }, 593 },
709 error: function (e) { 594 error: function (e) {
710 requestError(url); 595 requestError(url);
@@ -765,14 +650,14 @@ function editToGit(showMessage){ @@ -765,14 +650,14 @@ function editToGit(showMessage){
765 paramFront.projectName=scalingGroupName; 650 paramFront.projectName=scalingGroupName;
766 paramFront.scalingGroupId=souScalingGroupId; 651 paramFront.scalingGroupId=souScalingGroupId;
767 paramFront.oldInstanceIps=souInstanceIps; 652 paramFront.oldInstanceIps=souInstanceIps;
  653 + paramFront.newInstanceIps=newInstanceIps;
768 paramFront.upDownFlag=upDownFlag; 654 paramFront.upDownFlag=upDownFlag;
769 - // var url = contextPath+'autoScalingTool/updateIpToGit?  
770 - // cloudType='+$("#cloudType").val()+'&projectName='+scalingGroupName+'&scalingGroupId=' + souScalingGroupId+"&oldInstanceIps="+souInstanceIps +"&upDownFlag="+upDownFlag;  
771 var url=contextPath+'autoScalingTool/updateIpToGit'; 655 var url=contextPath+'autoScalingTool/updateIpToGit';
772 $.ajax({ 656 $.ajax({
773 url: url, 657 url: url,
774 type: 'POST', 658 type: 'POST',
775 data: paramFront, 659 data: paramFront,
  660 + timeout:0,
776 dataType: 'json', 661 dataType: 'json',
777 async: false, 662 async: false,
778 success: function (data) { 663 success: function (data) {
@@ -812,6 +697,14 @@ function unDeploy(showMessage){ @@ -812,6 +697,14 @@ function unDeploy(showMessage){
812 clear_Sour(); 697 clear_Sour();
813 } 698 }
814 699
  700 +//写入消息
  701 +function writeToText(msg){
  702 + var d = $("#resultScalingMessage").val();
  703 + $("#resultScalingMessage").html(d + "&#13" + msg);
  704 + var scrollTop = $("#resultScalingMessage")[0].scrollHeight;
  705 + $("#resultScalingMessage").scrollTop(scrollTop);
  706 +}
  707 +
815 //请求接口异常 708 //请求接口异常
816 function requestError(api){ 709 function requestError(api){
817 writeToText('系统异常:' + api); 710 writeToText('系统异常:' + api);