Browse Source

AMBARI-13090. Ambari UI doesn't show correct cluster info (alexantonenko)

Alex Antonenko 10 years ago
parent
commit
a7152651ba

+ 30 - 20
ambari-web/app/controllers/global/cluster_controller.js

@@ -19,7 +19,7 @@
 var App = require('app');
 var App = require('app');
 var stringUtils = require('utils/string_utils');
 var stringUtils = require('utils/string_utils');
 
 
-App.ClusterController = Em.Controller.extend({
+App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
   name: 'clusterController',
   name: 'clusterController',
   isLoaded: false,
   isLoaded: false,
   ambariProperties: null,
   ambariProperties: null,
@@ -89,8 +89,8 @@ App.ClusterController = Em.Controller.extend({
   /**
   /**
    * load cluster name
    * load cluster name
    */
    */
-  loadClusterName: function (reload) {
-    var dfd = $.Deferred();
+  loadClusterName: function (reload, deferred) {
+    var dfd = deferred || $.Deferred();
 
 
     if (App.get('clusterName') && !reload) {
     if (App.get('clusterName') && !reload) {
       App.set('clusterName', this.get('clusterName'));
       App.set('clusterName', this.get('clusterName'));
@@ -100,32 +100,42 @@ App.ClusterController = Em.Controller.extend({
       App.ajax.send({
       App.ajax.send({
         name: 'cluster.load_cluster_name',
         name: 'cluster.load_cluster_name',
         sender: this,
         sender: this,
-        success: 'loadClusterNameSuccessCallback',
-        error: 'loadClusterNameErrorCallback'
-      }).complete(function () {
-        if (!App.get('currentStackVersion')) {
-          App.set('currentStackVersion', App.defaultStackVersion);
+        data: {
+          reloadPopupText: Em.I18n.t('app.reloadPopup.noClusterName.text'),
+          errorLogMessage: 'failed on loading cluster name',
+          callback: this.loadClusterName,
+          args: [reload, dfd],
+          shouldUseDefaultHandler: true
+        },
+        success: 'reloadSuccessCallback',
+        error: 'reloadErrorCallback',
+        callback: function () {
+          if (!App.get('currentStackVersion')) {
+            App.set('currentStackVersion', App.defaultStackVersion);
+          }
         }
         }
-        dfd.resolve();
-      });
+      }).then(
+        function () {
+          dfd.resolve();
+        },
+        null
+      );
     }
     }
-    return dfd.promise()
+    return dfd.promise();
   },
   },
 
 
-  loadClusterNameSuccessCallback: function (data) {
+  reloadSuccessCallback: function (data) {
+    this._super();
     if (data.items && data.items.length > 0) {
     if (data.items && data.items.length > 0) {
-      App.set('clusterName', data.items[0].Clusters.cluster_name);
-      App.set('currentStackVersion', data.items[0].Clusters.version);
+      App.setProperties({
+        clusterName: data.items[0].Clusters.cluster_name,
+        currentStackVersion: data.items[0].Clusters.version,
+        isKerberosEnabled: data.items[0].Clusters.security_type === 'KERBEROS'
+      });
       this.set('isClusterNameLoaded', true);
       this.set('isClusterNameLoaded', true);
-      App.set('isKerberosEnabled', data.items[0].Clusters.security_type === 'KERBEROS');
     }
     }
   },
   },
 
 
-  loadClusterNameErrorCallback: function (request, ajaxOptions, error) {
-    console.log('failed on loading cluster name');
-    this.set('isLoaded', true);
-  },
-
   /**
   /**
    * load current server clock in milli-seconds
    * load current server clock in milli-seconds
    */
    */

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

@@ -23,6 +23,7 @@ Em.I18n.translations = {
   'app.name.subtitle.experimental':'Ambari Experimental',
   'app.name.subtitle.experimental':'Ambari Experimental',
   'app.reloadPopup.link': 'Reload Page',
   'app.reloadPopup.link': 'Reload Page',
   'app.reloadPopup.text': 'Trying to connect to server...',
   'app.reloadPopup.text': 'Trying to connect to server...',
+  'app.reloadPopup.noClusterName.text': 'Failed to retrieve cluster name, trying to reload...',
   'app.reloadPopup.header': 'Reload Page',
   'app.reloadPopup.header': 'Reload Page',
 
 
   'app.loadingPlaceholder': 'Loading...',
   'app.loadingPlaceholder': 'Loading...',

+ 5 - 4
ambari-web/app/mixins/common/reload_popup.js

@@ -40,7 +40,7 @@ App.ReloadPopupMixin = Em.Mixin.create({
     } else {
     } else {
       var times = Em.isNone(params.times) ? App.get('maxRetries') : params.times,
       var times = Em.isNone(params.times) ? App.get('maxRetries') : params.times,
         timeout = Em.isNone(params.timeout) ? App.get('timeout') : params.timeout;
         timeout = Em.isNone(params.timeout) ? App.get('timeout') : params.timeout;
-      this.showReloadPopup();
+      this.showReloadPopup(params.reloadPopupText);
       if (this.get('retryCount') < times) {
       if (this.get('retryCount') < times) {
         if (params.callback) {
         if (params.callback) {
           var self = this;
           var self = this;
@@ -53,8 +53,9 @@ App.ReloadPopupMixin = Em.Mixin.create({
     }
     }
   },
   },
 
 
-  showReloadPopup: function () {
-    var self = this;
+  showReloadPopup: function (text) {
+    var self = this,
+      bodyText = text || this.t('app.reloadPopup.text');
     if (!this.get('reloadPopup')) {
     if (!this.get('reloadPopup')) {
       this.set('reloadPopup', App.ModalPopup.show({
       this.set('reloadPopup', App.ModalPopup.show({
         primary: null,
         primary: null,
@@ -62,7 +63,7 @@ App.ReloadPopupMixin = Em.Mixin.create({
         showFooter: false,
         showFooter: false,
         header: this.t('app.reloadPopup.header'),
         header: this.t('app.reloadPopup.header'),
         body: "<div id='reload_popup' class='alert alert-info'><div class='spinner'><span>" +
         body: "<div id='reload_popup' class='alert alert-info'><div class='spinner'><span>" +
-          this.t('app.reloadPopup.text') + "</span></div></div><div><a href='javascript:void(null)' onclick='location.reload();'>" +
+          bodyText + "</span></div></div><div><a href='javascript:void(null)' onclick='location.reload();'>" +
           this.t('app.reloadPopup.link') + "</a></div>",
           this.t('app.reloadPopup.link') + "</a></div>",
         encodeBody: false,
         encodeBody: false,
         onClose: function () {
         onClose: function () {

+ 4 - 11
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -69,10 +69,10 @@ describe('App.clusterController', function () {
       modelSetup.setupStackVersion(this, 'HDP-2.0.5');
       modelSetup.setupStackVersion(this, 'HDP-2.0.5');
       sinon.stub(App.ajax, 'send', function () {
       sinon.stub(App.ajax, 'send', function () {
         return {
         return {
-          complete: function (callback) {
+          then: function (successCallback) {
             App.set('clusterName', 'clusterNameFromServer');
             App.set('clusterName', 'clusterNameFromServer');
             App.set('currentStackVersion', 'HDP-2.0.5');
             App.set('currentStackVersion', 'HDP-2.0.5');
-            callback();
+            successCallback();
           }
           }
         }
         }
       });
       });
@@ -107,7 +107,7 @@ describe('App.clusterController', function () {
 
 
   });
   });
 
 
-  describe('#loadClusterNameSuccessCallback', function () {
+  describe('#reloadSuccessCallback', function () {
     var test_data = {
     var test_data = {
       "items": [
       "items": [
         {
         {
@@ -119,19 +119,12 @@ describe('App.clusterController', function () {
       ]
       ]
     };
     };
     it('Check cluster', function () {
     it('Check cluster', function () {
-      controller.loadClusterNameSuccessCallback(test_data);
+      controller.reloadSuccessCallback(test_data);
       expect(App.get('clusterName')).to.equal('tdk');
       expect(App.get('clusterName')).to.equal('tdk');
       expect(App.get('currentStackVersion')).to.equal('HDP-1.3.0');
       expect(App.get('currentStackVersion')).to.equal('HDP-1.3.0');
     });
     });
   });
   });
 
 
-  describe('#loadClusterNameErrorCallback', function () {
-    controller.loadClusterNameErrorCallback();
-    it('', function () {
-      expect(controller.get('isLoaded')).to.equal(true);
-    });
-  });
-
   describe('#getServerClockSuccessCallback()', function () {
   describe('#getServerClockSuccessCallback()', function () {
     var testCases = [
     var testCases = [
       {
       {

+ 21 - 7
ambari-web/test/mixins/common/reload_popup_test.js

@@ -30,22 +30,36 @@ describe('App.ReloadPopupMixin', function () {
 
 
   describe('#showReloadPopup', function () {
   describe('#showReloadPopup', function () {
 
 
-    var mockObj = {
-      key: 'value'
-    };
+    var spanRegExp = new RegExp('<span>([\\s\\S]+)<\/span>'),
+      cases = [
+        {
+          result: Em.I18n.t('app.reloadPopup.text'),
+          title: 'should show modal popup with default message'
+        },
+        {
+          text: 'text',
+          result: 'text',
+          title: 'should show modal popup with custom message'
+        }
+      ];
 
 
     beforeEach(function () {
     beforeEach(function () {
-      sinon.stub(App.ModalPopup, 'show').returns(mockObj);
+      sinon.stub(App.ModalPopup, 'show', function (popup) {
+        return popup.body;
+      });
     });
     });
 
 
     afterEach(function () {
     afterEach(function () {
       App.ModalPopup.show.restore();
       App.ModalPopup.show.restore();
     });
     });
 
 
-    it('should show modal popup', function () {
-      obj.showReloadPopup();
-      expect(obj.get('reloadPopup')).to.eql(mockObj);
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        obj.showReloadPopup(item.text);
+        expect(obj.get('reloadPopup').match(spanRegExp)[1]).to.equal(item.result);
+      });
     });
     });
+
   });
   });
 
 
   describe('#closeReloadPopup', function () {
   describe('#closeReloadPopup', function () {