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 Thu, 16 Apr 2015 18:06:57 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 34e60b07f -> ecaf2d15f


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/ecaf2d15
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ecaf2d15
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ecaf2d15

Branch: refs/heads/trunk
Commit: ecaf2d15f3657ca53625434bbfcce2c36fbaf4b4
Parents: 34e60b0
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Thu Apr 16 21:06:52 2015 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Thu Apr 16 21:06:52 2015 +0300

----------------------------------------------------------------------
 .../assets/data/cluster/ambariServerInfo.json   |  7 +++
 .../main/resources/ui/admin-web/app/index.html  |  1 +
 .../app/scripts/controllers/mainCtrl.js         | 23 ++++----
 .../admin-web/app/scripts/services/Component.js | 30 +++++++++++
 .../admin-web/app/views/modals/AboutModal.html  |  4 +-
 .../test/unit/services/Component_test.js        | 56 ++++++++++++++++++++
 ambari-web/app/router.js                        | 28 +++++++---
 .../main/admin/stack_upgrade/versions_view.js   |  7 ++-
 ambari-web/test/router_test.js                  | 38 +++++++++++++
 .../admin/stack_upgrade/version_view_test.js    | 14 ++++-
 10 files changed, 188 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/app/assets/data/cluster/ambariServerInfo.json
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/assets/data/cluster/ambariServerInfo.json
b/ambari-admin/src/main/resources/ui/admin-web/app/assets/data/cluster/ambariServerInfo.json
new file mode 100644
index 0000000..bddc249
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/assets/data/cluster/ambariServerInfo.json
@@ -0,0 +1,7 @@
+{
+  "RootServiceComponents" : {
+    "component_name" : "AMBARI_SERVER",
+    "component_version" : "2.0.0",
+    "service_name" : "AMBARI"
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/app/index.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/index.html b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
index 17a1dc9..ca2ae8b 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/index.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/index.html
@@ -146,6 +146,7 @@
     <script src="scripts/services/User.js"></script>
     <script src="scripts/services/Group.js"></script>
     <script src="scripts/services/View.js"></script>
+    <script src="scripts/services/Component.js"></script>
     <script src="scripts/services/Cluster.js"></script>
     <script src="scripts/services/Alert.js"></script>
     <script src="scripts/services/PermissionLoader.js"></script>

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
index baec0cf..1bdfe05 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/mainCtrl.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('MainCtrl',['$scope', '$window','Auth', 'Alert', '$modal', 'Cluster', 'View',
function($scope, $window, Auth, Alert, $modal, Cluster, View) {
+.controller('MainCtrl',['$scope', '$window','Auth', 'Alert', '$modal', 'Cluster', 'Component',
'View', function($scope, $window, Auth, Alert, $modal, Cluster, Component, View) {
   $scope.signOut = function() {
     var data = JSON.parse(localStorage.ambari);
     delete data.app.authenticated;
@@ -31,14 +31,19 @@ angular.module('ambariAdminConsole')
   };
 
   $scope.about = function() {
-  	var modalInstance = $modal.open({
-  		templateUrl:'views/modals/AboutModal.html',
-  		controller: ['$scope', function($scope) {
-  			$scope.ok = function() {
-  				modalInstance.close();
-  			};
-  		}]
-  	});
+    Component.getAmbariServer().then(function(component) {
+      var modalInstance = $modal.open({
+        templateUrl:'views/modals/AboutModal.html',
+        controller: ['$scope', function($scope) {
+          $scope.component = component;
+          $scope.ok = function() {
+            modalInstance.close();
+          };
+        }]
+      });
+    }).catch(function() {
+      Alert.error('Cannot load component status');
+    });
   };
 
   $scope.currentUser = Auth.getCurrentUser();

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Component.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Component.js
b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Component.js
new file mode 100644
index 0000000..7432a90
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Component.js
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+'use strict';
+
+angular.module('ambariAdminConsole')
+  .factory('Component', ['$http', '$q', 'Settings', function($http, $q, Settings) {
+    return {
+      getAmbariServer: function() {
+        return $http.get(Settings.baseUrl + '/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/component_version&minimal_response=true')
+          .then(function(response) {
+            return response.data;
+          });
+      }
+    };
+  }]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AboutModal.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AboutModal.html
b/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AboutModal.html
index d1ac132..c2820df 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AboutModal.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/modals/AboutModal.html
@@ -28,7 +28,7 @@
       <div class="project">Apache Ambari</div>
       <br>
       <span id="i18n-33">Version</span>
-      <script id="metamorph-199-start" type="text/x-placeholder"></script>2.0.0<script
id="metamorph-199-end" type="text/x-placeholder"></script>
+      <span>{{component.RootServiceComponents.component_version}}</span>
       <br>
       <br>
       <a href="http://ambari.apache.org/" target="_blank"><span id="i18n-34">Get
involved!</span></a>
@@ -39,4 +39,4 @@
 </div>
 <div class="modal-footer">
     <button class="btn btn-success" ng-click="ok()">OK</button>
-</div>
\ No newline at end of file
+</div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Component_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Component_test.js
b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Component_test.js
new file mode 100644
index 0000000..03373b5
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/Component_test.js
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+describe('#Component', function () {
+  var componentService,
+    httpBackend,
+    Settings;
+
+  beforeEach(function() {
+    module('ambariAdminConsole');
+
+    inject(function(_Component_, $httpBackend, _Settings_) {
+      componentService = _Component_;
+      httpBackend = $httpBackend;
+      Settings = _Settings_;
+    });
+  });
+
+  afterEach(function() {
+    httpBackend.verifyNoOutstandingExpectation();
+    httpBackend.verifyNoOutstandingRequest();
+  });
+
+  var returnData = {
+    RootServiceComponents: {
+      'component_name': "AMBARI_SERVER",
+      'component_version': "2.0.0",
+      'service_name': "AMBARI"
+    }
+  };
+  it('should get the information of the Ambari server', function() {
+    httpBackend.whenGET(/\/api\/v1\/services\/AMBARI\/components\/AMBARI_SERVER\?.*/).respond(returnData);
+
+    componentService.getAmbariServer().then(function(response) {
+      expect(response).toEqual(returnData);
+      expect(response.RootServiceComponents.component_version).toEqual('2.0.0');
+    });
+
+    httpBackend.flush();
+  });
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index a256fee..9f715ad 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -270,12 +270,9 @@ App.Router = Em.Router.extend({
     } else {
       controller.postLogin(false, false, null);
     }
-
   },
 
   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 || [];
@@ -289,8 +286,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) {
@@ -326,6 +327,16 @@ App.Router = Em.Router.extend({
       }
   },
 
+  adminViewInfoSuccessCallback: function(data) {
+    if (data && data.RootServiceComponents && data.RootServiceComponents.component_version)
{
+      window.location.replace('/views/ADMIN_VIEW/'+data.RootServiceComponents.component_version+'/INSTANCE/#/');
+    }
+  },
+
+  adminViewInfoErrorCallback: function (req) {
+    console.log("Get admin view version error: " + req.statusCode);
+  },
+
   loginGetClustersErrorCallback: function (req) {
     console.log("Get clusters error: " + req.statusCode);
   },
@@ -504,7 +515,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/ecaf2d15/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..3cb7f79 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,12 @@ 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) {
+          window.location.replace('/views/ADMIN_VIEW/'+data.RootServiceComponents.component_version+'/INSTANCE/#/stackVersions');
+        });
     },
     Em.I18n.t('admin.stackVersions.manageVersions.popup.body'),
     null,

http://git-wip-us.apache.org/repos/asf/ambari/blob/ecaf2d15/ambari-web/test/router_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/router_test.js b/ambari-web/test/router_test.js
index eefb35a..3aa7751 100644
--- a/ambari-web/test/router_test.js
+++ b/ambari-web/test/router_test.js
@@ -108,4 +108,42 @@ 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: {
+            RootServiceComponents: {
+              component_version: '2.0.0'
+            }
+          },
+          expected: '/views/ADMIN_VIEW/2.0.0/INSTANCE/#/'
+        },
+        {
+          mockData: {
+            RootServiceComponents: {
+              component_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/ecaf2d15/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..29de70d 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,26 @@ describe('App.mainAdminStackVersionsView', function () {
     before(function () {
       sinon.spy(App, 'showConfirmationPopup', Em.K);
       sinon.stub(window.location, 'replace', Em.K);
+      var data = {
+        RootServiceComponents: {
+          component_version: '2.1.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