You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2015/01/06 23:59:52 UTC

ambari git commit: AMBARI-8981. Ambari View: Repo Version Management: Deregister is enabled on current / installed version. (Richard Zang via yusaku)

Repository: ambari
Updated Branches:
  refs/heads/trunk 4c5af44c8 -> 965188941


AMBARI-8981. Ambari View: Repo Version Management: Deregister is enabled on current / installed version. (Richard Zang via yusaku)


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

Branch: refs/heads/trunk
Commit: 9651889419332fb94636e1f6c71cffc6074f1b9f
Parents: 4c5af44
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Tue Jan 6 14:58:43 2015 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Tue Jan 6 14:58:43 2015 -0800

----------------------------------------------------------------------
 .../stackVersions/StackVersionsEditCtrl.js      | 70 ++++++++++++++------
 .../stackVersions/StackVersionsListCtrl.js      | 49 +++++++-------
 .../admin-web/app/scripts/services/Cluster.js   |  4 ++
 .../ui/admin-web/app/scripts/services/Stack.js  | 27 ++++++--
 .../admin-web/app/views/stackVersions/list.html |  6 +-
 5 files changed, 102 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/96518894/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
index e951c97..734650f 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsEditCtrl.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-.controller('StackVersionsEditCtrl', ['$scope', '$location', 'Stack', '$routeParams', 'ConfirmationModal', 'Alert', function($scope, $location, Stack, $routeParams, ConfirmationModal, Alert) {
+.controller('StackVersionsEditCtrl', ['$scope', '$location', 'Cluster', 'Stack', '$routeParams', 'ConfirmationModal', 'Alert', function($scope, $location, Cluster, Stack, $routeParams, ConfirmationModal, Alert) {
   $scope.loadStackVersionInfo = function () {
     return Stack.getRepo($routeParams.versionId, $routeParams.stackName).then(function (response) {
       $scope.id = response.id;
@@ -32,6 +32,20 @@ angular.module('ambariAdminConsole')
         os.selected = true;
       });
       $scope.osList = response.osList;
+      // if user reach here from UI click, repo status should be cached
+      // otherwise re-fetch repo status from cluster end point.
+      var repoStatus = Cluster.repoStatusCache[$scope.id];
+      if (!repoStatus) {
+        $scope.fetchClusters()
+        .then(function () {
+          return $scope.fetchRepoClusterStatus();
+        })
+        .then(function () {
+          $scope.deleteEnabled = ($scope.repoStatus == 'current' || $scope.repoStatus == 'installed')? false : true;
+        });
+      } else {
+        $scope.deleteEnabled = (repoStatus == 'current' || repoStatus == 'installed')? false : true;
+      }
       $scope.addMissingOSList();
     });
   }
@@ -46,28 +60,28 @@ angular.module('ambariAdminConsole')
       //TODO map data.operating_systems after API is fixed
       var operatingSystems = data.operating_systems || data.operatingSystems;
       var osList = operatingSystems.map(function (os) {
-          return existingOSHash[os.OperatingSystems.os_type] || {
-            OperatingSystems: {
-              os_type : os.OperatingSystems.os_type
+        return existingOSHash[os.OperatingSystems.os_type] || {
+          OperatingSystems: {
+            os_type : os.OperatingSystems.os_type
+          },
+          repositories: [
+            {
+              Repositories: {
+                base_url: '',
+                repo_id: 'HDP-' + $routeParams.versionId,
+                repo_name: 'HDP'
+              }
             },
-            repositories: [
-              {
-                Repositories: {
-                  base_url: '',
-                  repo_id: 'HDP-' + $routeParams.versionId,
-                  repo_name: 'HDP'
-                }
-              },
-              {
-                Repositories: {
-                  base_url: '',
-                  repo_id: 'HDP-UTILS-' + $routeParams.versionId,
-                  repo_name: 'HDP-UTILS'
-                }
+            {
+              Repositories: {
+                base_url: '',
+                repo_id: 'HDP-UTILS-' + $routeParams.versionId,
+                repo_name: 'HDP-UTILS'
               }
-            ],
-            selected: false
-          };
+            }
+          ],
+          selected: false
+        };
       });
       $scope.osList = osList;
     })
@@ -77,7 +91,6 @@ angular.module('ambariAdminConsole')
   }
 
   $scope.skipValidation = false;
-  $scope.deleteEnabled = true;
 
   $scope.save = function () {
     $scope.editVersionDisabled = true;
@@ -101,6 +114,19 @@ angular.module('ambariAdminConsole')
     $location.path('/stackVersions');
   };
 
+  $scope.fetchRepoClusterStatus = function () {
+    var clusterName = $scope.clusters[0].Clusters.cluster_name; // only support one cluster at the moment
+    return Cluster.getRepoVersionStatus(clusterName, $scope.id).then(function (response) {
+      $scope.repoStatus = response.status;
+    });
+  };
+
+  $scope.fetchClusters = function () {
+    return Cluster.getAllClusters().then(function (clusters) {
+      $scope.clusters = clusters;
+    });
+  };
+
   $scope.delete = function () {
     ConfirmationModal.show('Delete Version', 'Are you sure you want to delete version "'+ $scope.versionName +'"?').then(function() {
       Stack.deleteRepo($scope.stackName, $scope.stackVersion, $scope.id).then( function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/96518894/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
index da1d93a..569086d 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/controllers/stackVersions/StackVersionsListCtrl.js
@@ -18,7 +18,7 @@
 'use strict';
 
 angular.module('ambariAdminConsole')
-  .controller('StackVersionsListCtrl', ['$scope', 'Cluster', 'Stack', '$routeParams', function ($scope, Cluster, Stack, $routeParams) {
+.controller('StackVersionsListCtrl', ['$scope', 'Cluster', 'Stack', '$routeParams', function ($scope, Cluster, Stack, $routeParams) {
   $scope.clusterName = $routeParams.clusterName;
   $scope.filter = {
     version: '',
@@ -29,7 +29,7 @@ angular.module('ambariAdminConsole')
   };
 
   $scope.pagination = {
-    totalStacks: 10,
+    totalRepos: 10,
     maxVisiblePages: 20,
     itemsPerPage: 10,
     currentPage: 1
@@ -47,7 +47,11 @@ angular.module('ambariAdminConsole')
 
   $scope.resetPagination = function () {
     $scope.pagination.currentPage = 1;
-    $scope.fetchRepos();
+    $scope.loadAllData();
+  };
+
+  $scope.pageChanged = function () {
+    $scope.loadAllData();
   };
 
   $scope.goToCluster = function() {
@@ -75,24 +79,11 @@ angular.module('ambariAdminConsole')
   };
 
   $scope.fetchRepos = function () {
-    return Stack.allRepos($scope.filter, $scope.pagination).then(function (stacks) {
-      $scope.pagination.totalStacks = stacks.items.length;
-      var repos = [];
-      angular.forEach(stacks.items, function(stack) {
-        angular.forEach(stack.versions, function (version) {
-          var repoVersions = version.repository_versions;
-          if (repoVersions.length > 0) {
-            repos = repos.concat(repoVersions);
-          }
-        });
-      });
-      repos = repos.map(function (stack) {
-        return stack.RepositoryVersions;
-      });
-      $scope.repos = repos;
-      $scope.tableInfo.total = stacks.length;
-      $scope.tableInfo.showed = stacks.length;
-      $scope.fetchRepoClusterStatus();
+    return Stack.allRepos($scope.filter, $scope.pagination).then(function (repos) {
+      $scope.pagination.totalRepos = repos.itemTotal;
+      $scope.repos = repos.items;
+      $scope.tableInfo.total = repos.itemTotal;
+      $scope.tableInfo.showed = repos.showed;
     });
   };
 
@@ -117,11 +108,21 @@ angular.module('ambariAdminConsole')
   };
 
   $scope.fetchClusters = function () {
-    Cluster.getAllClusters().then(function (clusters) {
+    return Cluster.getAllClusters().then(function (clusters) {
       $scope.clusters = clusters;
       $scope.fillClusters(clusters);
-      $scope.fetchRepos();
     });
   };
-  $scope.fetchClusters();
+
+  $scope.loadAllData = function () {
+    $scope.fetchClusters()
+    .then(function () {
+      return $scope.fetchRepos();
+    })
+    .then(function () {
+      $scope.fetchRepoClusterStatus();
+    });
+  };
+
+  $scope.loadAllData();
 }]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/96518894/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
index 25f512c..d14baa4 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Cluster.js
@@ -20,6 +20,8 @@
 angular.module('ambariAdminConsole')
 .factory('Cluster', ['$http', '$q', 'Settings', function($http, $q, Settings) {
   return {
+    repoStatusCache : {},
+
     getAllClusters: function() {
       var deferred = $q.defer();
       $http.get(Settings.baseUrl + '/clusters', {mock: 'cluster/clusters.json'})
@@ -128,6 +130,7 @@ angular.module('ambariAdminConsole')
       });
     },
     getRepoVersionStatus: function (clusterName, repoId ) {
+      var me = this;
       var deferred = $q.defer();
       var url = Settings.baseUrl + '/clusters/' + clusterName +
         '/stack_versions?fields=*&ClusterStackVersions/repository_version=' + repoId;
@@ -153,6 +156,7 @@ angular.module('ambariAdminConsole')
         } else {
           response.status = '';
         }
+        me.repoStatusCache[repoId] = response.status;
         deferred.resolve(response);
       })
       .catch(function (data) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/96518894/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
index 784c8d1..83bd21a 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/Stack.js
@@ -85,12 +85,29 @@ angular.module('ambariAdminConsole')
       if (versionFilter) {
         url += '&versions/repository_versions/RepositoryVersions/display_name.matches(.*' + versionFilter + '.*)';
       }
-      url += '&from='+ (pagination.currentPage - 1) * pagination.itemsPerPage;
-      url += '&page_size=' + pagination.itemsPerPage;
       var deferred = $q.defer();
       $http.get(Settings.baseUrl + url, {mock: 'version/versions.json'})
       .success(function (data) {
-        deferred.resolve(data)
+        var repos = [];
+        angular.forEach(data.items, function(stack) {
+          angular.forEach(stack.versions, function (version) {
+            var repoVersions = version.repository_versions;
+            if (repoVersions.length > 0) {
+              repos = repos.concat(repoVersions);
+            }
+          });
+        });
+        repos = repos.map(function (stack) {
+          return stack.RepositoryVersions;
+        });
+        // prepare response data with client side pagination
+        var response = {};
+        response.itemTotal = repos.length;
+        var from = (pagination.currentPage - 1) * pagination.itemsPerPage;
+        var to = (repos.length - from > pagination.itemsPerPage)? from + pagination.itemsPerPage : repos.length;
+        response.items = repos.slice(from, to);
+        response.showed = to - from;
+        deferred.resolve(response)
       })
       .error(function (data) {
         deferred.reject(data);
@@ -129,8 +146,8 @@ angular.module('ambariAdminConsole')
 
     getRepo: function (repoVersion, stack_name) {
       var url = Settings.baseUrl + '/stacks/' + stack_name + '/versions?' +
-                'fields=repository_versions/operating_systems/repositories/*' +
-                '&repository_versions/RepositoryVersions/repository_version=' + repoVersion;
+      'fields=repository_versions/operating_systems/repositories/*' +
+      '&repository_versions/RepositoryVersions/repository_version=' + repoVersion;
       var deferred = $q.defer();
       $http.get(url, {mock: 'version/version.json'})
       .success(function (data) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/96518894/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html
index 2c37092..c661861 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/stackVersions/list.html
@@ -83,12 +83,12 @@
     </div>
     <div class="pull-right left-margin">
       <pagination class="paginator"
-                  total-items="pagination.totalStacks"
+                  total-items="pagination.totalRepos"
                   max-size="pagination.maxVisiblePages"
                   items-per-page="pagination.itemsPerPage"
                   ng-model="pagination.currentPage"
-                  ng-change="fetchRepos()"
-      ></pagination>
+                  ng-change="pageChanged()"
+        ></pagination>
     </div>
     <div class="pull-right">
       <select class="form-control"