ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [43/46] git commit: Revert "AMBARI-6967. Admin View: default login behavior (route to Admin View, Cluster Dashboard, or Views Landing page). (yusaku)"
Date Fri, 22 Aug 2014 12:48:41 GMT
Revert "AMBARI-6967. Admin View: default login behavior (route to Admin View, Cluster Dashboard,
or Views Landing page). (yusaku)"

This reverts commit b750cd8f22443cfb77e7849f6fe42dff400a6200.


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

Branch: refs/heads/branch-alerts-dev
Commit: fc600523a3842faad04b25fb2817638585d2fc18
Parents: 8831f36
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Thu Aug 21 17:03:10 2014 -0700
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Thu Aug 21 17:03:10 2014 -0700

----------------------------------------------------------------------
 ambari-web/app/controllers.js                   |   1 +
 .../controllers/global/cluster_controller.js    |  44 ++++++++
 ambari-web/app/controllers/main.js              |   1 -
 .../app/controllers/main/views_controller.js    |  80 +-------------
 ambari-web/app/mappers/users_mapper.js          |   2 +-
 ambari-web/app/messages.js                      |   2 +
 ambari-web/app/router.js                        | 108 ++++++++-----------
 ambari-web/app/routes/main.js                   |  22 ++++
 ambari-web/app/routes/views.js                  |  53 ---------
 ambari-web/app/utils/ajax/ajax.js               |   2 +-
 ambari-web/app/views/main/menu.js               |   7 +-
 ambari-web/app/views/main/views_view.js         |   4 +-
 ambari-web/test/mappers/users_mapper_test.js    |   2 +-
 13 files changed, 119 insertions(+), 209 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/controllers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers.js b/ambari-web/app/controllers.js
index c4a1001..063af6a 100644
--- a/ambari-web/app/controllers.js
+++ b/ambari-web/app/controllers.js
@@ -54,6 +54,7 @@ require('controllers/main/admin/highAvailability/resourceManager/step4_controlle
 require('controllers/main/admin/repositories');
 require('controllers/main/admin/stack_upgrade_controller');
 require('controllers/main/admin/serviceAccounts_controller');
+require('controllers/main/admin/access_controller');
 require('controllers/main/admin/advanced');
 require('utils/polling');
 require('controllers/main/admin/security');

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/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 3d14754..d612039 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/ambari-web/app/controllers/global/cluster_controller.js
@@ -22,6 +22,7 @@ App.ClusterController = Em.Controller.extend({
   name: 'clusterController',
   isLoaded: false,
   ambariProperties: null,
+  ambariViews: [],
   clusterDataLoadedPercent: 'width:0', // 0 to 1
 
   isGangliaUrlLoaded: false,
@@ -248,6 +249,7 @@ App.ClusterController = Em.Controller.extend({
   loadClusterData: function () {
     var self = this;
     this.loadAmbariProperties();
+    this.loadAmbariViews();
     if (!App.get('clusterName')) {
       return;
     }
@@ -347,6 +349,48 @@ App.ClusterController = Em.Controller.extend({
     }, callback)
   },
 
+  loadAmbariViews: function () {
+    App.ajax.send({
+      name: 'views.info',
+      sender: this,
+      success: 'loadAmbariViewsSuccess'
+    });
+  },
+
+  loadAmbariViewsSuccess: function (data) {
+    if (data.items.length) {
+      App.ajax.send({
+        name: 'views.instances',
+        sender: this,
+        success: 'loadViewInstancesSuccess'
+      });
+    } else {
+      this.set('ambariViews', []);
+    }
+  },
+
+  loadViewInstancesSuccess: function (data) {
+    this.set('ambariViews', []);
+    var self = this;
+    data.items.forEach(function (view) {
+      view.versions.forEach(function (version) {
+        version.instances.forEach(function (instance) {
+          var current_instance = Em.Object.create({
+            iconPath: instance.ViewInstanceInfo.icon_path || "/img/ambari-view-default.png",
+            label: instance.ViewInstanceInfo.label || version.ViewVersionInfo.label || instance.ViewInstanceInfo.view_name,
+            visible: instance.ViewInstanceInfo.visible || false,
+            version: instance.ViewInstanceInfo.version,
+            description: instance.ViewInstanceInfo.description || Em.I18n.t('views.main.instance.noDescription'),
+            viewName: instance.ViewInstanceInfo.view_name,
+            instanceName: instance.ViewInstanceInfo.instance_name,
+            href: instance.ViewInstanceInfo.context_path
+          });
+          self.get('ambariViews').pushObject(current_instance);
+        }, this);
+      }, this);
+    }, this);
+  },
+
   /**
    *
    * @param callback

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/controllers/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main.js b/ambari-web/app/controllers/main.js
index b5d83c4..55db450 100644
--- a/ambari-web/app/controllers/main.js
+++ b/ambari-web/app/controllers/main.js
@@ -44,7 +44,6 @@ App.MainController = Em.Controller.extend({
    */
   initialize: function(){
     App.router.get('clusterController').loadClusterData();
-    App.router.get('mainViewsController').loadAmbariViews();
   },
 
   dataLoading: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/controllers/main/views_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/views_controller.js b/ambari-web/app/controllers/main/views_controller.js
index 687554b..5d64da6 100644
--- a/ambari-web/app/controllers/main/views_controller.js
+++ b/ambari-web/app/controllers/main/views_controller.js
@@ -21,87 +21,9 @@ var App = require('app');
 App.MainViewsController = Em.Controller.extend({
   name:'mainViewsController',
 
-  isDataLoaded: false,
-
-  ambariViews: [],
-
-  dataLoading: function () {
-    var viewsController = this;
-    var dfd = $.Deferred();
-    if (this.get('isDataLoaded')) {
-      dfd.resolve(this.get('ambariViews'));
-    } else {
-      var interval = setInterval(function () {
-        if (viewsController.get('isDataLoaded')) {
-          dfd.resolve(viewsController.get('ambariViews'));
-          clearInterval(interval);
-        }
-      }, 50);
-    }
-    return dfd.promise();
-  },
-
-
-  loadAmbariViews: function () {
-    App.ajax.send({
-      name: 'views.info',
-      sender: this,
-      success: 'loadAmbariViewsSuccess',
-      error: 'loadAmbariViewsError'
-    });
-  },
-
-  loadAmbariViewsSuccess: function (data, opt, params) {
-    if (data.items.length) {
-      App.ajax.send({
-        name: 'views.instances',
-        sender: this,
-        success: 'loadViewInstancesSuccess',
-        error: 'loadViewInstancesError'
-      });
-    } else {
-      this.set('ambariViews', []);
-      this.set('isDataLoaded', true);
-    }
-  },
-
-  loadAmbariViewsError: function () {
-    this.set('ambariViews', []);
-    this.set('isDataLoaded', true);
-  },
-
-  loadViewInstancesSuccess: function (data, opt, params) {
-    this.set('ambariViews', []);
-    var instances = [];
-    data.items.forEach(function (view) {
-      view.versions.forEach(function (version) {
-        version.instances.forEach(function (instance) {
-          var current_instance = Em.Object.create({
-            iconPath: instance.ViewInstanceInfo.icon_path || "/img/ambari-view-default.png",
-            label: instance.ViewInstanceInfo.label || version.ViewVersionInfo.label || instance.ViewInstanceInfo.view_name,
-            visible: instance.ViewInstanceInfo.visible || false,
-            version: instance.ViewInstanceInfo.version,
-            description: instance.ViewInstanceInfo.description || Em.I18n.t('views.main.instance.noDescription'),
-            viewName: instance.ViewInstanceInfo.view_name,
-            instanceName: instance.ViewInstanceInfo.instance_name,
-            href: instance.ViewInstanceInfo.context_path
-          });
-          instances.push(current_instance);
-        }, this);
-      }, this);
-    }, this);
-    this.get('ambariViews').pushObjects(instances);
-    this.set('isDataLoaded', true);
-  },
-
-  loadViewInstancesError: function () {
-    this.set('ambariViews', []);
-    this.set('isDataLoaded', true);
-  },
-
   setView: function(event) {
     if(event.context){
-      App.router.transitionTo('views.viewDetails', event.context);
+      App.router.transitionTo('main.views.viewDetails', event.context);
     }
   }
 });
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/mappers/users_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/users_mapper.js b/ambari-web/app/mappers/users_mapper.js
index 0f86ef6..19b3098 100644
--- a/ambari-web/app/mappers/users_mapper.js
+++ b/ambari-web/app/mappers/users_mapper.js
@@ -49,6 +49,6 @@ App.usersMapper = App.QuickDataMapper.create({
    * @return {Boolean}
    **/
   isAdmin: function(permissionList) {
-    return permissionList.indexOf('AMBARI.ADMIN') > -1 || permissionList.indexOf('CLUSTER.OPERATE')
> -1;
+    return permissionList.indexOf('AMBARI.ADMIN') > -1 || permissionList.indexOf('CLUSTER.OPERATOR')
> -1;
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index f569411..eda41f7 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -276,6 +276,8 @@ Em.I18n.translations = {
   'popup.confirmationFeedBack.sending':'Sending...',
   'popup.confirmationFeedBack.query.fail':'Request failed',
 
+  'router.hadoopClusterNotSetUp':'Your administrator has not set up a Hadoop cluster yet.',
+
   'login.header':'Sign in',
   'login.username':'Username',
   'login.loginButton':'Sign in',

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index 5510434..3b4fb07 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -168,21 +168,22 @@ App.Router = Em.Router.extend({
       data: {
         userName: userName
       },
-      success: 'getUserPrivilegesSuccess',
-      error: 'getUserPrivilegesError'
+      success: 'getUserPrivilegesSuccess'
     });
   },
 
   getUserPrivilegesSuccess: function() {},
 
-  getUserPrivilegesError: function(req) {
-    console.log("Get user privileges error: " + req.statusCode);
-  },
-
   setUserLoggedIn: function(userName) {
+    var controller = this.get('loginController'),
+        self = this;
     this.setAuthenticated(true);
     this.setLoginName(userName);
     this.setUser(App.User.find().findProperty('id', userName));
+    this.getSection(function(route){
+      self.transitionTo(route);
+      controller.postLogin(true,true);
+    });
   },
 
   login: function () {
@@ -221,15 +222,29 @@ App.Router = Em.Router.extend({
 
   loginSuccessCallback: function(data, opt, params) {
     console.log('login success');
-    App.ajax.send({
-      name: 'router.login.clusters',
-      sender: this,
-      data: {
-        loginName: params.loginName,
-        loginData: data
-      },
-      success: 'loginGetClustersSuccessCallback',
-      error: 'loginGetClustersErrorCallback'
+    var isAdmin = false;
+    var self = this;
+    this.getUserPrivileges(data.Users.user_name).done(function(privileges) {
+      data.privileges = privileges;
+      App.usersMapper.map({"items": [data]});
+      isAdmin = App.usersMapper.isAdmin(privileges.items.mapProperty('PrivilegeInfo.permission_name'));
+      if (isAdmin) {
+        App.set('isAdmin', true);
+        self.setUserLoggedIn(params.loginName);
+        return true;
+      }
+      else {
+        return App.ajax.send({
+          name: 'router.login2',
+          sender: self,
+          data: {
+            loginName: params.loginName,
+            loginData: data
+          },
+          success: 'login2SuccessCallback',
+          error: 'login2ErrorCallback'
+        });
+      }
     });
   },
 
@@ -245,55 +260,19 @@ App.Router = Em.Router.extend({
 
   },
 
-  loginGetClustersSuccessCallback: function (clustersData, opt, params) {
-    var adminViewUrl = '/views/ADMIN_VIEW/1.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 router = this;
-
-    this.getUserPrivileges(params.loginName).done(function(privileges) {
-      loginData.privileges = privileges;
-      App.usersMapper.map({"items": [loginData]});
-      router.setUserLoggedIn(params.loginName);
-      var permissionList = privileges.items.mapProperty('PrivilegeInfo.permission_name');
-      var isAdmin = permissionList.indexOf('AMBARI.ADMIN') > -1;
-      var transitionToApp = false;
-      if (isAdmin) {
-        App.set('isAdmin', true);
-        if (clustersData.items.length) {
-          transitionToApp = true;
-        } else {
-          window.location = adminViewUrl;
-          return;
-        }
-      } else {
-        if (clustersData.items.length) {
-          //TODO: Iterate over clusters
-          var clusterName = clustersData.items[0].Clusters.cluster_name;
-          var clusterPermissions = privileges.items.filterProperty('PrivilegeInfo.cluster_name',
clusterName).mapProperty('PrivilegeInfo.permission_name');
-          if (clusterPermissions.indexOf('CLUSTER.OPERATE') > -1) {
-            App.set('isAdmin', true);
-            transitionToApp = true;
-          } else if (clusterPermissions.indexOf('CLUSTER.READ') > -1) {
-            transitionToApp = true;
-          }
-        }
-      }
-      if (transitionToApp) {
-        router.getSection(function (route) {
-          router.transitionTo(route);
-          loginController.postLogin(true, true);
-        });
-      } else {
-        router.transitionTo('views.index');
-        loginController.postLogin(true,true);
-      }
-    });
+  login2SuccessCallback: function (clusterResp, opt, params) {
+    var controller = this.get('loginController');
+    if (clusterResp.items.length) {
+      App.usersMapper.map({"items": [params.loginData]});
+      this.setUserLoggedIn(params.loginName);
+    }
+    else {
+      controller.set('errorMessage', Em.I18n.t('router.hadoopClusterNotSetUp'));
+    }
   },
 
-  loginGetClustersErrorCallback: function (req) {
-    console.log("Get clusters error: " + req.statusCode);
+  login2ErrorCallback: function (req) {
+    console.log("Server not responding: " + req.statusCode);
   },
 
   getSection: function (callback) {
@@ -368,7 +347,6 @@ App.Router = Em.Router.extend({
       });
     }
     this.transitionTo('login', context);
-    window.location.reload();
   },
 
   logOffSuccessCallback: function (data) {
@@ -430,9 +408,7 @@ App.Router = Em.Router.extend({
     installer: require('routes/installer'),
 
     main: require('routes/main'),
-
-    views: require('routes/views'),
-
+    
     experimental: Em.Route.extend({
       route: '/experimental',
       enter: function (router, context) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/routes/main.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/main.js b/ambari-web/app/routes/main.js
index f822c48..b73627a 100644
--- a/ambari-web/app/routes/main.js
+++ b/ambari-web/app/routes/main.js
@@ -67,6 +67,28 @@ module.exports = Em.Route.extend({
     router.get('applicationController').connectOutlet('main');
   },
 
+
+  views: Em.Route.extend({
+    route: '/views',
+    index: Em.Route.extend({
+      route: '/',
+      connectOutlets: function (router, context) {
+        router.get('mainController').connectOutlet('mainViews');
+      }
+    }),
+    viewDetails: Em.Route.extend({
+      route: '/:viewName/:version/:instanceName',
+      connectOutlets: function (router, params) {
+        router.get('mainController').dataLoading().done(function() {
+          // find and set content for `mainViewsDetails` and associated controller
+          router.get('mainController').connectOutlet('mainViewsDetails', App.router.get('clusterController.ambariViews')
+            .findProperty('href', ['/views', params.viewName, params.version, params.instanceName].join('/')));
+        });
+      }
+    })
+  }),
+
+
   test: Em.Route.extend({
     route: '/test',
     connectOutlets: function (router, context) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/routes/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/views.js b/ambari-web/app/routes/views.js
deleted file mode 100644
index d72dbf0..0000000
--- a/ambari-web/app/routes/views.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.
- */
-
-var App = require('app');
-var stringUtils = require('utils/string_utils');
-
-module.exports = Em.Route.extend({
-  route: '/views',
-  enter: function (router) {
-    router.getAuthenticated().done(function (loggedIn) {
-      if (loggedIn) {
-        router.get('mainViewsController').loadAmbariViews();
-      } else {
-        Em.run.next(function () {
-          router.transitionTo('login');
-        });
-      }
-    });
-  },
-  index: Em.Route.extend({
-    route: '/',
-    connectOutlets: function (router) {
-      router.get('mainViewsController').dataLoading().done(function() {
-        router.get('applicationController').connectOutlet('mainViews');
-      });
-    }
-  }),
-  viewDetails: Em.Route.extend({
-    route: '/:viewName/:version/:instanceName',
-    connectOutlets: function (router, params) {
-      // find and set content for `mainViewsDetails` and associated controller
-      router.get('mainViewsController').dataLoading().done(function() {
-        router.get('applicationController').connectOutlet('mainViewsDetails', App.router.get('mainViewsController.ambariViews')
-          .findProperty('href', ['/views', params.viewName, params.version, params.instanceName].join('/')));
-      });
-    }
-  })
-});

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/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 4213bc5..09d68c6 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/ambari-web/app/utils/ajax/ajax.js
@@ -1370,7 +1370,7 @@ var urls = {
     real: '/privileges?PrivilegeInfo/principal_name={userName}&fields=*',
     mock: '/data/users/privileges_{userName}.json'
   },
-  'router.login.clusters': {
+  'router.login2': {
     'real': '/clusters',
     'mock': '/data/clusters/info.json'
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/views/main/menu.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/menu.js b/ambari-web/app/views/main/menu.js
index c9d475a..ea4a2bd 100644
--- a/ambari-web/app/views/main/menu.js
+++ b/ambari-web/app/views/main/menu.js
@@ -27,8 +27,8 @@ App.MainMenuView = Em.CollectionView.extend({
   classNames:['nav', 'top-nav-menu'],
 
   views: function() {
-    return App.router.get('mainViewsController.ambariViews');
-  }.property('App.router.mainViewsController.ambariViews'),
+    return App.router.get('clusterController.ambariViews');
+  }.property('App.router.clusterController.ambariViews'),
 
   content: function(){
     var result = [];
@@ -121,9 +121,6 @@ App.MainMenuView = Em.CollectionView.extend({
     goToSection: function (event) {
       if (event.context === 'hosts') {
         App.router.set('mainHostController.showFilterConditionsFirstLoad', false);
-      } else if (event.context === 'views') {
-        App.router.route('views');
-        return;
       }
       App.router.route('main/' + event.context);
     },

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/app/views/main/views_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/views_view.js b/ambari-web/app/views/main/views_view.js
index 3c97baf..5a16bbd 100644
--- a/ambari-web/app/views/main/views_view.js
+++ b/ambari-web/app/views/main/views_view.js
@@ -25,8 +25,8 @@ App.MainViewsView = Em.View.extend({
   classNames: [""],
 
   views: function() {
-    return App.router.get('mainViewsController.ambariViews');
-  }.property('App.router.mainViewsController.ambariViews'),
+    return App.router.get('clusterController.ambariViews');
+  }.property('App.ClusterController.ambariViews'),
 
   selectedViewBinding: 'controller.selectedView'
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc600523/ambari-web/test/mappers/users_mapper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mappers/users_mapper_test.js b/ambari-web/test/mappers/users_mapper_test.js
index 767a002..20c6bae 100644
--- a/ambari-web/test/mappers/users_mapper_test.js
+++ b/ambari-web/test/mappers/users_mapper_test.js
@@ -29,7 +29,7 @@ describe('App.usersMapper', function () {
       {i:["AMBARI.ADMIN"],e:true,m:'has admin role'},
       {i:["CLUSTER.READ", "AMBARI.ADMIN"],e:true,m:'has admin role'},
       {i:["VIEW.USE"],e:false,m:'doesn\'t have admin role'},
-      {i:["CLUSTER.OPERATE"],e:true,m:'has admin role'}
+      {i:["CLUSTER.OPERATOR"],e:true,m:'has admin role'}
     ];
     tests.forEach(function(test) {
       it(test.m, function() {


Mime
View raw message