Explorar o código

AMBARI-9062 Kerberos Wizard: prereq check (with mock data). (ababiichuk)

aBabiichuk %!s(int64=10) %!d(string=hai) anos
pai
achega
7efa121200

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

@@ -55,6 +55,7 @@ App.isManagedMySQLForHiveEnabled = false;
 App.enableExperimental = false;
 
 App.supports = {
+  preKerberizeCheck: false,
   preUpgradeCheck: true,
   stackUpgrade: true,
   autoRollbackHA: false,

+ 38 - 0
ambari-web/app/controllers/main/admin/kerberos.js

@@ -64,6 +64,44 @@ App.MainAdminKerberosController = App.KerberosWizardStep4Controller.extend({
     return this.get('securityEnabled');
   },
 
+  /**
+   * performes clustere check before kerbefos security
+   * wizard starts if <code>preKerberizeCheck<code> supports is true
+   * otherwise runs <code>startKerberosWizard<code>
+   * @method checkAndStartKerberosWizard
+   */
+  checkAndStartKerberosWizard: function() {
+    if (App.get('supports.preKerberizeCheck')) {
+      App.ajax.send({
+        name: "admin.kerberos_security.checks",
+        sender: this,
+        success: "runSecurityCheckSuccess"
+      });
+    } else {
+      this.startKerberosWizard();
+    }
+  },
+
+  /**
+   * success callback of <code>checkAndStartKerberosWizard()</code>
+   * if there are some fails - it shows popup else open security wizard
+   * @param data {object}
+   * @param opt {object}
+   * @param params {object}
+   * @returns {App.ModalPopup|undefined}
+   */
+  runSecurityCheckSuccess: function (data, opt, params) {
+    //TODO correct check
+    if (data.items.someProperty('UpgradeChecks.status', "FAIL")) {
+      var header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label);
+      var title = Em.I18n.t('popup.clusterCheck.Security.title');
+      var alert = Em.I18n.t('popup.clusterCheck.Security.alert');
+      App.showClusterCheckPopup(data, header, title, alert);
+    } else {
+      this.startKerberosWizard();
+    }
+  },
+
   startKerberosWizard: function () {
     this.setAddSecurityWizardStatus('RUNNING');
     App.router.transitionTo('adminAddKerberos');

+ 4 - 9
ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js

@@ -316,15 +316,10 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
    */
   runPreUpgradeCheckSuccess: function (data, opt, params) {
     if (data.items.someProperty('UpgradeChecks.status', "FAIL")) {
-      return App.ModalPopup.show({
-        header: Em.I18n.t('admin.stackUpgrade.preupgradeCheck.header').format(params.label),
-        primary: Em.I18n.t('common.dismiss'),
-        secondary: false,
-        bodyClass: Em.View.extend({
-          templateName: require('templates/main/admin/stack_upgrade/pre_upgrade_check_dialog'),
-          checks: data.items.filterProperty('UpgradeChecks.status', "FAIL")
-        })
-      })
+      var header = Em.I18n.t('popup.clusterCheck.Upgrade.header').format(params.label);
+      var title = Em.I18n.t('popup.clusterCheck.Upgrade.title');
+      var alert = Em.I18n.t('popup.clusterCheck.Upgrade.alert');
+      App.showClusterCheckPopup(data, header, title, alert);
     } else {
       this.upgrade(params);
     }

+ 9 - 5
ambari-web/app/messages.js

@@ -312,6 +312,15 @@ Em.I18n.translations = {
   'popup.confirmationFeedBack.sending':'Sending...',
   'popup.confirmationFeedBack.query.fail':'Request failed',
 
+  'popup.clusterCheck.failedOn': 'Failed on: ',
+  'popup.clusterCheck.reason': 'Reason: ',
+  'popup.clusterCheck.Upgrade.header': 'Upgrade to {0}',
+  'popup.clusterCheck.Upgrade.title': 'Upgrade Requirements Not Met',
+  'popup.clusterCheck.Upgrade.alert': 'You must meet the following requirements before you can proceed with rolling upgrade.',
+  'popup.clusterCheck.Security.header': 'Enable Security',
+  'popup.clusterCheck.Security.title': 'Security Requirements Not Met',
+  'popup.clusterCheck.Security.alert': 'You must meet the following requirements before you can enable security.',
+
   'login.header':'Sign in',
   'login.username':'Username',
   'login.loginButton':'Sign in',
@@ -1347,11 +1356,6 @@ Em.I18n.translations = {
   'admin.stackUpgrade.dialog.closePause': "Upgrade is paused. \n If you dismiss this window, you can resume Upgrade later.",
   'admin.stackUpgrade.dialog.details.open': "show details",
   'admin.stackUpgrade.dialog.details.hide': "hide details",
-  'admin.stackUpgrade.preupgradeCheck.header': "Upgrade to {0}",
-  'admin.stackUpgrade.preupgradeCheck.title': "Upgrade Requirements Not Met",
-  'admin.stackUpgrade.preupgradeCheck.alert': "You must meet the following requirements before you can proceed with rolling upgrade.",
-  'admin.stackUpgrade.preupgradeCheck.failedOn': "Failed on: ",
-  'admin.stackUpgrade.preupgradeCheck.reason': "Reason: ",
   'services.service.start':'Start',
   'services.service.stop':'Stop',
   'services.service.metrics':'Metrics',

+ 3 - 3
ambari-web/app/templates/main/admin/stack_upgrade/pre_upgrade_check_dialog.hbs → ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs

@@ -16,14 +16,14 @@
 * limitations under the License.
 }}
 <div id="pre-upgrade-check">
-  <h4>{{t admin.stackUpgrade.preupgradeCheck.title}}</h4>
+  <h4>{{view.title}}</h4>
   <div class="alert alert-warning">
-    {{t admin.stackUpgrade.preupgradeCheck.alert}}
+    {{view.alert}}
   </div>
   <div class="limited-height-2">
     {{#each item in view.checks}}
         <i class="icon-remove"></i>&nbsp;<span>{{item.UpgradeChecks.check}}</span>
-        <pre>{{t admin.stackUpgrade.preupgradeCheck.reason}}{{item.UpgradeChecks.reason}}<br/>{{t admin.stackUpgrade.preupgradeCheck.failedOn}}{{item.UpgradeChecks.failed_on}}</pre>
+        <pre>{{t popup.clusterCheck.reason}}{{item.UpgradeChecks.reason}}<br/>{{t popup.clusterCheck.failedOn}}{{item.UpgradeChecks.failed_on}}</pre>
     {{/each}}
   </div>
 </div>

+ 1 - 1
ambari-web/app/templates/main/admin/kerberos.hbs

@@ -29,7 +29,7 @@
   {{else}}
     <div>
       <p class="muted">{{t admin.security.disabled}}
-        <a class="btn btn-padding btn-success admin-enable-security-btn" {{action startKerberosWizard target="controller"}}>{{t admin.kerberos.button.enable}} </a>
+        <a class="btn btn-padding btn-success admin-enable-security-btn" {{action checkAndStartKerberosWizard target="controller"}}>{{t admin.kerberos.button.enable}} </a>
         <br/>
       </p>
     </div>

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

@@ -1383,6 +1383,12 @@ var urls = {
     'mock': '/data/stack_versions/pre_upgrade_check.json'
   },
 
+  'admin.kerberos_security.checks': {
+    //TODO when api will be known
+    'real': '',
+    'mock': '/data/stack_versions/pre_upgrade_check.json'
+  },
+
   'wizard.advanced_repositories.valid_url': {
     'real': '/stacks/{stackName}/versions/{stackVersion}/operating_systems/{osType}/repositories/{repoId}',
     'mock': '',

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

@@ -30,6 +30,7 @@ require('views/common/modal_popups/confirmation_feedback_popup');
 require('views/common/modal_popups/confirmation_popup');
 require('views/common/modal_popups/prompt_popup');
 require('views/common/modal_popups/reload_popup');
+require('views/common/modal_popups/cluster_check_popup');
 require('views/common/editable_list');
 require('views/common/rolling_restart_view');
 require('views/common/select_custom_date_view');

+ 42 - 0
ambari-web/app/views/common/modal_popups/cluster_check_popup.js

@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+/**
+ * popup to display requirements that are not met
+ * for current action
+ * @param data
+ * @param header
+ * @param title
+ * @param alert
+ * @returns {*|void}
+ */
+App.showClusterCheckPopup = function (data, header, title, alert) {
+  return App.ModalPopup.show({
+    primary: Em.I18n.t('common.dismiss'),
+    secondary: false,
+    header: header,
+    bodyClass: Em.View.extend({
+      title: title,
+      alert: alert,
+      templateName: require('templates/common/modal_popups/cluster_check_dialog'),
+      checks: data.items.filterProperty('UpgradeChecks.status', "FAIL")
+    })
+  });
+};

+ 43 - 2
ambari-web/test/controllers/main/admin/kerberos_test.js

@@ -19,14 +19,16 @@
 var App = require('app');
 
 describe('App.MainAdminKerberosController', function() {
+
+  var controller = App.MainAdminKerberosController.create({});
+
   describe('#prepareConfigProperties', function() {
     beforeEach(function() {
-      this.controller = App.MainAdminKerberosController.create({});
       sinon.stub(App.Service, 'find').returns([
         Em.Object.create({ serviceName: 'KERBEROS'}),
         Em.Object.create({ serviceName: 'HDFS' })
       ]);
-      this.result = this.controller.prepareConfigProperties([
+      this.result = controller.prepareConfigProperties([
         Em.Object.create({ name: 'prop1', isEditable: true, serviceName: 'SERVICE1'}),
         Em.Object.create({ name: 'prop2', isEditable: true, serviceName: 'KERBEROS'}),
         Em.Object.create({ name: 'prop3', isEditable: true, serviceName: 'HDFS'}),
@@ -53,4 +55,43 @@ describe('App.MainAdminKerberosController', function() {
       });
     });
   });
+
+  describe("#runSecurityCheckSuccess()", function () {
+    beforeEach(function () {
+      sinon.stub(App, 'showClusterCheckPopup', Em.K);
+      sinon.stub(controller, 'startKerberosWizard', Em.K);
+    });
+    afterEach(function () {
+      App.showClusterCheckPopup.restore();
+      controller.startKerberosWizard.restore();
+    });
+    it("shows popup", function () {
+      var check =  { items: [{
+        UpgradeChecks: {
+          "check": "Work-preserving RM/NM restart is enabled in YARN configs",
+          "status": "FAIL",
+          "reason": "FAIL",
+          "failed_on": [],
+          "check_type": "SERVICE"
+        }
+      }]};
+      controller.runSecurityCheckSuccess(check,null,{label: "name"});
+      expect(controller.startKerberosWizard.called).to.be.false;
+      expect(App.showClusterCheckPopup.called).to.be.true;
+    });
+    it("runs startKerberosWizard", function () {
+      var check = { items: [{
+        UpgradeChecks: {
+          "check": "Work-preserving RM/NM restart is enabled in YARN configs",
+          "status": "PASS",
+          "reason": "OK",
+          "failed_on": [],
+          "check_type": "SERVICE"
+        }
+      }]};
+      controller.runSecurityCheckSuccess(check,null,{label: "name"});
+      expect(controller.startKerberosWizard.called).to.be.true;
+      expect(App.showClusterCheckPopup.called).to.be.false;
+    });
+  });
 });

+ 6 - 6
ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js

@@ -256,11 +256,11 @@ describe('App.MainAdminStackAndUpgradeController', function() {
 
   describe("#runPreUpgradeCheckSuccess()", function () {
     beforeEach(function () {
-      sinon.stub(App.ModalPopup, 'show', Em.K);
+      sinon.stub(App, 'showClusterCheckPopup', Em.K);
       sinon.stub(controller, 'upgrade', Em.K);
     });
     afterEach(function () {
-      App.ModalPopup.show.restore();
+      App.showClusterCheckPopup.restore();
       controller.upgrade.restore();
     });
     it("shows popup", function () {
@@ -274,8 +274,8 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         }
       }]};
       controller.runPreUpgradeCheckSuccess(check,null,{label: "name"});
-      expect(controller.upgrade.calledOnce).to.be.false;
-      expect(App.ModalPopup.show.calledOnce).to.be.true;
+      expect(controller.upgrade.called).to.be.false;
+      expect(App.showClusterCheckPopup.called).to.be.true;
     });
     it("runs upgrade popup", function () {
       var check = { items: [{
@@ -288,8 +288,8 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         }
       }]};
       controller.runPreUpgradeCheckSuccess(check,null,{label: "name"});
-      expect(controller.upgrade.calledOnce).to.be.true;
-      expect(App.ModalPopup.show.calledOnce).to.be.false;
+      expect(controller.upgrade.called).to.be.true;
+      expect(App.showClusterCheckPopup.called).to.be.false;
     });
   });