ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject ambari git commit: AMBARI-10533. Admin View About says 2.0.0 (and links to Admin View are hardcoded to 2.0.0) (alexantonenko)
Date Tue, 26 May 2015 19:17:39 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d636d70d7 -> 49403a68d


AMBARI-10533. Admin View About says 2.0.0 (and links to Admin View are hardcoded to 2.0.0)
(alexantonenko)


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

Branch: refs/heads/trunk
Commit: 49403a68d9afa9f544bfafe6a841f2f82a714e70
Parents: d636d70
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Tue May 26 22:16:36 2015 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Tue May 26 22:17:35 2015 +0300

----------------------------------------------------------------------
 ambari-admin/src/main/resources/view.xml        |  4 +-
 ambari-web/app/router.js                        | 36 ++++++++++---
 ambari-web/app/utils/ajax/ajax.js               |  6 +++
 .../main/admin/stack_upgrade/versions_view.js   | 18 ++++++-
 ambari-web/test/router_test.js                  | 56 ++++++++++++++++++++
 .../admin/stack_upgrade/version_view_test.js    | 26 ++++++++-
 6 files changed, 135 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-admin/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/view.xml b/ambari-admin/src/main/resources/view.xml
index fb3dde1..f6ce7ef 100644
--- a/ambari-admin/src/main/resources/view.xml
+++ b/ambari-admin/src/main/resources/view.xml
@@ -17,11 +17,11 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
 <view>
   <name>ADMIN_VIEW</name>
   <label>Ambari Admin View</label>
-  <version>2.0.0</version>
+  <version>2.1.0</version>
   <system>true</system>
   <instance>
     <name>INSTANCE</name>
     <description>This view provides administration capabilities for Ambari</description>
     <visible>false</visible>
   </instance>
-</view>
\ No newline at end of file
+</view>

http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 46e62aa..e72f971 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -275,8 +275,6 @@ App.Router = Em.Router.extend({
   },
 
   loginGetClustersSuccessCallback: function (clustersData, opt, params) {
-    var adminViewUrl = '/views/ADMIN_VIEW/2.0.0/INSTANCE/#/';
-    //TODO: Replace hard coded value with query. Same in templates/application.hbs
     var loginController = this.get('loginController');
     var loginData = params.loginData;
     var privileges = loginData.privileges || [];
@@ -290,8 +288,12 @@ App.Router = Em.Router.extend({
           router.setClusterInstalled(clustersData);
           transitionToApp = true;
         } else {
-          window.location = adminViewUrl;
-          return;
+          App.ajax.send({
+            name: 'ambari.service.load_server_version',
+            sender: this,
+            success: 'adminViewInfoSuccessCallback',
+            error: 'adminViewInfoErrorCallback'
+          });
         }
       } else {
         if (clustersData.items.length) {
@@ -312,7 +314,7 @@ App.Router = Em.Router.extend({
       }
       App.set('isPermissionDataLoaded', true);
       if (transitionToApp) {
-        if (!Em.isNone(router.get('preferedPath')) && 
+        if (!Em.isNone(router.get('preferedPath')) &&
             router.get('preferedPath') != "#/login") {
           window.location = router.get('preferedPath');
           router.set('preferedPath', null);
@@ -327,6 +329,23 @@ App.Router = Em.Router.extend({
         loginController.postLogin(true,true);
       }
   },
+  adminViewInfoSuccessCallback: function(data) {
+    var components = Em.get(data,'components');
+    if (Em.isArray(components)) {
+      var mappedVersions = components.map(function(component) {
+          if (Em.get(component, 'RootServiceComponents.component_version')) {
+            return Em.get(component, 'RootServiceComponents.component_version');
+          }
+        }),
+        sortedMappedVersions = mappedVersions.sort(),
+        latestVersion = sortedMappedVersions[sortedMappedVersions.length-1];
+      window.location.replace('/views/ADMIN_VIEW/' + latestVersion + '/INSTANCE/#/');
+    }
+  },
+
+  adminViewInfoErrorCallback: function (req) {
+    console.log("Get admin view version error: " + req.statusCode);
+  },
 
   loginGetClustersErrorCallback: function (req) {
     console.log("Get clusters error: " + req.statusCode);
@@ -506,7 +525,12 @@ App.Router = Em.Router.extend({
             router.transitionTo('login');
           });
         } else {
-            window.location.replace('/views/ADMIN_VIEW/2.0.0/INSTANCE/#/');
+          App.ajax.send({
+            name: 'ambari.service.load_server_version',
+            sender: router,
+            success: 'adminViewInfoSuccessCallback',
+            error: 'adminViewInfoErrorCallback'
+          });
         }
       }
     }),

http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js
index c0a24c1..f942054 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -201,6 +201,12 @@ var urls = {
     'mock': '/data/services/ambari.json'
   },
 
+  'ambari.service.load_server_version': {
+    'real': '/services/AMBARI?fields=components/RootServiceComponents/component_version&components/RootServiceComponents/component_name=AMBARI_SERVER&minimal_response=true',
+    'mock': '/data/services/ambari.json'
+  },
+
+
   'service.flume.agent.command': {
     'real': '/clusters/{clusterName}/hosts/{host}/host_components/FLUME_HANDLER',
     'mock': '',

http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js b/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
index 3b2848d..195320f 100644
--- a/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
+++ b/ambari-web/app/views/main/admin/stack_upgrade/versions_view.js
@@ -168,7 +168,23 @@ App.MainAdminStackVersionsView = Em.View.extend({
    */
   goToVersions: function () {
     return App.showConfirmationPopup(function () {
-      window.location.replace('/views/ADMIN_VIEW/2.0.0/INSTANCE/#/stackVersions');
+      App.ajax.send({
+        name: 'ambari.service.load_server_version',
+        sender: this
+      }).then(function(data) {
+        var components = Em.get(data,'components');
+        if (Em.isArray(components)) {
+          var mappedVersions = components.map(function(component) {
+              if (Em.get(component, 'RootServiceComponents.component_version')) {
+                return Em.get(component, 'RootServiceComponents.component_version');
+              }
+            }),
+            sortedMappedVersions = mappedVersions.sort(),
+            latestVersion = sortedMappedVersions[sortedMappedVersions.length-1];
+            console.log('/views/ADMIN_VIEW/' + latestVersion + '/INSTANCE/#/stackVersions');
+            window.location.replace('/views/ADMIN_VIEW/' + latestVersion + '/INSTANCE/#/stackVersions');
+        }
+      });
     },
     Em.I18n.t('admin.stackVersions.manageVersions.popup.body'),
     null,

http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-web/test/router_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js
index eefb35a..f5c66a3 100644
--- a/ambari-web/test/router_test.js
+++ b/ambari-web/test/router_test.js
@@ -108,4 +108,60 @@ describe('App.Router', function () {
 
   });
 
+  describe('#adminViewInfoSuccessCallback', function() {
+    beforeEach(function() {
+      sinon.stub(window.location, 'replace', Em.K);
+    });
+    afterEach(function() {
+      window.location.replace.restore();
+    });
+
+    it('should redirect to the latest version of admin view', function() {
+      var tests = [{
+        mockData: {
+          components: [{
+            'RootServiceComponents': {
+              'component_version': '1.9.0'
+            }
+          }, {
+            'RootServiceComponents': {
+              'component_version': '2.0.0'
+            }
+          }]
+        },
+        expected: '/views/ADMIN_VIEW/2.0.0/INSTANCE/#/'
+      }, {
+        mockData: {
+          components: [{
+            'RootServiceComponents': {
+              'component_version': '1.9.0'
+            }
+          }, {
+            'RootServiceComponents': {
+              'component_version': '2.1.0'
+            }
+          }, {
+            'RootServiceComponents': {
+              'component_version': '2.0.0'
+            }
+          }]
+        },
+        expected: '/views/ADMIN_VIEW/2.1.0/INSTANCE/#/'
+      }, {
+        mockData: {
+          versions: [{
+            'RootServiceComponents': {
+              version: '2.1.0'
+            }
+          }]
+        },
+        expected: '/views/ADMIN_VIEW/2.1.0/INSTANCE/#/'
+      }];
+
+      tests.forEach(function(data) {
+        router.adminViewInfoSuccessCallback(data.mockData);
+        expect(window.location.replace.calledWith(data.expected)).to.be.true;
+      });
+    });
+  });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/49403a68/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js b/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
index 5a457bf..8090482 100644
--- a/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
+++ b/ambari-web/test/views/main/admin/stack_upgrade/version_view_test.js
@@ -281,16 +281,38 @@ describe('App.mainAdminStackVersionsView', function () {
     before(function () {
       sinon.spy(App, 'showConfirmationPopup', Em.K);
       sinon.stub(window.location, 'replace', Em.K);
+      var data = {
+        components: [{
+          'RootServiceComponents': {
+            'component_version': '1.9.0'
+          }
+        }, {
+          'RootServiceComponents': {
+            'component_version': '2.1.0'
+          }
+        }, {
+          'RootServiceComponents': {
+            'component_version': '2.0.0'
+          }
+        }]
+      };
+      sinon.stub(App.ajax, 'send').returns({
+        then: function(callback) {
+          callback(data);
+        }
+      });
     });
     after(function () {
       App.showConfirmationPopup.restore();
       window.location.replace.restore();
+      App.ajax.send.restore();
     });
-    it("", function() {
+    it("should go to link using the version retrieved by query", function() {
       var popup = view.goToVersions();
       expect(App.showConfirmationPopup.calledOnce).to.be.true;
       popup.onPrimary();
-      expect(window.location.replace.calledWith('/views/ADMIN_VIEW/2.0.0/INSTANCE/#/stackVersions')).to.be.true;
+      expect(App.ajax.send.calledOnce).to.be.true;
+      expect(window.location.replace.calledWith('/views/ADMIN_VIEW/2.1.0/INSTANCE/#/stackVersions')).to.be.true;
     });
   });
 


Mime
View raw message