Skip to content

Commit 2094ee6

Browse files
committed
Health-Check UI development
1 parent 2a337d5 commit 2094ee6

3 files changed

Lines changed: 330 additions & 0 deletions

File tree

‎ui/index.jsp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,7 @@ under the License.
16451645
<script type="text/javascript" src="scripts/cloudStack.js?t=<%=now%>"></script>
16461646
<script type="text/javascript" src="scripts/lbStickyPolicy.js?t=<%=now%>"></script>
16471647
<script type="text/javascript" src="scripts/ui-custom/autoscaler.js?t=<%=now%>"></script>
1648+
<script type="text/javascript" src="scripts/ui-custom/healthCheck.js?t=<%=now%>"></script>
16481649
<script type="text/javascript" src="scripts/autoscaler.js?t=<%=now%>"></script>
16491650
<script type="text/javascript" src="scripts/ui-custom/zoneChart.js?t=<%=now%>"></script>
16501651
<script type="text/javascript" src="scripts/ui-custom/dashboard.js?t=<%=now%>"></script>

‎ui/scripts/network.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,17 @@
27862786
action: cloudStack.lbStickyPolicy.dialog()
27872787
}
27882788
},
2789+
2790+
'health-check':{
2791+
label:'Health Check',
2792+
custom:{
2793+
requireValidation: true ,
2794+
buttonLabel:'Configure',
2795+
action:cloudStack.uiCustom.healthCheck()
2796+
2797+
}
2798+
},
2799+
27892800
'autoScale': {
27902801
label: 'AutoScale',
27912802
custom: {
Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2+
// Apache License, Version 2.0 (the "License"); you may not use this
3+
// file except in compliance with the License. Citrix Systems, Inc.
4+
// reserves all rights not expressly granted by the License.
5+
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
12+
(function($, cloudStack) {
13+
14+
cloudStack.uiCustom.healthCheck = function(args) {
15+
16+
// Place outer args here as local variables
17+
// i.e, -- var dataProvider = args.dataProvider
18+
19+
return function(args){
20+
if(args.context.multiRules == undefined) { //LB rule is not created yet
21+
cloudStack.dialog.notice({ message: _l('Health Check can only be configured on a created LB rule') });
22+
return;
23+
}
24+
25+
var formData = args.formData;
26+
var forms = $.extend(true, {}, args.forms);
27+
var topFieldForm, bottomFieldForm , $topFieldForm , $bottomFieldForm;
28+
var topfields = forms.topFields;
29+
30+
var $healthCheckDesc = $('<div>Your load balancer will automatically perform health checks on your cloudstack instances and only route traffic to instances that pass the health check </div>').addClass('health-check-description');
31+
var $healthCheckConfigTitle = $('<div><br><br>Configuration Options :</div>').addClass('health-check-config-title');
32+
var $healthCheckAdvancedTitle = $('<div><br><br> Advanced Options : </div>').addClass('health-check-advanced-title');
33+
34+
var $healthCheckDialog = $('<div>').addClass('health-check');
35+
$healthCheckDialog.append($healthCheckDesc);
36+
$healthCheckDialog.append($healthCheckConfigTitle);
37+
var $loadingOnDialog = $('<div>').addClass('loading-overlay');
38+
39+
var policyObj = null;
40+
var pingpath1 = '/';
41+
var responsetimeout1 = '2';
42+
var healthinterval1 = '5';
43+
var healthythreshold1 = '2';
44+
var unhealthythreshold1 = '1';
45+
46+
$.ajax({
47+
url: createURL('listLBHealthCheckPolicies'),
48+
data: {
49+
lbruleid: args.context.multiRules[0].id
50+
},
51+
async: false,
52+
success: function(json) {
53+
if(json.listlbhealtcheckpoliciesresponse.healthcheckpolicies[0].healthcheckpolicy[0] != undefined) {
54+
policyObj = json.listlbhealtcheckpoliciesresponse.healthcheckpolicies[0].healthcheckpolicy[0];
55+
pingpath1 = policyObj.pingpath; //API bug: API doesn't return it
56+
responsetimeout1 = policyObj.responsetime;
57+
healthinterval1 = policyObj.healthcheckinterval;
58+
healthythreshold1 = policyObj.healthcheckthresshold;
59+
unhealthythreshold1 = policyObj.unhealthcheckthresshold;
60+
}
61+
}
62+
});
63+
64+
topFieldForm = cloudStack.dialog.createForm({
65+
context: args.context,
66+
noDialog: true, // Don't render a dialog, just return $formContainer
67+
form: {
68+
title: '',
69+
fields:{
70+
pingpath: {label: 'Ping Path', docID:'helpAccountUsername' , validation: {required: false}, defaultValue: pingpath1}
71+
}
72+
}
73+
});
74+
75+
$topFieldForm = topFieldForm.$formContainer;
76+
$topFieldForm.appendTo($healthCheckDialog);
77+
78+
$healthCheckDialog.append($healthCheckAdvancedTitle);
79+
80+
bottomFieldForm = cloudStack.dialog.createForm ({
81+
context:args.context,
82+
noDialog:true,
83+
form:{
84+
title:'',
85+
fields:{
86+
responsetimeout: {label: 'Response Timeout (in sec)' , validation:{required:false}, defaultValue: responsetimeout1},
87+
healthinterval: {label: 'Health Check Interval (in sec)', validation:{required:false}, defaultValue: healthinterval1},
88+
healthythreshold: {label: 'Healthy Threshold', validation: {required:false}, defaultValue: healthythreshold1},
89+
unhealthythreshold: {label: 'Unhealthy Threshold' , validation: { required:false}, defaultValue: unhealthythreshold1}
90+
}
91+
}
92+
});
93+
94+
$bottomFieldForm = bottomFieldForm.$formContainer;
95+
$bottomFieldForm.appendTo($healthCheckDialog);
96+
97+
98+
var buttons = [
99+
{
100+
text: _l('label.cancel'),
101+
'class': 'cancel',
102+
click: function() {
103+
$healthCheckDialog.dialog('destroy');
104+
$('.overlay').remove();
105+
}
106+
}
107+
];
108+
109+
if(policyObj == null) { //policy is not created yet
110+
buttons.push(
111+
{
112+
text: _l('Create'),
113+
'class': 'ok',
114+
click: function() {
115+
$loadingOnDialog.appendTo($healthCheckDialog);
116+
var formData = cloudStack.serializeForm($healthCheckDialog.find('form'));
117+
var data = {
118+
lbruleid: args.context.multiRules[0].id,
119+
pingpath: formData.pingpath,
120+
responsetimeout: formData.responsetimeout,
121+
intervaltime: formData.healthinterval,
122+
healthythreshold: formData.healthythreshold,
123+
unhealthythreshold: formData.unhealthythreshold
124+
};
125+
126+
var lbRuleData = {
127+
128+
algorithm:args.context.multiRules[0].algorithm,
129+
name:args.context.multiRules[0].name,
130+
publicport:args.context.multiRules[0].publicport,
131+
privateport:args.context.multiRules[0].privateport
132+
133+
134+
}
135+
136+
if(args.context.multiRules[0] != null)
137+
$.extend(data , lbRuleData);
138+
139+
$.ajax({
140+
url: createURL('createLBHealthCheckPolicy'),
141+
data: data,
142+
success: function(json) {
143+
var jobId = json.createlbhealthcheckpolicyresponse.jobid;
144+
var createLBHealthCheckPolicyIntervalId = setInterval(function(){
145+
$.ajax({
146+
url: createURL('queryAsyncJobResult'),
147+
data: {
148+
jobid: jobId
149+
},
150+
success: function(json) {
151+
var result = json.queryasyncjobresultresponse;
152+
if (result.jobstatus == 0) {
153+
return; //Job has not completed
154+
}
155+
else {
156+
clearInterval(createLBHealthCheckPolicyIntervalId);
157+
158+
if (result.jobstatus == 1) {
159+
cloudStack.dialog.notice({ message: _l('Health Check Policy has been created') });
160+
$loadingOnDialog.remove();
161+
$healthCheckDialog.dialog('destroy');
162+
$('.overlay').remove();
163+
}
164+
else if (result.jobstatus == 2) {
165+
cloudStack.dialog.notice({ message: _s(result.jobresult.errortext) });
166+
$loadingOnDialog.remove();
167+
$healthCheckDialog.dialog('destroy');
168+
$('.overlay').remove();
169+
}
170+
}
171+
}
172+
});
173+
}, g_queryAsyncJobResultInterval);
174+
},
175+
error:function(XMLHttpResponse){
176+
args.response.error(parseXMLHttpResponse(XMLHttpResponse));
177+
178+
179+
}
180+
});
181+
}
182+
}
183+
);
184+
}
185+
else { //policy exists already
186+
buttons.push(
187+
//Update Button (begin) - call delete API first, then create API
188+
{
189+
text: _l('Update'),
190+
'class': 'ok',
191+
click: function() {
192+
$loadingOnDialog.appendTo($healthCheckDialog);
193+
194+
$.ajax({
195+
url: createURL('deleteLBHealthCheckPolicy'),
196+
data: {
197+
id : policyObj.id
198+
},
199+
success: function(json) {
200+
var jobId = json.deletelbhealthcheckpolicyresponse.jobid;
201+
var deleteLBHealthCheckPolicyIntervalId = setInterval(function(){
202+
$.ajax({
203+
url: createURL('queryAsyncJobResult'),
204+
data: {
205+
jobid: jobId
206+
},
207+
success: function(json) {
208+
var result = json.queryasyncjobresultresponse;
209+
if (result.jobstatus == 0) {
210+
return; //Job has not completed
211+
}
212+
else {
213+
clearInterval(deleteLBHealthCheckPolicyIntervalId);
214+
215+
if (result.jobstatus == 1) {
216+
var formData = cloudStack.serializeForm($healthCheckDialog.find('form'));
217+
var data = {
218+
lbruleid: args.context.multiRules[0].id,
219+
pingpath: formData.pingpath,
220+
responsetimeout: formData.responsetimeout,
221+
intervaltime: formData.healthinterval,
222+
healthythreshold: formData.healthythreshold,
223+
unhealthythreshold: formData.unhealthythreshold
224+
};
225+
226+
var lbRuleData = {
227+
228+
algorithm:args.context.multiRules[0].algorithm,
229+
name:args.context.multiRules[0].name,
230+
publicport:args.context.multiRules[0].publicport,
231+
privateport:args.context.multiRules[0].privateport
232+
233+
234+
}
235+
236+
if(args.context.multiRules[0] != null)
237+
$.extend(data , lbRuleData);
238+
239+
$.ajax({
240+
url: createURL('createLBHealthCheckPolicy'),
241+
data: data,
242+
success: function(json) {
243+
var jobId = json.createlbhealthcheckpolicyresponse.jobid;
244+
var createLBHealthCheckPolicyIntervalId = setInterval(function(){
245+
$.ajax({
246+
url: createURL('queryAsyncJobResult'),
247+
data: {
248+
jobid: jobId
249+
},
250+
success: function(json) {
251+
var result = json.queryasyncjobresultresponse;
252+
if (result.jobstatus == 0) {
253+
return; //Job has not completed
254+
}
255+
else {
256+
clearInterval(createLBHealthCheckPolicyIntervalId);
257+
258+
if (result.jobstatus == 1) {
259+
cloudStack.dialog.notice({ message: _l('Health Check Policy has been updated') });
260+
$loadingOnDialog.remove();
261+
$healthCheckDialog.dialog('destroy');
262+
$('.overlay').remove();
263+
}
264+
else if (result.jobstatus == 2) {
265+
cloudStack.dialog.notice({ message: _s(result.jobresult.errortext) });
266+
$loadingOnDialog.remove();
267+
$healthCheckDialog.dialog('destroy');
268+
$('.overlay').remove();
269+
}
270+
}
271+
}
272+
});
273+
}, g_queryAsyncJobResultInterval);
274+
},
275+
error:function(json){
276+
args.response.error(parseXMLHttpResponse(json));
277+
278+
}
279+
});
280+
}
281+
else if (result.jobstatus == 2) {
282+
cloudStack.dialog.notice({ message: _s(result.jobresult.errortext) });
283+
$loadingOnDialog.remove();
284+
$healthCheckDialog.dialog('destroy');
285+
$('.overlay').remove();
286+
}
287+
}
288+
}
289+
});
290+
}, g_queryAsyncJobResultInterval);
291+
}
292+
});
293+
}
294+
}
295+
//Update Button (end)
296+
);
297+
}
298+
299+
$healthCheckDialog.dialog({
300+
title: 'Health Check Wizard',
301+
width: 600,
302+
height: 600,
303+
draggable: true,
304+
closeonEscape: false,
305+
overflow:'auto',
306+
open:function() {
307+
$("button").each(function(){
308+
$(this).attr("style", "left: 400px; position: relative; margin-right: 5px; ");
309+
});
310+
},
311+
buttons: buttons
312+
}).closest('.ui-dialog').overlay();
313+
314+
}
315+
}
316+
}(jQuery, cloudStack));
317+
318+

0 commit comments

Comments
 (0)