Преглед на файлове

AMBARI-9413 Once all hivemetastore servers are delete unable to add a new hive metastore. (ababiichuk)

aBabiichuk преди 10 години
родител
ревизия
30e4917970

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

@@ -569,7 +569,7 @@ App.MainServiceItemController = Em.Controller.extend({
    */
   addComponent: function (componentName) {
     var self = this;
-    var component = App.HostComponent.find().findProperty('componentName', componentName);
+    var component = App.StackServiceComponent.find().findProperty('componentName', componentName);
     var componentDisplayName = component.get('displayName');
 
     self.loadHostsWithoutComponent(componentName);

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

@@ -197,9 +197,22 @@ App.HostComponentView = Em.View.extend({
    * @type {bool}
    */
   isDeleteComponentDisabled: function () {
-    return ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
+    var stackComponentCount = App.StackServiceComponent.find(this.get('hostComponent.componentName')).get('minToInstall');
+    var installedCount = this.componentCounter();
+    return (installedCount <= stackComponentCount)
+      || ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus'));
   }.property('workStatus'),
 
+  /**
+   * gets number of current component that are applied to the cluster;
+   * @returns {Number}
+   */
+  componentCounter: function() {
+    return App.StackServiceComponent.find(this.get('hostComponent.componentName')).get('isMaster')
+      ? App.HostComponent.find().filterProperty('componentName', this.get('content.componentName')).length
+      : App.SlaveComponent.find().findProperty('componentName', this.get('content.componentName')).get('totalCount');
+  },
+
   /**
    * Check if component may be reassinged to another host
    * @type {bool}

+ 38 - 0
ambari-web/test/views/main/host/details/host_component_view_test.js

@@ -223,18 +223,56 @@ describe('App.HostComponentView', function() {
 
   describe('#isDeleteComponentDisabled', function() {
 
+    beforeEach(function() {
+      sinon.stub(hostComponentView, 'componentCounter', function() {
+        return 1;
+      });
+      sinon.stub(App.StackServiceComponent, 'find', function(component) {
+        var min = component == 'comp0' ? 0 : 1;
+        return Em.Object.create({minToInstall: min});
+      });
+    });
+    afterEach(function() {
+      hostComponentView.componentCounter.restore();
+      App.StackServiceComponent.find.restore();
+    });
+
     var tests = ['INSTALLED', 'UNKNOWN', 'INSTALL_FAILED', 'UPGRADE_FAILED', 'INIT'];
     var testE = false;
     var defaultE = true;
 
     App.HostComponentStatus.getStatusesList().forEach(function(status) {
       it(status, function() {
+        App.store.load(App.StackServiceComponent, {
+          id: 1,
+          component_name: 'comp0'
+        });
+        hostComponentView.get('hostComponent').set('componentName', 'comp0');
         hostComponentView.get('hostComponent').set('workStatus', status);
         var e = tests.contains(status) ? testE : defaultE;
         expect(hostComponentView.get('isDeleteComponentDisabled')).to.equal(e);
       });
     });
 
+    it('delete is disabled because min cardinality 1', function() {
+      App.store.load(App.StackServiceComponent, {
+        id: 2,
+        component_name: 'comp1'
+      });
+      hostComponentView.get('hostComponent').set('componentName', 'comp1');
+      hostComponentView.get('hostComponent').set('workStatus', 'INSTALLED');
+      expect(hostComponentView.get('isDeleteComponentDisabled')).to.equal(true);
+    });
+
+    it('delete is enabled because min cardinality 0', function() {
+      App.store.load(App.StackServiceComponent, {
+        id: 2,
+        component_name: 'comp0'
+      });
+      hostComponentView.get('hostComponent').set('componentName', 'comp0');
+      hostComponentView.get('hostComponent').set('workStatus', 'INSTALLED');
+      expect(hostComponentView.get('isDeleteComponentDisabled')).to.equal(false);
+    });
   });
 
   describe('#componentTextStatus', function() {