ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [12/22] ambari git commit: AMBARI-20724 Merge calls to server which fetch ambari properties. (atkach)
Date Tue, 11 Apr 2017 11:14:34 GMT
AMBARI-20724 Merge calls to server which fetch ambari properties. (atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e3794a3a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e3794a3a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e3794a3a

Branch: refs/heads/branch-3.0-perf
Commit: e3794a3a5d02367b0b3d0a052b29a861196f602c
Parents: 4bc4942
Author: Andrii Tkach <atkach@apache.org>
Authored: Mon Apr 10 17:52:43 2017 +0300
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Tue Apr 11 14:14:12 2017 +0300

----------------------------------------------------------------------
 .../controllers/global/cluster_controller.js    | 31 ++-------
 ambari-web/app/controllers/main.js              | 28 +-------
 ambari-web/app/routes/main.js                   | 32 ++++-----
 .../global/cluster_controller_test.js           | 73 ++++++--------------
 ambari-web/test/controllers/main_test.js        | 66 ------------------
 5 files changed, 45 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e3794a3a/ambari-web/app/controllers/global/cluster_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/cluster_controller.js b/ambari-web/app/controllers/global/cluster_controller.js
index b24219e..29c979e 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/ambari-web/app/controllers/global/cluster_controller.js
@@ -142,30 +142,7 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
     }
   },
 
-  /**
-   * load current server clock in milli-seconds
-   */
-  loadClientServerClockDistance: function () {
-    var dfd = $.Deferred();
-    this.getServerClock().done(function () {
-      dfd.resolve();
-    });
-    return dfd.promise();
-  },
-
-  getServerClock: function () {
-    return App.ajax.send({
-      name: 'ambari.service',
-      sender: this,
-      data: {
-        fields: '?fields=RootServiceComponents/server_clock'
-      },
-      success: 'getServerClockSuccessCallback',
-      error: 'getServerClockErrorCallback'
-    });
-  },
-
-  getServerClockSuccessCallback: function (data) {
+  setServerClock: function (data) {
     var clientClock = new Date().getTime();
     var serverClock = (data.RootServiceComponents.server_clock).toString();
     serverClock = serverClock.length < 13 ? serverClock + '000' : serverClock;
@@ -185,7 +162,6 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
   loadClusterData: function () {
     this.loadAuthorizations();
     this.getAllHostNames();
-    this.loadAmbariProperties();
 
     if (!App.get('clusterName')) {
       return;
@@ -441,10 +417,13 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
   },
 
   loadAmbariPropertiesSuccess: function (data) {
+    var mainController = App.router.get('mainController');
     this.set('ambariProperties', data.RootServiceComponents.properties);
     // Absence of 'jdk.name' and 'jce.name' properties says that ambari configured with custom
jdk.
     this.set('isCustomJDK', App.isEmptyObject(App.permit(data.RootServiceComponents.properties,
['jdk.name', 'jce.name'])));
-    App.router.get('mainController').monitorInactivity();
+    this.setServerClock(data);
+    mainController.setAmbariServerVersion.call(mainController, data);
+    mainController.monitorInactivity();
   },
 
   loadAmbariPropertiesError: Em.K,

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3794a3a/ambari-web/app/controllers/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main.js b/ambari-web/app/controllers/main.js
index 798115f..499df74 100644
--- a/ambari-web/app/controllers/main.js
+++ b/ambari-web/app/controllers/main.js
@@ -123,42 +123,18 @@ App.MainController = Em.Controller.extend({
     );
   }.observes("App.router.location.lastSetURL", "App.clusterStatus.isInstalled"),
 
-  /**
-   * check server version and web client version
-   */
-  checkServerClientVersion: function () {
-    var dfd = $.Deferred();
-    var self = this;
-    self.getServerVersion().done(function () {
-      dfd.resolve();
-    });
-    return dfd.promise();
-  },
-  getServerVersion: function(){
-    return App.ajax.send({
-      name: 'ambari.service',
-      sender: this,
-      data: {
-        fields: '?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true'
-      },
-      success: 'getServerVersionSuccessCallback',
-      error: 'getServerVersionErrorCallback'
-    });
-  },
-  getServerVersionSuccessCallback: function (data) {
+  setAmbariServerVersion: function (data) {
     var clientVersion = App.get('version');
     var serverVersion = (data.RootServiceComponents.component_version).toString();
     this.set('ambariServerVersion', serverVersion);
     if (clientVersion) {
       this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion,
clientVersion));
-      this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
+      this.set('isServerClientVersionMismatch', clientVersion !== serverVersion);
     } else {
       this.set('isServerClientVersionMismatch', false);
     }
     App.set('isManagedMySQLForHiveEnabled', App.config.isManagedMySQLForHiveAllowed(data.RootServiceComponents.properties['server.os_family']));
   },
-  getServerVersionErrorCallback: function () {
-  },
 
   monitorInactivity: function() {
     var timeout = Number(App.router.get('clusterController.ambariProperties')['user.inactivity.timeout.default']);

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3794a3a/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index 88776b3..0a2375e 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -30,31 +30,31 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
     App.db.updateStorage();
     var self = this;
     var location = router.location.location.hash;
+    var clusterController = App.router.get('clusterController');
+
     router.getAuthenticated().done(function (loggedIn) {
       if (loggedIn) {
         var applicationController = App.router.get('applicationController');
         App.router.get('experimentalController').loadSupports().complete(function () {
           applicationController.startKeepAlivePoller();
-          App.router.get('mainController').checkServerClientVersion().done(function () {
+          clusterController.loadAmbariProperties().complete(function () {
             App.router.get('mainViewsController').loadAmbariViews();
-            App.router.get('clusterController').loadClusterName(false).done(function () {
+            clusterController.loadClusterName(false).done(function () {
               if (App.get('testMode')) {
                 router.get('mainController').initialize();
               } else {
                 if (router.get('clusterInstallCompleted')) {
-                  App.router.get('clusterController').loadClientServerClockDistance().done(function
() {
-                    if (!App.get('isOnlyViewUser')) {
-                      App.router.get('clusterController').checkDetailedRepoVersion().done(function
() {
-                        router.get('mainController').initialize();
-                      });
-                    } else {
-                      // Don't transit to Views when user already on View page
-                      if (App.router.currentState.name !== 'viewDetails') {
-                        App.router.transitionTo('main.views.index');
-                      }
-                      App.router.get('clusterController').set('isLoaded', true); // hide
loading bar
+                  if (!App.get('isOnlyViewUser')) {
+                    clusterController.checkDetailedRepoVersion().done(function () {
+                      router.get('mainController').initialize();
+                    });
+                  } else {
+                    // Don't transit to Views when user already on View page
+                    if (App.router.currentState.name !== 'viewDetails') {
+                      App.router.transitionTo('main.views.index');
                     }
-                  });
+                    clusterController.set('isLoaded', true); // hide loading bar
+                  }
                 }
                 else {
                   Em.run.next(function () {
@@ -65,13 +65,13 @@ module.exports = Em.Route.extend(App.RouterRedirections, {
                         if (App.isAuthorized('AMBARI.ADD_DELETE_CLUSTERS')) {
                           self.redirectToInstaller(router, currentClusterStatus, false);
                         } else {
-                          App.router.get('clusterController').set('isLoaded', true);
+                          clusterController.set('isLoaded', true);
                           Em.run.next(function () {
                             App.router.transitionTo('main.views.index');
                           });
                         }
                       } else {
-                        App.router.get('clusterController').set('isLoaded', true);
+                        clusterController.set('isLoaded', true);
                       }
                     });
                   });

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3794a3a/ambari-web/test/controllers/global/cluster_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/cluster_controller_test.js b/ambari-web/test/controllers/global/cluster_controller_test.js
index e7b71f9..170ed78 100644
--- a/ambari-web/test/controllers/global/cluster_controller_test.js
+++ b/ambari-web/test/controllers/global/cluster_controller_test.js
@@ -134,7 +134,7 @@ describe('App.clusterController', function () {
     });
   });
 
-  describe('#getServerClockSuccessCallback()', function () {
+  describe('#setServerClock()', function () {
     var testCases = [
       {
         title: 'if server clock is 1 then currentServerTime should be 1000',
@@ -178,7 +178,7 @@ describe('App.clusterController', function () {
 
     testCases.forEach(function (test) {
       it(test.title, function () {
-        controller.getServerClockSuccessCallback(test.data);
+        controller.setServerClock(test.data);
         expect(App.get('currentServerTime')).to.equal(test.result);
         App.set('clockDistance', clockDistance);
         App.set('currentServerTime', currentServerTime);
@@ -572,41 +572,6 @@ describe('App.clusterController', function () {
     });
   });
 
-  describe('#loadClientServerClockDistance()', function() {
-
-    beforeEach(function() {
-      sinon.stub(controller, 'getServerClock').returns({
-        done: Em.clb
-      });
-    });
-
-    afterEach(function() {
-      controller.getServerClock.restore();
-    });
-
-    it('getServerClock should be called', function() {
-      expect(controller.loadClientServerClockDistance()).to.be.an.object;
-      expect(controller.getServerClock).to.be.calledOnce;
-    });
-  });
-
-  describe('#getServerClock()', function() {
-
-    it('App.ajax.send should be called', function() {
-      controller.getServerClock();
-      var args = testHelpers.findAjaxRequest('name', 'ambari.service');
-      expect(args[0]).to.eql({
-        name: 'ambari.service',
-        sender: controller,
-        data: {
-          fields: '?fields=RootServiceComponents/server_clock'
-        },
-        success: 'getServerClockSuccessCallback',
-        error: 'getServerClockErrorCallback'
-      });
-    });
-  });
-
   describe('#isRunningState()', function() {
     var testCases = [
       {
@@ -738,20 +703,25 @@ describe('App.clusterController', function () {
   });
 
   describe('#loadAmbariPropertiesSuccess()', function() {
+    var data = {
+      RootServiceComponents: {
+        properties: {
+          p1: '1'
+        }
+      }
+    };
 
     beforeEach(function() {
       sinon.stub(App.router.get('mainController'), 'monitorInactivity');
-      controller.loadAmbariPropertiesSuccess({
-        RootServiceComponents: {
-          properties: {
-            p1: '1'
-          }
-        }
-      });
+      sinon.stub(App.router.get('mainController'), 'setAmbariServerVersion');
+      sinon.stub(controller, 'setServerClock');
+      controller.loadAmbariPropertiesSuccess(data);
     });
 
     afterEach(function() {
       App.router.get('mainController').monitorInactivity.restore();
+      App.router.get('mainController').setAmbariServerVersion.restore();
+      controller.setServerClock.restore();
     });
 
     it('should set ambariProperties', function() {
@@ -765,6 +735,14 @@ describe('App.clusterController', function () {
     it('monitorInactivity should be called', function() {
       expect(App.router.get('mainController').monitorInactivity).to.be.calledOnce;
     });
+
+    it('setAmbariServerVersion should be called', function() {
+      expect(App.router.get('mainController').setAmbariServerVersion.calledWith(data)).to.be.true;
+    });
+
+    it('setServerClock should be called', function() {
+      expect(controller.setServerClock.calledWith(data)).to.be.true;
+    });
   });
 
   describe('#updateClusterData()', function() {
@@ -849,7 +827,6 @@ describe('App.clusterController', function () {
     beforeEach(function() {
       sinon.stub(controller, 'loadAuthorizations');
       sinon.stub(controller, 'getAllHostNames');
-      sinon.stub(controller, 'loadAmbariProperties');
       sinon.stub(controller, 'loadClusterInfo');
       sinon.stub(controller, 'restoreUpgradeState');
       sinon.stub(controller, 'loadClusterDataToModel');
@@ -871,7 +848,6 @@ describe('App.clusterController', function () {
       App.router.get('mainController').startPolling.restore();
       controller.loadAuthorizations.restore();
       controller.getAllHostNames.restore();
-      controller.loadAmbariProperties.restore();
       controller.loadClusterInfo.restore();
       controller.restoreUpgradeState.restore();
       controller.loadClusterDataToModel.restore();
@@ -887,11 +863,6 @@ describe('App.clusterController', function () {
       expect(controller.getAllHostNames.calledOnce).to.be.true;
     });
 
-    it('loadAmbariProperties should be called', function() {
-      controller.loadClusterData();
-      expect(controller.loadAmbariProperties.calledOnce).to.be.true;
-    });
-
     it('getAllUserSettings should be called', function() {
       controller.loadClusterData();
       expect(App.router.get('userSettingsController').getAllUserSettings.calledOnce).to.be.true;

http://git-wip-us.apache.org/repos/asf/ambari/blob/e3794a3a/ambari-web/test/controllers/main_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main_test.js b/ambari-web/test/controllers/main_test.js
index c026604..9673092 100644
--- a/ambari-web/test/controllers/main_test.js
+++ b/ambari-web/test/controllers/main_test.js
@@ -22,40 +22,6 @@ var testHelpers = require('test/helpers');
 describe('App.MainController', function () {
   var mainController = App.MainController.create();
 
-  describe('#getServerVersionSuccessCallback', function () {
-
-    var controller = App.MainController.create(),
-      cases = [
-        {
-          osFamily: 'redhat5',
-          expected: false
-        },
-        {
-          osFamily: 'redhat6',
-          expected: true
-        },
-        {
-          osFamily: 'suse11',
-          expected: false
-        }
-      ],
-      title = 'App.isManagedMySQLForHiveEnabled should be {0} for {1}';
-
-    cases.forEach(function (item) {
-      it(title.format(item.expected, item.osFamily), function () {
-        controller.getServerVersionSuccessCallback({
-          'RootServiceComponents': {
-            'component_version': '',
-            'properties': {
-              'server.os_family': item.osFamily
-            }
-          }
-        });
-        expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
-      });
-    });
-  });
-
   App.TestAliases.testAsComputedAlias(mainController, 'isClusterDataLoaded', 'App.router.clusterController.isLoaded',
'boolean');
 
   App.TestAliases.testAsComputedAlias(mainController, 'clusterDataLoadedPercent', 'App.router.clusterController.clusterDataLoadedPercent',
'string');
@@ -110,38 +76,6 @@ describe('App.MainController', function () {
     });
   });
 
-  describe('#checkServerClientVersion', function() {
-    beforeEach(function () {
-      sinon.stub(mainController, 'getServerVersion').returns({
-        done: function(func) {
-          if (func) {
-            func();
-          }
-        }
-      });
-    });
-    afterEach(function () {
-      mainController.getServerVersion.restore();
-    });
-    it ('Should resolve promise', function() {
-      var deffer = mainController.checkServerClientVersion();
-      deffer.then(function(val){
-        expect(val).to.be.undefined;
-      });
-    });
-  });
-
-  describe('#getServerVersion', function() {
-
-    it ('Should send data', function() {
-      mainController.getServerVersion();
-      var args = testHelpers.findAjaxRequest('name', 'ambari.service');
-      expect(args[0]).to.exists;
-      expect(args[0].sender).to.be.eql(mainController);
-      expect(args[0].data.fields).to.be.equal('?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true');
-    });
-  });
-
   describe('#updateTitle', function() {
     beforeEach(function () {
       sinon.stub(App.router, 'get').withArgs('clusterController.clusterName').returns('c1')


Mime
View raw message