ソースを参照

AMBARI-7750 After change decommission mechanism for RS it fails due time outю (atkach)

atkach 10 年 前
コミット
4862ae3b38

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

@@ -888,7 +888,7 @@ App.MainHostController = Em.ArrayController.extend({
     if (Em.get(data, 'items.length')) {
       App.router.get('mainHostDetailsController').showHbaseActiveWarning();
     } else {
-      App.router.get('mainHostDetailsController').doDecommissionRegionServer(params.hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
+      App.router.get('mainHostDetailsController').checkRegionServerState(params.hostNames);
     }
   },
   /**

+ 52 - 2
ambari-web/app/controllers/main/host/details.js

@@ -927,15 +927,65 @@ App.MainHostDetailsController = Em.Controller.extend({
    * @method warnBeforeDecommission
    * @param {string} hostNames - list of host when run from bulk operations or current host
    */
-
   warnBeforeDecommission: function (hostNames) {
     if (this.get('content.hostComponents').findProperty('componentName', 'HBASE_REGIONSERVER').get('passiveState') == "OFF") {
       this.showHbaseActiveWarning();
     } else {
-      this.doDecommissionRegionServer(hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
+      this.checkRegionServerState(hostNames);
+    }
+  },
+
+  /**
+   *  send call to check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
+   * @method checkRegionServerState
+   * @param hostNames
+   */
+  checkRegionServerState: function (hostNames) {
+    return App.ajax.send({
+      name: 'host.region_servers.in_inservice',
+      sender: this,
+      data: {
+        hostNames: hostNames
+      },
+      success: 'checkRegionServerStateSuccessCallback'
+    });
+  },
+
+  /**
+   * check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
+   * @method checkRegionServerStateSuccessCallback
+   * @param data
+   * @param opt
+   * @param params
+   */
+  checkRegionServerStateSuccessCallback: function (data, opt, params) {
+    var hostArray = params.hostNames.split(",");
+    var decommissionPossible = (data.items.mapProperty('HostRoles.host_name').filter(function (hostName) {
+      return !hostArray.contains(hostName);
+    }, this).length >= 1);
+    if (decommissionPossible) {
+      this.doDecommissionRegionServer(params.hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
+    } else {
+      this.showRegionServerWarning();
     }
   },
 
+  /**
+   * show warning that regionserver is last in cluster which has desired_admin_state property "INSERVICE"
+   * @method showRegionServerWarning
+   * @param hostNames
+   */
+  showRegionServerWarning: function () {
+    return App.ModalPopup.show({
+      header: Em.I18n.t('common.warning'),
+      message: Em.I18n.t('hosts.host.hbase_regionserver.decommission.warning'),
+      bodyClass: Ember.View.extend({
+        template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
+      }),
+      secondary: false
+    });
+  },
+
   /**
    * shows warning: put hbase regionserver in passive state
    * @method showHbaseActiveWarning

+ 1 - 0
ambari-web/app/messages.js

@@ -1732,6 +1732,7 @@ Em.I18n.translations = {
   'hosts.host.regionserver.decommission.batch3':'Decommission RegionServer - Turn drain mode off',
   'hosts.host.hbase_regionserver.recommission':'Recommission RegionServer',
   'hosts.host.hbase_regionserver.decommission':'Decommission RegionServer',
+  'hosts.host.hbase_regionserver.decommission.warning':'Last RegionServer can\'t be decommissioned',
   'hosts.host.decommissioned':'Decommissioned',
   'hosts.host.decommissioning':'Decommissioning',
 

+ 4 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -533,6 +533,10 @@ var urls = {
     'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}?fields=metrics/dfs/namenode',
     'mock': ''
   },
+  'host.region_servers.in_inservice': {
+    'real': '/clusters/{clusterName}/host_components?HostRoles/component_name=HBASE_REGIONSERVER&HostRoles/desired_admin_state=INSERVICE&fields=HostRoles/host_name&minimal_response=true',
+    'mock': ''
+  },
   'host.host_component.decommission_slave': {
     'real' : '/clusters/{clusterName}/requests',
     'mock' : '',

+ 116 - 100
ambari-web/test/controllers/main/host/details_test.js

@@ -27,14 +27,19 @@ var controller;
 describe('App.MainHostDetailsController', function () {
 
 
-  beforeEach(function() {
+  beforeEach(function () {
+    sinon.stub(App.ajax, 'send', Em.K);
     controller = App.MainHostDetailsController.create({
       securityEnabled: function () {
         return this.get('mockSecurityStatus');
       }.property(),
+      content: Em.Object.create(),
       mockSecurityStatus: false
     });
   });
+  afterEach(function () {
+    App.ajax.send.restore();
+  });
 
 
   describe('#serviceActiveComponents', function () {
@@ -144,11 +149,9 @@ describe('App.MainHostDetailsController', function () {
 
     beforeEach(function () {
       sinon.spy(App, "showConfirmationPopup");
-      sinon.stub(App.ajax, "send", Em.K);
     });
     afterEach(function () {
       App.showConfirmationPopup.restore();
-      App.ajax.send.restore();
     });
 
     it('confirm popup should be displayed', function () {
@@ -315,14 +318,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#primary()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       var component = Em.Object.create({
         componentName: 'COMP1',
@@ -380,14 +375,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#sendRefreshComponentConfigsCommand()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       var component = Em.Object.create({
         service: {},
@@ -400,14 +387,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#loadConfigs()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       controller.loadConfigs();
       expect(App.ajax.send.calledOnce).to.be.true;
@@ -477,13 +456,11 @@ describe('App.MainHostDetailsController', function () {
   describe('#loadConfigsSuccessCallback()', function () {
 
     beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
       sinon.stub(controller, "constructConfigUrlParams", function () {
         return this.get('mockUrlParams');
       });
     });
     afterEach(function () {
-      App.ajax.send.restore();
       controller.constructConfigUrlParams.restore();
     });
 
@@ -505,13 +482,11 @@ describe('App.MainHostDetailsController', function () {
       sinon.stub(controller, "getZkServerHosts", Em.K);
       sinon.stub(controller, "concatZkNames", Em.K);
       sinon.stub(controller, "setZKConfigs", Em.K);
-      sinon.spy(App.ajax, "send");
     });
     afterEach(function () {
       controller.getZkServerHosts.restore();
       controller.concatZkNames.restore();
       controller.setZKConfigs.restore();
-      App.ajax.send.restore();
     });
 
     it('data.items is empty', function () {
@@ -679,12 +654,10 @@ describe('App.MainHostDetailsController', function () {
 
     beforeEach(function () {
       sinon.spy(App.ModalPopup, "show");
-      sinon.stub(App.ajax, "send", Em.K);
     });
 
     afterEach(function () {
       App.ModalPopup.show.restore();
-      App.ajax.send.restore();
     });
 
     it('popup should be displayed', function () {
@@ -778,14 +751,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#doDecommission()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       controller.doDecommission('', '', '', '');
       expect(App.ajax.send.calledOnce).to.be.true;
@@ -793,63 +758,132 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#doDecommissionRegionServer()', function () {
+    it('Query should be sent', function () {
+      controller.doDecommissionRegionServer('', '', '', '');
+      expect(App.ajax.send.calledOnce).to.be.true;
+    });
+  });
 
+  describe('#warnBeforeDecommission()', function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
+      sinon.stub(controller, "showHbaseActiveWarning", Em.K);
+      sinon.stub(controller, "checkRegionServerState", Em.K);
     });
     afterEach(function () {
-      App.ajax.send.restore();
+      controller.checkRegionServerState.restore();
+      controller.showHbaseActiveWarning.restore();
     });
 
-    it('Query should be sent', function () {
-      controller.doDecommissionRegionServer('', '', '', '');
-      expect(App.ajax.send.calledOnce).to.be.true;
+    it('Component in passive state', function () {
+      controller.set('content.hostComponents', [Em.Object.create({
+        componentName: 'HBASE_REGIONSERVER',
+        passiveState: 'ON'
+      })]);
+      controller.warnBeforeDecommission('host1');
+      expect(controller.checkRegionServerState.calledOnce).to.be.true;
+    });
+    it('Component is not in passive state', function () {
+      controller.set('content.hostComponents', [Em.Object.create({
+        componentName: 'HBASE_REGIONSERVER',
+        passiveState: 'OFF'
+      })]);
+      controller.warnBeforeDecommission('host1');
+      expect(controller.showHbaseActiveWarning.calledOnce).to.be.true;
     });
   });
 
-  /**
-   * TODO uncomment test when final rules will be implemented into warnBeforeDecommission function
-   */
-  /* describe('#warnBeforeDecommission()', function () {
-
-   beforeEach(function () {
-   sinon.stub(controller, "doDecommissionRegionServer", Em.K);
-   sinon.stub(App.ModalPopup, "show", Em.K);
-   });
-   afterEach(function () {
-   App.ModalPopup.show.restore();
-   controller.doDecommissionRegionServer.restore();
-   });
-
-   it('Component in passive state', function () {
-   controller.set('content.hostComponents', [Em.Object.create({
-   componentName: 'HBASE_REGIONSERVER',
-   passiveState: 'ON'
-   })]);
-   controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
-   expect(App.ModalPopup.show.called).to.be.false;
-   expect(controller.doDecommissionRegionServer.calledWith('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE')).to.be.true;
-   });
-   it('Component is not in passive state', function () {
-   controller.set('content.hostComponents', [Em.Object.create({
-   componentName: 'HBASE_REGIONSERVER',
-   passiveState: 'OFF'
-   })]);
-   controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
-   expect(App.ModalPopup.show.calledOnce).to.be.true;
-   expect(controller.doDecommissionRegionServer.called).to.be.false;
-   });
-   });*/
+  describe('#checkRegionServerState()', function () {
+    it('', function () {
+      expect(controller.checkRegionServerState('host1')).to.be.an('object');
+      expect(App.ajax.send.getCall(0).args[0].data.hostNames).to.equal('host1');
+    });
+  });
 
-  describe('#doRecommissionAndStart()', function () {
+  describe('#checkRegionServerStateSuccessCallback()', function () {
+    beforeEach(function () {
+      sinon.stub(controller, "doDecommissionRegionServer", Em.K);
+      sinon.stub(controller, "showRegionServerWarning", Em.K);
+    });
+    afterEach(function () {
+      controller.doDecommissionRegionServer.restore();
+      controller.showRegionServerWarning.restore();
+    });
+
+    it('Decommission all regionservers', function () {
+      var data = {
+        items: [
+          {
+            HostRoles: {
+              host_name: 'host1'
+            }
+          },
+          {
+            HostRoles: {
+              host_name: 'host2'
+            }
+          }
+        ]
+      };
+      controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1,host2'});
+      expect(controller.showRegionServerWarning.calledOnce).to.be.true;
+    });
+    it('Decommission one of two regionservers', function () {
+      var data = {
+        items: [
+          {
+            HostRoles: {
+              host_name: 'host1'
+            }
+          },
+          {
+            HostRoles: {
+              host_name: 'host2'
+            }
+          }
+        ]
+      };
+      controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1'});
+      expect(controller.doDecommissionRegionServer.calledWith('host1', "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
+    });
+    it('Decommission one of three regionservers', function () {
+      var data = {
+        items: [
+          {
+            HostRoles: {
+              host_name: 'host1'
+            }
+          },
+          {
+            HostRoles: {
+              host_name: 'host2'
+            }
+          },
+          {
+            HostRoles: {
+              host_name: 'host3'
+            }
+          }
+        ]
+      };
+      controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1'});
+      expect(controller.doDecommissionRegionServer.calledWith('host1', "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
+    });
+  });
 
+  describe('#showRegionServerWarning()', function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
+      sinon.stub(App.ModalPopup, 'show', Em.K);
     });
     afterEach(function () {
-      App.ajax.send.restore();
+      App.ModalPopup.show.restore();
     });
+    it('', function () {
+      controller.showRegionServerWarning();
+      expect(App.ModalPopup.show.calledOnce).to.be.true;
+    });
+  });
 
+  describe('#doRecommissionAndStart()', function () {
     it('Query should be sent', function () {
       controller.doRecommissionAndStart('', '', '', '');
       expect(App.ajax.send.calledOnce).to.be.true;
@@ -882,14 +916,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#doRecommissionAndRestart()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       controller.doRecommissionAndRestart('', '', '', '');
       expect(App.ajax.send.calledOnce).to.be.true;
@@ -995,14 +1021,6 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#hostPassiveModeRequest()', function () {
-
-    beforeEach(function () {
-      sinon.stub(App.ajax, "send", Em.K);
-    });
-    afterEach(function () {
-      App.ajax.send.restore();
-    });
-
     it('Query should be sent', function () {
       controller.hostPassiveModeRequest('', '');
       expect(App.ajax.send.calledOnce).to.be.true;
@@ -1456,11 +1474,9 @@ describe('App.MainHostDetailsController', function () {
   describe('#executeCustomCommands', function() {
     beforeEach(function () {
       sinon.spy(App, "showConfirmationPopup");
-      sinon.stub(App.ajax, "send", Em.K);
     });
     afterEach(function () {
       App.showConfirmationPopup.restore();
-      App.ajax.send.restore();
     });
 
     it('confirm popup should be displayed', function () {

+ 28 - 0
ambari-web/test/controllers/main/host_test.js

@@ -156,4 +156,32 @@ describe('MainHostController', function () {
     });
   });
 
+  describe('#warnBeforeDecommissionSuccess()', function () {
+    var mock = {
+      showHbaseActiveWarning: Em.K,
+      checkRegionServerState: Em.K
+    };
+    beforeEach(function () {
+      hostController = App.MainHostController.create({});
+      sinon.stub(App.router, 'get', function () {
+        return mock;
+      });
+      sinon.spy(mock, 'showHbaseActiveWarning');
+      sinon.spy(mock, 'checkRegionServerState');
+    });
+    afterEach(function () {
+      App.router.get.restore();
+      mock.showHbaseActiveWarning.restore();
+      mock.checkRegionServerState.restore();
+    });
+
+    it('items length more than 0', function () {
+      hostController.warnBeforeDecommissionSuccess({items: [1]}, {}, {});
+      expect(mock.showHbaseActiveWarning.calledOnce).to.be.true;
+    });
+    it('items length equal 0', function () {
+      hostController.warnBeforeDecommissionSuccess({items: []}, {}, {hostNames: 'host1'});
+      expect(mock.checkRegionServerState.calledWith('host1')).to.be.true;
+    });
+  });
 });