浏览代码

AMBARI-16419: PXF should be collocated with NAMENODE even if NAMENODE is moved to another host (mithmatt)

Matt 9 年之前
父节点
当前提交
b86507829d

+ 18 - 0
ambari-web/app/controllers/main/service/reassign/step6_controller.js

@@ -42,6 +42,20 @@ App.ReassignMasterWizardStep6Controller = App.HighAvailabilityProgressPageContro
     } else {
       this.set('hostComponents', [this.get('content.reassign.component_name')]);
     }
+
+    if (App.Service.find().someProperty('serviceName', 'PXF') && this.get('content.reassign.component_name') === 'NAMENODE') {
+      var pxfHosts = App.HostComponent.find().filterProperty('componentName', 'PXF').mapProperty('hostName');
+      var dataNodeHosts = App.HostComponent.find().filterProperty('componentName', 'DATANODE').mapProperty('hostName');
+
+      // If NAMENODE is being moved and source host does not have DATANODE, PXF should be removed from source host
+      if (pxfHosts.contains(this.get('content.reassignHosts.source')) && !dataNodeHosts.contains(this.get('content.reassignHosts.source')))
+        this.get('hostComponents').push('PXF');
+
+      // If NAMENODE is being moved and target host does not have PXF, PXF should be added to target host
+      if (!pxfHosts.contains(this.get('content.reassignHosts.target')))
+        this.get('commands').splice(this.get('commands').indexOf('startAllServices'), 0, 'installPxf');
+    }
+
     this._super();
   },
 
@@ -118,6 +132,10 @@ App.ReassignMasterWizardStep6Controller = App.HighAvailabilityProgressPageContro
     }
   },
 
+  installPxf: function () {
+    this.createInstallComponentTask('PXF', this.get('content.reassignHosts.target'), "PXF");
+  },
+
   startAllServices: function () {
     this.startServices(true);
   },

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

@@ -2231,6 +2231,7 @@ Em.I18n.translations = {
   'services.reassign.step6.tasks.putHostComponentsInMaintenanceMode.title':'Disable {0}',
   'services.reassign.step6.tasks.deleteHostComponents.title': 'Delete disabled {0}',
   'services.reassign.step6.tasks.startAllServices.title': 'Start All Services',
+  'services.reassign.step6.tasks.installPxf.title': 'Install PXF on NameNode',
   'services.reassign.step6.tasks.stopMysqlService.title': 'Stop Mysql Server',
   'services.reassign.step6.tasks.stopHostComponentsInMaintenanceMode.title': 'Stop {0}',
   'services.reassign.step6.status.success': 'Successfully moved <b>{0}</b> from <b>{1}</b> host to <b>{2}</b> host.',

+ 95 - 0
ambari-web/test/controllers/main/service/reassign/step6_controller_test.js

@@ -138,6 +138,101 @@ describe('App.ReassignMasterWizardStep6Controller', function () {
     });
   });
 
+  describe('#loadStep() for reassign NameNode with PXF service installed', function () {
+
+    var serviceStub, hostComponentStub, pxfHosts, dataNodeHosts;
+
+    var commands = [
+      'stopMysqlService',
+      'putHostComponentsInMaintenanceMode',
+      'stopHostComponentsInMaintenanceMode',
+      'deleteHostComponents',
+      'startAllServices'
+    ];
+
+    var reassignHosts = {
+      "source": "c6401.ambari.apache.org",
+      "target": "c6403.ambari.apache.org"
+    };
+
+    beforeEach(function () {
+      controller.set('content.reassign.service_id', 'HDFS');
+      controller.set('content.reassign.component_name', 'NAMENODE');
+      controller.set('commands', commands.copy());
+      controller.set('content.reassignHosts', reassignHosts);
+      sinon.stub(controller, 'onTaskStatusChange', Em.K);
+      sinon.stub(controller, 'initializeTasks', Em.K);
+      serviceStub = sinon.stub(App.Service.find(), 'someProperty');
+      hostComponentStub = sinon.stub(App.HostComponent.find(), 'filterProperty');
+      serviceStub.withArgs('serviceName', 'PXF').returns(true);
+    });
+
+    afterEach(function () {
+      controller.onTaskStatusChange.restore();
+      controller.initializeTasks.restore();
+      serviceStub.restore();
+      hostComponentStub.restore();
+    });
+
+    var setUpHosts = function (pxfHosts, dataNodeHosts) {
+      hostComponentStub.withArgs('componentName', 'PXF').returns(pxfHosts);
+      hostComponentStub.withArgs('componentName', 'DATANODE').returns(dataNodeHosts);
+    };
+
+    it('does not delete PXF from source host if PXF and DATANODE are not installed on the source host', function () {
+      pxfHosts = [{"hostName": "c6402.ambari.apache.org"}];
+      dataNodeHosts = [{"hostName": "c6402.ambari.apache.org"}];
+      setUpHosts(pxfHosts, dataNodeHosts);
+
+      controller.loadStep();
+      expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
+    });
+
+    it('does not delete PXF from source host if PXF is not installed on the source host and DATANODE is installed on the source host', function () {
+      pxfHosts = [{"hostName": "c6402.ambari.apache.org"}];
+      dataNodeHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
+      setUpHosts(pxfHosts, dataNodeHosts);
+
+      controller.loadStep();
+      expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
+    });
+
+    it('deletes PXF from source host if PXF is installed on the source host and DATANODE is not installed on the source host', function () {
+      pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
+      dataNodeHosts = [{"hostName": "c6402.ambari.apache.org"}];
+      setUpHosts(pxfHosts, dataNodeHosts);
+
+      controller.loadStep();
+      expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'PXF']);
+    });
+
+    it('does not delete PXF from source host if PXF and DATANODE are installed on the source host', function () {
+      pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
+      dataNodeHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
+      setUpHosts(pxfHosts, dataNodeHosts);
+
+      controller.loadStep();
+      expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
+    });
+
+    it('does not install PXF on the target host if PXF is already installed on the target host', function () {
+      pxfHosts = [{"hostName": "c6403.ambari.apache.org"}];
+      setUpHosts(pxfHosts, []);
+
+      controller.loadStep();
+      expect(controller.get('commands').indexOf('installPxf')).to.eql(-1);
+    });
+
+    it('installs PXF on the target host if PXF is not installed on the target host', function () {
+      pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
+      setUpHosts(pxfHosts, []);
+
+      controller.loadStep();
+      expect(controller.get('commands').indexOf('installPxf')).to.eql(4);
+    });
+
+  });
+
   describe('#deleteHostComponents()', function () {
 
     it('No host components', function () {