From 301a3be8ec5c2f1a329ea62ab1c6203c2f241268 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 1 Aug 2012 10:19:50 -0700 Subject: [PATCH] cloudstack 3.0 UI - autoscale - edit mode - disable autoscaleVmGroup before calling other updateXXXXXXX APIs and enable it back afterwards. --- ui/scripts/autoscaler.js | 80 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/ui/scripts/autoscaler.js b/ui/scripts/autoscaler.js index 085ef34b170..d3ecd2fbe28 100644 --- a/ui/scripts/autoscaler.js +++ b/ui/scripts/autoscaler.js @@ -1030,8 +1030,43 @@ if(!('multiRules' in args.context)) { //from a new LB loadBalancer(args); } - else { //from an existing LB - args.response.success(); //modification completes here + else { //from an existing LB + //if original state of autoscaleVmGroup is enabled, we enable it back. + if(args.context.originalAutoscaleData.context.autoscaleVmGroup.state == 'enabled') { + $.ajax({ + url: createURL('enableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var disableAutoScaleVmGroupIntervalID = setInterval(function() { + $.ajax({ + url: createURL("queryAsyncJobResult&jobid=" + json.enableautoscalevmGroupresponse.jobid), + dataType: "json", + success: function(json) { + var result = json.queryasyncjobresultresponse; + if(result.jobstatus == 0) { + return; + } + else { + clearInterval(disableAutoScaleVmGroupIntervalID); + if(result.jobstatus == 1) { + //json.queryasyncjobresultresponse.jobresult.autoscalevmgroup //do NOT update args.context.originalAutoscaleData.context.autoscaleVmGroup. So, we have original data before making API calls. + args.response.success(); //modification is completed here + } + else if(result.jobstatus == 2) { + args.response.error(_s(result.jobresult.errortext)); + } + } + } + }); + }, 3000); + } + }); + } + else { + args.response.success(); //modification is completed here + } } } else if (result.jobstatus == 2) { @@ -1151,7 +1186,46 @@ }); }; - scaleUp(args); + if(!('multiRules' in args.context)) { //from a new LB + scaleUp(args); + } + else { //from an existing LB + if(args.context.originalAutoscaleData.context.autoscaleVmGroup.state == 'disabled') { + scaleUp(args); + } + else { + $.ajax({ + url: createURL('disableAutoScaleVmGroup'), + data: { + id: args.context.originalAutoscaleData.context.autoscaleVmGroup.id + }, + success: function(json) { + var disableAutoScaleVmGroupIntervalID = setInterval(function() { + $.ajax({ + url: createURL("queryAsyncJobResult&jobid=" + json.disableautoscalevmGroupresponse.jobid), + dataType: "json", + success: function(json) { + var result = json.queryasyncjobresultresponse; + if(result.jobstatus == 0) { + return; + } + else { + clearInterval(disableAutoScaleVmGroupIntervalID); + if(result.jobstatus == 1) { + //json.queryasyncjobresultresponse.jobresult.autoscalevmgroup //do NOT update args.context.originalAutoscaleData.context.autoscaleVmGroup. So, we have original data before making API calls. + scaleUp(args); + } + else if(result.jobstatus == 2) { + args.response.error(_s(result.jobresult.errortext)); + } + } + } + }); + }, 3000); + } + }); + } + } //setTimeout(function() { args.response.success(); }, 1000); //setTimeout(function() { args.response.error('Error!'); }, 1000);