浏览代码

AMBARI-7608 Warning when deleting not last host-component. (atkach)

atkach 10 年之前
父节点
当前提交
a23758831a
共有 2 个文件被更改,包括 70 次插入1 次删除
  1. 19 1
      ambari-web/app/controllers/main/host/details.js
  2. 51 0
      ambari-web/test/controllers/main/host/details_test.js

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

@@ -212,7 +212,7 @@ App.MainHostDetailsController = Em.Controller.extend({
     var component = event.context;
     var componentName = component.get('componentName');
     var displayName = component.get('displayName');
-    var isLastComponent = (App.HostComponent.find().filterProperty('componentName', componentName).get('length') === 1);
+    var isLastComponent = (this.getTotalComponent(component) === 1);
     App.ModalPopup.show({
       header: Em.I18n.t('popup.confirmation.commonHeader'),
       primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
@@ -252,6 +252,24 @@ App.MainHostDetailsController = Em.Controller.extend({
     });
   },
 
+  /**
+   * get total count of host-components
+   * @method getTotalComponent
+   * @param component
+   * @return {Number}
+   */
+  getTotalComponent: function (component) {
+    var count;
+    if (component.get('isSlave')) {
+      count = App.SlaveComponent.find(component.get('componentName')).get('totalCount');
+    } else if (component.get('isClient')) {
+      count = App.ClientComponent.find(component.get('componentName')).get('totalCount');
+    } else {
+      count = App.HostComponent.find().filterProperty('componentName', component.get('componentName')).get('length')
+    }
+    return count || 0;
+  },
+
   /**
    * Trigger to reset list of master/slaves components on the view
    * @type {bool}

+ 51 - 0
ambari-web/test/controllers/main/host/details_test.js

@@ -1355,6 +1355,57 @@ describe('App.MainHostDetailsController', function () {
     });
   });
 
+  describe('#getTotalComponent()', function () {
+
+    beforeEach(function () {
+      sinon.stub(App.SlaveComponent, 'find', function() {
+        return Em.Object.create({
+          componentName: "SLAVE",
+          totalCount: 1
+        });
+      });
+      sinon.stub(App.ClientComponent, 'find', function() {
+        return Em.Object.create({
+          componentName: "CLIENT",
+          totalCount: 1
+        });
+      });
+      sinon.stub(App.HostComponent, 'find', function() {
+        return [Em.Object.create({
+          componentName: "MASTER",
+          totalCount: 1
+        })]
+      });
+    });
+    afterEach(function () {
+      App.SlaveComponent.find.restore();
+      App.ClientComponent.find.restore();
+      App.HostComponent.find.restore();
+    });
+
+    it('component is slave', function () {
+      expect(controller.getTotalComponent(Em.Object.create({
+        componentName: "SLAVE",
+        isSlave: true
+      }))).to.equal(1);
+    });
+    it('component is client', function () {
+      expect(controller.getTotalComponent(Em.Object.create({
+        componentName: "CLIENT",
+        isClient: true
+      }))).to.equal(1);
+    });
+    it('component is master', function () {
+      expect(controller.getTotalComponent(Em.Object.create({
+        componentName: "MASTER"
+      }))).to.equal(1);
+    });
+    it('unknown component', function () {
+      expect(controller.getTotalComponent(Em.Object.create({
+        componentName: "UNKNOWN"
+      }))).to.equal(0);
+    });
+  });
   describe('#downloadClientConfigs()', function () {
 
     beforeEach(function () {