Pārlūkot izejas kodu

AMBARI-9044 Various issues on Repo Distribution page. (ababiichuk)

aBabiichuk 10 gadi atpakaļ
vecāks
revīzija
37e3f924e5

+ 16 - 3
ambari-web/app/controllers/main/admin/stack_versions/repo_version_management_controller.js

@@ -163,16 +163,29 @@ App.RepoVersionsManagementController = Em.ArrayController.extend({
   },
 
   /**
-   * shows popup with listed hosts wich has current state of hostStackVersion
+   * runs <code>showHostsListPopup<code>
    * @param event
-   * @returns {*|void}
+   * @returns {void}
    * @method showHosts
    */
   showHosts: function(event) {
-    var self = this;
     var status = event.contexts[0];
     var version = event.contexts[1];
     var hosts = event.contexts[2];
+    this.showHostsListPopup(status, version, hosts);
+  },
+
+  /**
+   * shows popup with listed hosts wich has current state of hostStackVersion
+   * @param {Object} status - status of repoverion
+   *    {id: "string", label: "string"}
+   * @param {string} version - repo version name
+   * @param {[string]} hosts - array of host containing current repo version in proper state
+   * @returns {App.ModalPopup}
+   * @method showHostsListPopup
+   */
+  showHostsListPopup: function(status, version, hosts) {
+    var self = this;
     if (hosts.length) {
       return App.ModalPopup.show({
         bodyClass: Ember.View.extend({

+ 1 - 0
ambari-web/app/controllers/main/admin/stack_versions/stack_version_details_controller.js

@@ -186,6 +186,7 @@ App.MainStackVersionsDetailsController = Em.Controller.extend({
         App.router.transitionTo('main.admin.adminStackVersions.version', repoVersion);
       } else {
         self.set('content', repoVersion);
+        self.doPolling();
       }
     });
   }

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

@@ -930,7 +930,7 @@ App.MainHostController = Em.ArrayController.extend(App.TableServerMixin, {
     associations[8] = 'componentsWithStaleConfigsCount';
     associations[9] = 'componentsInPassiveStateCount';
     associations[10] = 'selected';
-    associations[11] = 'stackVersions';
+    associations[11] = 'stackVersions.repoVersion';
     return associations;
   }.property()
 

+ 3 - 3
ambari-web/app/templates/main/admin/stack_versions/stack_version_details.hbs

@@ -31,7 +31,7 @@
               <div class="span3">{{t admin.stackVersions.details.not.installed.on}}</div>
               <div {{bindAttr class="view.noInitHosts:not-active-link :span6"}}>
                 <a href="#" class="not-installed-hosts-count"
-                  {{action showHosts view.versionStateMap.not_installed content.repositoryVersion view.notInstalledHosts target="App.router.mainStackVersionsController"}}>
+                  {{action showNotInstalledHosts target="view"}}>
                   {{view.notInstalledHosts.length}}&nbsp;
                   {{pluralize view.notInstalledHosts.length singular="t:admin.stackVersions.details.host" plural="t:admin.stackVersions.details.hosts"}}
                 </a>
@@ -42,7 +42,7 @@
             <div class="span3">{{t admin.stackVersions.details.installed.on}}</div>
             <div {{bindAttr class="view.noInstalledHosts:not-active-link :span6"}}>
               <a href="#" class="installed-hosts-count"
-                {{action showHosts view.versionStateMap.installed content.repositoryVersion view.installedHosts target="App.router.mainStackVersionsController"}}>
+                {{action showInstalledHosts target="view"}}>
                 {{view.installedHosts.length}}&nbsp;
                 {{pluralize view.installedHosts.length singular="t:admin.stackVersions.details.host" plural="t:admin.stackVersions.details.hosts"}}
               </a>
@@ -52,7 +52,7 @@
             <div class="span3">{{t admin.stackVersions.details.current.on}}</div>
             <div {{bindAttr class="view.noCurrentHosts:not-active-link :span6"}}>
               <a href="#" class="current-hosts-count"
-                {{action showHosts view.versionStateMap.current content.repositoryVersion view.currentHosts target="App.router.mainStackVersionsController"}}>
+                {{action showCurrentHosts target="view"}}>
                 {{view.currentHosts.length}}&nbsp;
                 {{pluralize view.currentHosts.length singular="t:admin.stackVersions.details.host" plural="t:admin.stackVersions.details.hosts"}}
               </a>

+ 61 - 28
ambari-web/app/views/main/admin/stack_versions/stack_version_details_view.js

@@ -23,7 +23,7 @@ App.MainStackVersionsDetailsView = Em.View.extend({
   templateName: require('templates/main/admin/stack_versions/stack_version_details'),
 
   content: function() {
-    return this.get('controller.content')
+    return this.get('controller.content');
   }.property('controller.content'),
 
   /**
@@ -34,7 +34,7 @@ App.MainStackVersionsDetailsView = Em.View.extend({
   installButtonMsg: function() {
     return this.get('content.stackVersion.state') == 'INSTALL_FAILED'
       ? Em.I18n.t('admin.stackVersions.details.hosts.btn.reinstall')
-      : Em.I18n.t('admin.stackVersions.details.hosts.btn.install').format(this.get('controller.hostsToInstall'))
+      : Em.I18n.t('admin.stackVersions.details.hosts.btn.install').format(this.get('controller.hostsToInstall'));
   }.property('content.stackVersion.state', 'parentView.content.stackVersion.initHosts.length'),
 
   /**
@@ -54,56 +54,59 @@ App.MainStackVersionsDetailsView = Em.View.extend({
     return "width:" + this.get('controller.progress') + "%";
   }.property('controller.progress'),
 
-  /**
-   * true if repoVersion has ClusterStackVersion
-   * defines show host counters on repoversionDetails page
-   * @type {Boolean}
-   */
-  showCounters: function() {
-    return this.get('content.stackVersion') != null;
-  }.property('content.stackVersion'),
-
-
   /**
    * hosts with stack versions in not installed state
    * when stack version for repoversion is not created returns all hosts in cluster
    */
   notInstalledHosts: function() {
-    if (this.get('showCounters') && this.get('content.stackVersion.notInstalledHosts')) {
-      return this.get('content.stackVersion.notInstalledHosts');
-    } else {
-      return App.get('allHostNames');
-    }
-  }.property('showCounters', 'content.stackVersion.notInstalledHosts.length', 'App.allHostNames'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.notInstalledHosts') : App.get('allHostNames');
+  }.property('content.stackVersion.notInstalledHosts.length', 'App.allHostNames'),
 
   /**
    * hosts with stack versions in installed state
    * when stack version for repoversion is not created returns an empty array
    */
   installedHosts: function() {
-    return this.get('showCounters') ? this.get('content.stackVersion.installedHosts') : [];
-  }.property('showCounters', 'content.stackVersion.installedHosts.length'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.installedHosts') : [];
+  }.property('content.stackVersion.installedHosts.length'),
 
   /**
    * hosts with stack versions in current state
    * when stack version for repoversion is not created returns an empty array
    */
   currentHosts: function() {
-    return this.get('showCounters') ? this.get('content.stackVersion.currentHosts') : [];
-  }.property('showCounters', 'content.stackVersion.currentHosts.length'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.currentHosts') : [];
+  }.property('content.stackVersion.currentHosts.length'),
 
+  /**
+   * true if there are no hosts without this repoversion
+   * @type {boolean}
+   */
   noInitHosts: function() {
-    return this.get('showCounters') ? this.get('content.stackVersion.noInitHosts') : false;
-  }.property('showCounters', 'content.stackVersion.noInitHosts'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.noInitHosts') : false;
+  }.property('content.stackVersion.noInitHosts'),
 
+  /**
+   * true if there are no hosts with this repoversion
+   * @type {boolean}
+   */
   noInstalledHosts:  function() {
-    return this.get('showCounters') ? this.get('content.stackVersion.noInstalledHosts') : true;
-  }.property('showCounters', 'content.stackVersion.noInstalledHosts'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.noInstalledHosts') : true;
+  }.property('content.stackVersion.noInstalledHosts'),
 
+  /**
+   * true if there are no hosts with this repoversion as current
+   * @type {boolean}
+   */
   noCurrentHosts: function() {
-    return this.get('showCounters') ? this.get('content.stackVersion.noCurrentHosts') : true;
-  }.property('showCounters', 'content.stackVersion.noCurrentHosts'),
+    return this.get('content.stackVersion') ? this.get('content.stackVersion.noCurrentHosts') : true;
+  }.property('content.stackVersion.noCurrentHosts'),
 
+  /**
+   * map containing version (id, label)
+   * this is used as param for <code>showHosts<code> method
+   * @type {Object}
+   */
   versionStateMap: {
     'current': {
       'id': 'current',
@@ -119,6 +122,36 @@ App.MainStackVersionsDetailsView = Em.View.extend({
     }
   },
 
+  /**
+   * runs <code>showHostsListPopup<code> from <code>repoVersionsManagementController<code>
+   * to open popup with hosts that has this repo version
+   * in not_installed state
+   */
+  showNotInstalledHosts: function() {
+    App.router.get('repoVersionsManagementController').showHostsListPopup(this.get('versionStateMap.not_installed'),
+      this.get('content.repositoryVersion'), this.get('notInstalledHosts'));
+  },
+
+  /**
+   * runs <code>showHostsListPopup<code> from <code>repoVersionsManagementController<code>
+   * to open popup with hosts that has this repo version
+   * in installed state
+   */
+  showInstalledHosts: function() {
+    App.router.get('repoVersionsManagementController').showHostsListPopup(this.get('versionStateMap.installed'),
+      this.get('content.repositoryVersion'), this.get('installedHosts'));
+  },
+
+  /**
+   * runs <code>showHostsListPopup<code> from <code>repoVersionsManagementController<code>
+   * to open popup with hosts that has this repo version
+   * in current state
+   */
+  showCurrentHosts: function() {
+    App.router.get('repoVersionsManagementController').showHostsListPopup(this.get('versionStateMap.current'),
+      this.get('content.repositoryVersion'), this.get('currentHosts'));
+  },
+
   didInsertElement: function() {
     App.get('router.mainStackVersionsController').set('isPolling', true);
     if (!App.RepositoryVersion.find().findProperty('id', this.get('content.id'))) {

+ 15 - 4
ambari-web/test/controllers/main/admin/stack_version/repo_version_management_controller_test.js

@@ -124,8 +124,7 @@ describe('App.RepoVersionsManagementController', function () {
       App.router.get('mainHostController').filterByStack.restore();
       App.router.transitionTo.restore();
     });
-    var tests = [
-      {
+    [{
         version: "version1",
         state: "state1",
         m: 'go to hosts filtered by host stack version and host stack state',
@@ -156,14 +155,26 @@ describe('App.RepoVersionsManagementController', function () {
       });
   });
 
-  describe('#showHosts()', function () {
+  describe('#showHostsListPopup()', function () {
     it('show list of hosts for current version in choosen state', function () {
       sinon.stub(controller, 'filterHostsByStack', Em.K);
 
-      controller.showHosts({ contexts: [{id: "state", label: "label"}, "version",["host"]]}).onPrimary();
+      controller.showHostsListPopup({id: "state", label: "label"}, "version", ["host"]).onPrimary();
       expect(controller.filterHostsByStack.calledWith("version", "state")).to.be.true;
 
       controller.filterHostsByStack.restore();
     });
   });
+
+  describe('#showHosts()', function () {
+    it('show list of hosts for current version in choosen state', function () {
+      sinon.stub(controller, 'showHostsListPopup', Em.K);
+
+      controller.showHosts({contexts: [{id: "state", label: "label"}, "version", ["host"]]});
+      expect(controller.showHostsListPopup.calledWith({id: "state", label: "label"}, "version", ["host"])).to.be.true;
+
+      controller.showHostsListPopup.restore();
+    });
+  });
+
 });

+ 61 - 13
ambari-web/test/views/main/admin/stack_version/stack_version_details_test.js

@@ -23,6 +23,7 @@ var view;
 
 describe('App.MainStackVersionsDetailsView', function () {
 
+  var defaultRepoVersion = "2.2.1.0";
   beforeEach(function () {
     view = App.MainStackVersionsDetailsView.create({
       "controller": {
@@ -34,8 +35,12 @@ describe('App.MainStackVersionsDetailsView', function () {
         "stackVersion":
           {
             "state" : "ANY"
-          }
-      }
+          },
+        'repositoryVersion': defaultRepoVersion
+      },
+      "currentHosts": ['currentHost'],
+      "installedHosts": ['installedHost'],
+      "notInstalledHosts": ['notInstalledHost']
     });
   });
 
@@ -82,17 +87,6 @@ describe('App.MainStackVersionsDetailsView', function () {
     });
   });
 
-  describe('#showCounters', function () {
-    it("true when repo version has cluster stack version" , function() {
-      view.set("content.stackVersion", Em.Object.create({}));
-      expect(view.get('showCounters')).to.be.true;
-    });
-    it("false when repo version has no cluster stack version" , function() {
-      view.set("content.stackVersion", null);
-      expect(view.get('showCounters')).to.be.false;
-    });
-  });
-
   describe('#didInsertElement', function () {
     beforeEach(function() {
       sinon.stub(App.get('router.mainStackVersionsController'), 'set', Em.K);
@@ -141,4 +135,58 @@ describe('App.MainStackVersionsDetailsView', function () {
       expect(App.get('router.mainStackVersionsController').set.calledWith('isPolling', false)).to.be.true;
     });
   });
+
+  describe('#showNotInstalledHosts', function() {
+    beforeEach(function() {
+      sinon.stub(App.get('router.repoVersionsManagementController'), 'showHostsListPopup', Em.K);
+    });
+    afterEach(function () {
+      App.get('router.repoVersionsManagementController').showHostsListPopup.restore();
+    });
+
+    it("runs showHostsListPopup from repoVersionsManagementController", function () {
+      var state = {
+        'id': 'installing',
+        'label': Em.I18n.t('admin.stackVersions.hosts.popup.header.not_installed')
+      };
+      view.showNotInstalledHosts();
+      expect(App.get('router.repoVersionsManagementController').showHostsListPopup.calledWith(state, defaultRepoVersion, ['notInstalledHost'])).to.be.true;
+    });
+  });
+
+  describe('#showInstalledHosts', function() {
+    beforeEach(function() {
+      sinon.stub(App.get('router.repoVersionsManagementController'), 'showHostsListPopup', Em.K);
+    });
+    afterEach(function () {
+      App.get('router.repoVersionsManagementController').showHostsListPopup.restore();
+    });
+
+    it("runs showHostsListPopup from repoVersionsManagementController", function () {
+      var state = {
+        'id': 'installed',
+        'label': Em.I18n.t('admin.stackVersions.hosts.popup.header.installed')
+      };
+      view.showInstalledHosts();
+      expect(App.get('router.repoVersionsManagementController').showHostsListPopup.calledWith(state, defaultRepoVersion, ['installedHost'])).to.be.true;
+    });
+  });
+
+  describe('#showCurrentHosts', function() {
+    beforeEach(function() {
+      sinon.stub(App.get('router.repoVersionsManagementController'), 'showHostsListPopup', Em.K);
+    });
+    afterEach(function () {
+      App.get('router.repoVersionsManagementController').showHostsListPopup.restore();
+    });
+
+    it("runs showHostsListPopup from repoVersionsManagementController", function () {
+      var state = {
+        'id': 'current',
+        'label': Em.I18n.t('admin.stackVersions.hosts.popup.header.current')
+      };
+      view.showCurrentHosts();
+      expect(App.get('router.repoVersionsManagementController').showHostsListPopup.calledWith(state, defaultRepoVersion, ['currentHost'])).to.be.true;
+    });
+  });
 });