Skip to content

Commit f0aefda

Browse files
author
Daniel Vega
committed
Dialog to create and edit autoscale conditions/policies/groups for load balancer
1 parent d0b02ac commit f0aefda

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

‎ui/scripts/autoscaler.js‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@
119119
lbruleid: args.context.multiRules[0].id
120120
},
121121
success: function(json) {
122-
var autoscaleVmGroup = json.listautoscalevmgroupsresponse.autoscalevmgroup[0];
122+
var response = json.listautoscalevmgroupsresponse.autoscalevmgroup;
123+
if (!response || !response[0]) {
124+
// Existing LB, but no configured VM Group yet
125+
args.response.success({
126+
data: null
127+
});
128+
return;
129+
}
130+
131+
var autoscaleVmGroup = response[0];
123132

124133
$.ajax({
125134
url: createURL('listAutoScaleVmProfiles'),
@@ -329,7 +338,7 @@
329338

330339
minInstance: {
331340
label: 'label.min.instances',
332-
defaultValue: '3',
341+
defaultValue: '1',
333342
validation: {
334343
required: true,
335344
number: true
@@ -338,7 +347,7 @@
338347

339348
maxInstance: {
340349
label: 'label.max.instances',
341-
defaultValue: '10',
350+
defaultValue: '5',
342351
validation: {
343352
required: true,
344353
number: true
@@ -742,7 +751,7 @@
742751
actions: {
743752
apply: function(args) {
744753
//validation (begin) *****
745-
if (!('multiRules' in args.context)) { //from a new LB
754+
if (!('multiRules' in args.context) || !args.context.originalAutoscaleData) { //from a new LB or from existing LB without AutoscaleVmGroup
746755
if (args.formData.name == '' || args.formData.publicport == '' || args.formData.privateport == '') {
747756
args.response.error('Name, Public Port, Private Port of Load Balancing are required. Please close this dialog box and fill Name, Public Port, Private Port first.');
748757
return;
@@ -872,7 +881,7 @@
872881
var item = json.queryasyncjobresultresponse.jobresult.condition;
873882
scaleUpConditionIds.push(item.id);
874883
if (scaleUpConditionIds.length == scaleUpData.length) {
875-
if (!('multiRules' in args.context)) { //from a new LB
884+
if (!('multiRules' in args.context) || !args.context.originalAutoscaleData) { //from a new LB or from existing LB without AutoscaleVmGroup
876885
var data = {
877886
action: 'scaleup',
878887
conditionids: scaleUpConditionIds.join(","),
@@ -1004,7 +1013,7 @@
10041013
var item = json.queryasyncjobresultresponse.jobresult.condition;
10051014
scaleDownConditionIds.push(item.id);
10061015
if (scaleDownConditionIds.length == scaleDownData.length) {
1007-
if (!('multiRules' in args.context)) { //from a new LB
1016+
if (!('multiRules' in args.context) || !args.context.originalAutoscaleData) { //from a new LB or from existing LB without AutoscaleVmGroup
10081017
var data = {
10091018
action: 'scaledown',
10101019
conditionids: scaleDownConditionIds.join(","),
@@ -1114,7 +1123,7 @@
11141123
var createOrUpdateVmProfile = function(args) {
11151124
var array1 = [];
11161125
var apiCmd, apiCmdRes;
1117-
if (!('multiRules' in args.context)) { //from a new LB
1126+
if (!('multiRules' in args.context) || !args.context.originalAutoscaleData) { //from a new LB or from existing LB without AutoscaleVmGroup) { //from a new LB
11181127
var data = {
11191128
zoneid: args.context.networks[0].zoneid, //get zoneid from args.context.networks[0] instead of args.context.ipAddresses[0] because args.context.ipAddresses is null when adding AutoScale rule from Add Load Balancer tab in Network page
11201129
serviceofferingid: args.data.serviceOfferingId,
@@ -1266,6 +1275,13 @@
12661275
};
12671276

12681277
var loadBalancer = function(args) {
1278+
// In case load balancer was already created, but no autoscale options yet
1279+
if ('loadbalancer' in args.context) {
1280+
loadBalancerResponse = args.context.loadbalancer;
1281+
autoScaleVmGroup(args);
1282+
return;
1283+
}
1284+
12691285
var networkid;
12701286
if ('vpc' in args.context) { //from VPC section
12711287
if (args.data.tier == null) {
@@ -1332,7 +1348,7 @@
13321348
};
13331349

13341350
var autoScaleVmGroup = function(args) {
1335-
if (!('multiRules' in args.context)) { //from a new LB
1351+
if (!('multiRules' in args.context) || !args.context.originalAutoscaleData) { //from a new LB or from existing LB without AutoscaleVmGroup) { //from a new LB
13361352
var array1 = [];
13371353
array1.push("&lbruleid=" + loadBalancerResponse.id);
13381354
array1.push("&minMembers=" + args.data.minInstance);

‎ui/scripts/loadbalancer.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,29 @@
548548
},
549549
},
550550
actions: {
551+
editAutoscale: {
552+
label: 'Edit Autoscale',
553+
custom: {
554+
buttonLabel: 'label.configure',
555+
},
556+
action: function(args) {
557+
args.context.networks = [];
558+
args.context.networks.push({zoneid: args.context.loadbalancers[0].zoneid});
559+
args.context.multiRules = [];
560+
args.context.multiRules.push(args.context.loadbalancers[0]);
561+
args.context.loadbalancer = args.context.loadbalancers[0];
562+
var returnFunction = cloudStack.uiCustom.autoscaler(cloudStack.autoscaler);
563+
return returnFunction(args);
564+
},
565+
messages: {
566+
notification: function() {
567+
return 'Update Autoscale';
568+
}
569+
},
570+
notification: {
571+
poll: pollAsyncJobResult
572+
},
573+
},
551574
editHealthcheck: {
552575
label: 'Edit Healthcheck',
553576
custom: {

‎ui/scripts/ui-custom/autoscaler.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@
350350
click: function() {
351351
$autoscalerDialog.dialog('destroy');
352352
$('.overlay').remove();
353+
$('.loading-overlay').remove()
353354
}
354355
}, {
355356
text: _l('Apply'),
@@ -373,6 +374,7 @@
373374
response: {
374375
success: function() {
375376
$loading.remove();
377+
$('.loading-overlay').remove()
376378
$autoscalerDialog.dialog('destroy');
377379
$autoscalerDialog.closest(':ui-dialog').remove();
378380
$('.overlay').remove();

0 commit comments

Comments
 (0)