Repository: ambari
Updated Branches:
  refs/heads/trunk 4aae5e4c8 -> b7fca7277


AMBARI-8210. Install Wizard > Customize Services > Config Groups (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b7fca727
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b7fca727
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b7fca727

Branch: refs/heads/trunk
Commit: b7fca727722b5ca5983ebd7ba05439e6d3fabc16
Parents: 4aae5e4
Author: Oleg Nechiporenko <onechipore...@apache.org>
Authored: Fri Nov 7 19:22:45 2014 +0200
Committer: Oleg Nechiporenko <onechipore...@apache.org>
Committed: Fri Nov 7 19:42:30 2014 +0200

----------------------------------------------------------------------
 .../service/manage_config_groups_controller.js  | 25 +++++-------
 .../manage_config_groups_controller_test.js     | 42 +++++++++++++++++++-
 2 files changed, 50 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b7fca727/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js 
b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
index 4f74f28..a1f0ee7 100644
--- a/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
+++ b/ambari-web/app/controllers/main/service/manage_config_groups_controller.js
@@ -322,42 +322,35 @@ App.ManageConfigGroupsController = Em.Controller.extend({
 
   /**
    * add hosts callback
+   * @param {string[]} selectedHosts
+   * @method addHostsCallback
    */
   addHostsCallback: function (selectedHosts) {
     var group = this.get('selectedConfigGroup');
     if (selectedHosts) {
-      var defaultHosts = group.get('parentConfigGroup.hosts').slice();
-      var defaultPublicHosts = 
group.get('parentConfigGroup.publicHosts').slice();
-      var configGroupHosts = group.get('hosts');
       selectedHosts.forEach(function (hostName) {
-        configGroupHosts.pushObject(hostName);
+        group.get('hosts').pushObject(hostName);
         group.get('publicHosts').pushObject(this.hostsToPublic(hostName));
-        defaultHosts.removeObject(hostName);
-        defaultPublicHosts.removeObject(this.hostsToPublic(hostName));
+        group.get('parentConfigGroup.hosts').removeObject(hostName);
+        
group.get('parentConfigGroup.publicHosts').removeObject(this.hostsToPublic(hostName));
       }, this);
-      group.set('parentConfigGroup.hosts', defaultHosts);
-      group.set('parentConfigGroup.publicHosts', 
this.hostsToPublic(defaultHosts));
     }
   },
 
   /**
    * delete hosts from group
+   * @method deleteHosts
    */
   deleteHosts: function () {
     if (this.get('isDeleteHostsDisabled')) {
       return;
     }
-    var groupHosts = this.get('selectedConfigGroup.hosts');
-    var defaultGroupHosts = 
this.get('selectedConfigGroup.parentConfigGroup.hosts').slice();
-    var defaultGroupPublicHosts = 
this.get('selectedConfigGroup.parentConfigGroup.publicHosts').slice();
     this.get('selectedHosts').slice().forEach(function (hostName) {
-      defaultGroupHosts.pushObject(this.publicToHostName(hostName));
-      defaultGroupPublicHosts.pushObject(hostName);
-      groupHosts.removeObject(this.publicToHostName(hostName));
+      
this.get('selectedConfigGroup.parentConfigGroup.hosts').pushObject(this.publicToHostName(hostName));
+      
this.get('selectedConfigGroup.parentConfigGroup.publicHosts').pushObject(hostName);
+      
this.get('selectedConfigGroup.hosts').removeObject(this.publicToHostName(hostName));
       this.get('selectedConfigGroup.publicHosts').removeObject(hostName);
     }, this);
-    this.set('selectedConfigGroup.parentConfigGroup.hosts', defaultGroupHosts);
-    this.set('selectedConfigGroup.parentConfigGroup.publicHosts', 
this.hostsToPublic(defaultGroupHosts));
     this.set('selectedHosts', []);
   },
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b7fca727/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
 
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
index a234079..2572bdd 100644
--- 
a/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
+++ 
b/ambari-web/test/controllers/main/service/manage_config_groups_controller_test.js
@@ -17,9 +17,13 @@
  */
 
 var App = require('app');
-
+var c;
 describe('App.ManageConfigGroupsController', function() {
+  var controller = App.ManageConfigGroupsController.create({});
 
+  beforeEach(function() {
+    c = App.ManageConfigGroupsController.create({});
+  });
        var manageConfigGroupsController = 
App.ManageConfigGroupsController.create({});
 
        describe('#addConfigGroup', function() {
@@ -204,4 +208,40 @@ describe('App.ManageConfigGroupsController', function() {
     });
 
   });
+
+  describe('#addHostsCallback', function() {
+
+    beforeEach(function() {
+
+      c.reopen({
+        selectedConfigGroup: Em.Object.create({
+          hosts: ['h1'],
+          publicHosts: ['p_h1'],
+          parentConfigGroup: Em.Object.create({
+            hosts: ['h2', 'h3'],
+            publicHosts: ['p_h2', 'p_h3']
+          })
+        })
+      });
+
+      sinon.stub(c, 'hostsToPublic', function(s) {return 'p_' + s;});
+
+    });
+
+    afterEach(function() {
+      c.hostsToPublic.restore();
+    });
+
+    it('should set hosts to selectedConfigGroup and remove them form default 
group', function () {
+
+      c.addHostsCallback(['h2', 'h3']);
+
+      
expect(c.get('selectedConfigGroup.hosts')).to.include.members(['h1','h2','h3']);
+      
expect(c.get('selectedConfigGroup.publicHosts')).to.include.members(['p_h1','p_h2','p_h3']);
+      
expect(c.get('selectedConfigGroup.parentConfigGroup.hosts').toArray()).to.be.empty;
+      
expect(c.get('selectedConfigGroup.parentConfigGroup.publicHosts').toArray()).to.be.empty;
+    });
+
+  });
+
 });

Reply via email to