| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379 |
1
1
1
1
4
4
3
4
4
2
2
2
8
1
7
1
6
3
3
3
3
2
1
1
3
4
1
2
1
2
2
1
1
1
1
2
2
1
1
1
1
12
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
5
5
5
5
5
3
5
1
1
3
3
3
3
1
1
1
68
68
| 'use strict';
;require.register("mixins/main/host/details/host_components/decommissionable", function (exports, require, module) {
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var App = require('app');
var uiEffects = require('utils/ui_effects');
/**
* Mixin for <code>App.HostComponentView</code>
* Contains code for processing components with allowed decommission
* @type {Em.Mixin}
*/
App.Decommissionable = Em.Mixin.create({
/**
* Should be redeclared in views that use this mixin
* @type {String}
*/
componentForCheckDecommission: '',
/**
* Is component in decommission process right know
* @type {boolean}
*/
isComponentDecommissioning: false,
/**
* May component be decommissioned
* @type {boolean}
*/
isComponentDecommissionAvailable: false,
/**
* May component be recommissioned
* @type {boolean}
*/
isComponentRecommissionAvailable: false,
/**
* Timer id for decommission status polling
* @type {number}
*/
decommissionStatusPollingTimer: null,
/**
* Interval for decommission status polling
* @type {number}
*/
POLLING_INTERVAL: 6000,
/**
* Component with stopped masters can't be docommissioned
* @type {bool}
*/
isComponentDecommissionDisable: function () {
var masterComponent = this.get('content.service.hostComponents').findProperty('componentName', this.get('componentForCheckDecommission'));
if (masterComponent && masterComponent.get('workStatus') != App.HostComponentStatus.started) return true;
return this.get('content.service.workStatus') != App.HostComponentStatus.started;
}.property('content.service.workStatus', 'content.service.hostComponents.@each.workStatus'),
/**
* @override App.HostComponentView.isRestartableComponent
*/
isRestartableComponent: function () {
return this.get('isComponentDecommissionAvailable') && App.get('components.restartable').contains(this.get('content.componentName'));
}.property('isComponentDecommissionAvailable'),
/**
* Tooltip message shows if decommission/recommission is disabled
* when masters for current component is down
* @type {string}
*/
decommissionTooltipMessage: function () {
if (this.get('isComponentDecommissionDisable') && (this.get('isComponentRecommissionAvailable') || this.get('isComponentDecommissionAvailable'))) {
var decom = this.get('isComponentRecommissionAvailable') ? Em.I18n.t('common.recommission') : Em.I18n.t('common.decommission');
return Em.I18n.t('hosts.decommission.tooltip.warning').format(decom, App.format.role(this.get('componentForCheckDecommission'), false));
}
return '';
}.property('isComponentDecommissionDisable', 'isComponentRecommissionAvailable', 'isComponentDecommissionAvailable', 'componentForCheckDecommission'),
/**
* Recalculated component status based on decommission
* @type {string}
*/
statusClass: function () {
//Class when install failed
if (this.get('workStatus') === App.HostComponentStatus.install_failed) {
return 'health-status-color-red glyphicon glyphicon-cog';
}
//Class when installing
if (this.get('workStatus') === App.HostComponentStatus.installing) {
return 'health-status-color-blue glyphicon glyphicon-cog';
}
if (this.get('isComponentRecommissionAvailable') && (this.get('isStart') || this.get('workStatus') == 'INSTALLED')) {
return 'health-status-DEAD-ORANGE';
}
//For all other cases
return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
}.property('workStatus', 'isComponentRecommissionAvailable', 'isComponentDecommissioning'),
/**
* Return host component text status
* @type {String}
*/
componentTextStatus: function () {
var componentTextStatus = this.get('content.componentTextStatus');
if (this.get('isComponentRecommissionAvailable')) {
if (this.get('isComponentDecommissioning')) {
componentTextStatus = Em.I18n.t('hosts.host.decommissioning');
} else {
componentTextStatus = Em.I18n.t('hosts.host.decommissioned');
}
}
return componentTextStatus;
}.property('workStatus', 'isComponentRecommissionAvailable', 'isComponentDecommissioning'),
/**
* For Stopping or Starting states, also for decommissioning
* @type {bool}
*/
isInProgress: function () {
return this.get('workStatus') === App.HostComponentStatus.stopping || this.get('workStatus') === App.HostComponentStatus.starting || this.get('isDecommissioning');
}.property('workStatus', 'isDecommissioning'),
/**
* load Recommission/Decommission status of component
*/
loadComponentDecommissionStatus: function loadComponentDecommissionStatus() {
return this.getDesiredAdminState();
},
/**
* Get desired_admin_state status from server
*/
getDesiredAdminState: function getDesiredAdminState() {
if (Em.isNone(this.get('content'))) return null;
return App.ajax.send({
name: 'host.host_component.slave_desired_admin_state',
sender: this,
data: {
hostName: this.get('content.hostName'),
componentName: this.get('content.componentName')
},
success: 'getDesiredAdminStateSuccessCallback',
error: 'getDesiredAdminStateErrorCallback'
});
},
/**
* pass received value or null to <code>setDesiredAdminState</code>
* @param {Object} response
* @returns {String|null}
*/
getDesiredAdminStateSuccessCallback: function getDesiredAdminStateSuccessCallback(response) {
var status = response.HostRoles.desired_admin_state;
if (!Em.isNone(status)) {
this.setDesiredAdminState(status);
return status;
}
return null;
},
/**
* error callback of <code>getDesiredAdminState</code>
*/
getDesiredAdminStateErrorCallback: Em.K,
/**
* compute decommission state by desiredAdminState
* @param {Object} status
*/
setDesiredAdminState: Em.K,
/**
* Get component decommission status from server
* @returns {$.ajax}
*/
getDecommissionStatus: function getDecommissionStatus() {
return App.ajax.send({
name: 'host.host_component.decommission_status',
sender: this,
data: {
hostName: this.get('content.hostName'),
componentName: this.get('componentForCheckDecommission'),
serviceName: this.get('content.service.serviceName')
},
success: 'getDecommissionStatusSuccessCallback',
error: 'getDecommissionStatusErrorCallback'
});
},
/**
* pass received value or null to <code>setDecommissionStatus</code>
* @param {Object} response
* @returns {Object|null}
*/
getDecommissionStatusSuccessCallback: function getDecommissionStatusSuccessCallback(response) {
var statusObject = response.ServiceComponentInfo;
if (!Em.isNone(statusObject)) {
statusObject.component_state = response.host_components[0].HostRoles.state;
this.setDecommissionStatus(statusObject);
return statusObject;
}
return null;
},
/**
* Set null to <code>decommissionedStatusObject</code> if server returns error
* @returns {null}
*/
getDecommissionStatusErrorCallback: Em.K,
/**
* compute decommission state by component info
* @param {Object} status
*/
setDecommissionStatus: Em.K,
/**
* set decommission and recommission flags according to status
* @param status
*/
setStatusAs: function setStatusAs(status) {
switch (status) {
case "INSERVICE":
this.set('isComponentRecommissionAvailable', false);
this.set('isComponentDecommissioning', false);
this.set('isComponentDecommissionAvailable', this.get('isStart'));
break;
case "DECOMMISSIONING":
this.set('isComponentRecommissionAvailable', true);
this.set('isComponentDecommissioning', true);
this.set('isComponentDecommissionAvailable', false);
break;
case "DECOMMISSIONED":
this.set('isComponentRecommissionAvailable', true);
this.set('isComponentDecommissioning', false);
this.set('isComponentDecommissionAvailable', false);
break;
case "RS_DECOMMISSIONED":
this.set('isComponentRecommissionAvailable', true);
this.set('isComponentDecommissioning', this.get('isStart'));
this.set('isComponentDecommissionAvailable', false);
break;
}
},
/**
* Do blinking for 1 minute
*/
doBlinking: function doBlinking() {
var workStatus = this.get('workStatus');
var pulsate = [App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
Eif (!pulsate) {
var component = this.get('content');
if (component && workStatus !== "INSTALLED") {
pulsate = this.get('isDecommissioning');
}
}
if (pulsate && !this.get('isBlinking')) {
this.set('isBlinking', true);
this.pulsate();
}
},
/**
* perform the pulsation
*/
pulsate: function pulsate() {
var self = this;
uiEffects.pulsate(self.$('.components-health'), 1000, function () {
self.set('isBlinking', false);
self.doBlinking();
});
},
/**
* Start blinking when host component is starting/stopping/decommissioning
*/
startBlinking: function () {
this.$('.components-health').stop(true, true);
this.$('.components-health').css({ opacity: 1.0 });
this.doBlinking();
}.observes('workStatus', 'isComponentRecommissionAvailable', 'isDecommissioning'),
didInsertElement: function didInsertElement() {
var self = this;
this._super();
App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(function () {
self.loadComponentDecommissionStatus();
});
},
willDestroyElement: function willDestroyElement() {
this._super();
var timer = this.get('decommissionStatusPollingTimer');
if (timer) {
clearInterval(timer);
this.set('decommissionStatusPollingTimer', null);
}
},
/**
* Update Decommission status only one time when component was changed
*/
updateDecommissionStatus: function () {
var self = this;
App.router.get('mainController').isLoading.call(App.router.get('clusterController'), 'isServiceContentFullyLoaded').done(function () {
Em.run.once(self, 'loadComponentDecommissionStatus');
});
}.observes('content.workStatus', 'content.passiveState'),
/**
* Update Decommission status periodically
*/
decommissionStatusPolling: function decommissionStatusPolling() {
var self = this;
this.set('decommissionStatusPollingTimer', setTimeout(function () {
self.loadComponentDecommissionStatus().done(function () {
self.decommissionStatusPolling();
});
}, this.POLLING_INTERVAL));
},
/**
* Start Decommission status polling if it is not started yet
*/
startDecommissionStatusPolling: function startDecommissionStatusPolling() {
if (!this.get('decommissionStatusPollingTimer')) {
this.decommissionStatusPolling();
}
},
decommissionView: Em.View.extend({
classNameBindings: ['parentView.noActionAvailable'],
tagName: 'li',
templateName: require('templates/main/host/decommission'),
text: Em.computed.ifThenElse('parentView.isComponentDecommissionAvailable', Em.I18n.t('common.decommission'), Em.I18n.t('common.recommission')),
didInsertElement: function didInsertElement() {
this._super();
App.tooltip($("[rel='decommissionTooltip']"));
},
click: function click() {
if (!this.get('parentView.isComponentDecommissionDisable')) {
if (this.get('parentView.isComponentDecommissionAvailable')) {
this.get('controller').decommission(this.get('parentView.content'), this.get('parentView.startDecommissionStatusPolling').bind(this.get('parentView')));
} else {
this.get('controller').recommission(this.get('parentView.content'), this.get('parentView.startDecommissionStatusPolling').bind(this.get('parentView')));
}
}
}
})
});
}); |