| 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421 |
1
1
1
1
6
1
5
1
4
1
3
7
4
2
4
4
4
4
4
2
4
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
2
1
1
1
1
1
| 'use strict';
;require.register("views/main/host/details/host_component_view", 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');
App.HostComponentView = Em.View.extend({
templateName: require('templates/main/host/details/host_component'),
tagName: 'tr',
/**
* @type {App.HostComponent}
*/
content: null,
/**
* @type {Array}
* @const
*/
excludedMasterCommands: ['DECOMMISSION', 'RECOMMISSION'],
/**
* @type {string}
* @const
*/
upgradeFailedMessage: Em.I18n.t('hosts.host.details.upgradeFailed'),
/**
* @type {String}
*/
workStatus: Em.computed.alias('content.workStatus'),
/**
* Return host component text status
* @type {String}
*/
componentTextStatus: Em.computed.alias('content.componentTextStatus'),
/**
* @type {string}
*/
typeDisplay: function () {
if (this.get('content.isMaster')) {
return Em.I18n.t('common.master');
} else if (this.get('content.isSlave')) {
return Em.I18n.t('common.slave');
} else if (this.get('content.isClient')) {
return Em.I18n.t('common.client');
}
}.property('content'),
/**
* CSS-class for host component status
* @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';
}
// Client can't be started, it has only INSTALLED as a working state, so show working/green icon
if (this.get('workStatus') === App.HostComponentStatus.stopped && this.get('content.isClient')) {
return 'health-status-started';
}
//For all other cases
return 'health-status-' + App.HostComponentStatus.getKeyName(this.get('workStatus'));
}.property('workStatus'),
/**
* CSS-icon-class for host component status
* @type {String}
*/
statusIconClass: function () {
return Em.getWithDefault({
'health-status-started': App.healthIconClassGreen,
'health-status-starting': App.healthIconClassGreen,
'health-status-installed': App.healthIconClassRed,
'health-status-stopping': App.healthIconClassRed,
'health-status-unknown': App.healthIconClassYellow,
'health-status-DEAD-ORANGE': App.healthIconClassOrange
}, this.get('statusClass'), '');
}.property('statusClass'),
/**
* CSS-class for disabling drop-down menu with list of host component actions
* Disabled if host's <code>healthClass</code> is health-status-DEAD-YELLOW (lost heartbeat)
* Disabled if component's action list is empty
* @type {boolean}
*/
isDisabled: function () {
return this.get('parentView.content.healthClass') === "health-status-DEAD-YELLOW" || this.get('noActionAvailable') === 'hidden' && this.get('isRestartComponentDisabled') || App.router.get('wizardWatcherController.isNonWizardUser');
}.property('parentView.content.healthClass', 'noActionAvailable', 'isRestartComponentDisabled', 'App.router.wizardWatcherController.isNonWizardUser'),
/**
* For Upgrade failed state
* @type {bool}
*/
isUpgradeFailed: Em.computed.equal('workStatus', App.HostComponentStatus.upgrade_failed),
/**
* For Install failed state
* @type {bool}
*/
isInstallFailed: Em.computed.equal('workStatus', App.HostComponentStatus.install_failed),
/**
* For Started and Starting states
* @type {bool}
*/
isStart: Em.computed.existsIn('workStatus', [App.HostComponentStatus.started, App.HostComponentStatus.starting]),
/**
* For Installed state
* @type {bool}
*/
isStop: Em.computed.equal('workStatus', App.HostComponentStatus.stopped),
/**
* For Installing state
* @type {bool}
*/
isInstalling: Em.computed.equal('workStatus', App.HostComponentStatus.installing),
/**
* For Init state
* @type {bool}
*/
isInit: Em.computed.equal('workStatus', App.HostComponentStatus.init),
/**
* For Stopping or Starting states
* @type {bool}
*/
isInProgress: Em.computed.existsIn('workStatus', [App.HostComponentStatus.stopping, App.HostComponentStatus.starting]),
withoutActions: Em.computed.existsIn('workStatus', [App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.unknown, App.HostComponentStatus.disabled]),
/**
* No action available while component is starting/stopping/unknown
* @type {String}
*/
noActionAvailable: Em.computed.ifThenElse('withoutActions', 'hidden', ''),
/**
* For OFF <code>passiveState</code> of host component
* @type {bool}
*/
isActive: Em.computed.equal('content.passiveState', 'OFF'),
/**
* Tooltip message for switch maintenance mode option
* @type {String}
*/
maintenanceTooltip: function () {
switch (this.get('content.passiveState')) {
case 'IMPLIED_FROM_SERVICE':
return Em.I18n.t('passiveState.disabled.impliedFromHighLevel').format(this.get('content.displayName'), this.get('content.service.serviceName'));
case 'IMPLIED_FROM_HOST':
return Em.I18n.t('passiveState.disabled.impliedFromHighLevel').format(this.get('content.displayName'), this.get('content.host.hostName'));
case 'IMPLIED_FROM_SERVICE_AND_HOST':
return Em.I18n.t('passiveState.disabled.impliedFromServiceAndHost').format(this.get('content.displayName'), this.get('content.service.serviceName'), this.get('content.host.hostName'));
default:
return '';
}
}.property('content.passiveState'),
/**
* Shows whether we need to show Delete button
* @type {bool}
*/
isDeletableComponent: Em.computed.existsInByKey('content.componentName', 'App.components.deletable'),
/**
* Host component with some <code>workStatus</code> can't be moved (so, disable such action in the dropdown list)
* @type {boolean}
*/
isMoveComponentDisabled: function () {
return App.get('allHostNames').length === App.HostComponent.find().filterProperty('componentName', this.get('content.componentName')).mapProperty('hostName').length;
}.property('content.componentName', 'App.allHostNames'),
/**
* Host component with some <code>workStatus</code> can't be deleted (so, disable such action in the dropdown list)
* @type {bool}
*/
isDeleteComponentDisabled: function () {
var stackComponentCount = App.StackServiceComponent.find(this.get('content.componentName')).get('minToInstall');
var installedCount = App.HostComponent.getCount(this.get('content.componentName'), 'totalCount');
Iif (this.get('content.componentName') === 'MYSQL_SERVER' && this.get('content.serviceDisplayName') === 'Hive') {
var db_type = App.db.getConfigs().findProperty('type', 'hive-env').properties['hive_database'];
var status = [App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
if (db_type.indexOf('Existing') > -1 && status) return false;else return true;
}
Iif (this.get('content.componentName') === 'JOURNALNODE') {
var count_JN = App.HostComponent.find().filterProperty('componentName', 'JOURNALNODE').get('length');
return count_JN <= 3; // TODO get 3 from stack
}
return installedCount <= stackComponentCount || ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
}.property('workStatus'),
/**
* Gets number of current running components that are applied to the cluster
* @returns {Number}
*/
runningComponentCounter: function runningComponentCounter() {
return App.HostComponent.find().filter(function (component) {
return component.get('componentName') === this.get('content.componentName') && [App.HostComponentStatus.started, App.HostComponentStatus.starting].contains(component.get('workStatus'));
}, this).length;
},
/**
* Check if component may be reassinged to another host
* @type {bool}
*/
isReassignable: function () {
return App.get('components.reassignable').contains(this.get('content.componentName')) && App.get('allHostNames.length') > 1;
}.property('content.componentName'),
/**
* Check if component is restartable
* @type {bool}
*/
isRestartableComponent: Em.computed.existsInByKey('content.componentName', 'App.components.restartable'),
/**
* Host component with some <code>workStatus</code> can't be restarted (so, disable such action in the dropdown list)
* @type {bool}
*/
isRestartComponentDisabled: Em.computed.notEqual('workStatus', App.HostComponentStatus.started),
/**
* Check if component configs can be refreshed
* @type {bool}
*/
isRefreshConfigsAllowed: Em.computed.existsInByKey('content.componentName', 'App.components.refreshConfigsAllowed'),
willInsertElement: function willInsertElement() {
//make link to view instance to get decommission state
this.set('content.view', this);
},
didInsertElement: function didInsertElement() {
App.tooltip($('[rel=componentHealthTooltip]'));
App.tooltip($('[rel=passiveTooltip]'));
App.tooltip($('[rel=componentNameTooltip]'));
if (this.get('isInProgress')) {
this.doBlinking();
}
},
/**
* Do blinking for 1 minute
*/
doBlinking: function doBlinking() {
var workStatus = this.get('workStatus');
var self = this;
var pulsate = [App.HostComponentStatus.starting, App.HostComponentStatus.stopping, App.HostComponentStatus.installing].contains(workStatus);
if (pulsate && !self.get('isBlinking')) {
self.set('isBlinking', true);
uiEffects.pulsate(self.$('.components-health'), 1000, function () {
self.set('isBlinking', false);
self.doBlinking();
});
}
},
/**
* Start blinking when host component is starting/stopping
*/
startBlinking: function () {
this.$('.components-health').stop(true, true);
this.$('.components-health').css({ opacity: 1.0 });
this.doBlinking();
}.observes('workStatus'),
/**
* Get custom commands for slave components
*/
customCommands: function () {
var customCommands;
var hostComponent = this.get('content');
var component = App.StackServiceComponent.find(hostComponent.get('componentName'));
customCommands = this.getCustomCommands(component, hostComponent, component.get('isSlave'));
return customCommands;
}.property('content', 'workStatus'),
/**
* Get a list of custom commands
*
* @param component
* @param hostComponent
* @param isSlave
* @returns {Array}
*/
getCustomCommands: function getCustomCommands(component, hostComponent, isSlave) {
isSlave = isSlave || false;
Iif (!component || !hostComponent) {
return [];
}
var self = this;
var commands = component.get('customCommands');
var customCommands = [];
commands.forEach(function (command) {
Iif (!isSlave && !self.meetsCustomCommandReq(component, command)) {
return;
}
var commandMap = App.HostComponentActionMap.getMap(self)[command];
// push command if either there is no map or map is not instructing to hide command from this view
Eif (!commandMap || !commandMap.hideFromComponentView) {
customCommands.push({
label: self.getCustomCommandLabel(command),
service: component.get('serviceName'),
hosts: hostComponent.get('hostName'),
context: !!commandMap && !!commandMap.context ? commandMap.context : null,
component: component.get('componentName'),
command: command,
disabled: !!commandMap ? !!commandMap.disabled : false
});
}
});
return customCommands;
},
/**
* Get the Label of the custom command
*
* @param command
* @returns {String}
*/
getCustomCommandLabel: function getCustomCommandLabel(command) {
if (command in App.HostComponentActionMap.getMap(this) && App.HostComponentActionMap.getMap(this)[command].label) return App.HostComponentActionMap.getMap(this)[command].label;
return Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command, ["_", "-", " "]));
},
/**
* The custom command meets the requirements to be active on master
*
* @param component
* @param command
*
* @return {Boolean}
*/
meetsCustomCommandReq: function meetsCustomCommandReq(component, command) {
var excludedMasterCommands = this.get('excludedMasterCommands');
if (excludedMasterCommands.indexOf(command) >= 0) {
return false;
}
if (component.get('cardinality') !== '1') {
if (!this.get('isStart')) {
if (App.HostComponent.getCount(this.get('content.componentName'), 'totalCount') > 1) {
if (this.runningComponentCounter()) {
return false;
}
} else {
return false;
}
}
}
return true;
},
/**
* @type {Array}
*/
clientCustomCommands: function () {
var componentName = this.get('content.componentName');
Iif (componentName === 'KERBEROS_CLIENT') {
return [];
}
return App.StackServiceComponent.find(componentName).get('customCommands').map(function (command) {
return {
label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command),
command: command
};
});
}.property('controller'),
installClient: function installClient() {
this.get('controller').installClients([this.get('content')]);
}
});
}); |