Browse Source

AMBARI-4937 Refactoring of Choose Services step in wizard. (atkach)

atkach 11 years ago
parent
commit
489d145ca8

+ 65 - 87
ambari-web/app/controllers/wizard/step4_controller.js

@@ -46,23 +46,18 @@ App.WizardStep4Controller = Em.ArrayController.extend({
    * Update hidden services. Make them to have the same status as master ones.
    */
   checkDependencies: function () {
-    var hbase = this.findProperty('serviceName', 'HBASE');
-    var zookeeper = this.findProperty('serviceName', 'ZOOKEEPER');
-    var hive = this.findProperty('serviceName', 'HIVE');
-    var hcatalog = this.findProperty('serviceName', 'HCATALOG');
-    var webhcat = this.findProperty('serviceName', 'WEBHCAT');
-    var yarn = this.findProperty('serviceName', 'YARN');
-    var mapreduce2 = this.findProperty('serviceName', 'MAPREDUCE2');
-    var oozie = this.findProperty('serviceName', 'OOZIE');
-    var falcon = this.findProperty('serviceName', 'FALCON');
+    var services = {};
+    this.forEach(function (service) {
+      services[service.get('serviceName')] = service;
+    });
 
     // prevent against getting error when not all elements have been loaded yet
-    if (hbase && zookeeper && hive && hcatalog && webhcat) {
-      if (yarn && mapreduce2) {
-        mapreduce2.set('isSelected', yarn.get('isSelected'));
+    if (services['HBASE'] && services['ZOOKEEPER'] && services['HIVE'] && services['HCATALOG'] && services['WEBHCAT']) {
+      if (services['YARN'] && services['MAPREDUCE2']) {
+        services['MAPREDUCE2'].set('isSelected', services['YARN'].get('isSelected'));
       }
-      hcatalog.set('isSelected', hive.get('isSelected'));
-      webhcat.set('isSelected', hive.get('isSelected'));
+      services['HCATALOG'].set('isSelected', services['HIVE'].get('isSelected'));
+      services['WEBHCAT'].set('isSelected', services['HIVE'].get('isSelected'));
     }
   }.observes('@each.isSelected'),
 
@@ -132,15 +127,12 @@ App.WizardStep4Controller = Em.ArrayController.extend({
    * Check whether we should turn on <code>ZooKeeper</code> service
    * @return {Boolean}
    */
-  needToAddZooKeeper: function() {
-    return this.needAddService('ZOOKEEPER', ['HBASE','HIVE','WEBHCAT','STORM']);
-  },
-  /**
-   * Check whether we should turn on <code>ZooKeeper</code> service (on 2.x stack)
-   * @returns {Boolean}
-   */
-  needToAddZooKeeperOnStack2x: function() {
-    return this.findProperty('serviceName', 'ZOOKEEPER') && this.findProperty('serviceName', 'ZOOKEEPER').get('isSelected') === false;
+  needToAddZooKeeper: function () {
+    if (App.get('isHadoop2Stack')) {
+      return this.findProperty('serviceName', 'ZOOKEEPER') && this.findProperty('serviceName', 'ZOOKEEPER').get('isSelected') === false;
+    } else {
+      return this.needAddService('ZOOKEEPER', ['HBASE', 'HIVE', 'WEBHCAT', 'STORM']);
+    }
   },
   /** 
    * Check whether we should turn on <code>HDFS or GLUSTERFS</code> service
@@ -179,45 +171,62 @@ App.WizardStep4Controller = Em.ArrayController.extend({
     }
   },
 
+  /**
+   * submit checks describe dependency rules between services
+   * @checkCallback - callback, which check for dependency
+   * @popupParams - parameters for popup
+   */
+  submitChecks: [
+    {
+      checkCallback: 'needToAddMapReduce',
+      popupParams: [{serviceName: 'MAPREDUCE', selected: true}, 'mapreduceCheck']
+    },
+    {
+      checkCallback: 'noDFSs',
+      popupParams: [{serviceName:'HDFS', selected: true}, 'hdfsCheck']
+    },
+    {
+      checkCallback: 'needToAddYarnMapReduce2',
+      popupParams: [{serviceName:'YARN', selected:true}, 'yarnCheck']
+    },
+    {
+      checkCallback: 'needToAddZooKeeper',
+      popupParams: [{serviceName:'ZOOKEEPER', selected: true}, 'zooKeeperCheck']
+    },
+    {
+      checkCallback: 'multipleDFSs',
+      popupParams: [[
+        {serviceName: 'HDFS', selected: true},
+        {serviceName: 'GLUSTERFS', selected: false}
+      ], 'multipleDFS']
+    },
+    {
+      checkCallback: 'needToAddOozie',
+      popupParams: [{serviceName:'OOZIE', selected: true}, 'oozieCheck']
+    },
+    {
+      checkCallback: 'needToAddTez',
+      popupParams: [{serviceName:'TEZ', selected: true}, 'tezCheck']
+    }
+  ],
+
   /**
    * Onclick handler for <code>Next</code> button
    */
   submit: function () {
-    if(!this.get("isSubmitDisabled")) {
-      if (this.needToAddMapReduce()) {
-        this.mapReduceCheckPopup();
-      }
-      else {
-        if (this.noDFSs()) {
-          this.needToAddHDFSPopup();
-        }
-        else {
-          if (this.needToAddYarnMapReduce2()) {
-            this.mapReduce2CheckPopup();
-          }
-          else {
-            if ((!App.get('isHadoop2Stack') && this.needToAddZooKeeper()) || (App.get('isHadoop2Stack') && this.needToAddZooKeeperOnStack2x())) {
-              this.zooKeeperCheckPopup();
-            }
-            else {
-              if (this.multipleDFSs()) {
-                this.multipleDFSPopup();
-              }
-              else {
-                if(this.needToAddOozie()) {
-                  this.oozieCheckPopup();
-                }
-                else if (this.needToAddTez()) {
-                  this.tezCheckPopup();
-                }
-                else {
-                  this.validateMonitoring();
-                }
-              }
-            }
-          }
+    var submitChecks = this.get('submitChecks');
+    var doValidateMonitoring = true;
+    if (!this.get("isSubmitDisabled")) {
+      for (var i = 0; i < submitChecks.length; i++) {
+        if (this[submitChecks[i].checkCallback].call(this)) {
+          doValidateMonitoring = false;
+          this.needToAddServicePopup.apply(this, submitChecks[i].popupParams);
+          break;
         }
       }
+      if (doValidateMonitoring) {
+        this.validateMonitoring();
+      }
     }
   },
   
@@ -253,37 +262,6 @@ App.WizardStep4Controller = Em.ArrayController.extend({
     });
   },
 
-  multipleDFSPopup: function() {
-    var services = [
-      {serviceName: 'HDFS', selected: true},
-      {serviceName: 'GLUSTERFS', selected: false}
-    ];
-    this.needToAddServicePopup(services, 'multipleDFS');
-  },
-  needToAddHDFSPopup: function() {
-    this.needToAddServicePopup({serviceName:'HDFS', selected: true}, 'hdfsCheck');
-  },
-
-  mapReduceCheckPopup: function () {
-    this.needToAddServicePopup({serviceName:'MAPREDUCE', selected: true}, 'mapreduceCheck');
-  },
-
-  mapReduce2CheckPopup: function () {
-    this.needToAddServicePopup({serviceName:'YARN', selected:true}, 'yarnCheck');
-  },
-
-  tezCheckPopup: function() {
-    this.needToAddServicePopup({serviceName:'TEZ', selected: true}, 'tezCheck');
-  },
-
-  zooKeeperCheckPopup: function () {
-    this.needToAddServicePopup({serviceName:'ZOOKEEPER', selected: true}, 'zooKeeperCheck');
-  },
-
-  oozieCheckPopup: function () {
-    this.needToAddServicePopup({serviceName:'OOZIE', selected: true}, 'oozieCheck');
-  },
-
   monitoringCheckPopup: function () {
     App.ModalPopup.show({
       header: Em.I18n.t('installer.step4.monitoringCheck.popup.header'),

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

@@ -21,6 +21,7 @@ var validator = require('utils/validator');
 require('utils/component');
 require('utils/batch_scheduled_requests');
 require('controllers/main/host');
+require('mappers/server_data_mapper');
 
 describe('MainHostController', function () {
 

+ 176 - 35
ambari-web/test/installer/step4_test.js

@@ -23,13 +23,14 @@ require('controllers/wizard/step4_controller');
 describe('App.WizardStep4Controller', function () {
 
   var services = [
-    'HDFS', 'MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER', 'HCATALOG', 'WEBHCAT', 'YARN', 'MAPREDUCE2'
+    'HDFS', 'MAPREDUCE', 'NAGIOS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER', 'HCATALOG',
+    'WEBHCAT', 'YARN', 'MAPREDUCE2', 'FALCON', 'TEZ', 'STORM'
   ];
 
   var controller = App.WizardStep4Controller.create();
   services.forEach(function(serviceName, index){
     controller.pushObject(Ember.Object.create({
-      'serviceName':serviceName, 'isSelected': true, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': index == 0
+      'serviceName':serviceName, 'isSelected': true, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName
     }));
   });
 
@@ -68,37 +69,6 @@ describe('App.WizardStep4Controller', function () {
     });
   });
 
-  var ajax_send;
-  describe('#checkDependencies()', function () {
-
-    beforeEach(function() {
-      ajax_send = App.ajax.send;
-      App.ajax.send = function() {};
-    });
-
-    afterEach(function() {
-      App.ajax.send = ajax_send;
-    });
-
-    it('should set ZooKeeper, HCatalog, WebHCatalog isSelected property like in Hive', function () {
-      controller.setEach('isSelected', false);
-      controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
-      controller.checkDependencies();
-      expect(controller.findProperty('serviceName', 'HCATALOG').get('isSelected')).to.equal(true);
-      expect(controller.findProperty('serviceName', 'WEBHCAT').get('isSelected')).to.equal(true);
-    });
-    it('should set MapReduce2 isSelected property like in Yarn', function () {
-      App.set('currentStackVersion', 'HDP-2.0.1');
-      App.set('defaultStackVersion', 'HDP-2.0.1');
-      controller.setEach('isSelected', false);
-      controller.findProperty('serviceName', 'YARN').set('isSelected', true);
-      controller.checkDependencies();
-      expect(controller.findProperty('serviceName', 'MAPREDUCE2').get('isSelected')).to.equal(true);
-      App.set('currentStackVersion', 'HDP-1.2.2');
-      App.set('defaultStackVersion', 'HDP-1.2.2');
-    });
-  });
-
   describe('#selectAll()', function () {
     it('should select all services', function () {
       controller.setEach('isSelected', false);
@@ -171,12 +141,40 @@ describe('App.WizardStep4Controller', function () {
   });
 
   describe('#needToAddZooKeeper()', function () {
-    it('should return false if ZOOKEEPER is selected or HBASE is not selected', function () {
+    beforeEach(function() {
+      ajax_send = App.ajax.send;
+      App.ajax.send = function() {};
+    });
+
+    afterEach(function() {
+      App.ajax.send = ajax_send;
+    });
+    var originalStackVersion = App.get('currentStackVersion');
+
+    it('should return false if ZOOKEEPER is selected and Hadoop version above 2', function () {
+      App.set('currentStackVersion', 'HDP-2.1.1');
       controller.findProperty('serviceName', 'ZOOKEEPER').set('isSelected', true);
       expect(controller.needToAddZooKeeper()).to.equal(false);
-      controller.setEach('isSelected', false);
+    });
+    it('should return true if ZOOKEEPER is not selected and Hadoop version above 2', function () {
+      controller.findProperty('serviceName', 'ZOOKEEPER').set('isSelected', false);
+      expect(controller.needToAddZooKeeper()).to.equal(true);
+    });
+    it('should return false if none of the HBASE, HIVE, WEBHCAT, STORM is selected and Hadoop version below 2', function () {
+      App.set('currentStackVersion', 'HDP-1.3.0');
       expect(controller.needToAddZooKeeper()).to.equal(false);
     });
+    it('should return true if HBASE is not selected and Hadoop version below 2', function () {
+      controller.findProperty('serviceName', 'HBASE').set('isSelected', true);
+      expect(controller.needToAddZooKeeper()).to.equal(true);
+    });
+    it('should return true if HBASE, HIVE, WEBHCAT, STORM are selected and Hadoop version below 2', function () {
+      controller.findProperty('serviceName', 'HIVE').set('isSelected', true);
+      controller.findProperty('serviceName', 'WEBHCAT').set('isSelected', true);
+      controller.findProperty('serviceName', 'STORM').set('isSelected', true);
+      expect(controller.needToAddZooKeeper()).to.equal(true);
+      App.set('currentStackVersion', originalStackVersion);
+    });
   });
 
   describe('#gangliaOrNagiosNotSelected()', function () {
@@ -197,4 +195,147 @@ describe('App.WizardStep4Controller', function () {
     });
   });
 
+  describe('#needToAddTez()', function () {
+    it('should return false if YARN is present, but not selected', function () {
+      controller.findProperty('serviceName', 'YARN').set('isSelected', false);
+      expect(controller.needToAddTez()).to.equal(false);
+    });
+    it('should return true if YARN is selected', function () {
+      controller.findProperty('serviceName', 'YARN').set('isSelected', true);
+      expect(controller.needToAddTez()).to.equal(true);
+    });
+  });
+
+  describe('#needToAddOozie()', function () {
+    it('should return false if FALCON is present, but not selected', function () {
+      controller.findProperty('serviceName', 'FALCON').set('isSelected', false);
+      expect(controller.needToAddOozie()).to.equal(false);
+    });
+    it('should return true if FALCON is selected', function () {
+      controller.findProperty('serviceName', 'FALCON').set('isSelected', true);
+      expect(controller.needToAddOozie()).to.equal(true);
+    });
+  });
+
+  describe('#noDFSs()', function () {
+    it('should return true if HDFS is not selected and GLUSTERFS is absent', function () {
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
+      expect(controller.noDFSs()).to.equal(true);
+    });
+    it('should return false if HDFS is selected and GLUSTERFS is absent', function () {
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
+      expect(controller.noDFSs()).to.equal(false);
+    });
+    it('should return true if HDFS is not selected and GLUSTERFS is not selected, but present', function () {
+      controller.pushObject(Ember.Object.create({
+        'serviceName':'GLUSTERFS', 'isSelected': false, 'canBeSelected': true, 'isInstalled': false, 'isDisabled': false
+      }));
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
+      expect(controller.noDFSs()).to.equal(true);
+    });
+    it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
+      controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
+      expect(controller.noDFSs()).to.equal(false);
+    });
+  });
+
+  describe('#multipleDFSs()', function () {
+    it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
+      controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', true);
+      expect(controller.multipleDFSs()).to.equal(true);
+    });
+    it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
+      expect(controller.multipleDFSs()).to.equal(false);
+    });
+    it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
+      controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
+      controller.findProperty('serviceName', 'GLUSTERFS').set('isSelected', false);
+      expect(controller.multipleDFSs()).to.equal(false);
+    });
+  });
+
+  describe('#checkDependencies()', function () {
+    var testCases = [
+      {
+        title: 'should set HCATALOG and WEBHCAT isSelected to true when HIVE is selected',
+        condition: {
+          'HBASE': true,
+          'ZOOKEEPER': true,
+          'HIVE': true,
+          'HCATALOG': true,
+          'WEBHCAT': true
+        },
+        result: {
+          'HCATALOG': true,
+          'WEBHCAT': true
+        }
+      },
+      {
+        title: 'should set HCATALOG and WEBHCAT isSelected to false when HIVE is not selected',
+        condition: {
+          'HBASE': true,
+          'ZOOKEEPER': true,
+          'HIVE': false,
+          'HCATALOG': true,
+          'WEBHCAT': true
+        },
+        result: {
+          'HCATALOG': false,
+          'WEBHCAT': false
+        }
+      },
+      {
+        title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
+        condition: {
+          'HBASE': true,
+          'ZOOKEEPER': true,
+          'HIVE': false,
+          'HCATALOG': true,
+          'WEBHCAT': true,
+          'YARN': true,
+          'MAPREDUCE2': true
+        },
+        result: {
+          'MAPREDUCE2': true,
+          'HCATALOG': false,
+          'WEBHCAT': false
+        }
+      },
+      {
+        title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
+        condition: {
+          'HBASE': true,
+          'ZOOKEEPER': true,
+          'HIVE': true,
+          'HCATALOG': true,
+          'WEBHCAT': true,
+          'YARN': false,
+          'MAPREDUCE2': true
+        },
+        result: {
+          'MAPREDUCE2': false,
+          'HCATALOG': true,
+          'WEBHCAT': true
+        }
+      }
+    ];
+
+    testCases.forEach(function(testCase){
+      it(testCase.title, function () {
+        controller.clear();
+        for(var id in testCase.condition) {
+          controller.pushObject(Ember.Object.create({
+            'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false
+          }));
+        }
+        controller.checkDependencies();
+        for(var service in testCase.result) {
+          expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
+        }
+      });
+    }, this);
+  });
+
 });