Bläddra i källkod

AMBARI-16904. 'Reload Page' popup is still shown when connection is established (alexantonenko)

Alex Antonenko 9 år sedan
förälder
incheckning
55b2654072

+ 12 - 2
ambari-web/app/controllers/wizard/step3_controller.js

@@ -533,6 +533,16 @@ App.WizardStep3Controller = Em.Controller.extend(App.ReloadPopupMixin, {
     }).setEach('value', this.get('isBackDisabled'));
   }.observes('isBackDisabled'),
 
+  /**
+   * Close reload popup on exit from Confirm Hosts step
+   * @method closeReloadPopupOnExit
+   */
+  closeReloadPopupOnExit: function () {
+    if (this.get('stopBootstrap')) {
+      this.closeReloadPopup();
+    }
+  }.observes('stopBootstrap'),
+
   /**
    * Do bootstrap calls
    * @method doBootstrap
@@ -550,8 +560,8 @@ App.WizardStep3Controller = Em.Controller.extend(App.ReloadPopupMixin, {
       data: {
         bootRequestId: this.get('content.installOptions.bootRequestId'),
         numPolls: this.get('numPolls'),
-        errorLogMessage: 'Bootstrap failed',
         callback: this.doBootstrap,
+        timeout: 3000,
         shouldUseDefaultHandler: true
       },
       success: 'doBootstrapSuccessCallback',
@@ -640,8 +650,8 @@ App.WizardStep3Controller = Em.Controller.extend(App.ReloadPopupMixin, {
       success: 'isHostsRegisteredSuccessCallback',
       error: 'reloadErrorCallback',
       data: {
-        errorLogMessage: 'Error: Getting registered host information from the server',
         callback: this.isHostsRegistered,
+        timeout: 3000,
         shouldUseDefaultHandler: true
       }
     });

+ 4 - 3
ambari-web/app/controllers/wizard/step9_controller.js

@@ -1053,8 +1053,7 @@ App.WizardStep9Controller = Em.Controller.extend(App.ReloadPopupMixin, {
         numPolls: this.get('numPolls'),
         callback: this.getLogsByRequest,
         args: [polling, requestId],
-        timeout: 3000,
-        errorLogMessage: 'Install services all retries failed'
+        timeout: 3000
       },
       success: 'reloadSuccessCallback',
       error: 'reloadErrorCallback'
@@ -1085,9 +1084,11 @@ App.WizardStep9Controller = Em.Controller.extend(App.ReloadPopupMixin, {
    * @method reloadErrorCallback
    */
   reloadErrorCallback: function (jqXHR, ajaxOptions, error, opt, params) {
-    this._super(jqXHR, ajaxOptions, error, opt, params);
     if (jqXHR.status) {
+      this.closeReloadPopup();
       this.loadLogData(true);
+    } else {
+      this._super(jqXHR, ajaxOptions, error, opt, params);
     }
   },
 

+ 7 - 16
ambari-web/app/mixins/common/reload_popup.js

@@ -20,8 +20,6 @@ var App = require('app');
 
 App.ReloadPopupMixin = Em.Mixin.create({
 
-  retryCount: 0,
-
   reloadPopup: null,
 
   reloadSuccessCallback: function () {
@@ -35,17 +33,13 @@ App.ReloadPopupMixin = Em.Mixin.create({
         App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.type, jqXHR.status);
       }
     } else {
-      var times = Em.isNone(params.times) ? App.get('maxRetries') : params.times,
-        timeout = Em.isNone(params.timeout) ? App.get('timeout') : params.timeout;
+      var timeout = Em.isNone(params.timeout) ? App.get('timeout') : params.timeout;
       this.showReloadPopup(params.reloadPopupText);
-      if (this.get('retryCount') < times) {
-        if (params.callback) {
-          var self = this;
-          window.setTimeout(function () {
-            params.callback.apply(self, params.args || []);
-          }, timeout);
-        }
-        this.incrementProperty('retryCount');
+      if (params.callback) {
+        var self = this;
+        window.setTimeout(function () {
+          params.callback.apply(self, params.args || []);
+        }, timeout);
       }
     }
   },
@@ -70,10 +64,7 @@ App.ReloadPopupMixin = Em.Mixin.create({
             + this.t('app.reloadPopup.link') + "</a></div>")
         }),
         onClose: function () {
-          self.setProperties({
-            reloadPopup: null,
-            retryCount: 0
-          });
+          self.set('reloadPopup', null);
           this._super();
         }
       }));

+ 1 - 2
ambari-web/app/utils/polling.js

@@ -147,8 +147,7 @@ App.Poll = Em.Object.extend(App.ReloadPopupMixin, {
       sender: this,
       data: {
         requestId: this.get('requestId'),
-        callback: this.startPolling,
-        errorLogMessage: 'Install services all retries failed'
+        callback: this.startPolling
       },
       success: 'reloadSuccessCallback',
       error: 'reloadErrorCallback'

+ 38 - 0
ambari-web/test/controllers/wizard/step3_test.js

@@ -3149,4 +3149,42 @@ describe('App.WizardStep3Controller', function () {
 
   });
 
+  describe('#closeReloadPopupOnExit', function () {
+
+    var cases = [
+      {
+        stopBootstrap: true,
+        closeReloadPopupCallCount: 1,
+        title: 'bootstrap should be stopped'
+      },
+      {
+        stopBootstrap: false,
+        closeReloadPopupCallCount: 0,
+        title: 'bootstrap should not be stopped'
+      }
+    ];
+
+    beforeEach(function () {
+      sinon.stub(c, 'closeReloadPopup', Em.K);
+    });
+
+    afterEach(function () {
+      c.closeReloadPopup.restore();
+    });
+
+    cases.forEach(function (item) {
+
+      it(item.title, function () {
+        if (c.get('stopBootstrap') === item.stopBootstrap) {
+          c.propertyDidChange('stopBootstrap');
+        } else {
+          c.set('stopBootstrap', item.stopBootstrap);
+        }
+        expect(c.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
+      });
+
+    });
+
+  });
+
 });

+ 96 - 78
ambari-web/test/mixins/common/reload_popup_test.js

@@ -52,11 +52,9 @@ describe('App.ReloadPopupMixin', function () {
   describe('#closeReloadPopup', function () {
 
     it('should hide modal popup', function () {
-      obj.set('retryCount', 1);
       obj.showReloadPopup();
       obj.closeReloadPopup();
       expect(obj.get('reloadPopup')).to.be.null;
-      expect(obj.get('retryCount')).to.equal(0);
     });
 
   });
@@ -64,110 +62,130 @@ describe('App.ReloadPopupMixin', function () {
   describe('#reloadSuccessCallback', function () {
 
     it('should hide modal popup', function () {
-      obj.set('retryCount', 1);
       obj.showReloadPopup();
       obj.reloadSuccessCallback();
       expect(obj.get('reloadPopup')).to.be.null;
-      expect(obj.get('retryCount')).to.equal(0);
     });
 
   });
 
   describe('#reloadErrorCallback', function () {
 
-    var cases = [
-      {
-        args: [{status: 404}, null, null, {}, {shouldUseDefaultHandler: true}],
-        closeReloadPopupCallCount: 1,
-        consoleLogCallCount: 0,
-        defaultErrorHandlerCallCount: 1,
-        showReloadPopupCallCount: 0,
-        setTimeoutCount: 0,
-        title: 'status received, no console message, default error handler'
-      },
-      {
-        args: [{status: 404}, null, null, {}, {errorLogMessage: 'error'}],
-        closeReloadPopupCallCount: 1,
-        consoleLogCallCount: 1,
-        defaultErrorHandlerCallCount: 0,
-        showReloadPopupCallCount: 0,
-        setTimeoutCount: 0,
-        title: 'status received, console message displayed, no default error handler'
-      },
-      {
-        args: [{status: 0}, null, null, {}, {times: 5}],
-        retryCount: 5,
-        retryCountResult: 5,
-        closeReloadPopupCallCount: 0,
-        consoleLogCallCount: 0,
-        defaultErrorHandlerCallCount: 0,
-        showReloadPopupCallCount: 1,
-        setTimeoutCount: 0,
-        title: 'no status received, custom retries count, max retries reached'
-      },
-      {
-        args: [{status: 0}, null, null, {}, {}],
-        retryCount: 2,
-        retryCountResult: 3,
-        closeReloadPopupCallCount: 0,
-        consoleLogCallCount: 0,
-        defaultErrorHandlerCallCount: 0,
-        showReloadPopupCallCount: 1,
-        setTimeoutCount: 0,
-        title: 'no status received, default retries count, max retries not reached, no callback'
-      },
-      {
-        args: [{status: 0}, null, null, {}, {callback: Em.K}],
-        retryCount: 2,
-        retryCountResult: 3,
-        closeReloadPopupCallCount: 0,
-        consoleLogCallCount: 0,
-        defaultErrorHandlerCallCount: 0,
-        showReloadPopupCallCount: 1,
-        setTimeoutCount: 1,
-        title: 'no status received, default retries count, max retries not reached, callback specified'
-      }
-    ];
-
-    beforeEach(function () {
-      sinon.stub(obj, 'closeReloadPopup', Em.K);
-      sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
-      sinon.stub(obj, 'showReloadPopup', Em.K);
-      sinon.stub(App, 'get').withArgs('maxRetries').returns(3);
-    });
-
-    afterEach(function () {
-      obj.closeReloadPopup.restore();
-      App.ajax.defaultErrorHandler.restore();
-      obj.showReloadPopup.restore();
-      App.get.restore();
-    });
+    var clock,
+      cases = [
+        {
+          args: [{status: 404}, null, null, {}, {shouldUseDefaultHandler: true}],
+          closeReloadPopupCallCount: 1,
+          defaultErrorHandlerCallCount: 1,
+          showReloadPopupCallCount: 0,
+          isCallbackCalled: false,
+          title: 'status received, default error handler'
+        },
+        {
+          args: [{status: 404}, null, null, {}, {}],
+          closeReloadPopupCallCount: 1,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 0,
+          isCallbackCalled: false,
+          title: 'status received, no default error handler'
+        },
+        {
+          args: [{status: 0}, null, null, {}, {}],
+          closeReloadPopupCallCount: 0,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 1,
+          isCallbackCalled: false,
+          title: 'no status received, no callback'
+        },
+        {
+          args: [{status: 0}, null, null, {}, {callback: Em.K, timeout: 2000}],
+          timeout: 1999,
+          closeReloadPopupCallCount: 0,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 1,
+          isCallbackCalled: false,
+          title: 'no status received, callback specified, custom timeout, not enough time passed'
+        },
+        {
+          args: [{status: 0}, null, null, {}, {callback: Em.K}],
+          timeout: 999,
+          closeReloadPopupCallCount: 0,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 1,
+          isCallbackCalled: false,
+          title: 'no status received, callback specified, default timeout, not enough time passed'
+        },
+        {
+          args: [{status: 0}, null, null, {}, {callback: Em.K, args: [{}], timeout: 2000}],
+          timeout: 2000,
+          closeReloadPopupCallCount: 0,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 1,
+          isCallbackCalled: true,
+          callbackArgs: [{}],
+          title: 'no status received, callback with arguments specified, custom timeout, enough time passed'
+        },
+        {
+          args: [{status: 0}, null, null, {}, {callback: Em.K}],
+          timeout: 1000,
+          closeReloadPopupCallCount: 0,
+          defaultErrorHandlerCallCount: 0,
+          showReloadPopupCallCount: 1,
+          isCallbackCalled: true,
+          callbackArgs: [],
+          title: 'no status received, callback with no arguments specified, default timeout, enough time passed'
+        }
+      ];
 
     cases.forEach(function (item) {
       describe(item.title, function () {
 
         beforeEach(function () {
-          if (!Em.isNone(item.retryCount)) {
-            obj.set('retryCount', item.retryCount);
+          sinon.stub(obj, 'closeReloadPopup', Em.K);
+          sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
+          sinon.stub(obj, 'showReloadPopup', Em.K);
+          sinon.stub(App, 'get').withArgs('timeout').returns(1000);
+          if (item.args[4].callback) {
+            sinon.spy(item.args[4], 'callback');
           }
+          clock = sinon.useFakeTimers();
           obj.reloadErrorCallback.apply(obj, item.args);
+          clock.tick(item.timeout);
         });
 
         afterEach(function () {
-          if (!Em.isNone(item.retryCountResult)) {
-            obj.set('retryCount', item.retryCountResult);
+          obj.closeReloadPopup.restore();
+          App.ajax.defaultErrorHandler.restore();
+          obj.showReloadPopup.restore();
+          App.get.restore();
+          if (item.args[4].callback) {
+            item.args[4].callback.restore();
           }
+          clock.restore();
         });
 
-        it('closeReloadPopup is called needed number of times', function () {
+        it('closeReloadPopup call', function () {
           expect(obj.closeReloadPopup.callCount).to.equal(item.closeReloadPopupCallCount);
         });
-        it('defaultErrorHandler is called needed number of times', function () {
+        it('defaultErrorHandler call', function () {
           expect(App.ajax.defaultErrorHandler.callCount).to.equal(item.defaultErrorHandlerCallCount);
         });
-        it('showReloadPopup is called needed number of times', function () {
+        it('showReloadPopup call', function () {
           expect(obj.showReloadPopup.callCount).to.equal(item.showReloadPopupCallCount);
         });
+
+        if (item.isCallbackCalled) {
+          it('callback call', function () {
+            expect(item.args[4].callback.calledOnce).to.be.true;
+          });
+          it('callback context', function () {
+            expect(item.args[4].callback.calledOn(obj)).to.be.true;
+          });
+          it('callback arguments', function () {
+            expect(item.args[4].callback.firstCall.args).to.eql(item.callbackArgs);
+          });
+        }
+
       });
     });
 

+ 2 - 4
ambari-web/test/utils/polling_test.js

@@ -515,8 +515,7 @@ describe('App.Poll', function () {
         ajaxCallArguments: [{
           name: 'background_operations.get_by_request',
           data: {
-            requestId: 0,
-            errorLogMessage: 'Install services all retries failed'
+            requestId: 0
           },
           success: 'reloadSuccessCallback',
           error: 'reloadErrorCallback'
@@ -530,8 +529,7 @@ describe('App.Poll', function () {
         ajaxCallArguments: [{
           name: 'background_operations.get_by_request',
           data: {
-            requestId: 1,
-            errorLogMessage: 'Install services all retries failed'
+            requestId: 1
           },
           success: 'reloadSuccessCallback',
           error: 'reloadErrorCallback'