123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- /**
- * 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 filters = require('views/common/filter_view');
- var sort = require('views/common/sort_view');
- var date = require('utils/date');
- App.MainHostView = App.TableView.extend({
- templateName:require('templates/main/host'),
- content:function () {
- return this.get('controller.content');
- }.property('controller.content.length'),
- willInsertElement: function() {
- this._super();
- },
- clearFiltersObs: function() {
- var self = this;
- Em.run.next(function() {
- if (self.get('controller.clearFilters')) {
- self.clearFilters();
- self.clearStartIndex();
- }
- });
- },
- didInsertElement: function() {
- this.addObserver('controller.clearFilters', this, this.clearFiltersObs);
- this.clearFiltersObs();
- this.addObserver('content.@each.hostComponents.@each', this, this.filter);
- },
- sortView: sort.wrapperView,
- nameSort: sort.fieldView.extend({
- column: 1,
- name:'publicHostName',
- displayName: Em.I18n.t('common.name')
- }),
- ipSort: sort.fieldView.extend({
- column: 2,
- name:'ip',
- displayName: Em.I18n.t('common.ipAddress'),
- type: 'ip'
- }),
- cpuSort: sort.fieldView.extend({
- column: 3,
- name:'cpu',
- displayName: Em.I18n.t('common.cores'),
- type: 'number'
- }),
- memorySort: sort.fieldView.extend({
- column: 4,
- name:'memory',
- displayName: Em.I18n.t('common.ram'),
- type: 'number'
- }),
- diskUsageSort: sort.fieldView.extend({
- name:'diskUsage',
- displayName: Em.I18n.t('common.diskUsage')
- }),
- loadAvgSort: sort.fieldView.extend({
- column: 5,
- name:'loadAvg',
- displayName: Em.I18n.t('common.loadAvg'),
- type: 'number'
- }),
- HostView:Em.View.extend({
- content:null,
- tagName: 'tr',
- didInsertElement: function(){
- App.tooltip(this.$("[rel='HealthTooltip'], [rel='UsageTooltip'], [rel='ComponentsTooltip']"));
- },
- toggleComponents: function(event) {
- this.$(event.target).find('.caret').toggleClass('right');
- this.$('.host-components').toggle();
- },
- /**
- * Tooltip message for "Restart Required" icon
- * @returns {String}
- */
- restartRequiredComponentsMessage: function() {
- var restartRequiredComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
- var count = restartRequiredComponents.length;
- if (count <= 5) {
- var word = (count == 1) ? Em.I18n.t('common.component') : Em.I18n.t('common.components');
- return Em.I18n.t('hosts.table.restartComponents.withNames').format(restartRequiredComponents.getEach('displayName').join(', ')) + ' ' + word.toLowerCase();
- }
- return Em.I18n.t('hosts.table.restartComponents.withoutNames').format(count);
- }.property('content.hostComponents.@each.staleConfigs'),
- /**
- * Tooltip message for "Maintenance" icon
- * @returns {String}
- */
- componentsInMaintenanceMessage: function() {
- var componentsInMaintenance = this.get('content.hostComponents').filterProperty('workStatus', App.HostComponentStatus.maintenance);
- var count = componentsInMaintenance.length;
- if (count <= 5) {
- return Em.I18n.t('hosts.table.componentsInMaintenance.withNames').format(componentsInMaintenance.getEach('displayName').join(', '));
- }
- return Em.I18n.t('hosts.table.componentsInMaintenance.withoutNames').format(count);
- }.property('content.hostComponents.@each.workStatus'),
- /**
- * String with list of host components <code>displayName</code>
- * @returns {String}
- */
- labels: function() {
- return this.get('content.hostComponents').getEach('displayName').join("<br />");
- }.property('content.hostComponents.@each'),
- /**
- * CSS value for disk usage bar
- * @returns {String}
- */
- usageStyle:function () {
- return "width:" + this.get('content.diskUsage') + "%";
- }.property('content.diskUsage')
- }),
- /**
- * Category view for all hosts
- */
- categoryObject: Em.Object.extend({
- hostsCount: function () {
- var statusString = this.get('healthStatusValue');
- var alerts = this.get('alerts');
- var restart = this.get('restart');
- var maintenance = this.get('maintenance');
- if(alerts) {
- return this.get('view.content').filterProperty('criticalAlertsCount').get('length');
- }
- else {
- if (restart) {
- return this.get('view.content').filterProperty('componentsWithStaleConfigsCount').get('length');
- }
- else {
- if (maintenance) {
- return this.get('view.content').filterProperty('componentsInMaintenanceCount').get('length');
- }
- else {
- if (statusString == "") {
- return this.get('view.content').get('length');
- }
- else {
- return this.get('view.content').filterProperty('healthClass', statusString ).get('length');
- }
- }
- }
- }
- }.property('view.content.@each.healthClass', 'view.content.@each.criticalAlertsCount', 'view.content.@each.componentsInMaintenanceCount', 'view.content.@each.hostComponents.@each.staleConfigs'),
- label: function () {
- return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
- }.property('value', 'hostsCount')
- }),
- categories: function () {
- var self = this;
- self.categoryObject.reopen({
- view: self,
- isActive: false,
- itemClass: function() {
- return this.get('isActive') ? 'active' : '';
- }.property('isActive')
- });
- var categories = [
- self.categoryObject.create({value: Em.I18n.t('common.all'), healthStatusValue: '', isActive: true, isVisible: false}),
- self.categoryObject.create({value: Em.I18n.t('hosts.host.healthStatusCategory.green'), healthStatusValue: 'health-status-LIVE', isVisible: true}),
- self.categoryObject.create({value: Em.I18n.t('hosts.host.healthStatusCategory.red'), healthStatusValue: 'health-status-DEAD-RED', isVisible: true}),
- self.categoryObject.create({value: Em.I18n.t('hosts.host.healthStatusCategory.orange'), healthStatusValue: 'health-status-DEAD-ORANGE', isVisible: true}),
- self.categoryObject.create({value: Em.I18n.t('hosts.host.healthStatusCategory.yellow'), healthStatusValue: 'health-status-DEAD-YELLOW', isVisible: true}),
- self.categoryObject.create({value: Em.I18n.t('hosts.host.alerts.label'), healthStatusValue: 'health-status-WITH-ALERTS', alerts: true, isVisible: true }),
- self.categoryObject.create({value: Em.I18n.t('common.restart'), healthStatusValue: 'health-status-RESTART', restart: true, isVisible: true }),
- self.categoryObject.create({value: Em.I18n.t('common.maintenance'), healthStatusValue: 'health-status-MAINTENANCE', maintenance: true, last: true, isVisible: true })
- ];
- return categories;
- }.property(),
- statusFilter: Em.View.extend({
- column: 0,
- categories: [],
- value: null,
- /**
- * switch active category label
- */
- onCategoryChange: function(){
- this.get('categories').setEach('isActive', false);
- this.get('categories').findProperty('healthStatusValue', this.get('value')).set('isActive', true);
- }.observes('value'),
- showClearFilter: function(){
- var mockEvent = {
- context: this.get('categories').findProperty('healthStatusValue', this.get('value'))
- };
- this.selectCategory(mockEvent);
- },
- selectCategory: function(event){
- var category = event.context;
- this.set('value', category.get('healthStatusValue'));
- if(category.get('alerts')) {
- this.get('parentView').updateFilter(0, '', 'string');
- this.get('parentView').updateFilter(7, '>0', 'number');
- this.get('parentView').updateFilter(8, '', 'number');
- this.get('parentView').updateFilter(9, '', 'number');
- }
- else {
- if(category.get('restart')) {
- this.get('parentView').updateFilter(0, '', 'string');
- this.get('parentView').updateFilter(7, '', 'number');
- this.get('parentView').updateFilter(8, '>0', 'number');
- this.get('parentView').updateFilter(9, '', 'number');
- }
- else {
- if(category.get('maintenance')) {
- this.get('parentView').updateFilter(0, '', 'string');
- this.get('parentView').updateFilter(7, '', 'number');
- this.get('parentView').updateFilter(8, '', 'number');
- this.get('parentView').updateFilter(9, '>0', 'number');
- }
- else {
- this.get('parentView').updateFilter(0, category.get('healthStatusValue'), 'string');
- this.get('parentView').updateFilter(7, '', 'number');
- this.get('parentView').updateFilter(8, '', 'number');
- this.get('parentView').updateFilter(9, '', 'number');
- }
- }
- }
- },
- clearFilter: function() {
- this.get('categories').setEach('isActive', false);
- this.set('value', '');
- this.showClearFilter();
- }
- }),
- /**
- * view of the alert filter implemented as a category of host statuses
- */
- alertFilter: Em.View.extend({
- column: 7,
- value: null,
- classNames: ['noDisplay'],
- showClearFilter: function(){
- var mockEvent = {
- context: this.get('parentView.categories').findProperty('healthStatusValue', 'health-status-WITH-ALERTS')
- };
- if(this.get('value')) {
- this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
- }
- }
- }),
- /**
- * view of the staleConfigs filter implemented as a category of host statuses
- */
- restartFilter: Em.View.extend({
- column: 8,
- value: null,
- classNames: ['noDisplay'],
- showClearFilter: function(){
- var mockEvent = {
- context: this.get('parentView.categories').findProperty('healthStatusValue', 'health-status-RESTART')
- };
- if(this.get('value')) {
- this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
- }
- }
- }),
- /**
- * view of the maintenance filter implemented as a category of host statuses
- */
- maintenanceFilter: Em.View.extend({
- column: 9,
- value: null,
- classNames: ['noDisplay'],
- showClearFilter: function(){
- var mockEvent = {
- context: this.get('parentView.categories').findProperty('healthStatusValue', 'health-status-MAINTENANCE')
- };
- if(this.get('value')) {
- this.get('parentView.childViews').findProperty('column', 0).selectCategory(mockEvent);
- }
- }
- }),
- /**
- * Filter view for name column
- * Based on <code>filters</code> library
- */
- nameFilterView: filters.createTextView({
- column: 1,
- fieldType: 'width70',
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
- }
- }),
- /**
- * Filter view for ip column
- * Based on <code>filters</code> library
- */
- ipFilterView: filters.createTextView({
- column: 2,
- fieldType: 'width70',
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'string');
- }
- }),
- /**
- * Filter view for Cpu column
- * Based on <code>filters</code> library
- */
- cpuFilterView: filters.createTextView({
- fieldType: 'width70',
- fieldId: 'cpu_filter',
- column: 3,
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'number');
- }
- }),
- /**
- * Filter view for LoadAverage column
- * Based on <code>filters</code> library
- */
- loadAvgFilterView: filters.createTextView({
- fieldType: 'width70',
- fieldId: 'load_avg_filter',
- column: 5,
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'number');
- }
- }),
- /**
- * Filter view for Ram column
- * Based on <code>filters</code> library
- */
- ramFilterView: filters.createTextView({
- fieldType: 'width70',
- fieldId: 'ram_filter',
- column: 4,
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'ambari-bandwidth');
- }
- }),
- /**
- * Filter view for HostComponents column
- * Based on <code>filters</code> library
- */
- componentsFilterView: filters.createComponentView({
- column: 6,
- /**
- * Inner FilterView. Used just to render component. Value bind to <code>mainview.value</code> property
- * Base methods was implemented in <code>filters.componentFieldView</code>
- */
- filterView: filters.componentFieldView.extend({
- templateName: require('templates/main/host/component_filter'),
- /**
- * Next three lines bind data to this view
- */
- masterComponentsBinding: 'controller.masterComponents',
- slaveComponentsBinding: 'controller.slaveComponents',
- clientComponentsBinding: 'controller.clientComponents',
- /**
- * Checkbox for quick selecting/deselecting of master components
- */
- masterComponentsChecked:false,
- toggleMasterComponents:function () {
- this.get('masterComponents').setEach('checkedForHostFilter', this.get('masterComponentsChecked'));
- }.observes('masterComponentsChecked'),
- /**
- * Checkbox for quick selecting/deselecting of slave components
- */
- slaveComponentsChecked:false,
- toggleSlaveComponents:function () {
- this.get('slaveComponents').setEach('checkedForHostFilter', this.get('slaveComponentsChecked'));
- }.observes('slaveComponentsChecked'),
- /**
- * Checkbox for quick selecting/deselecting of client components
- */
- clientComponentsChecked: false,
- toggleClientComponents: function() {
- this.get('clientComponents').setEach('checkedForHostFilter', this.get('clientComponentsChecked'));
- }.observes('clientComponentsChecked'),
- /**
- * Clear filter.
- * Called by parent view, when user clicks on <code>x</code> button(clear button)
- */
- clearFilter:function() {
- this.set('masterComponentsChecked', false);
- this.set('slaveComponentsChecked', false);
- this.set('clientComponentsChecked', false);
- this.get('masterComponents').setEach('checkedForHostFilter', false);
- this.get('slaveComponents').setEach('checkedForHostFilter', false);
- this.get('clientComponents').setEach('checkedForHostFilter', false);
- this._super();
- },
- /**
- * Onclick handler for <code>Apply filter</code> button
- */
- applyFilter:function() {
- this._super();
- var self = this;
- var chosenComponents = [];
- this.get('masterComponents').filterProperty('checkedForHostFilter', true).forEach(function(item){
- chosenComponents.push(item.get('id'));
- });
- this.get('slaveComponents').filterProperty('checkedForHostFilter', true).forEach(function(item){
- chosenComponents.push(item.get('id'));
- });
- this.get('clientComponents').filterProperty('checkedForHostFilter', true).forEach(function(item){
- chosenComponents.push(item.get('id'));
- });
- Em.run.next(function() {
- self.set('value', chosenComponents.toString());
- });
- },
- /**
- * Verify that checked checkboxes are equal to value stored in hidden field (components ids list)
- */
- checkComponents: function() {
- var components = this.get('value').split(',');
- var self = this;
- if (components) {
- components.forEach(function(componentId) {
- if(!self.tryCheckComponent(self, 'masterComponents', componentId)) {
- if(!self.tryCheckComponent(self, 'slaveComponents', componentId)) {
- self.tryCheckComponent(self, 'clientComponents', componentId);
- }
- }
- });
- }
- }.observes('value'),
- tryCheckComponent: function(self, category, componentId) {
- var c = self.get(category).findProperty('id', componentId);
- if (c) {
- if (!c.get('checkedForHostFilter')) {
- c.set('checkedForHostFilter', true);
- return true;
- }
- }
- return false;
- }
- }),
- onChangeValue: function(){
- this.get('parentView').updateFilter(this.get('column'), this.get('value'), 'multiple');
- }
- }),
- /**
- * associations between host property and column index
- */
- colPropAssoc: function(){
- var associations = [];
- associations[0] = 'healthClass';
- associations[1] = 'publicHostName';
- associations[2] = 'ip';
- associations[3] = 'cpu';
- associations[4] = 'memoryFormatted';
- associations[5] = 'loadAvg';
- associations[6] = 'hostComponents';
- associations[7] = 'criticalAlertsCount';
- associations[8] = 'componentsWithStaleConfigsCount';
- associations[9] = 'componentsInMaintenanceCount';
- return associations;
- }.property()
- });
|