You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2013/08/21 13:47:57 UTC

git commit: AMBARI-2972 Provide read-only view of security wizard entries. (atkach)

Updated Branches:
  refs/heads/trunk b009c49b5 -> a811db6d4


AMBARI-2972 Provide read-only view of security wizard entries. (atkach)


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

Branch: refs/heads/trunk
Commit: a811db6d4aabddacfbde2c0507137001cc06b49a
Parents: b009c49
Author: atkach <an...@gmail.com>
Authored: Wed Aug 21 14:47:47 2013 +0300
Committer: atkach <an...@gmail.com>
Committed: Wed Aug 21 14:47:47 2013 +0300

----------------------------------------------------------------------
 .../app/controllers/main/admin/security.js      | 175 ++++++++++++++++++-
 .../main/admin/security/add/step2.js            |  13 +-
 .../common/configs/services_config.hbs          |   2 +-
 .../app/templates/main/admin/security.hbs       |   6 +-
 .../app/views/common/configs/services_config.js |   3 +
 ambari-web/app/views/main/admin/security.js     |  27 ++-
 6 files changed, 213 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/controllers/main/admin/security.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security.js b/ambari-web/app/controllers/main/admin/security.js
index a0f6894..3c662f7 100644
--- a/ambari-web/app/controllers/main/admin/security.js
+++ b/ambari-web/app/controllers/main/admin/security.js
@@ -41,6 +41,178 @@ App.MainAdminSecurityController = Em.Controller.extend({
   notifySecurityOff: false,
   notifySecurityAdd: false,
 
+  stepConfigs: [],
+  desiredConfigs: [],
+  securityUsers: [],
+  serviceConfigTags: [],
+  selectedService: null,
+  isNotEditable: true,
+  services: function(){
+    var secureServices;
+    var services = [];
+    if(App.get('isHadoop2Stack')) {
+      secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
+    } else {
+      secureServices = $.extend(true, [], require('data/secure_configs'));
+    }
+
+    var installedServices = App.Service.find().mapProperty('serviceName');
+    //General (only non service tab) tab is always displayed
+    services.push(secureServices.findProperty('serviceName', 'GENERAL'));
+    installedServices.forEach(function (_service) {
+      var secureService = secureServices.findProperty('serviceName', _service);
+      if (secureService) {
+        services.push(secureService);
+      }
+    }, this);
+    return services;
+  }.property(),
+
+  loadStep: function(){
+    var step2Controller = App.router.get('mainAdminSecurityAddStep2Controller');
+    var services = this.get('services');
+    this.get('stepConfigs').clear();
+    this.get('securityUsers').clear();
+    this.get('serviceConfigTags').clear();
+    this.loadSecurityUsers();
+    //loadSecurityUsers - desired configs fetched from server
+    step2Controller.addUserPrincipals(services, this.get('securityUsers'));
+    step2Controller.addMasterHostToGlobals(services);
+    step2Controller.addSlaveHostToGlobals(services);
+    this.renderServiceConfigs(services);
+    step2Controller.changeCategoryOnHa(services, this.get('stepConfigs'));
+
+    services.forEach(function (_secureService) {
+      this.setServiceTagNames(_secureService, this.get('desiredConfigs'));
+    }, this);
+    var serverConfigs = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
+    this.setConfigValuesFromServer(this.get('stepConfigs'), serverConfigs);
+
+    this.set('installedServices', App.Service.find().mapProperty('serviceName'));
+  },
+
+  /**
+   * get actual values of configurations from server
+   * @param stepConfigs
+   * @param serverConfigs
+   */
+  setConfigValuesFromServer: function(stepConfigs, serverConfigs){
+    var allConfigs = {};
+    serverConfigs.mapProperty('properties').forEach(function(_properties){
+      allConfigs = $.extend(allConfigs, _properties);
+    }, this);
+    // for all services`
+    stepConfigs.forEach(function (_content) {
+      //for all components
+      _content.get('configs').forEach(function (_config) {
+
+        var componentVal = allConfigs[_config.get('name')];
+        //if we have config for specified component
+        if (componentVal) {
+          //set it
+          _config.set('value', componentVal);
+        }
+      }, this);
+    }, this);
+
+  },
+
+  /**
+   * set tag names according to installed services and desired configs
+   * @param secureService
+   * @param configs
+   * @return {Object}
+   */
+  setServiceTagNames: function (secureService, configs) {
+    //var serviceConfigTags = this.get('serviceConfigTags');
+    for (var index in configs) {
+      if (secureService.sites && secureService.sites.contains(index)) {
+        var serviceConfigObj = {
+          siteName: index,
+          tagName: configs[index].tag,
+          newTagName: null,
+          configs: {}
+        };
+        console.log("The value of serviceConfigTags[index]: " + configs[index]);
+        this.get('serviceConfigTags').pushObject(serviceConfigObj);
+      }
+    }
+    return serviceConfigObj;
+  },
+
+  loadSecurityUsers: function () {
+    var securityUsers = this.get('serviceUsers');
+    if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
+      if (App.testMode) {
+        securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
+        securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
+        securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
+        securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
+        securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
+      } else {
+        this.setSecurityStatus();
+        securityUsers = this.get('serviceUsers');
+      }
+    }
+    this.set('securityUsers', securityUsers);
+  },
+  /**
+   * fill config with hosts of component
+   * @param service
+   * @param configName
+   * @param componentName
+   */
+  setHostsToConfig: function (service, configName, componentName) {
+    if (service) {
+      var hosts = service.configs.findProperty('name', configName);
+      if (hosts) {
+        hosts.defaultValue = App.Service.find(service.serviceName)
+          .get('hostComponents')
+          .filterProperty('componentName', componentName)
+          .mapProperty('host.hostName');
+      }
+    }
+  },
+
+  /**
+   * Load child components to service config object
+   * @param _componentConfig
+   * @param componentConfig
+   */
+  loadComponentConfigs: function (_componentConfig, componentConfig) {
+    _componentConfig.configs.forEach(function (_serviceConfigProperty) {
+      var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
+      componentConfig.configs.pushObject(serviceConfigProperty);
+      serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
+      serviceConfigProperty.validate();
+    }, this);
+  },
+
+  /**
+   * Render configs for active services
+   * @param serviceConfigs
+   */
+  renderServiceConfigs: function (serviceConfigs) {
+    serviceConfigs.forEach(function (_serviceConfig) {
+
+      var serviceConfig = App.ServiceConfig.create({
+        filename: _serviceConfig.filename,
+        serviceName: _serviceConfig.serviceName,
+        displayName: _serviceConfig.displayName,
+        configCategories: _serviceConfig.configCategories,
+        showConfig: true,
+        configs: []
+      });
+
+      this.loadComponentConfigs(_serviceConfig, serviceConfig);
+
+      console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
+
+      this.get('stepConfigs').pushObject(serviceConfig);
+    }, this);
+    this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
+  },
+
   notifySecurityOffPopup: function () {
     var self = this;
     if (!this.get('isSubmitDisabled')) {
@@ -96,6 +268,7 @@ App.MainAdminSecurityController = Em.Controller.extend({
 
   getSecurityStatusFromServerSuccessCallback: function (data) {
     var configs = data.Clusters.desired_configs;
+    this.set('desiredConfigs', configs);
     if ('global' in configs && 'hdfs-site' in configs) {
       this.set('tag.global', configs['global'].tag);
       this.set('tag.hdfs-site', configs['hdfs-site'].tag);
@@ -138,7 +311,7 @@ App.MainAdminSecurityController = Em.Controller.extend({
 
   setNnHaStatus: function(hdfsConfigs) {
     var nnHaStatus = hdfsConfigs && hdfsConfigs['dfs.nameservices'];
-    var namenodes;
+    var namenodesKey;
     if (nnHaStatus) {
       namenodesKey = 'dfs.ha.namenodes.' + hdfsConfigs['dfs.nameservices'];
     }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/controllers/main/admin/security/add/step2.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security/add/step2.js b/ambari-web/app/controllers/main/admin/security/add/step2.js
index 7511b86..b85a8c5 100644
--- a/ambari-web/app/controllers/main/admin/security/add/step2.js
+++ b/ambari-web/app/controllers/main/admin/security/add/step2.js
@@ -44,11 +44,11 @@ App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
     console.log("TRACE: Loading addSecurity step2: Configure Services");
     this.clearStep();
     this.loadUsers();
-    this.addUserPrincipals(this.get('content.services'));
+    this.addUserPrincipals(this.get('content.services'), this.get('securityUsers'));
     this.addMasterHostToGlobals(this.get('content.services'));
     this.addSlaveHostToGlobals(this.get('content.services'));
     this.renderServiceConfigs(this.get('content.services'));
-    this.changeCategoryOnHa(this.get('content.services'));
+    this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
     var storedServices = this.get('content.serviceConfigProperties');
     if (storedServices) {
       var configs = new Ember.Set();
@@ -149,8 +149,7 @@ App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
     this.set('securityUsers', securityUsers);
   },
 
-  addUserPrincipals: function (serviceConfigs) {
-    var securityUsers = this.get('securityUsers');
+  addUserPrincipals: function (serviceConfigs, securityUsers) {
     var smokeUser = securityUsers.findProperty('name', 'smokeuser');
     var hdfsUser = securityUsers.findProperty('name', 'hdfs_user');
     var hbaseUser = securityUsers.findProperty('name', 'hbase_user');
@@ -263,10 +262,10 @@ App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
     this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
   },
 
-  changeCategoryOnHa: function (serviceConfigs) {
+  changeCategoryOnHa: function (serviceConfigs, stepConfigs) {
     var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
     if (hdfsService) {
-      var hdfsProperties = this.get('stepConfigs').findProperty('serviceName','HDFS').get('configs');
+      var hdfsProperties = stepConfigs.findProperty('serviceName','HDFS').get('configs');
       var configCategories = hdfsService.configCategories;
       var dfsHttpPrincipal = hdfsProperties.findProperty('name', 'hadoop_http_principal_name');
       var dfsHttpKeytab = hdfsProperties.findProperty('name', 'hadoop_http_keytab');
@@ -305,4 +304,4 @@ App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
     }
   }
 
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/templates/common/configs/services_config.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/configs/services_config.hbs b/ambari-web/app/templates/common/configs/services_config.hbs
index b10df6e..98992e3 100644
--- a/ambari-web/app/templates/common/configs/services_config.hbs
+++ b/ambari-web/app/templates/common/configs/services_config.hbs
@@ -28,7 +28,7 @@
     {{/if}}
   {{/each}}
 </ul>
-{{view App.ServiceConfigView}}
+{{view App.ServiceConfigView isNotEditableBinding="controller.isNotEditable"}}
 {{#if isSubmitDisabled}}
   <div class="alert">{{t installer.step7.attentionNeeded}}</div>
 {{/if}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/templates/main/admin/security.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/admin/security.hbs b/ambari-web/app/templates/main/admin/security.hbs
index 2c1ab01..56c75f7 100644
--- a/ambari-web/app/templates/main/admin/security.hbs
+++ b/ambari-web/app/templates/main/admin/security.hbs
@@ -24,8 +24,8 @@
         </a> <br/>
       </p>
     </div>
-    <div>
-      {{outlet}}
+    <div id="serviceConfig">
+      {{view App.ServicesConfigView}}
     </div>
   {{else}}
     <div>
@@ -38,4 +38,4 @@
   {{/if}}
 {{else}}
   <div class="spinner"></div>
-{{/if}}
\ No newline at end of file
+{{/if}}

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/views/common/configs/services_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/services_config.js b/ambari-web/app/views/common/configs/services_config.js
index a22eacc..38c14ca 100644
--- a/ambari-web/app/views/common/configs/services_config.js
+++ b/ambari-web/app/views/common/configs/services_config.js
@@ -39,6 +39,9 @@ App.ServiceConfigView = Em.View.extend({
     this.set('isRestartMessageCollapsed', !this.get('isRestartMessageCollapsed'));
   },
   didInsertElement: function () {
+    if(this.get('isNotEditable') === true) {
+      this.set('canEdit', false);
+    }
     this.$('.service-body').hide();
     $(".restart-required-property").tooltip({html: true});
     $(".icon-lock").tooltip({placement: 'right'});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a811db6d/ambari-web/app/views/main/admin/security.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/admin/security.js b/ambari-web/app/views/main/admin/security.js
index d52002d..4c7ee14 100644
--- a/ambari-web/app/views/main/admin/security.js
+++ b/ambari-web/app/views/main/admin/security.js
@@ -22,6 +22,31 @@ App.MainAdminSecurityView = Em.View.extend({
   templateName: require('templates/main/admin/security'),
   didInsertElement: function() {
     this.get('controller').setSecurityStatus();
-  }
+  },
+
+  configProperties: function () {
+    var configProperties = [];
+    var stepConfigs = this.get('controller.stepConfigs');
+    if (stepConfigs) {
+      this.get('controller.stepConfigs').mapProperty('configs').forEach(function (_stepProperties) {
+        _stepProperties.forEach(function (_stepConfigProperty) {
+          configProperties.pushObject(_stepConfigProperty);
+        }, this);
+      }, this);
+    }
+    return configProperties;
+  }.property('controller.stepConfigs.@each.configs'),
+
+  realmName: function () {
+    return this.get('configProperties').findProperty('name', 'kerberos_domain');
+  }.property('configProperties'),
+
+  onRealmNameChange: function () {
+    this.get('configProperties').forEach(function (_globalProperty) {
+      if (/principal_name?$/.test(_globalProperty.get('name'))) {
+        _globalProperty.set('unit', '@' + this.get('realmName.value'));
+      }
+    }, this);
+  }.observes('realmName.value')
 
 });
\ No newline at end of file