Переглянути джерело

AMBARI-5638 Error in persisting web client state when enabling security on cluster with ambari-server database set to MySQL. (atkach)

atkach 11 роки тому
батько
коміт
9ede3dee3a

+ 22 - 0
ambari-web/app/controllers/installer.js

@@ -40,6 +40,28 @@ App.InstallerController = App.WizardController.extend({
     controllerName: 'installerController'
   }),
 
+  /**
+   * Wizard properties in local storage, which should be cleaned right after wizard has been finished
+   */
+  dbPropertiesToClean: [
+    'service',
+    'hosts',
+    'masterComponentHosts',
+    'slaveComponentHosts',
+    'cluster',
+    'allHostNames',
+    'installOptions',
+    'allHostNamesPattern',
+    'serviceComponents',
+    'advancedServiceConfig',
+    'clientInfo',
+    'selectedServiceNames',
+    'serviceConfigGroups',
+    'serviceConfigProperties',
+    'configsToUpdate',
+    'bootStatus'
+  ],
+
   init: function () {
     this._super();
     this.get('isStepDisabled').setEach('value', true);

+ 26 - 0
ambari-web/app/controllers/main/admin/security/security_progress_controller.js

@@ -62,12 +62,38 @@ App.MainAdminSecurityProgressController = Em.Controller.extend({
   retry: function () {
     var failedCommand = this.get('commands').findProperty('isError');
     if (failedCommand) {
+      failedCommand.set('requestId', null);
       failedCommand.set('isStarted', false);
       failedCommand.set('isError', false);
       this.startCommand(failedCommand);
     }
   },
 
+  /**
+   * start updating current task in parallel
+   * @param requestId
+   * @param taskId
+   * @return {Boolean}
+   */
+  startUpdatingTask: function (requestId, taskId) {
+    if (!requestId || !taskId) return false;
+    var command = this.get('commands').findProperty('requestId', requestId);
+    command.updateTaskLog(taskId);
+    return true;
+  },
+
+  /**
+   * stop updating current task
+   * @param requestId
+   * @return {Boolean}
+   */
+  stopUpdatingTask: function (requestId) {
+    if (!requestId) return false;
+    var command = this.get('commands').findProperty('requestId', requestId);
+    command.set('currentTaskId', null);
+    return true;
+  },
+
   /**
    * update info about progress of operation of commands
    */

+ 18 - 9
ambari-web/app/controllers/wizard.js

@@ -24,6 +24,21 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
 
   isStepDisabled: null,
 
+  /**
+   * Wizard properties in local storage, which should be cleaned right after wizard has been finished
+   */
+  dbPropertiesToClean: [
+    'service',
+    'hosts',
+    'masterComponentHosts',
+    'slaveComponentHosts',
+    'cluster',
+    'allHostNames',
+    'installOptions',
+    'allHostNamesPattern',
+    'serviceComponents'
+  ],
+
   init: function () {
     this.set('isStepDisabled', []);
     this.clusters = App.Cluster.find();
@@ -403,15 +418,9 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, {
   },
 
   clearStorageData: function () {
-    this.setDBProperty('service',undefined); //not to use this data at AddService page
-    this.setDBProperty('hosts', undefined);
-    this.setDBProperty('masterComponentHosts', undefined);
-    this.setDBProperty('slaveComponentHosts', undefined);
-    this.setDBProperty('cluster', undefined);
-    this.setDBProperty('allHostNames', undefined);
-    this.setDBProperty('installOptions', undefined);
-    this.setDBProperty('allHostNamesPattern', undefined);
-    this.setDBProperty('serviceComponents', undefined);
+    this.get('dbPropertiesToClean').forEach(function (key) {
+      this.setDBProperty(key, undefined);
+    }, this);
   },
 
   installOptionsTemplate: {

+ 21 - 8
ambari-web/app/utils/host_progress_popup.js

@@ -68,14 +68,17 @@ App.HostPopup = Em.Object.create({
   /**
    * Entering point of this component
    * @param {String} serviceName
-   * @param {App.Controller} controller
-   * @param {bool} isBackgroundOperations
+   * @param {Object} controller
+   * @param {Boolean} isBackgroundOperations
+   * @param {Integer} requestId
    */
-  initPopup: function (serviceName, controller, isBackgroundOperations) {
+  initPopup: function (serviceName, controller, isBackgroundOperations, requestId) {
     if (!isBackgroundOperations) {
       this.clearHostPopup();
       this.set("popupHeaderName", serviceName);
     }
+
+    this.set('currentServiceId', requestId);
     this.set("serviceName", serviceName);
     this.set("dataSourceController", controller);
     this.set("isBackgroundOperations", isBackgroundOperations);
@@ -697,21 +700,31 @@ App.HostPopup = Em.Object.create({
          * @param levelName
          */
         switchLevel: function (levelName) {
+          var dataSourceController = this.get('controller.dataSourceController');
+          var securityControllers = [
+            'mainAdminSecurityDisableController',
+            'mainAdminSecurityAddStep4Controller'
+          ];
           if (this.get("controller.isBackgroundOperations")) {
-            var BGController = App.router.get('backgroundOperationsController');
-            var levelInfo = BGController.get('levelInfo');
+            var levelInfo = dataSourceController.get('levelInfo');
             levelInfo.set('taskId', this.get('openedTaskId'));
             levelInfo.set('requestId', this.get('controller.currentServiceId'));
             levelInfo.set('name', levelName);
             if (levelName === 'HOSTS_LIST') {
               levelInfo.set('sync', (this.get('controller.hosts').length === 0));
-              BGController.requestMostRecent();
+              dataSourceController.requestMostRecent();
             } else if (levelName === 'TASK_DETAILS') {
               levelInfo.set('sync', true);
-              BGController.requestMostRecent();
+              dataSourceController.requestMostRecent();
             } else if (levelName === 'REQUESTS_LIST') {
               this.get('controller.hosts').clear();
-              BGController.requestMostRecent();
+              dataSourceController.requestMostRecent();
+            }
+          } else if (securityControllers.contains(dataSourceController.get('name'))) {
+            if (levelName === 'TASK_DETAILS') {
+              dataSourceController.startUpdatingTask(this.get('controller.currentServiceId'), this.get('openedTaskId'));
+            } else {
+              dataSourceController.stopUpdatingTask(this.get('controller.currentServiceId'));
             }
           }
         },

+ 88 - 48
ambari-web/app/utils/polling.js

@@ -25,7 +25,7 @@ App.Poll = Em.Object.extend({
   isStarted: false,
   isPolling: true,
   clusterName: null,
-  requestId: undefined,
+  requestId: null,
   temp: false,
   progress: 0,
   url: null,
@@ -37,6 +37,7 @@ App.Poll = Em.Object.extend({
   polledData: [],
   numPolls: 0,
   mockDataPrefix: '/data/wizard/deploy/5_hosts',
+  currentTaskId: null,
 
   barWidth: function () {
     return 'width: ' + this.get('progress') + '%;';
@@ -51,7 +52,7 @@ App.Poll = Em.Object.extend({
   }.property('isPolling', 'isStarted'),
 
   start: function () {
-    if (this.get('requestId') === undefined) {
+    if (Em.isNone(this.get('requestId'))) {
       this.setRequestId();
     } else {
       this.startPolling();
@@ -81,10 +82,9 @@ App.Poll = Em.Object.extend({
         console.log("TRACE: Polling -> value of the url is: " + url);
         console.log("TRACE: Polling-> value of the sent data is: " + self.get('data'));
         console.log("TRACE: Polling-> value of the received data is: " + jsonData);
-        if (jsonData === null) {
+        if (Em.isNone(jsonData)) {
           self.set('isSuccess', true);
           self.set('isError', false);
-          self.set('requestId',undefined);
         } else {
           var requestId = jsonData.Requests.id;
           self.set('requestId', requestId);
@@ -103,59 +103,93 @@ App.Poll = Em.Object.extend({
     });
   },
 
+  /**
+   * set current task id and send request
+   * @param taskId
+   */
+  updateTaskLog: function (taskId) {
+    this.set('currentTaskId', taskId);
+    this.pollTaskLog();
+  },
+
   doPolling: function () {
     if (this.get('requestId')) {
       this.startPolling();
     }
   },
 
-  startPolling: function () {
-    if (!this.get('requestId')) {
-      return;
-    }
-    var self = this;
-    var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/requests/' + this.get('requestId') + '?fields=tasks/*';
-    if (App.testMode) {
-      this.set('POLL_INTERVAL', 1);
-      this.numPolls++;
-      url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
+  /**
+   * server call to obtain task logs
+   */
+  pollTaskLog: function () {
+    if (this.get('currentTaskId')) {
+      App.ajax.send({
+        name: 'background_operations.get_by_task',
+        sender: this,
+        data: {
+          requestId: this.get('requestId'),
+          taskId: this.get('currentTaskId'),
+          sync: true
+        },
+        success: 'pollTaskLogSuccessCallback'
+      })
     }
+  },
 
-    $.ajax({
-      type: 'GET',
-      url: url,
-      async: true,
-      dataType: 'text',
-      timeout: App.timeout,
-      success: function (data) {
-        console.log("TRACE: In success function for the GET logs data");
-        console.log("TRACE: The value is: ", jQuery.parseJSON(data));
-        var result = self.parseInfo(jQuery.parseJSON(data));
-        if (result !== true) {
-          window.setTimeout(function () {
-            self.startPolling();
-          }, self.POLL_INTERVAL);
-        } else {
-          self.set('requestId', undefined);
-        }
-      },
+  /**
+   * update logs of current task
+   * @param data
+   */
+  pollTaskLogSuccessCallback: function (data) {
+    var currentTask = this.get('polledData').findProperty('Tasks.id', data.Tasks.id);
+    currentTask.Tasks.stdout = data.Tasks.stdout;
+    currentTask.Tasks.stderr = data.Tasks.stderr;
+    Em.propertyDidChange(this, 'polledData');
+  },
 
-      error: function (request, ajaxOptions, error) {
-        console.log("TRACE: In error function for the GET data");
-        console.log("TRACE: value of the url is: " + url);
-        console.log("TRACE: error code status is: " + request.status);
-        if (!self.get('isSuccess')) {
-          self.set('isError', true);
-        }
-      },
+  /**
+   * start polling operation data
+   * @return {Boolean}
+   */
+  startPolling: function () {
+    if (!this.get('requestId')) return false;
 
-      statusCode: require('data/statusCodes')
-    }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
-      function () {
+    this.pollTaskLog();
+    App.ajax.send({
+      name: 'background_operations.get_by_request',
+      sender: this,
+      data: {
+        requestId: this.get('requestId'),
+        sync: false
+      },
+      success: 'startPollingSuccessCallback',
+      error: 'startPollingErrorCallback'
+    })
+      .retry({times: App.maxRetries, timeout: App.timeout})
+      .then(null, function () {
         App.showReloadPopup();
         console.log('Install services all retries failed');
-      }
-    );
+      });
+    return true;
+  },
+
+  startPollingSuccessCallback: function (data) {
+    var self = this;
+    var result = this.parseInfo(data);
+    if (!result) {
+      window.setTimeout(function () {
+        self.startPolling();
+      }, this.POLL_INTERVAL);
+    }
+  },
+
+  startPollingErrorCallback: function (request, ajaxOptions, error) {
+    console.log("TRACE: In error function for the GET data");
+    console.log("TRACE: value of the url is: " + url);
+    console.log("TRACE: error code status is: " + request.status);
+    if (!this.get('isSuccess')) {
+      this.set('isError', true);
+    }
   },
 
   stopPolling: function () {
@@ -163,7 +197,13 @@ App.Poll = Em.Object.extend({
   },
 
   replacePolledData: function (polledData) {
-    this.polledData.clear();
+    var currentTaskId = this.get('currentTaskId');
+    if (currentTaskId) {
+      var task = this.get('polledData').findProperty('Tasks.id', currentTaskId);
+      var currentTask = polledData.findProperty('Tasks.id', currentTaskId);
+      currentTask.Tasks.stdout = task.Tasks.stdout;
+      currentTask.Tasks.stderr = task.Tasks.stderr;
+    }
     this.set('polledData', polledData);
   },
 
@@ -208,9 +248,9 @@ App.Poll = Em.Object.extend({
     }
     var requestId = this.get('requestId');
     if (polledData.Requests && polledData.Requests.id && polledData.Requests.id != requestId) {
-      // We dont want to use non-current requestId's tasks data to
+      // We don't want to use non-current requestId's tasks data to
       // determine the current install status.
-      // Also, we dont want to keep polling if it is not the
+      // Also, we don't want to keep polling if it is not the
       // current requestId.
       return false;
     }

+ 4 - 5
ambari-web/app/views/main/service/reconfigure.js

@@ -42,16 +42,15 @@ App.StageLabelView = Em.View.extend({
   command: null,
   click: function () {
     if (this.get('command') && this.get('showLink')) {
-      this.showHostPopup(this.get('command.label'));
+      this.showHostPopup(this.get('command'));
     }
   },
 
-  showHostPopup: function (label) {
-    var serviceName = label;
+  showHostPopup: function (command) {
     var controller = this.get("controller");
     App.router.get('applicationController').dataLoading().done(function (initValue) {
-      var popupView = App.HostPopup.initPopup(serviceName, controller);
-      popupView.set ('isNotShowBgChecked', !initValue);
+      var popupView = App.HostPopup.initPopup(command.get('label'), controller, false, command.get('requestId'));
+      popupView.set('isNotShowBgChecked', !initValue);
     })
   },