ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [09/50] ambari git commit: AMBARI-14759 When remove service Ambari require to remove wrong services. (atkach)
Date Tue, 26 Jan 2016 21:45:12 GMT
AMBARI-14759 When remove service Ambari require to remove wrong services. (atkach)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 034cb321b7407be77dd7754d369c1b29de161436
Parents: e9b167e
Author: Andrii Tkach <atkach@hortonworks.com>
Authored: Thu Jan 21 16:48:05 2016 +0200
Committer: Andrii Tkach <atkach@hortonworks.com>
Committed: Fri Jan 22 15:35:31 2016 +0200

----------------------------------------------------------------------
 ambari-web/app/controllers/main/service/item.js | 23 +++++--
 .../test/controllers/main/service/item_test.js  | 63 +++++++++++++++-----
 2 files changed, 66 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/034cb321/ambari-web/app/controllers/main/service/item.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/item.js b/ambari-web/app/controllers/main/service/item.js
index 59559eb..14552a1 100644
--- a/ambari-web/app/controllers/main/service/item.js
+++ b/ambari-web/app/controllers/main/service/item.js
@@ -973,13 +973,28 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
   },
 
   /**
+   * find dependent services
+   * @param {string} serviceName
+   * @returns {Array}
+   */
+  findDependentServices: function(serviceName) {
+    var dependentServices = [];
+
+    App.StackService.find().forEach(function(stackService) {
+      if (App.Service.find(stackService.get('serviceName')).get('isLoaded')
+          && stackService.get('requiredServices').contains(serviceName)) {
+        dependentServices.push(stackService.get('serviceName'));
+      }
+    }, this);
+    return dependentServices;
+  },
+
+  /**
    * delete service action
    * @param {string} serviceName
    */
   deleteService: function(serviceName) {
-    var dependentServices = App.StackService.find(serviceName).get('requiredServices').filter(function(_serviceName)
{
-          return App.Service.find(_serviceName).get('isLoaded');
-        }),
+    var dependentServices = this.findDependentServices(serviceName),
         self = this,
         displayName = App.format.role(serviceName),
         popupHeader = Em.I18n.t('services.service.delete.popup.header');
@@ -1016,7 +1031,7 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow
   /**
    * warning that show dependent services which must be deleted prior to chosen service deletion
    * @param {string} origin
-   * @param {string} dependent
+   * @param {Array.<string>} dependent
    * @returns {App.ModalPopup}
    */
   dependentServicesWarning: function(origin, dependent) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/034cb321/ambari-web/test/controllers/main/service/item_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/service/item_test.js b/ambari-web/test/controllers/main/service/item_test.js
index e361bc7..de09e1a 100644
--- a/ambari-web/test/controllers/main/service/item_test.js
+++ b/ambari-web/test/controllers/main/service/item_test.js
@@ -1177,12 +1177,50 @@ describe('App.MainServiceItemController', function () {
     });
   });
 
-  describe("#deleteService()", function() {
+  describe("#findDependentServices()", function() {
     var mainServiceItemController;
 
     beforeEach(function() {
       mainServiceItemController = App.MainServiceItemController.create({});
       this.mockStackService = sinon.stub(App.StackService, 'find');
+      this.mockService = sinon.stub(App.Service, 'find');
+    });
+    afterEach(function() {
+      this.mockStackService.restore();
+      this.mockService.restore();
+    });
+
+    it("no stack services", function() {
+      this.mockStackService.returns([]);
+      expect(mainServiceItemController.findDependentServices('S1')).to.be.empty;
+    });
+
+    it("dependent service not installed", function() {
+      this.mockStackService.returns([Em.Object.create({serviceName: 'S2'})]);
+      this.mockService.withArgs('S2').returns(Em.Object.create({isLoaded: false}));
+      expect(mainServiceItemController.findDependentServices('S1')).to.be.empty;
+    });
+
+    it("service has no dependencies", function() {
+      this.mockStackService.returns([Em.Object.create({serviceName: 'S2', requiredServices:
[]})]);
+      this.mockService.withArgs('S2').returns(Em.Object.create({isLoaded: true}));
+      expect(mainServiceItemController.findDependentServices('S1')).to.be.empty;
+    });
+
+    it("service has dependencies", function() {
+      this.mockStackService.returns([Em.Object.create({serviceName: 'S2', requiredServices:
['S1']})]);
+      this.mockService.withArgs('S2').returns(Em.Object.create({isLoaded: true}));
+      expect(mainServiceItemController.findDependentServices('S1')).to.eql(['S2']);
+    });
+
+  });
+
+  describe("#deleteService()", function() {
+    var mainServiceItemController;
+
+    beforeEach(function() {
+      mainServiceItemController = App.MainServiceItemController.create({});
+      this.mockDependentServices = sinon.stub(mainServiceItemController, 'findDependentServices');
       sinon.stub(mainServiceItemController, 'dependentServicesWarning');
       this.mockService = sinon.stub(App.Service, 'find');
       sinon.stub(App, 'showConfirmationPopup');
@@ -1190,7 +1228,7 @@ describe('App.MainServiceItemController', function () {
       sinon.stub(App.format, 'role', function(name) {return name});
     });
     afterEach(function() {
-      this.mockStackService.restore();
+      this.mockDependentServices.restore();
       this.mockService.restore();
       mainServiceItemController.dependentServicesWarning.restore();
       App.showConfirmationPopup.restore();
@@ -1199,7 +1237,7 @@ describe('App.MainServiceItemController', function () {
     });
 
     it("only one service installed", function() {
-      this.mockStackService.returns(Em.Object.create({requiredServices: ['S2']}));
+      this.mockDependentServices.returns(['S2']);
       this.mockService.returns(Em.Object.create({length: 1}));
       mainServiceItemController.deleteService('S1');
       expect(App.ModalPopup.show.calledWith({
@@ -1211,29 +1249,22 @@ describe('App.MainServiceItemController', function () {
     });
 
     it("service has installed dependent services", function() {
-      this.mockStackService.returns(Em.Object.create({requiredServices: ['S2']}));
-      this.mockService.returns(Em.Object.create({workStatus: 'INSTALLED', isLoaded: true}));
+      this.mockDependentServices.returns(['S2']);
+      this.mockService.returns(Em.Object.create({workStatus: 'INSTALLED'}));
       mainServiceItemController.deleteService('S1');
       expect(mainServiceItemController.dependentServicesWarning.calledWith('S1', ['S2'])).to.be.true;
     });
 
-    it("service has not-installed dependent services, and stopped", function() {
-      this.mockStackService.returns(Em.Object.create({requiredServices: ['S2']}));
-      this.mockService.returns(Em.Object.create({workStatus: 'INSTALLED', isLoaded: false}));
-      mainServiceItemController.deleteService('S1');
-      expect(App.showConfirmationPopup.calledOnce).to.be.true;
-    });
-
     it("service has not dependent services, and stopped", function() {
-      this.mockStackService.returns(Em.Object.create({requiredServices: []}));
-      this.mockService.returns(Em.Object.create({workStatus: 'INSTALLED', isLoaded: true}));
+      this.mockDependentServices.returns([]);
+      this.mockService.returns(Em.Object.create({workStatus: 'INSTALLED'}));
       mainServiceItemController.deleteService('S1');
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
     });
 
     it("service has not dependent services, and not stopped", function() {
-      this.mockStackService.returns(Em.Object.create({requiredServices: []}));
-      this.mockService.returns(Em.Object.create({workStatus: 'STARTED', isLoaded: true}));
+      this.mockDependentServices.returns([]);
+      this.mockService.returns(Em.Object.create({workStatus: 'STARTED'}));
       mainServiceItemController.deleteService('S1');
       expect(App.ModalPopup.show.calledWith({
         secondary: null,


Mime
View raw message