| 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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528 |
1
1
1
2
2
2
2
| 'use strict';
;require.register("controllers/main/service/info/metric", 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');
App.MainServiceInfoMetricsController = Em.Controller.extend(App.WidgetSectionMixin, {
name: 'mainServiceInfoMetricsController',
layoutNameSuffix: "_dashboard",
sectionNameSuffix: "_SUMMARY",
/**
* Some widget has type `GRAPH`
*
* @type {boolean}
*/
someWidgetGraphExists: Em.computed.someBy('widgets', 'widgetType', 'GRAPH'),
/**
* @type {boolean}
*/
showTimeRangeControl: Em.computed.or('!isServiceWithEnhancedWidgets', 'someWidgetGraphExists'),
/**
* @type {boolean}
*/
isWidgetLayoutsLoaded: false,
/**
* @type {boolean}
*/
isAllSharedWidgetsLoaded: false,
/**
* @type {boolean}
*/
isMineWidgetsLoaded: false,
/**
* load widget layouts across all users in CLUSTER scope
* @returns {$.ajax}
*/
loadWidgetLayouts: function loadWidgetLayouts() {
this.set('isWidgetLayoutsLoaded', false);
return App.ajax.send({
name: 'widgets.layouts.get',
sender: this,
data: {
sectionName: this.get('sectionName')
},
success: 'loadWidgetLayoutsSuccessCallback'
});
},
loadWidgetLayoutsSuccessCallback: function loadWidgetLayoutsSuccessCallback(data) {
App.widgetLayoutMapper.map(data);
this.set('isWidgetLayoutsLoaded', true);
},
/**
* load all shared widgets to show on widget browser
* @returns {$.ajax}
*/
loadAllSharedWidgets: function loadAllSharedWidgets() {
this.set('isAllSharedWidgetsLoaded', false);
return App.ajax.send({
name: 'widgets.all.shared.get',
sender: this,
success: 'loadAllSharedWidgetsSuccessCallback'
});
},
/**
* success callback of <code>loadAllSharedWidgets</code>
* @param {object|null} data
*/
loadAllSharedWidgetsSuccessCallback: function loadAllSharedWidgetsSuccessCallback(data) {
var widgetIds = this.get('widgets').mapProperty('id');
var activeNSWidgetLayouts = this.get('activeNSWidgetLayouts');
if (data.items[0] && data.items.length) {
this.set("allSharedWidgets", data.items.filter(function (widget) {
return widget.WidgetInfo.widget_type != "HEATMAP";
}).map(function (widget) {
var widgetType = widget.WidgetInfo.widget_type;
var widgetName = widget.WidgetInfo.widget_name;
var widgetId = widget.WidgetInfo.id;
var widgetTag = widget.WidgetInfo.tag;
var inNSLayouts = false;
if (widgetTag) {
inNSLayouts = activeNSWidgetLayouts.findProperty('nameServiceId', widgetTag).get('widgets').someProperty('id', widgetId) && activeNSWidgetLayouts.findProperty('nameServiceId', 'all').get('widgets').someProperty('id', widgetId);
}
return Em.Object.create({
id: widgetId,
widgetName: widgetName,
tag: widgetTag,
metrics: widget.WidgetInfo.metrics,
description: widget.WidgetInfo.description,
widgetType: widgetType,
iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
added: widgetTag ? inNSLayouts : widgetIds.contains(widgetId),
isShared: widget.WidgetInfo.scope == "CLUSTER"
});
}));
}
this.set('isAllSharedWidgetsLoaded', true);
},
allSharedWidgets: [],
mineWidgets: [],
/**
* load all mine widgets of current user to show on widget browser
* @returns {$.ajax}
*/
loadMineWidgets: function loadMineWidgets() {
this.set('isMineWidgetsLoaded', false);
return App.ajax.send({
name: 'widgets.all.mine.get',
sender: this,
data: {
loginName: App.router.get('loginName')
},
success: 'loadMineWidgetsSuccessCallback'
});
},
/**
* success callback of <code>loadMineWidgets</code>
* @param {object|null} data
*/
loadMineWidgetsSuccessCallback: function loadMineWidgetsSuccessCallback(data) {
var widgetIds = this.get('widgets').mapProperty('id');
var activeNSWidgetLayouts = this.get('activeNSWidgetLayouts');
if (data.items[0] && data.items.length) {
this.set("mineWidgets", data.items.filter(function (widget) {
return widget.WidgetInfo.widget_type != "HEATMAP";
}).map(function (widget) {
var widgetType = widget.WidgetInfo.widget_type;
var widgetName = widget.WidgetInfo.widget_name;
var widgetId = widget.WidgetInfo.id;
var widgetTag = widget.WidgetInfo.tag;
var inNSLayouts = false;
if (widgetTag) {
inNSLayouts = activeNSWidgetLayouts.findProperty('nameServiceId', widgetTag).get('widgets').someProperty('id', widgetId) && activeNSWidgetLayouts.findProperty('nameServiceId', 'all').get('widgets').someProperty('id', widgetId);
}
return Em.Object.create({
id: widget.WidgetInfo.id,
widgetName: widgetName,
tag: widgetTag,
metrics: widget.WidgetInfo.metrics,
description: widget.WidgetInfo.description,
widgetType: widgetType,
iconPath: "/img/widget-" + widgetType.toLowerCase() + ".png",
serviceName: JSON.parse(widget.WidgetInfo.metrics).mapProperty('service_name').uniq().join('-'),
added: widgetTag ? inNSLayouts : widgetIds.contains(widgetId),
isShared: widget.WidgetInfo.scope == "CLUSTER"
});
}));
} else {
this.set("mineWidgets", []);
}
this.set('isMineWidgetsLoaded', true);
},
/**
* add widgets, on click handler for "Add"
*/
addWidget: function addWidget(event) {
var self = this;
var widgetToAdd = event.context;
var activeLayouts = widgetToAdd.tag ? this.get('activeNSWidgetLayouts').filter(function (l) {
return ['all', widgetToAdd.tag].contains(l.get('nameServiceId'));
}) : [this.get('activeWidgetLayout')];
activeLayouts.forEach(function (activeLayout) {
var widgetIds = activeLayout.get('widgets').map(function (widget) {
return {
"id": widget.get("id")
};
});
if (!widgetIds.mapProperty('id').contains(widgetToAdd.id)) {
widgetIds.pushObject({
"id": widgetToAdd.id
});
var data = {
"WidgetLayoutInfo": {
"display_name": activeLayout.get("displayName"),
"id": activeLayout.get("id"),
"layout_name": activeLayout.get("layoutName"),
"scope": activeLayout.get("scope"),
"section_name": activeLayout.get("sectionName"),
"widgets": widgetIds
}
};
return App.ajax.send({
name: 'widget.layout.edit',
sender: self,
data: {
layoutId: activeLayout.get("id"),
data: data
},
success: 'updateActiveLayout'
});
}
});
widgetToAdd.set('added', true);
},
/**
* find and hide widgets from all layouts
* @param event
*/
hideWidgetBrowser: function hideWidgetBrowser(event) {
var activeLayouts = event.context.tag ? this.get('activeNSWidgetLayouts').filter(function (l) {
return l.get('widgets').mapProperty('id').contains(event.context.id);
}) : [this.get('activeWidgetLayout')];
activeLayouts.forEach(function (layout) {
event.context.nsLayout = layout;
this.hideWidget(event);
}, this);
},
/**
* hide widgets, on click handler for "Added"
*/
hideWidget: function hideWidget(event) {
var widgetToHide = event.context;
var widgetLayout = event.context.nsLayout;
var activeLayout = widgetLayout || this.get('activeWidgetLayout');
var widgetIds = activeLayout.get('widgets').map(function (widget) {
return {
"id": widget.get("id")
};
});
var data = {
"WidgetLayoutInfo": {
"display_name": activeLayout.get("displayName"),
"id": activeLayout.get("id"),
"layout_name": activeLayout.get("layoutName"),
"scope": activeLayout.get("scope"),
"section_name": activeLayout.get("sectionName"),
"widgets": widgetIds.filter(function (widget) {
return widget.id !== widgetToHide.id;
})
}
};
widgetToHide.set('added', false);
return App.ajax.send({
name: 'widget.layout.edit',
sender: this,
data: {
layoutId: activeLayout.get("id"),
data: data
},
success: 'hideWidgetSuccessCallback'
});
},
/**
* @param {object|null} data
* @param {object} opt
* @param {object} params
*/
hideWidgetSuccessCallback: function hideWidgetSuccessCallback(data, opt, params) {
params.data.WidgetLayoutInfo.widgets = params.data.WidgetLayoutInfo.widgets.map(function (widget) {
return {
WidgetInfo: {
id: widget.id
}
};
});
App.widgetLayoutMapper.map({ items: [params.data] });
this.propertyDidChange('widgets');
},
/**
* update current active widget layout
*/
updateActiveLayout: function updateActiveLayout() {
this.getActiveWidgetLayout();
},
/**
* delete widgets, on click handler for "Delete"
*/
deleteWidget: function deleteWidget(event) {
var widget = event.context;
var self = this;
var confirmMsg = widget.get('isShared') ? Em.I18n.t('dashboard.widgets.browser.action.delete.shared.bodyMsg').format(widget.widgetName) : Em.I18n.t('dashboard.widgets.browser.action.delete.mine.bodyMsg').format(widget.widgetName);
var bodyMessage = Em.Object.create({
confirmMsg: confirmMsg,
confirmButton: Em.I18n.t('dashboard.widgets.browser.action.delete.btnMsg')
});
return App.showConfirmationFeedBackPopup(function (query) {
return App.ajax.send({
name: 'widget.action.delete',
sender: self,
data: {
id: widget.id
},
success: 'updateWidgetBrowser'
});
}, bodyMessage);
},
/**
* update widget browser content after deleted some widget
*/
updateWidgetBrowser: function updateWidgetBrowser() {
this.loadAllSharedWidgets();
this.loadMineWidgets();
},
/**
* Share widgets, on click handler for "Share"
*/
shareWidget: function shareWidget(event) {
var widget = event.context;
var self = this;
var bodyMessage = Em.Object.create({
confirmMsg: Em.I18n.t('dashboard.widgets.browser.action.share.confirmation'),
confirmButton: Em.I18n.t('dashboard.widgets.browser.action.share')
});
return App.showConfirmationFeedBackPopup(function (query) {
return App.ajax.send({
name: 'widgets.wizard.edit',
sender: self,
data: {
data: {
"WidgetInfo": {
"widget_name": widget.get("widgetName"),
"scope": "CLUSTER"
}
},
widgetId: widget.get("id")
},
success: 'updateWidgetBrowser'
});
}, bodyMessage);
},
/**
* create widget
*/
createWidget: function createWidget() {
App.router.send('createServiceWidget', Em.Object.create({
layout: this.get('activeWidgetLayout'),
serviceName: this.get('content.serviceName')
}));
},
/**
* edit widget
* @param {App.Widget} content
*/
editWidget: function editWidget(content) {
content.set('serviceName', this.get('content.serviceName'));
App.router.send('editServiceWidget', content);
},
/**
* launch Widgets Browser popup
* @method showPopup
* @return {App.ModalPopup}
*/
goToWidgetsBrowser: function goToWidgetsBrowser() {
var self = this;
return App.ModalPopup.show({
header: Em.I18n.t('dashboard.widgets.browser.header'),
classNames: ['common-modal-wrapper', 'widgets-browser-popup'],
modalDialogClasses: ['modal-lg'],
onPrimary: function onPrimary() {
this.hide();
self.set('isAllSharedWidgetsLoaded', false);
self.set('allSharedWidgets', []);
self.set('isMineWidgetsLoaded', false);
self.set('mineWidgets', []);
},
autoHeight: false,
isHideBodyScroll: false,
footerClass: Ember.View.extend({
templateName: require('templates/common/modal_popups/widget_browser_footer'),
isShowMineOnly: false,
onPrimary: function onPrimary() {
this.get('parentView').onPrimary();
}
}),
isShowMineOnly: false,
showTopShadow: false,
didInsertElement: function didInsertElement() {
this._super();
this.$().find('.modal-body').on('scroll', function (event) {
var modalBody = $(event.currentTarget);
if (modalBody.scrollTop() > 0) {
modalBody.addClass('top-shadow');
} else {
modalBody.removeClass('top-shadow');
}
});
},
bodyClass: Ember.View.extend({
templateName: require('templates/common/modal_popups/widget_browser_popup'),
controller: self,
willInsertElement: function willInsertElement() {
this.get('controller').loadAllSharedWidgets();
this.get('controller').loadMineWidgets();
},
isLoaded: Em.computed.and('controller.isAllSharedWidgetsLoaded', 'controller.isMineWidgetsLoaded'),
isWidgetEmptyList: Em.computed.empty('filteredContent'),
activeService: '',
activeStatus: '',
content: function () {
var content = [];
if (this.get('parentView.isShowMineOnly')) {
content = this.get('controller.mineWidgets');
} else {
// merge my widgets and all shared widgets, no duplicated is allowed
var widgetMap = {};
var allWidgets = this.get('controller.allSharedWidgets').concat(this.get('controller.mineWidgets'));
allWidgets.forEach(function (widget) {
if (!widgetMap[widget.get("id")]) {
content.pushObject(widget);
widgetMap[widget.get("id")] = true;
}
});
}
//remove NameNode widgets with no tag if federation is enabled
if (App.get('hasNameNodeFederation')) {
content = content.filter(function (w) {
var parsedMetric;
try {
parsedMetric = JSON.parse(w.metrics);
} catch (e) {}
return w.tag || !(parsedMetric && parsedMetric.someProperty('component_name', 'NAMENODE'));
});
}
return content;
}.property('controller.allSharedWidgets.length', 'controller.isAllSharedWidgetsLoaded', 'controller.mineWidgets.length', 'controller.isMineWidgetsLoaded', 'parentView.isShowMineOnly'),
/**
* displaying content filtered by service name and status.
*/
filteredContent: function () {
var activeService = this.get('activeService') ? this.get('activeService') : this.get('controller.content.serviceName');
var result = [];
this.get('content').forEach(function (widget) {
if (widget.get('serviceName').indexOf(activeService) >= 0) {
result.pushObject(widget);
}
});
return result;
}.property('content', 'activeService', 'activeStatus'),
/**
* service name filter
*/
services: function () {
var view = this;
var services = App.Service.find().filter(function (item) {
var stackService = App.StackService.find().findProperty('serviceName', item.get('serviceName'));
return stackService.get('isServiceWithWidgets');
});
return services.map(function (service) {
return Em.Object.create({
value: service.get('serviceName'),
label: service.get('displayName'),
isActive: function () {
var activeService = view.get('activeService') ? view.get('activeService') : view.get('controller.content.serviceName');
return this.get('value') == activeService;
}.property('value', 'view.activeService')
});
});
}.property('activeService'),
filterByService: function filterByService(event) {
this.set('activeService', event.context);
},
createWidget: function createWidget() {
this.get('parentView').onPrimary();
this.get('controller').createWidget();
},
ensureTooltip: function () {
Em.run.later(this, function () {
App.tooltip($("[rel='shared-icon-tooltip']"));
}, 1000);
}.observes('activeService', 'parentView.isShowMineOnly'),
didInsertElement: function didInsertElement() {
this.ensureTooltip();
}
})
});
}
});
}); |