| 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 |
1
1
1
1
1
1
1
2
1
1
2
1
1
1
1
1
2
2
2
2
1
1
1
1
| 'use strict';
;require.register("views/main/host/hosts_table_menu_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 O = Em.Object;
/**
* @class HostTableMenuView
*/
App.HostTableMenuView = Em.View.extend({
classNames: ['btn-group', 'pull-right', 'bulk-menu'],
templateName: require('templates/main/host/bulk_operation_menu'),
controllerBinding: 'App.router.bulkOperationsController',
menuItems: function () {
return {
s: { label: Em.I18n.t('hosts.table.menu.l1.selectedHosts') },
f: { label: Em.I18n.t('hosts.table.menu.l1.filteredHosts') },
a: { label: Em.I18n.t('hosts.table.menu.l1.allHosts') }
};
}.property('App.router.clusterController.isLoaded'),
components: function () {
var serviceNames = App.Service.find().mapProperty('serviceName');
var menuItems = this.getBulkMenuItemsPerServiceComponent();
return menuItems.filter(function (item) {
return serviceNames.contains(item.serviceName);
});
}.property(),
getBulkMenuItemsPerServiceComponent: function getBulkMenuItemsPerServiceComponent() {
var menuItems = [];
App.StackServiceComponent.find().forEach(function (stackComponent) {
if (stackComponent.get('hasBulkCommandsDefinition')) {
var menuItem = O.create({
serviceName: stackComponent.get('serviceName'),
componentName: stackComponent.get('componentName'),
masterComponentName: stackComponent.get('bulkCommandsMasterComponentName'),
componentNameFormatted: stackComponent.get('bulkCommandsDisplayName')
});
menuItems.push(menuItem);
}
}, this);
return menuItems;
},
/**
* slaveItemView build second-level menu
* for slave component
*/
slaveItemView: Em.View.extend({
tagName: 'li',
classNames: ['dropdown-submenu', 'submenu-left'],
/**
* Get third-level menu items ingo for slave components
* operationData format:
* <code>
* {
* action: 'STARTED|INSTALLED|RESTART|DECOMMISSION|DECOMMISSION_OFF', // action for selected host components
* message: 'some text', // just text to BG popup
* componentName: 'DATANODE|NODEMANAGER...', //component name that should be processed
* realComponentName: 'DATANODE|NODEMANAGER...', // used only for decommission(_off) actions
* serviceName: 'HDFS|YARN|HBASE...', // service name of the processed component
* componentNameFormatted: 'DataNodes|NodeManagers...' // "user-friendly" string with component name (used in BG popup)
* }
* </code>
*
* @returns {Array}
*/
operationsInfo: function () {
var content = this.get('content');
var menuItems = Em.A();
if (App.isAuthorized("SERVICE.START_STOP")) {
menuItems.pushObjects([O.create({
label: Em.I18n.t('common.start'),
operationData: O.create({
action: App.HostComponentStatus.started,
message: Em.I18n.t('common.start'),
componentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
}), O.create({
label: Em.I18n.t('common.stop'),
operationData: O.create({
action: App.HostComponentStatus.stopped,
message: Em.I18n.t('common.stop'),
componentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
}), O.create({
label: Em.I18n.t('common.restart'),
operationData: O.create({
action: 'RESTART',
message: Em.I18n.t('common.restart'),
componentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
})]);
}
if (App.isAuthorized("HOST.ADD_DELETE_COMPONENTS")) {
menuItems.pushObjects([O.create({
label: Em.I18n.t('common.add'),
operationData: O.create({
action: 'ADD',
message: Em.I18n.t('common.add'),
componentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
}), O.create({
label: Em.I18n.t('common.delete'),
delete: true,
operationData: O.create({
action: 'DELETE',
message: Em.I18n.t('common.delete'),
componentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
})]);
}
if (App.isAuthorized("SERVICE.DECOMMISSION_RECOMMISSION") && App.get('components.decommissionAllowed').contains(content.componentName)) {
menuItems.pushObjects([O.create({
label: Em.I18n.t('common.decommission'),
decommission: true,
operationData: O.create({
action: 'DECOMMISSION',
message: Em.I18n.t('common.decommission'),
componentName: content.masterComponentName,
realComponentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
}), O.create({
label: Em.I18n.t('common.recommission'),
decommission: true,
operationData: O.create({
action: 'DECOMMISSION_OFF',
message: Em.I18n.t('common.recommission'),
componentName: content.masterComponentName,
realComponentName: content.componentName,
serviceName: content.serviceName,
componentNameFormatted: content.componentNameFormatted
})
})]);
}
return menuItems;
}.property("content"),
/**
* commonOperationView is used for third-level menu items
* for simple operations ('START','STOP','RESTART')
*/
commonOperationView: Em.View.extend({
tagName: 'li',
click: function click() {
this.get('controller').bulkOperationConfirm(this.get('content'), this.get('selection'));
}
}),
/**
* advancedOperationView is used for third level menu item
* for advanced operations ('RECOMMISSION','DECOMMISSION')
*/
advancedOperationView: Em.View.extend({
tagName: 'li',
rel: 'menuTooltip',
classNameBindings: ['disabledElement'],
attributeBindings: ['tooltipMsg:data-original-title'],
service: function () {
return App.router.get('mainServiceController.content').findProperty('serviceName', this.get('content.serviceName'));
}.property('App.router.mainServiceController.content.@each', 'content'),
tooltipMsg: function () {
var displayName = App.format.role(this.get('content.componentName'), false);
return this.get('disabledElement') === 'disabled' ? Em.I18n.t('hosts.decommission.tooltip.warning').format(this.get('content.message'), displayName) : '';
}.property('disabledElement', 'content.componentName'),
disabledElement: function () {
return this.get('service.workStatus') === 'STARTED' ? '' : 'disabled';
}.property('service.workStatus'),
click: function click() {
if (this.get('disabledElement') === 'disabled') {
return;
}
this.get('controller').bulkOperationConfirm(this.get('content'), this.get('selection'));
},
didInsertElement: function didInsertElement() {
App.tooltip($(this.get('element')));
}
})
}),
/**
* hostItemView build second-level menu
* for host
*/
hostItemView: Em.View.extend({
tagName: 'li',
classNames: ['dropdown-submenu', 'submenu-left'],
label: Em.I18n.t('common.hosts'),
/** Get third-level menu items for Hosts
* operationData format:
* <code>
* {
* action: 'STARTED|INSTALLED|RESTART..', // action for selected hosts (will be applied for each host component in selected hosts)
* actionToCheck: 'INSTALLED|STARTED..' // state to filter host components should be processed
* message: 'some text', // just text to BG popup
* }
* </code>
* @returns {Array}
*/
operationsInfo: function () {
var result = [];
if (App.isAuthorized("SERVICE.START_STOP")) {
result = result.concat([O.create({
label: Em.I18n.t('hosts.host.details.startAllComponents'),
operationData: O.create({
action: 'STARTED',
actionToCheck: 'INSTALLED',
message: Em.I18n.t('hosts.host.details.startAllComponents')
})
}), O.create({
label: Em.I18n.t('hosts.host.details.stopAllComponents'),
operationData: O.create({
action: 'INSTALLED',
actionToCheck: 'STARTED',
message: Em.I18n.t('hosts.host.details.stopAllComponents')
})
}), O.create({
label: Em.I18n.t('hosts.table.menu.l2.restartAllComponents'),
operationData: O.create({
action: 'RESTART',
message: Em.I18n.t('hosts.table.menu.l2.restartAllComponents')
})
}), O.create({
label: Em.I18n.t('hosts.table.menu.l2.reinstallFailedComponents'),
operationData: O.create({
action: 'REINSTALL',
message: Em.I18n.t('hosts.table.menu.l2.reinstallFailedComponents')
})
}), O.create({
label: Em.I18n.t('hosts.table.menu.l2.refreshConfigsClientComponents'),
operationData: O.create({
action: 'CONFIGURE',
message: Em.I18n.t('hosts.table.menu.l2.refreshConfigsClientComponents')
})
})]);
}
if (App.isAuthorized("HOST.TOGGLE_MAINTENANCE")) {
result = result.concat([O.create({
label: Em.I18n.t('passiveState.turnOn'),
operationData: O.create({
state: 'ON',
action: 'PASSIVE_STATE',
message: Em.I18n.t('passiveState.turnOnFor').format('hosts')
})
}), O.create({
label: Em.I18n.t('passiveState.turnOff'),
operationData: O.create({
state: 'OFF',
action: 'PASSIVE_STATE',
message: Em.I18n.t('passiveState.turnOffFor').format('hosts')
})
})]);
}
result = result.concat(O.create({
label: Em.I18n.t('hosts.host.details.setRackId'),
operationData: O.create({
action: 'SET_RACK_INFO',
message: Em.I18n.t('hosts.host.details.setRackId').format('hosts')
})
}));
if (App.isAuthorized("HOST.ADD_DELETE_HOSTS")) {
result = result.concat(O.create({
label: Em.I18n.t('hosts.host.details.deleteHosts'),
operationData: O.create({
action: 'DELETE',
message: Em.I18n.t('hosts.host.details.deleteHosts')
})
}));
}
return result;
}.property(),
/**
* commonOperationView is used for third-level menu items
* for all operations for host
*/
operationView: Em.View.extend({
tagName: 'li',
click: function click() {
this.get('controller').bulkOperationConfirm(this.get('content'), this.get('selection'));
}
})
})
});
}); |