Browse Source

AMBARI-9565 Add service wizard: check (and fix if needed) handling KDC credentials error. (ababiichuk)

aBabiichuk 10 years ago
parent
commit
7e667816a5

+ 2 - 2
ambari-web/app/controllers/main/admin/kerberos/step2_controller.js

@@ -263,8 +263,8 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend({
    * puts kerberos admin credentials in the live cluster session
    * @returns {*} jqXHr
    */
-  createKerberosAdminSession: function () {
-    var configs = this.get('stepConfigs')[0].get('configs');
+  createKerberosAdminSession: function (configs) {
+    configs = configs || this.get('stepConfigs')[0].get('configs');
     var adminPrincipalValue = configs.findProperty('name', 'admin_principal').value;
     var adminPasswordValue = configs.findProperty('name', 'admin_password').value;
     return App.ajax.send({

+ 95 - 18
ambari-web/app/controllers/main/service/add_controller.js

@@ -35,6 +35,11 @@ App.AddServiceController = App.WizardController.extend({
    */
   serviceToInstall: null,
 
+  /**
+   *
+   */
+  installClientQueueLength: 0,
+
   /**
    * All wizards data will be stored in this variable
    *
@@ -128,6 +133,8 @@ App.AddServiceController = App.WizardController.extend({
           this.checkSecurityStatus();
           this.load('cluster');
           this.set('content.additionalClients', []);
+          this.set('installClientQueueLength', 0);
+          this.set('installClietsQueue', App.ajaxQueue.create({}));
         }
       }
     ]
@@ -500,13 +507,37 @@ App.AddServiceController = App.WizardController.extend({
       "urlParams": "ServiceInfo/service_name.in(" + selectedServices.join(',')  + ")"
     };
   },
-  installServices: function (callback) {
+
+  /**
+   * run this method after success/error callbacks
+   * for <code>installServicesRequest<code>
+   */
+  installServicesComplete: function () {
+    this.setDBProperty('KDCAuthRequired', false);
+    App.get('router.wizardStep8Controller').set('servicesInstalled', true);
+    this.setInfoForStep9();
+    this.saveClusterState('ADD_SERVICES_INSTALLING_3');
+    App.router.transitionTo('step7');
+  },
+
+  /**
+   * main method for installinf clients
+   * @method installServices
+   */
+  installServices: function () {
+    var self = this;
+    this.setDBProperty('KDCAuthRequired', false);
     this.set('content.cluster.oldRequestsId', []);
-    this.installAdditionalClients();
+    this.installAdditionalClients().done(function () {
+      self.installSelectedServices();
+    });
+  },
+
+  installSelectedServices: function () {
     var name = 'common.services.update';
     var selectedServices = this.get('content.services').filterProperty('isInstalled', false).filterProperty('isSelected', true).mapProperty('serviceName');
     var data = this.generateDataForInstallServices(selectedServices);
-    this.installServicesRequest(name, data, callback);
+    this.installServicesRequest(name, data, this.installServicesComplete.bind(this));
   },
 
   installServicesRequest: function (name, data, callback) {
@@ -526,22 +557,68 @@ App.AddServiceController = App.WizardController.extend({
    * @method installAdditionalClients
    */
   installAdditionalClients: function () {
-    this.get('content.additionalClients').forEach(function (c) {
-      if (c.hostNames.length > 0) {
-        var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
-        App.ajax.send({
-          name: 'common.host_component.update',
-          sender: this,
-          data: {
-            query: queryStr,
-            context: 'Install ' + App.format.role(c.componentName),
-            HostRoles: {
-              state: 'INSTALLED'
-            }
-          }
-        });
+    var dfd = $.Deferred();
+    if (this.get('content.additionalClients.length') > 0) {
+      this.get('content.additionalClients').forEach(function (c, k) {
+        if (c.hostNames.length > 0) {
+          var queryStr = 'HostRoles/component_name='+ c.componentName + '&HostRoles/host_name.in(' + c.hostNames.join() + ')';
+          this.get('installClietsQueue').addRequest({
+            name: 'common.host_component.update',
+            sender: this,
+            data: {
+              query: queryStr,
+              context: 'Install ' + App.format.role(c.componentName),
+              HostRoles: {
+                state: 'INSTALLED'
+              },
+              counter: k,
+              deferred: dfd
+            },
+            success: 'installClientComplete',
+            error: 'installClientComplete',
+            kdcFailHandler: 'kdcFailHandler',
+            kdcCancelHandler: 'installSelectedServices'
+          });
+        }
+      }, this);
+      if (this.get('installClietsQueue.queue.length') == 0) {
+        return dfd.resolve();
+      } else {
+        this.set('installClientQueueLength', this.get('installClietsQueue.queue.length'));
+        App.get('router.wizardStep8Controller').set('servicesInstalled', true);
+        this.get('installClietsQueue').start();
       }
-    }, this);
+    } else {
+      dfd.resolve();
+    }
+    return dfd.promise();
+  },
+
+  /**
+   * callback for when install clients success
+   * of fail with not KDC error
+   * @param data
+   * @param params
+   * @param opt
+   * @method installClientComplete
+   */
+  installClientComplete: function(data, params, opt) {
+    if (this.getDBProperty('KDCAuthRequired')) {
+      this.setDBProperty('KDCAuthRequired', false);
+      this.installServices();
+      opt.deferred.reject();
+    } else if (this.get('installClientQueueLength') - 1 == opt.counter) {
+      opt.deferred.resolve();
+    }
+  },
+
+  /**
+   * kdc fail handler for installClients method
+   * @method kdcFailHandler
+   */
+  kdcFailHandler: function() {
+    this.setDBProperty('KDCAuthRequired', true);
+    this.saveClusterState('ADD_SERVICE_KDC_AUTHORIZATION');
   },
 
   checkSecurityStatus: function() {

+ 2 - 9
ambari-web/app/routes/add_service_routes.js

@@ -263,6 +263,7 @@ module.exports = App.WizardRoute.extend({
       }
     },
     next: function (router) {
+      router.get('kerberosWizardStep2Controller').createKerberosAdminSession(router.get('kerberosWizardStep4Controller.stepConfigs')[0].get('configs'));
       router.transitionTo('step6');
     }
   }),
@@ -305,15 +306,7 @@ module.exports = App.WizardRoute.extend({
       }
     },
     next: function (router) {
-      var addServiceController = router.get('addServiceController');
-      var wizardStep8Controller = router.get('wizardStep8Controller');
-      addServiceController.installServices(function () {
-        addServiceController.setInfoForStep9();
-
-        addServiceController.saveClusterState('ADD_SERVICES_INSTALLING_3');
-        wizardStep8Controller.set('servicesInstalled', true);
-        router.transitionTo('step7');
-      });
+      router.get('addServiceController').installServices();
     }
   }),
 

+ 18 - 2
ambari-web/app/utils/ajax/ajax.js

@@ -2313,7 +2313,8 @@ var formatRequest = function (data) {
  */
 var specialMsg = {
   "missingKDC": "Missing KDC administrator credentials.",
-  "invalidKDC": "Invalid KDC administrator credentials."
+  "invalidKDC": "Invalid KDC administrator credentials.",
+  "missingRDCForRealm": "Failed to find a KDC for the specified realm - kadmin"
 };
 /**
  * Wrapper for all ajax requests
@@ -2377,6 +2378,20 @@ var ajax = Em.Object.extend({
     opt.error = function (request, ajaxOptions, error) {
       var KDCErrorMsg = this.getKDCErrorMgs(request);
       if (!Em.isNone(KDCErrorMsg)) {
+        /**
+         * run this handler before show KDC error popup
+         */
+        if (config.kdcFailHandler) {
+          config.sender[config.kdcFailHandler](request, ajaxOptions, error, opt, params);
+        }
+        /**
+         * run this handler when click cancle on KDC error popup
+         */
+        if (config.kdcCancelHandler) {
+          opt.kdcCancelHandler = function() {
+            config.sender[config.kdcCancelHandler]();
+          };
+        }
         this.defaultErrorKDCHandler(opt, KDCErrorMsg);
       } else if (config.error) {
         config.sender[config.error](request, ajaxOptions, error, opt, params);
@@ -2445,7 +2460,8 @@ var ajax = Em.Object.extend({
     } catch (err) {}
     if (jqXHR.status === 400 && message) {
       return message.contains(specialMsg.missingKDC) ? specialMsg.missingKDC
-        : message.contains(specialMsg.invalidKDC) ? specialMsg.invalidKDC : null;
+        : message.contains(specialMsg.invalidKDC) ? specialMsg.invalidKDC :
+        specialMsg.missingRDCForRealm ? specialMsg.missingRDCForRealm : null;
     } else {
       return null;
     }

+ 12 - 0
ambari-web/app/views/common/modal_popups/invalid_KDC_popup.js

@@ -33,6 +33,18 @@ App.showInvalidKDCPopup = function (ajaxOpt, message) {
       warningMsg: message + Em.I18n.t('popup.invalid.KDC.msg'),
       templateName: require('templates/common/modal_popups/invalid_KDC_popup')
     }),
+    onClose: function() {
+      this.hide();
+      if (ajaxOpt.kdcCancelHandler) {
+        ajaxOpt.kdcCancelHandler();
+      }
+    },
+    onSecondary: function() {
+      this.hide();
+      if (ajaxOpt.kdcCancelHandler) {
+        ajaxOpt.kdcCancelHandler();
+      }
+    },
     onPrimary: function () {
       this.hide();
       App.get('router.clusterController').createKerberosAdminSession(this.get('principal'), this.get('password'), ajaxOpt);

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

@@ -55,6 +55,7 @@ describe('App.AddServiceController', function() {
         if ('clusterName' === k) return 'tdk';
         return Em.get(App, k);
       });
+      addServiceController.set('installClietsQueue', App.ajaxQueue.create())
     });
 
     afterEach(function () {