Просмотр исходного кода

AMBARI-11587. Test DB connection popup issues (alexantonenko)

Alex Antonenko 10 лет назад
Родитель
Сommit
aefc39aaa3

+ 3 - 0
ambari-web/app/messages.js

@@ -252,6 +252,7 @@ Em.I18n.translations = {
   'common.dismiss': "Dismiss",
   'common.dismiss': "Dismiss",
   'common.stdout': "stdout",
   'common.stdout': "stdout",
   'common.stderr': "stderr",
   'common.stderr': "stderr",
+  'common.structuredOut': "structured_out",
   'common.fileName': 'File name',
   'common.fileName': 'File name',
   'common.days': "Days",
   'common.days': "Days",
   'common.hours': "Hours",
   'common.hours': "Hours",
@@ -266,6 +267,7 @@ Em.I18n.translations = {
   'common.scope': 'Scope',
   'common.scope': 'Scope',
   'common.clone': 'Clone',
   'common.clone': 'Clone',
   'common.removed': 'Removed',
   'common.removed': 'Removed',
+  'common.testing': 'Testing',
 
 
   'models.alert_instance.tiggered.verbose': "Occured on {0} <br> Checked on {1}",
   'models.alert_instance.tiggered.verbose': "Occured on {0} <br> Checked on {1}",
   'models.alert_definition.triggered.verbose': "Occured on {0}",
   'models.alert_definition.triggered.verbose': "Occured on {0}",
@@ -1766,6 +1768,7 @@ Em.I18n.translations = {
   'services.service.config.database.connection.success': 'Connection OK',
   'services.service.config.database.connection.success': 'Connection OK',
   'services.service.config.database.connection.inProgress': 'Checking connectivity',
   'services.service.config.database.connection.inProgress': 'Checking connectivity',
   'services.service.config.database.connection.failed': 'Connection Failed',
   'services.service.config.database.connection.failed': 'Connection Failed',
+  'services.service.config.connection.logsPopup.header': '{0} Connection: {1}',
   'services.service.config.connection.exitPopup.msg': 'Test connection is in progress. It\'s recommended to wait until it wil be complete. Are you sure you want to exit Enable Kerberos Wizard?',
   'services.service.config.connection.exitPopup.msg': 'Test connection is in progress. It\'s recommended to wait until it wil be complete. Are you sure you want to exit Enable Kerberos Wizard?',
   'services.service.config.database.btn.idle': 'Test Connection',
   'services.service.config.database.btn.idle': 'Test Connection',
   'services.service.config.kdc.btn.idle': 'Test KDC Connection',
   'services.service.config.kdc.btn.idle': 'Test KDC Connection',

+ 1 - 1
ambari-web/app/templates/common/error_log_body.hbs

@@ -25,7 +25,7 @@
       <h5>{{t common.stdout}}: &nbsp; <span class="muted"> {{view.openedTask.outputLog}} </span></h5>
       <h5>{{t common.stdout}}: &nbsp; <span class="muted"> {{view.openedTask.outputLog}} </span></h5>
       <pre class="stdout">{{view.openedTask.stdout}}</pre>
       <pre class="stdout">{{view.openedTask.stdout}}</pre>
       {{#if view.openedTask.structuredOut}}
       {{#if view.openedTask.structuredOut}}
-        <h5>structured_out: &nbsp;</h5>
+        <h5>{{t common.structuredOut}}: &nbsp;</h5>
         <pre class="stdout">{{view.openedTask.structuredOut}}</pre>
         <pre class="stdout">{{view.openedTask.structuredOut}}</pre>
       {{/if}}
       {{/if}}
     </div>
     </div>

+ 21 - 2
ambari-web/app/views/common/controls_view.js

@@ -1195,6 +1195,8 @@ App.CheckDBConnectionView = Ember.View.extend({
   request: null,
   request: null,
   /** @property {Number} pollInterval - timeout interval for ajax polling **/
   /** @property {Number} pollInterval - timeout interval for ajax polling **/
   pollInterval: 3000,
   pollInterval: 3000,
+  /** @property {Object} logsPopup - popup with DB connection check info **/
+  logsPopup: null,
   /** @property {string} hostNameProperty - host name property based on service and database names **/
   /** @property {string} hostNameProperty - host name property based on service and database names **/
   hostNameProperty: function() {
   hostNameProperty: function() {
     if (!/wizard/i.test(this.get('controller.name')) && this.get('parentView.service.serviceName') === 'HIVE') {
     if (!/wizard/i.test(this.get('controller.name')) && this.get('parentView.service.serviceName') === 'HIVE') {
@@ -1526,6 +1528,10 @@ App.CheckDBConnectionView = Ember.View.extend({
     this.set('responseCaption', isSuccess ? Em.I18n.t('services.service.config.database.connection.success') : Em.I18n.t('services.service.config.database.connection.failed'));
     this.set('responseCaption', isSuccess ? Em.I18n.t('services.service.config.database.connection.success') : Em.I18n.t('services.service.config.database.connection.failed'));
     this.set('isConnectionSuccess', isSuccess);
     this.set('isConnectionSuccess', isSuccess);
     this.set('isRequestResolved', true);
     this.set('isRequestResolved', true);
+    if (this.get('logsPopup')) {
+      var statusString = isSuccess ? 'common.success' : 'common.error';
+      this.set('logsPopup.header', Em.I18n.t('services.service.config.connection.logsPopup.header').format(this.get('databaseName'), Em.I18n.t(statusString)));
+    }
   },
   },
   /**
   /**
    * Switch captions and statuses for active/non-active request.
    * Switch captions and statuses for active/non-active request.
@@ -1564,15 +1570,28 @@ App.CheckDBConnectionView = Ember.View.extend({
   showLogsPopup: function() {
   showLogsPopup: function() {
     if (this.get('isConnectionSuccess')) return;
     if (this.get('isConnectionSuccess')) return;
     var _this = this;
     var _this = this;
-    var popup = App.showAlertPopup('Error: {0} connection'.format(this.get('databaseName')));
+    var statusString = this.get('isRequestResolved') ? 'common.error' : 'common.testing';
+    var popup = App.showAlertPopup(Em.I18n.t('services.service.config.connection.logsPopup.header').format(this.get('databaseName'), Em.I18n.t(statusString)), null, function () {
+      _this.set('logsPopup', null);
+    });
+    popup.reopen({
+      onClose: function () {
+        this._super();
+        _this.set('logsPopup', null);
+      }
+    });
     if (typeof this.get('responseFromServer') == 'object') {
     if (typeof this.get('responseFromServer') == 'object') {
       popup.set('bodyClass', Em.View.extend({
       popup.set('bodyClass', Em.View.extend({
+        checkDBConnectionView: _this,
         templateName: require('templates/common/error_log_body'),
         templateName: require('templates/common/error_log_body'),
-        openedTask: _this.get('responseFromServer')
+        openedTask: function () {
+          return this.get('checkDBConnectionView.responseFromServer');
+        }.property('checkDBConnectionView.responseFromServer.stderr', 'checkDBConnectionView.responseFromServer.stdout', 'checkDBConnectionView.responseFromServer.structuredOut')
       }));
       }));
     } else {
     } else {
       popup.set('body', this.get('responseFromServer'));
       popup.set('body', this.get('responseFromServer'));
     }
     }
+    this.set('logsPopup', popup);
     return popup;
     return popup;
   }
   }
 });
 });

+ 128 - 0
ambari-web/test/views/common/controls_view_test.js

@@ -952,6 +952,134 @@ describe('App.CheckDBConnectionView', function () {
 
 
   });
   });
 
 
+  describe('#setResponseStatus', function () {
+
+    var view,
+      cases = [
+        {
+          isSuccess: 'success',
+          logsPopupBefore: null,
+          logsPopup: null,
+          responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
+          isConnectionSuccess: true,
+          title: 'success, no popup displayed'
+        },
+        {
+          isSuccess: 'success',
+          logsPopupBefore: {},
+          logsPopup: {
+            header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.success'))
+          },
+          responseCaption: Em.I18n.t('services.service.config.database.connection.success'),
+          isConnectionSuccess: true,
+          title: 'success, popup is displayed'
+        },
+        {
+          isSuccess: 'error',
+          logsPopupBefore: {},
+          logsPopup: {
+            header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error'))
+          },
+          responseCaption: Em.I18n.t('services.service.config.database.connection.failed'),
+          isConnectionSuccess: false,
+          title: 'error, popup is displayed'
+        }
+      ];
+
+    beforeEach(function () {
+      view = App.CheckDBConnectionView.create({
+        databaseName: 'MySQL'
+      });
+      sinon.stub(view, 'setConnectingStatus', Em.K);
+    });
+
+    afterEach(function () {
+      view.setConnectingStatus.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        view.set('logsPopup', item.logsPopupBefore);
+        view.setResponseStatus(item.isSuccess);
+        expect(view.get('isRequestResolved')).to.be.true;
+        expect(view.setConnectingStatus.calledOnce).to.be.true;
+        expect(view.setConnectingStatus.calledWith(false)).to.be.true;
+        expect(view.get('responseCaption')).to.equal(item.responseCaption);
+        expect(view.get('isConnectionSuccess')).to.equal(item.isConnectionSuccess);
+        expect(view.get('logsPopup')).to.eql(item.logsPopup);
+      });
+    });
+
+  });
+
+  describe('#showLogsPopup', function () {
+
+    var view,
+      cases = [
+        {
+          isConnectionSuccess: true,
+          showAlertPopupCallCount: 0,
+          title: 'successful connection'
+        },
+        {
+          isConnectionSuccess: false,
+          isRequestResolved: true,
+          showAlertPopupCallCount: 1,
+          responseFromServer: 'fail',
+          header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.error')),
+          popupMethodExecuted: 'onClose',
+          title: 'failed connection without output data, popup dismissed with Close button'
+        },
+        {
+          isConnectionSuccess: false,
+          isRequestResolved: false,
+          showAlertPopupCallCount: 1,
+          responseFromServer: {
+            stderr: 'stderr',
+            stdout: 'stdout',
+            structuredOut: 'structuredOut'
+          },
+          header: Em.I18n.t('services.service.config.connection.logsPopup.header').format('MySQL', Em.I18n.t('common.testing')),
+          popupMethodExecuted: 'onPrimary',
+          title: 'check in progress with output data, popup dismissed with OK button'
+        }
+      ];
+
+    beforeEach(function () {
+      view = App.CheckDBConnectionView.create({
+        databaseName: 'MySQL'
+      });
+      sinon.spy(App, 'showAlertPopup');
+    });
+
+    afterEach(function () {
+      App.showAlertPopup.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        view.setProperties({
+          isConnectionSuccess: item.isConnectionSuccess,
+          isRequestResolved: item.isRequestResolved,
+          responseFromServer: item.responseFromServer
+        });
+        view.showLogsPopup();
+        expect(App.showAlertPopup.callCount).to.equal(item.showAlertPopupCallCount);
+        if (!item.isConnectionSuccess) {
+          expect(view.get('logsPopup.header')).to.equal(item.header);
+          if (typeof item.responseFromServer == 'object') {
+            expect(view.get('logsPopup.bodyClass').create().get('openedTask')).to.eql(item.responseFromServer);
+          } else {
+            expect(view.get('logsPopup.body')).to.equal(item.responseFromServer);
+          }
+          view.get('logsPopup')[item.popupMethodExecuted]();
+          expect(view.get('logsPopup')).to.be.null;
+        }
+      });
+    });
+
+  });
+
 });
 });
 
 
 describe('App.BaseUrlTextField', function () {
 describe('App.BaseUrlTextField', function () {