step2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
  21. name: 'mainAdminSecurityAddStep2Controller',
  22. stepConfigs: [],
  23. installedServices: [],
  24. selectedService: null,
  25. securityUsers: [],
  26. isSubmitDisabled: function () {
  27. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  28. }.property('stepConfigs.@each.errorCount'),
  29. clearStep: function () {
  30. this.get('stepConfigs').clear();
  31. this.get('securityUsers').clear();
  32. },
  33. /**
  34. * Function is called whenever the step is loaded
  35. */
  36. loadStep: function () {
  37. console.log("TRACE: Loading addSecurity step2: Configure Services");
  38. this.clearStep();
  39. this.loadUsers();
  40. this.addUserPrincipals(this.get('content.services'));
  41. this.addMasterHostToGlobals(this.get('content.services'));
  42. this.addSlaveHostToGlobals(this.get('content.services'));
  43. this.renderServiceConfigs(this.get('content.services'));
  44. var storedServices = this.get('content.serviceConfigProperties');
  45. if (storedServices) {
  46. var configs = new Ember.Set();
  47. // for all services`
  48. this.get('stepConfigs').forEach(function (_content) {
  49. //for all components
  50. _content.get('configs').forEach(function (_config) {
  51. var componentVal = storedServices.findProperty('name', _config.get('name'));
  52. //if we have config for specified component
  53. if (componentVal) {
  54. //set it
  55. _config.set('value', componentVal.value);
  56. }
  57. }, this);
  58. }, this);
  59. }
  60. //
  61. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  62. console.log("The services are: " + this.get('installedServices'));
  63. //
  64. },
  65. /**
  66. * Render configs for active services
  67. * @param serviceConfigs
  68. */
  69. renderServiceConfigs: function (serviceConfigs) {
  70. serviceConfigs.forEach(function (_serviceConfig) {
  71. var serviceConfig = App.ServiceConfig.create({
  72. filename: _serviceConfig.filename,
  73. serviceName: _serviceConfig.serviceName,
  74. displayName: _serviceConfig.displayName,
  75. configCategories: _serviceConfig.configCategories,
  76. showConfig: true,
  77. configs: []
  78. });
  79. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  80. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  81. this.get('stepConfigs').pushObject(serviceConfig);
  82. }, this);
  83. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  84. },
  85. /**
  86. * Load child components to service config object
  87. * @param _componentConfig
  88. * @param componentConfig
  89. */
  90. loadComponentConfigs: function (_componentConfig, componentConfig) {
  91. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  92. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  93. componentConfig.configs.pushObject(serviceConfigProperty);
  94. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  95. serviceConfigProperty.validate();
  96. }, this);
  97. },
  98. /**
  99. * fill config with hosts of component
  100. * @param service
  101. * @param configName
  102. * @param componentName
  103. */
  104. setHostsToConfig: function(service, configName, componentName){
  105. if(service){
  106. var hosts = service.configs.findProperty('name', configName);
  107. if(hosts){
  108. hosts.defaultValue = App.Service.find(service.serviceName)
  109. .get('hostComponents')
  110. .filterProperty('componentName', componentName)
  111. .mapProperty('host.hostName');
  112. }
  113. }
  114. },
  115. loadUsers: function() {
  116. var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  117. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  118. if (App.testMode) {
  119. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  120. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  121. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  122. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  123. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  124. } else {
  125. App.router.get('mainAdminSecurityController').setSecurityStatus();
  126. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  127. }
  128. }
  129. this.set('securityUsers',securityUsers);
  130. },
  131. addUserPrincipals: function(serviceConfigs) {
  132. var securityUsers = this.get('securityUsers');
  133. var smokeUser = securityUsers.findProperty('name', 'smokeuser');
  134. var hdfsUser = securityUsers.findProperty('name', 'hdfs_user');
  135. var hbaseUser = securityUsers.findProperty('name', 'hbase_user');
  136. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  137. var smokeUserPrincipal = generalService.configs.findProperty('name', 'smokeuser_principal_name');
  138. var hdfsUserPrincipal = generalService.configs.findProperty('name', 'hdfs_principal_name');
  139. var hbaseUserPrincipal = generalService.configs.findProperty('name', 'hbase_principal_name');
  140. var hbaseUserKeytab = generalService.configs.findProperty('name', 'hbase_user_keytab');
  141. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  142. if(smokeUser && smokeUserPrincipal) {
  143. smokeUserPrincipal.defaultValue = smokeUser.value;
  144. }
  145. if(hdfsUser && hdfsUserPrincipal) {
  146. hdfsUserPrincipal.defaultValue = hdfsUser.value;
  147. }
  148. if(hbaseService && hbaseUser && hbaseUserPrincipal) {
  149. hbaseUserPrincipal.defaultValue = hbaseUser.value;
  150. hbaseUserPrincipal.isVisible = true;
  151. hbaseUserKeytab.isVisible = true;
  152. }
  153. },
  154. addSlaveHostToGlobals: function(serviceConfigs){
  155. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  156. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  157. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  158. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  159. this.setHostsToConfig(hdfsService, 'datanode_hosts', 'DATANODE');
  160. this.setHostsToConfig(mapReduceService, 'tasktracker_hosts', 'TASKTRACKER');
  161. this.setHostsToConfig(yarnService, 'nodemanager_host', 'NODEMANAGER');
  162. this.setHostsToConfig(hbaseService, 'regionserver_hosts', 'HBASE_REGIONSERVER');
  163. },
  164. addMasterHostToGlobals: function (serviceConfigs) {
  165. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  166. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  167. var webHcatService = serviceConfigs.findProperty('serviceName', 'WEBHCAT');
  168. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  169. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  170. var zooKeeperService = serviceConfigs.findProperty('serviceName', 'ZOOKEEPER');
  171. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  172. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  173. var mapReduce2Service = serviceConfigs.findProperty('serviceName', 'MAPREDUCE2');
  174. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  175. if (oozieService) {
  176. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  177. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  178. var oozieSpnegoPrincipal = oozieService.configs.findProperty('name', 'oozie_http_principal_name');
  179. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  180. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  181. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue;
  182. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue;
  183. }
  184. }
  185. if (hiveService) {
  186. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  187. if (hiveServerHost) {
  188. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  189. }
  190. }
  191. if(webHcatService) {
  192. var webHcatHost = webHcatService.configs.findProperty('name', 'webhcatserver_host');
  193. var webHcatSpnegoPrincipal = webHcatService.configs.findProperty('name', 'webHCat_http_principal_name');
  194. if(webHcatHost && webHcatSpnegoPrincipal) {
  195. webHcatHost.defaultValue = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  196. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost.defaultValue;
  197. }
  198. }
  199. if(nagiosService) {
  200. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  201. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  202. if (nagiosServerHost && nagiosServerPrincipal) {
  203. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  204. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue;
  205. }
  206. }
  207. if(hdfsService){
  208. var namenodeHost = hdfsService.configs.findProperty('name', 'namenode_host');
  209. var sNamenodeHost = hdfsService.configs.findProperty('name', 'snamenode_host');
  210. if (namenodeHost && sNamenodeHost) {
  211. namenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('host.hostName');
  212. sNamenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
  213. }
  214. }
  215. if(mapReduceService){
  216. var jobTrackerHost = mapReduceService.configs.findProperty('name', 'jobtracker_host');
  217. if (jobTrackerHost) {
  218. jobTrackerHost.defaultValue = App.Service.find('MAPREDUCE').get('hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  219. }
  220. }
  221. if(mapReduce2Service){
  222. var jobHistoryServerHost = mapReduce2Service.configs.findProperty('name', 'jobhistoryserver_host');
  223. if (jobHistoryServerHost) {
  224. jobHistoryServerHost.defaultValue = App.Service.find('MAPREDUCE2').get('hostComponents').findProperty('componentName', 'HISTORYSERVER').get('host.hostName');
  225. }
  226. }
  227. if(yarnService){
  228. var resourceManagerHost = yarnService.configs.findProperty('name', 'resourcemanager_host');
  229. if (resourceManagerHost) {
  230. resourceManagerHost.defaultValue = App.Service.find('YARN').get('hostComponents').findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName');
  231. }
  232. }
  233. this.setHostsToConfig(hbaseService, 'hbasemaster_host', 'HBASE_MASTER');
  234. this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
  235. },
  236. /**
  237. * submit and move to step3
  238. */
  239. submit: function () {
  240. if (!this.get('isSubmitDisabled')) {
  241. App.router.send('next');
  242. }
  243. }
  244. });