Bladeren bron

AMBARI-6032 Remove minor dependencies with Host and HostComponent models. (atkach)

atkach 11 jaren geleden
bovenliggende
commit
930c4a4394

+ 6 - 0
ambari-web/app/controllers/global/cluster_controller.js

@@ -293,6 +293,12 @@ App.ClusterController = Em.Controller.extend({
     var usersUrl = App.testMode ? '/data/users/users.json' : App.apiPrefix + '/users/?fields=*';
     var racksUrl = "/data/racks/racks.json";
 
+
+    var hostsController = App.router.get('mainHostController');
+    hostsController.set('isCountersUpdating', true);
+    hostsController.updateStatusCounters();
+    hostsController.set('isCountersUpdating', false);
+
     App.HttpClient.get(racksUrl, App.racksMapper, {
       complete: function (jqXHR, textStatus) {
         self.updateLoadStatus('racks');

+ 55 - 1
ambari-web/app/controllers/main/host.js

@@ -28,13 +28,19 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, {
   clearFilters: null,
 
   filteredCount: 0,
+  /**
+   * flag responsible for updating status counters of hosts
+   */
+  isCountersUpdating: false,
+
+  hostsCountMap: {},
 
   /**
    * Components which will be shown in component filter
    * @returns {Array}
    */
   componentsForFilter: function () {
-    var installedComponents = componentHelper.getInstalledComponents();
+    var installedComponents = App.StackServiceComponent.find().toArray();
     installedComponents.setEach('checkedForHostFilter', false);
     return installedComponents;
   }.property('App.router.clusterController.isLoaded'),
@@ -251,6 +257,54 @@ App.MainHostController = Em.ArrayController.extend(App.UserPref, {
     return queryParams;
   },
 
+  /**
+   * update status counters of hosts
+   */
+  updateStatusCounters: function () {
+    var self = this;
+
+    if (this.get('isCountersUpdating')) {
+      App.ajax.send({
+        name: 'host.status.counters',
+        sender: this,
+        data: {},
+        success: 'updateStatusCountersSuccessCallback',
+        error: 'updateStatusCountersErrorCallback'
+      });
+
+      setTimeout(function () {
+        self.updateStatusCounters();
+      }, App.get('componentsUpdateInterval'));
+    }
+  },
+
+  /**
+   * success callback on <code>updateStatusCounters()</code>
+   * map counters' value to categories
+   * @param data
+   */
+  updateStatusCountersSuccessCallback: function (data) {
+    var hostsCountMap = {
+      'HEALTHY': data.Clusters.health_report['Host/host_status/HEALTHY'],
+      'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'],
+      'ALERT': data.Clusters.health_report['Host/host_status/ALERT'],
+      'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'],
+      'health-status-WITH-ALERTS': (data.alerts) ? data.alerts.summary.CRITICAL + data.alerts.summary.WARNING : 0,
+      'health-status-RESTART': data.Clusters.health_report['Host/stale_config'],
+      'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'],
+      'TOTAL': data.Clusters.total_hosts
+    };
+
+    this.set('hostsCountMap', hostsCountMap);
+  },
+
+  /**
+   * success callback on <code>updateStatusCounters()</code>
+   */
+  updateStatusCountersErrorCallback: function() {
+    console.warn('ERROR: updateStatusCounters failed')
+  },
+
   /**
    * Return value without predicate
    * @param {String} value

+ 3 - 0
ambari-web/app/mappers/components_state_mapper.js

@@ -86,6 +86,9 @@ App.componentsStateMapper = App.QuickDataMapper.create({
     },
     'HDFS_CLIENT': {
       installed_clients: 'INSTALLED_PATH'
+    },
+    'FLUME_HANDLER': {
+      flume_handlers_total: 'TOTAL_PATH'
     }
   },
   /**

+ 2 - 1
ambari-web/app/models/service/flume.js

@@ -19,7 +19,8 @@ var App = require('app');
 
 App.FlumeService = App.Service.extend({
   version: DS.attr('string'),
-  agents: DS.hasMany('App.FlumeAgent')
+  agents: DS.hasMany('App.FlumeAgent'),
+  flumeHandlersTotal: DS.attr('number')
 });
 
 App.FlumeAgent = DS.Model.extend({

+ 1 - 0
ambari-web/app/models/service_config.js

@@ -493,6 +493,7 @@ App.ServiceConfigProperty = Ember.Object.extend({
     var masterComponentHostsInDB = localDB.masterComponentHosts;
     var slaveComponentHostsInDB = localDB.slaveComponentHosts;
     var hostsInfo = localDB.hosts; // which we are setting in installerController in step3.
+    //all hosts should be in local storage without using App.Host model
     App.Host.find().forEach(function(item){
       if(!hostsInfo[item.get('id')]){
         hostsInfo[item.get('id')] = {

+ 31 - 24
ambari-web/app/templates/main/admin/rollbackHA/step1.hbs

@@ -16,28 +16,35 @@
 * limitations under the License.
 }}
 <div>
-  <h2>{{t admin.rollbackHighAvailability.wizard.step1.header}}</h2>
-  <div class="alert alert-info">
-    <p>
-      Select Additional NameNode host:
-      {{view Ember.Select
-        contentBinding="view.addNNHosts"
-        valueBinding="view.selectedAddNNHost"
-      }}
-    </p>
-    <div class="code-snippet">Tip: Suggested host <b>{{view.tipAddNNHost}}</b></div>
-  </div>
-  <div class="alert alert-info">
-    <p>
-      Select Secondary NameNode host:
-      {{view Ember.Select
-        contentBinding="view.sNNHosts"
-        valueBinding="view.selectedSNNHost"
-      }}
-    </p>
-    <div class="code-snippet">Tip: Suggested host <b>{{view.tipSNNHost}}</b></div>
-  </div>
-  <div class="btn-area">
-    <a {{bindAttr class=":btn controller.isNameServiceIdValid::disabled :btn-success :pull-right"}} {{action done target="view"}}>{{t common.next}} &rarr;</a>
-  </div>
+  {{#if view.isLoaded}}
+      <h2>{{t admin.rollbackHighAvailability.wizard.step1.header}}</h2>
+
+      <div class="alert alert-info">
+          <p>
+              Select Additional NameNode host:
+            {{view Ember.Select
+            contentBinding="view.addNNHosts"
+            valueBinding="view.selectedAddNNHost"
+            }}
+          </p>
+
+          <div class="code-snippet">Tip: Suggested host <b>{{view.tipAddNNHost}}</b></div>
+      </div>
+      <div class="alert alert-info">
+          <p>
+              Select Secondary NameNode host:
+            {{view Ember.Select
+            contentBinding="view.sNNHosts"
+            valueBinding="view.selectedSNNHost"
+            }}
+          </p>
+
+          <div class="code-snippet">Tip: Suggested host <b>{{view.tipSNNHost}}</b></div>
+      </div>
+      <div class="btn-area">
+          <a {{bindAttr class=":btn controller.isNameServiceIdValid::disabled :btn-success :pull-right"}} {{action done target="view"}}>{{t common.next}} &rarr;</a>
+      </div>
+  {{else}}
+      <div class="spinner"></div>
+  {{/if}}
 </div>

+ 0 - 35
ambari-web/app/utils/component.js

@@ -23,41 +23,6 @@
 
 var App = require('app');
 module.exports = {
-
-  /**
-   * Return list of installed components. Syntax is:
-   *
-   * [{
-   *    id : 'DATANODE',
-   *    displayName : 'DataNode',
-   *    isMaster : true,
-   *    isSlave : false,
-   *    isClient : false
-   * }]
-   *
-   *  @method getInstalledComponents
-   *  @return {object[]}
-   */
-  getInstalledComponents : function(){
-    var components = App.HostComponent.find();
-    var names = components.mapProperty('componentName').uniq();
-    var result = [];
-
-    names.forEach(function(componentName){
-      var component = components.findProperty('componentName', componentName);
-      result.push(Ember.Object.create({
-        id: componentName,
-        isMaster: component.get('isMaster'),
-        isSlave: component.get('isSlave'),
-        isClient: component.get('isClient'),
-        displayName: component.get('displayName'),
-        serviceName: component.get('service.id')
-      }));
-    });
-
-    return result;
-  },
-
   /**
    * Format and load info about components to StackServiceComponent model.
    *

+ 27 - 7
ambari-web/app/views/main/admin/rollbackHA/step1_view.js

@@ -28,20 +28,40 @@ App.RollbackHighAvailabilityWizardStep1View = Em.View.extend({
   selectedSNNHost: null,
   selectedAddNNHost: null,
 
-  didInsertElement: function() {
-    var addNNHosts = App.HostComponent.find().filterProperty('componentName','NAMENODE');
-    this.secondaryNNHosts = [];
+  isLoaded: false,
+
+  loadHostsName: function () {
+    App.ajax.send({
+      name: 'hosts.all',
+      sender: this,
+      data: {},
+      success: 'loadHostsNameSuccessCallback',
+      error: 'loadHostsNameErrorCallback'
+    });
+  },
+
+  loadHostsNameSuccessCallback: function (data) {
+    var addNNHosts = App.HostComponent.find().filterProperty('componentName', 'NAMENODE');
 
+    this.secondaryNNHosts = [];
     this.set('selectedSNNHost', this.get('controller.content.sNNHost'));
     this.set('selectedAddNNHost', this.get('controller.content.addNNHost'));
 
-    if(addNNHosts.length == 2){
+    if (addNNHosts.length == 2) {
       this.set('addNNHosts', addNNHosts.mapProperty('host.hostName'));
     }
-    App.Host.find().forEach(function(host){
-      this.secondaryNNHosts.push(host.get('id'));
-    },this);
+    data.items.forEach(function (host) {
+      this.secondaryNNHosts.push(host.Hosts.host_name);
+    }, this);
     this.set('sNNHosts', this.secondaryNNHosts);
+    this.set('isLoaded', true);
+  },
+  loadHostsNameErrorCallback: function(){
+    this.set('isLoaded', true);
+  },
+
+  didInsertElement: function() {
+    this.loadHostsName();
   },
 
   tipAddNNHost: function () {

+ 10 - 59
ambari-web/app/views/main/host.js

@@ -32,10 +32,6 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
    */
   selectAllHosts: false,
 
-  /**
-   * flag responsible for updating status counters of hosts
-   */
-  isCountersUpdating: false,
   /**
    * Contains all selected hosts on cluster
    */
@@ -43,7 +39,9 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
   /**
    * total number of installed hosts
    */
-  totalCount: 0,
+  totalCount: function () {
+    return this.get('controller.hostsCountMap')['TOTAL'] || 0;
+  }.property('controller.hostsCountMap'),
 
   filteredCount: function () {
     return this.get('controller.filteredCount');
@@ -148,8 +146,8 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
     this.addObserver('controller.clearFilters', this, this.clearFiltersObs);
     this.clearFiltersObs();
     this.addObserver('selectAllHosts', this, this.toggleAllHosts);
-    this.set('isCountersUpdating', true);
-    this.updateStatusCounters();
+    this.set('controller.isCountersUpdating', true);
+    this.get('controller').updateStatusCounters();
   },
 
   /**
@@ -161,7 +159,7 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
   }.observes('displayLength', 'startIndex'),
 
   willDestroyElement: function() {
-    this.set('isCountersUpdating', false);
+    this.set('controller.isCountersUpdating', false);
   },
 
   /**
@@ -419,59 +417,12 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
 
   }),
 
-  /**
-   * update status counters of hosts
-   */
-  updateStatusCounters: function () {
-    var self = this;
-
-    if (this.get('isCountersUpdating')) {
-      App.ajax.send({
-        name: 'host.status.counters',
-        sender: this,
-        data: {},
-        success: 'updateStatusCountersSuccessCallback',
-        error: 'updateStatusCountersErrorCallback'
-      });
-
-      setTimeout(function () {
-        self.updateStatusCounters();
-      }, App.get('componentsUpdateInterval'));
-    }
-  },
-
-  /**
-   * success callback on <code>updateStatusCounters()</code>
-   * map counters' value to categories
-   * @param data
-   */
-  updateStatusCountersSuccessCallback: function (data) {
-    var hostsCountMap = {
-      'HEALTHY': data.Clusters.health_report['Host/host_status/HEALTHY'],
-      'UNHEALTHY': data.Clusters.health_report['Host/host_status/UNHEALTHY'],
-      'ALERT': data.Clusters.health_report['Host/host_status/ALERT'],
-      'UNKNOWN': data.Clusters.health_report['Host/host_status/UNKNOWN'],
-      'health-status-WITH-ALERTS': (data.alerts) ? data.alerts.summary.CRITICAL + data.alerts.summary.WARNING : 0,
-      'health-status-RESTART': data.Clusters.health_report['Host/stale_config'],
-      'health-status-PASSIVE_STATE': data.Clusters.health_report['Host/maintenance_state'],
-      'TOTAL': data.Clusters.total_hosts
-    };
-
-    this.set('totalCount', data.Clusters.total_hosts);
-    this.updateHostsCount(hostsCountMap);
-  },
-
-  /**
-   * success callback on <code>updateStatusCounters()</code>
-   */
-  updateStatusCountersErrorCallback: function() {
-    console.warn('ERROR: updateStatusCounters failed')
-  },
-
   /**
    * Update <code>hostsCount</code> in every category
    */
-  updateHostsCount: function(hostsCountMap) {
+  updateHostsCount: function() {
+    var hostsCountMap = this.get('controller.hostsCountMap');
+
     this.get('categories').forEach(function(category) {
       var hostsCount = (category.get('healthStatus').trim() === "") ? hostsCountMap['TOTAL'] : hostsCountMap[category.get('healthStatus')];
 
@@ -480,7 +431,7 @@ App.MainHostView = App.TableView.extend(App.TableServerProvider, {
         category.set('hasHosts', (hostsCount > 0));
       }
     }, this);
-  },
+  }.observes('controller.hostsCountMap'),
 
   /**
    * Category view for all hosts

+ 1 - 1
ambari-web/app/views/main/host/details/host_component_view.js

@@ -213,7 +213,7 @@ App.HostComponentView = Em.View.extend({
    * @type {bool}
    */
   isReassignable: function () {
-    return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.Host.find().content.length > 1;
+    return App.supports.reassignMaster && App.get('components.reassignable').contains(this.get('content.componentName')) && App.router.get('mainHostController.hostsCountMap')['TOTAL'] > 1;
   }.property('content.componentName'),
 
   /**

+ 1 - 26
ambari-web/app/views/main/service/info/summary.js

@@ -470,30 +470,5 @@ App.MainServiceInfoSummaryView = Em.View.extend({
         $(alertsList).attr('style', "height:" + summaryActualHeight + "px;");
       }
     }
-  }.observes('alertsController.isLoaded'),
-
-  clientHosts:App.Host.find(),
-
-  clientHostsLength:function () {
-    var text = this.t('services.service.summary.clientCount');
-    var self = this;
-    return text.format(self.get('clientHosts.length'));
-  }.property('clientHosts'),
-
-  clientComponents:function () {
-    return App.HostComponent.find().filterProperty('isClient', true);
-  }.property(),
-
-  clientComponentsString:function () {
-    var components = this.get('clientComponents');
-    var names = [];
-    components.forEach(function (component) {
-      if (names.indexOf(component.get('displayName')) == -1) {
-        names.push(component.get('displayName'));
-      }
-    });
-
-    return names.length ? names.join(', ') : false;
-  }.property('clientComponents')
-
+  }.observes('alertsController.isLoaded')
 });

+ 1 - 1
ambari-web/app/views/main/service/item.js

@@ -24,7 +24,7 @@ App.MainServiceItemView = Em.View.extend({
   maintenance: function(){
     var options = [];
     var service = this.get('controller.content');
-    var hosts = App.Host.find().content.length;
+    var hosts = App.router.get('mainHostController.hostsCountMap')['TOTAL'];
     var allMasters = this.get('controller.content.hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
     var disabled = this.get('controller.isStopDisabled');
     var serviceName = service.get('serviceName');

+ 5 - 2
ambari-web/app/views/main/service/services/flume.js

@@ -37,7 +37,7 @@ App.MainDashboardServiceFlumeView = App.TableView.extend({
   summaryHeader: function () {
     var agents = App.FlumeService.find().objectAt(0).get('agents');//this.get('service.agents');
     var agentCount = agents.get('length');
-    var hostCount = this.get('service.hostComponents').filterProperty('componentName', 'FLUME_HANDLER').length;
+    var hostCount = this.get('service.flumeHandlersTotal');
     var prefix = agentCount == 1 ? this.t("dashboard.services.flume.summary.single") :
         this.t("dashboard.services.flume.summary.multiple").format(agentCount);
     var suffix = hostCount == 1 ? this.t("dashboard.services.flume.summary.hosts.single") :
@@ -46,7 +46,10 @@ App.MainDashboardServiceFlumeView = App.TableView.extend({
   }.property('service.agents', 'service.hostComponents.length'),
 
   flumeHandlerComponent: function () {
-    return App.HostComponent.find().findProperty('componentName', 'FLUME_HANDLER');
+    return Em.Object.create({
+      componentName: 'FLUME_HANDLER'
+    });
+    //return App.HostComponent.find().findProperty('componentName', 'FLUME_HANDLER');
   }.property(),
 
   agentView: Em.View.extend({

+ 0 - 25
ambari-web/test/utils/component_test.js

@@ -22,31 +22,6 @@ require('models/host_component');
 require('models/stack_service_component');
 
 describe('utils/component', function(){
-  describe('#getInstalledComponents()', function(){
-    beforeEach(function(){
-      App.HostComponent.find().set('content',[]);
-      App.store.loadMany(App.HostComponent, [
-        {
-          "component_name" : "HISTORYSERVER",
-          "is_client" : false,
-          "is_master" : true,
-          "is_slave" : false
-        },
-        {
-          "component_name" : "TASKTRACKER",
-          "is_client" : false,
-          "is_master" : false,
-          "is_slave" : true
-        }
-      ]);
-    });
-    afterEach(function(){
-      App.HostComponent.find().set('content',[]);
-    });
-    it('names of components should be equal for input and output arrays', function(){
-      expect(component.getInstalledComponents().mapProperty('id')).to.have.members(App.HostComponent.find().mapProperty('componentName'));
-    });
-  });
   describe('#loadStackServiceComponentModel()', function(){
     var data = {
       "items": [