Browse Source

AMBARI-2702. UI cleanup after merge branch-1.4.0 into trunk. (Andrii Tkach via srimanth)

Srimanth Gunturi 12 years ago
parent
commit
256c309176

+ 7 - 1
ambari-web/app/app.js

@@ -18,6 +18,8 @@
 
 // Application bootstrapper
 
+var stringUtils = require('utils/string_utils');
+
 module.exports = Em.Application.create({
   name: 'Ambari Web',
   rootElement: '#wrapper',
@@ -54,7 +56,11 @@ module.exports = Em.Application.create({
   currentStackVersion: '',
   currentStackVersionNumber: function(){
     return this.get('currentStackVersion').replace(/HDP(Local)?-/, '');
-  }.property('currentStackVersion')
+  }.property('currentStackVersion'),
+  isHadoop2Stack: function(){
+    return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") === 1 ||
+      stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") === 0)
+  }.property('currentStackVersionNumber')
 });
 
 /**

+ 5 - 2
ambari-web/app/controllers/global/update_controller.js

@@ -83,12 +83,15 @@ App.UpdateController = Em.Controller.extend({
     if (App.Service.find().findProperty('serviceName', 'FLUME')) {
       conditionalFields.push("components/host_components/metrics/flume/flume");
     }
+    if (App.Service.find().findProperty('serviceName', 'YARN')) {
+      conditionalFields.push("components/host_components/metrics/yarn/Queue");
+    }
     var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
     var methodStartTs = new Date().getTime();
     var servicesUrl = isInitialLoad ? 
       //this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles') :
-      this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString+',components/host_components/metrics/yarn/Queue') :
-      this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString+',components/host_components/metrics/yarn/Queue');
+      this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString) :
+      this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString);
     var callback = callback || function (jqXHR, textStatus) {
       self.set('isUpdated', true);
     };

+ 1 - 2
ambari-web/app/controllers/main/apps/item_controller.js

@@ -17,7 +17,6 @@
  */
 
 var App = require('app');
-var stringUtils = require('utils/string_utils');
 
 App.MainAppsItemController = Em.Controller.extend({
   name:'mainAppsItemController',
@@ -35,7 +34,7 @@ App.MainAppsItemController = Em.Controller.extend({
     }
     var self = this;
 
-    if (!App.testMode && stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === -1) {
+    if (!App.testMode && !App.get('isHadoop2Stack')) {
       var url = App.testMode ? '/data/apps/jobs/'+ currentId +'.json' :
         App.apiPrefix + "/jobhistory/job?workflowId=" + currentId;
 

+ 21 - 16
ambari-web/app/controllers/main/apps_controller.js

@@ -19,7 +19,6 @@
 var App = require('app');
 var misc = require('utils/misc');
 var date = require('utils/date');
-var stringUtils = require('utils/string_utils');
 
 App.MainAppsController = Em.ArrayController.extend({
 
@@ -49,7 +48,12 @@ App.MainAppsController = Em.ArrayController.extend({
     var self = this;
 
     //var runsUrl = App.testMode ? "/data/apps/runs.json" : App.apiPrefix + "/jobhistory/workflow?orderBy=startTime&sortDir=DESC&limit=" + App.maxRunsForAppBrowser;
-    var runsUrl = App.testMode ? "/data/apps/runs2.json" : App.apiPrefix + this.get("runUrl");
+    var runsUrl;
+    if (App.testMode) {
+      runsUrl = App.get('isHadoop2Stack') ? "/data/apps/runs2.json" : "/data/apps/runs.json";
+    } else {
+      runsUrl = App.apiPrefix + this.get("runUrl");
+    }
 
     App.HttpClient.get(runsUrl, App.runsMapper, {
       complete:function (jqXHR, textStatus) {
@@ -110,20 +114,21 @@ App.MainAppsController = Em.ArrayController.extend({
      * Direct binding to job filter field
      */
     runType:"",
-    onRunTypeChange:function(){
-      if(this.runType == "MapReduce"){
-        if (!App.testMode && stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === -1)
-          this.set("sSearch_2","mr");
-        else
-          this.set("sSearch_2","mapreduce");
-      }else if(this.runType == "Hive"){
-        this.set("sSearch_2","hive");
-      }else if(this.runType == "Pig"){
-        this.set("sSearch_2","pig");
-      }else if(this.runType == "Yarn"){
-        this.set("sSearch_2","yarn");
-      }else{
-        this.set("sSearch_2","");
+    onRunTypeChange: function () {
+      if (this.runType == "MapReduce") {
+        if (!App.testMode && !App.get('isHadoop2Stack')) {
+          this.set("sSearch_2", "mr");
+        } else {
+          this.set("sSearch_2", "mapreduce");
+        }
+      } else if (this.runType == "Hive") {
+        this.set("sSearch_2", "hive");
+      } else if (this.runType == "Pig") {
+        this.set("sSearch_2", "pig");
+      } else if (this.runType == "Yarn") {
+        this.set("sSearch_2", "yarn");
+      } else {
+        this.set("sSearch_2", "");
       }
     }.observes("runType"),
 

+ 3 - 1
ambari-web/app/controllers/main/service/info/configs.js

@@ -32,10 +32,12 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   serviceConfigs: function(){
     return App.config.get('preDefinedServiceConfigs');
   }.property('App.config.preDefinedServiceConfigs'),
+  customConfigs: function(){
+    return App.config.get('preDefinedCustomConfigs');
+  }.property('App.config.preDefinedCustomConfigs'),
   configMapping: function(){
     return App.config.get('configMapping');
   }.property('App.config.configMapping'),
-  customConfigs: require('data/custom_configs'),
   configs: function() {
     return  App.config.get('preDefinedConfigProperties');
   }.property('App.config.preDefinedConfigProperties'),

+ 27 - 18
ambari-web/app/utils/config.js

@@ -25,10 +25,6 @@ var globalPropertyToServicesMap = null;
 
 App.config = Em.Object.create({
 
-  isHDP2: function(){
-    return (stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === 1 ||
-      stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === 0)
-  }.property('App.currentStackVersionNumber'),
   preDefinedServiceConfigs: function(){
     var configs = this.get('preDefinedConfigProperties');
     var services = [];
@@ -39,37 +35,36 @@ App.config = Em.Object.create({
     return services;
   }.property('preDefinedConfigProperties'),
   configMapping: function() {
-      if (stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === 1 ||
-        stringUtils.compareVersions(App.get('currentStackVersionNumber'), "2.0") === 0) {
+      if (App.get('isHadoop2Stack')) {
         return require('data/HDP2/config_mapping');
       }
     return require('data/config_mapping');
-  }.property('App.currentStackVersionNumber'),
+  }.property('App.isHadoop2Stack'),
   preDefinedConfigProperties: function() {
-    if (this.get('isHDP2')) {
+    if (App.get('isHadoop2Stack')) {
       return require('data/HDP2/config_properties').configProperties;
     }
     return require('data/config_properties').configProperties;
-  }.property('isHDP2'),
+  }.property('App.isHadoop2Stack'),
   preDefinedCustomConfigs: function () {
-    if (this.get('isHDP2')) {
+    if (App.get('isHadoop2Stack')) {
       return require('data/HDP2/custom_configs');
     }
     return require('data/custom_configs');
-  }.property('isHDP2'),
+  }.property('App.isHadoop2Stack'),
   //categories which contain custom configs
   categoriesWithCustom: ['CapacityScheduler'],
   //configs with these filenames go to appropriate category not in Advanced
   customFileNames: function() {
     if (App.supports.capacitySchedulerUi) {
-      if(this.get('isHDP2')){
+      if(App.get('isHadoop2Stack')){
         return ['capacity-scheduler.xml'];
       }
       return ['capacity-scheduler.xml', 'mapred-queue-acls.xml'];
     } else {
       return [];
     }
-  }.property('isHDP2'),
+  }.property('App.isHadoop2Stack'),
   /**
    * Cache of loaded configurations. This is useful in not loading
    * same configuration multiple times. It is populated in multiple
@@ -141,7 +136,7 @@ App.config = Em.Object.create({
   capacitySchedulerFilter: function () {
     var yarnRegex = /^yarn\.scheduler\.capacity\.root\.(?!unfunded)([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
     var self = this;
-    if(this.get('isHDP2')){
+    if(App.get('isHadoop2Stack')){
       return function (_config) {
         return (yarnRegex.test(_config.name));
       }
@@ -151,7 +146,7 @@ App.config = Em.Object.create({
           (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
       }
     }
-  }.property('isHDP2'),
+  }.property('App.isHadoop2Stack'),
   /**
    * return:
    *   configs,
@@ -403,7 +398,7 @@ App.config = Em.Object.create({
   /**
   Takes care of the "dynamic defaults" for the HCFS configs.  Sets
   some of the config defaults to previously user-entered data.
-  **/ 
+  **/
   tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
     console.log("Step7: Tweaking Dynamic defaults");
     var firstHost = null;
@@ -415,11 +410,11 @@ App.config = Em.Object.create({
       if (typeof(config == "string") && config.defaultValue.indexOf("{firstHost}") >= 0) {
         serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
         serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
-      } 
+      }
     } catch (err) {
       // Nothing to worry about here, most likely trying indexOf on a non-string
     }
-  },  
+  },
   /**
    * create new child configs from overrides, attach them to parent config
    * override - value of config, related to particular host(s)
@@ -445,6 +440,20 @@ App.config = Em.Object.create({
       configProperty.set('overrides', overrides);
     }
   },
+  capacitySchedulerFilter: function () {
+    var yarnRegex = /^yarn\.scheduler\.capacity\.root\.(?!unfunded)([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
+    var self = this;
+    if(App.get('isHadoop2Stack')){
+      return function (_config) {
+        return (yarnRegex.test(_config.name));
+      }
+    } else {
+      return function (_config) {
+        return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
+          (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
+      }
+    }
+  }.property('App.isHadoop2Stack'),
   /**
    * create new ServiceConfig object by service name
    * @param serviceName

+ 76 - 49
ambari-web/app/views/common/configs/services_config.js

@@ -18,7 +18,6 @@
 
 var App = require('app');
 var validator = require('utils/validator');
-var stringUtils = require('utils/string_utils');
 
 App.ServicesConfigView = Em.View.extend({
   templateName: require('templates/common/configs/services_config'),
@@ -699,7 +698,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
   },
   //list of fields which will be populated by default in a new queue
   fieldsToPopulate: function(){
-    if(App.config.get('isHDP2')){
+    if(App.get('isHadoop2Stack')){
       return ["yarn.scheduler.capacity.root.<queue-name>.user-limit-factor",
       "yarn.scheduler.capacity.root.<queue-name>.state"];
     }
@@ -711,7 +710,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
       "mapred.capacity-scheduler.queue.<queue-name>.maximum-initialized-active-tasks-per-user",
       "mapred.capacity-scheduler.queue.<queue-name>.init-accept-jobs-factor"
     ];
-  }.property('App.config.isHDP2'),
+  }.property('App.isHadoop2Stack'),
   /**
    * create empty queue
    * take some queue then copy it and set all config values to null
@@ -726,7 +725,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
     customConfigs.forEach(function (config) {
       var newConfig = $.extend({}, config);
       if (fieldsToPopulate.contains(config.name)) {
-        App.config.setDefaultQueue(newConfig, emptyQueue.name);
+        newConfig.value = config.defaultValue;
       }
       newConfig = App.ServiceConfigProperty.create(newConfig);
       newConfig.validate();
@@ -734,18 +733,27 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
     });
     this.set('emptyQueue', emptyQueue);
   },
-  queues: function () {
-    var configs = this.get('categoryConfigs').filterProperty('isQueue', true);
+  deriveQueueNames: function(configs){
     var queueNames = [];
-    var queues = [];
-    configs.mapProperty('name').forEach(function (name) {
-      var queueName = /^mapred\.capacity-scheduler\.queue\.(.*?)\./.exec(name);
-      if (queueName) {
+    configs.mapProperty('name').forEach(function(name){
+      var queueName;
+      if(App.get('isHadoop2Stack')){
+        queueName = /^yarn\.scheduler\.capacity\.root\.(.*?)\./.exec(name);
+      } else {
+        queueName = /^mapred\.capacity-scheduler\.queue\.(.*?)\./.exec(name);
+      }
+      if(queueName){
         queueNames.push(queueName[1]);
       }
     });
-    queueNames = queueNames.uniq();
-    queueNames.forEach(function (queueName) {
+    return queueNames.uniq();
+  },
+  queues: function(){
+    var configs = this.get('categoryConfigs').filterProperty('isQueue', true);
+    var queueNames = this.deriveQueueNames(configs);
+    var queues = [];
+
+    queueNames.forEach(function(queueName){
       queues.push({
         name: queueName,
         color: this.generateColor(queueName),
@@ -782,9 +790,8 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
         queue.push(config);
       }
     });
-    //each queue consists of 10 properties if less then add missing properties
-    if (queue.length < 10) {
-      this.addMissingProperties(queue, queueName);
+    if(queue.length < customConfigs.length){
+      this.addMissingProperties(queue, customConfigs);
     }
     return queue;
   },
@@ -793,14 +800,12 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
    * @param queue
    * @param customConfigs
    */
-  addMissingProperties: function (queue, queueName) {
-    var customConfigs = this.get('customConfigs');
-    customConfigs.forEach(function (_config) {
-      var serviceConfigProperty = $.extend({}, _config);
-      serviceConfigProperty.name = serviceConfigProperty.name.replace(/<queue-name>/, queueName);
-      if (!queue.someProperty('name', serviceConfigProperty.name)) {
-        App.config.setDefaultQueue(serviceConfigProperty, queueName);
-        serviceConfigProperty = App.ServiceConfigProperty.create(serviceConfigProperty);
+  addMissingProperties: function(queue, customConfigs){
+    customConfigs.forEach(function(_config){
+      var serviceConfigProperty;
+      if(!queue.someProperty('name', _config.name)){
+        _config.value = _config.defaultValue;
+        serviceConfigProperty = App.ServiceConfigProperty.create(_config);
         serviceConfigProperty.validate();
         queue.push(serviceConfigProperty);
       }
@@ -812,7 +817,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
   tableContent: function () {
     var result = [];
     this.get('queues').forEach(function (queue) {
-      var usersAndGroups = queue.configs.findProperty('name', 'mapred.queue.' + queue.name + '.acl-submit-job').get('value');
+      var usersAndGroups = queue.configs.findProperty('name', this.getUserAndGroupNames(queue.name)[0]).get('value');
       usersAndGroups = (usersAndGroups) ? usersAndGroups.split(' ') : [''];
       if (usersAndGroups.length == 1) {
         usersAndGroups.push('');
@@ -853,7 +858,37 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
   /**
    * uses as template for adding new queue
    */
-  emptyQueue: [],
+  emptyQueue: {},
+  /**
+   * get capacities sum of queues except of current
+   * @param queueName
+   * @return {Number}
+   */
+  getQueuesCapacitySum: function(queueName){
+    var capacitySum = 0;
+    this.get('queues').filter(function(queue){
+      return queue.name !== queueName;
+    }).forEach(function(queue){
+        capacitySum = capacitySum + window.parseInt(queue.configs.find(function(config){
+          return config.get('name').substr(-9, 9) === '.capacity';
+        }).get('value'));
+      });
+    return capacitySum;
+  },
+  /**
+   * get names of configs, for users and groups, which have different names in HDP1 and HDP2
+   * @param queueName
+   * @return {Array}
+   */
+  getUserAndGroupNames: function(queueName){
+    queueName = queueName || '<queue-name>';
+    if(App.config.get('isHDP2')){
+      return ['yarn.scheduler.capacity.root.' + queueName + '.acl_submit_jobs',
+        'yarn.scheduler.capacity.root.' + queueName + '.acl_administer_jobs']
+    }
+    return ['mapred.queue.' + queueName + '.acl-submit-job',
+      'mapred.queue.' + queueName + '.acl-administer-jobs']
+  },
   generateColor: function (str) {
     var hash = 0;
     for (var i = 0; i < str.length; i++) {
@@ -874,7 +909,9 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
     var adminConfig;
     queue.name = queue.configs.findProperty('name', 'queueName').get('value');
     queue.configs.forEach(function (config) {
-      if (config.name == 'mapred.queue.<queue-name>.acl-administer-jobs') {
+      var adminName = this.getUserAndGroupNames()[1];
+      var submitName = this.getUserAndGroupNames()[0];
+      if(config.name == adminName){
         if (config.type == 'USERS') {
           admin[0] = config.value;
         }
@@ -885,7 +922,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
           adminConfig = config;
         }
       }
-      if (config.name == 'mapred.queue.<queue-name>.acl-submit-job') {
+      if(config.name == submitName){
         if (config.type == 'USERS') {
           submit[0] = config.value;
         }
@@ -935,12 +972,14 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
       var configName = _config.get('name');
       var admin = [];
       var submit = [];
+      //comparison executes including 'queue.<queue-name>' to avoid false matches
+      var queueNamePrefix = App.config.get('isHDP2') ? 'root.' : 'queue.';
       if (configNames.contains(_config.get('name'))) {
-        if (configName == 'mapred.queue.' + queue.name + '.acl-submit-job') {
+        if(configName == this.getUserAndGroupNames(queue.name)[0]){
           submit = queue.configs.filterProperty('name', configName);
           submit = submit.findProperty('type', 'USERS').get('value') + ' ' + submit.findProperty('type', 'GROUPS').get('value');
           _config.set('value', submit);
-        } else if (configName == 'mapred.queue.' + queue.name + '.acl-administer-jobs') {
+        } else if(configName == this.getUserAndGroupNames(queue.name)[1]){
           admin = queue.configs.filterProperty('name', configName);
           admin = admin.findProperty('type', 'USERS').get('value') + ' ' + admin.findProperty('type', 'GROUPS').get('value');
           _config.set('value', admin);
@@ -959,15 +998,16 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
     didInsertElement: function () {
       this.update();
     },
-    data: [
-      {"label": "default", "value": 100}
-    ],
+    data: [{"label":"default", "value":100}],
     update: function () {
       var self = this;
       var data = [];
       var queues = this.get('queues');
       var capacitiesSum = 0;
       queues.forEach(function (queue) {
+        var value = window.parseInt(queue.configs.find(function(_config){
+          return _config.get('name').substr(-9, 9) === '.capacity';
+        }).get('value'));
         data.push({
           label: queue.name,
           value: value,
@@ -1042,12 +1082,9 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
         }
         var content = this.get('content');
         var configs = content.configs.filter(function (config) {
-          if ((config.name == 'mapred.queue.' + content.name + '.acl-submit-job' ||
-            config.name == 'mapred.queue.' + content.name + '.acl-administer-jobs') &&
-            (config.isQueue)) {
-            return false;
-          }
-          return true;
+          return !(config.name == self.getUserAndGroupNames(content.name)[0] ||
+            config.name == self.getUserAndGroupNames(content.name)[1] &&
+              config.isQueue);
         });
         return configs.someProperty('isValid', false);
       }.property('content.configs.@each.isValid'),
@@ -1095,17 +1132,7 @@ App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
               validate: function () {
                 var value = this.get('value');
                 var isError = false;
-                var capacities = [];
-                var capacitySum = 0;
-                if (tableContent) {
-                  capacities = tableContent.mapProperty('capacity');
-                  for (var i = 0, l = capacities.length; i < l; i++) {
-                    capacitySum += parseInt(capacities[i]);
-                  }
-                  if (content.name != '<queue-name>') {
-                    capacitySum = capacitySum - parseInt(tableContent.findProperty('name', content.name).capacity);
-                  }
-                }
+                var capacitySum = self.getQueuesCapacitySum(content.name);
                 if (value == '') {
                   if (this.get('isRequired')) {
                     this.set('errorMessage', 'This is required');