Browse Source

AMBARI-15736. Service can't be deleted if all component are in state "install failed". (onechiporenko)

Oleg Nechiporenko 9 năm trước cách đây
mục cha
commit
9c3fe327d4

+ 15 - 3
ambari-web/app/models/client_component.js

@@ -34,9 +34,21 @@ App.ClientComponent = DS.Model.extend({
    *
    * @type {boolean}
    */
-  allStopped: function() {
-    return this.get('installedCount') === this.get('totalCount');
-  }.property('installedCount', 'totalCount'),
+  allStopped: Em.computed.equalProperties('installedCount', 'totalCount'),
+
+  /**
+   * No stated and no installed component
+   *
+   * @type {boolean}
+   */
+  noOneInstalled: Em.computed.and('!installedCount', '!startedCount'),
+
+  /**
+   * Determines if component may be deleted
+   *
+   * @type {boolean}
+   */
+  allowToDelete: Em.computed.or('allStopped', 'noOneInstalled'),
 
   summaryLabelClassName:function(){
     return 'label_for_'+this.get('componentName').toLowerCase();

+ 5 - 4
ambari-web/app/models/service.js

@@ -47,10 +47,11 @@ App.Service = DS.Model.extend({
    * @type {boolean}
    */
   allowToDelete: function() {
-    return App.Service.allowUninstallStates.contains(this.get('workStatus'))
-      && this.get('slaveComponents').everyProperty('allStopped')
-      && this.get('masterComponents').everyProperty('allStopped');
-  }.property('slaveComponents.@each.allStopped', 'masterComponents.@each.allStopped', 'workStatus'),
+    var workStatus = this.get('workStatus');
+    return App.Service.allowUninstallStates.contains(workStatus)
+      && this.get('slaveComponents').everyProperty('allowToDelete')
+      && this.get('masterComponents').everyProperty('allowToDelete');
+  }.property('slaveComponents.@each.allowToDelete', 'masterComponents.@each.allowToDelete', 'workStatus'),
 
   /**
    * @type {bool}

+ 1 - 2
ambari-web/test/controllers/wizard/step8_test.js

@@ -20,7 +20,7 @@ var App = require('app');
 require('utils/ajax/ajax_queue');
 require('controllers/main/service/info/configs');
 require('controllers/wizard/step8_controller');
-var installerStep8Controller, configurationController;
+var installerStep8Controller;
 var testHelpers = require('test/helpers');
 
 var configs = Em.A([
@@ -64,7 +64,6 @@ describe('App.WizardStep8Controller', function () {
 
   beforeEach(function () {
     installerStep8Controller = getController();
-    configurationController = App.MainServiceInfoConfigsController.create({});
   });
 
   App.TestAliases.testAsComputedFilterBy(getController(), 'installedServices', 'content.services', 'isInstalled', true);

+ 77 - 0
ambari-web/test/models/service_test.js

@@ -187,5 +187,82 @@ describe('App.Service', function () {
     });
   });
 
+  describe('#allowToDelete', function () {
+
+    beforeEach(function () {
+      this.stub = sinon.stub(service, 'get');
+    });
+
+    afterEach(function () {
+      this.stub.restore();
+    });
+
+    Em.A([
+      {
+        m: 'may be deleted (1)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'INIT',
+        e: true
+      },
+      {
+        m: 'may be deleted (2)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'INSTALL_FAILED',
+        e: true
+      },
+      {
+        m: 'may be deleted (3)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'INSTALLED',
+        e: true
+      },
+      {
+        m: 'may be deleted (4)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'UNKNOWN',
+        e: true
+      },
+      {
+        m: 'deleting is not allowed (1)',
+        slaveComponents: [{allowToDelete: false}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'UNKNOWN',
+        e: false
+      },
+      {
+        m: 'deleting is not allowed (2)',
+        slaveComponents: [{allowToDelete: false}],
+        masterComponents: [{allowToDelete: false}],
+        workStatus: 'UNKNOWN',
+        e: false
+      },
+      {
+        m: 'deleting is not allowed (3)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: false}],
+        workStatus: 'UNKNOWN',
+        e: false
+      },
+      {
+        m: 'deleting is not allowed (4)',
+        slaveComponents: [{allowToDelete: true}],
+        masterComponents: [{allowToDelete: true}],
+        workStatus: 'STARTED',
+        e: false
+      }
+    ]).forEach(function (test) {
+      it(test.m, function () {
+        this.stub.withArgs('workStatus').returns(test.workStatus);
+        this.stub.withArgs('slaveComponents').returns(test.slaveComponents);
+        this.stub.withArgs('masterComponents').returns(test.masterComponents);
+        expect(Em.get(service, 'allowToDelete')).to.be.equal(test.e);
+      });
+    });
+
+  });
 
 });