step2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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.changeCategoryOnHa(this.get('content.services'));
  44. this.renderServiceConfigs(this.get('content.services'));
  45. var storedServices = this.get('content.serviceConfigProperties');
  46. if (storedServices) {
  47. var configs = new Ember.Set();
  48. // for all services`
  49. this.get('stepConfigs').forEach(function (_content) {
  50. //for all components
  51. _content.get('configs').forEach(function (_config) {
  52. var componentVal = storedServices.findProperty('name', _config.get('name'));
  53. //if we have config for specified component
  54. if (componentVal) {
  55. //set it
  56. _config.set('value', componentVal.value);
  57. }
  58. }, this);
  59. }, this);
  60. }
  61. //
  62. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  63. console.log("The services are: " + this.get('installedServices'));
  64. //
  65. },
  66. /**
  67. * Render configs for active services
  68. * @param serviceConfigs
  69. */
  70. renderServiceConfigs: function (serviceConfigs) {
  71. serviceConfigs.forEach(function (_serviceConfig) {
  72. var serviceConfig = App.ServiceConfig.create({
  73. filename: _serviceConfig.filename,
  74. serviceName: _serviceConfig.serviceName,
  75. displayName: _serviceConfig.displayName,
  76. configCategories: _serviceConfig.configCategories,
  77. showConfig: true,
  78. configs: []
  79. });
  80. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  81. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  82. this.get('stepConfigs').pushObject(serviceConfig);
  83. }, this);
  84. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  85. },
  86. /**
  87. * Load child components to service config object
  88. * @param _componentConfig
  89. * @param componentConfig
  90. */
  91. loadComponentConfigs: function (_componentConfig, componentConfig) {
  92. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  93. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  94. componentConfig.configs.pushObject(serviceConfigProperty);
  95. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  96. serviceConfigProperty.validate();
  97. }, this);
  98. },
  99. /**
  100. * fill config with hosts of component
  101. * @param service
  102. * @param configName
  103. * @param componentName
  104. */
  105. setHostsToConfig: function (service, configName, componentName) {
  106. if (service) {
  107. var hosts = service.configs.findProperty('name', configName);
  108. if (hosts) {
  109. hosts.defaultValue = App.Service.find(service.serviceName)
  110. .get('hostComponents')
  111. .filterProperty('componentName', componentName)
  112. .mapProperty('host.hostName');
  113. }
  114. }
  115. },
  116. loadUsers: function () {
  117. var securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  118. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  119. if (App.testMode) {
  120. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  121. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  122. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  123. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  124. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  125. } else {
  126. App.router.get('mainAdminSecurityController').setSecurityStatus();
  127. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  128. }
  129. }
  130. this.set('securityUsers', securityUsers);
  131. },
  132. addUserPrincipals: function (serviceConfigs) {
  133. var securityUsers = this.get('securityUsers');
  134. var smokeUser = securityUsers.findProperty('name', 'smokeuser');
  135. var hdfsUser = securityUsers.findProperty('name', 'hdfs_user');
  136. var hbaseUser = securityUsers.findProperty('name', 'hbase_user');
  137. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  138. var smokeUserPrincipal = generalService.configs.findProperty('name', 'smokeuser_principal_name');
  139. var hdfsUserPrincipal = generalService.configs.findProperty('name', 'hdfs_principal_name');
  140. var hbaseUserPrincipal = generalService.configs.findProperty('name', 'hbase_principal_name');
  141. var hbaseUserKeytab = generalService.configs.findProperty('name', 'hbase_user_keytab');
  142. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  143. if (smokeUser && smokeUserPrincipal) {
  144. smokeUserPrincipal.defaultValue = smokeUser.value;
  145. }
  146. if (hdfsUser && hdfsUserPrincipal) {
  147. hdfsUserPrincipal.defaultValue = hdfsUser.value;
  148. }
  149. if (hbaseService && hbaseUser && hbaseUserPrincipal) {
  150. hbaseUserPrincipal.defaultValue = hbaseUser.value;
  151. hbaseUserPrincipal.isVisible = true;
  152. hbaseUserKeytab.isVisible = true;
  153. }
  154. },
  155. addSlaveHostToGlobals: function (serviceConfigs) {
  156. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  157. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  158. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  159. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  160. this.setHostsToConfig(hdfsService, 'datanode_hosts', 'DATANODE');
  161. this.setHostsToConfig(mapReduceService, 'tasktracker_hosts', 'TASKTRACKER');
  162. this.setHostsToConfig(yarnService, 'nodemanager_host', 'NODEMANAGER');
  163. this.setHostsToConfig(hbaseService, 'regionserver_hosts', 'HBASE_REGIONSERVER');
  164. },
  165. addMasterHostToGlobals: function (serviceConfigs) {
  166. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  167. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  168. var webHcatService = serviceConfigs.findProperty('serviceName', 'WEBHCAT');
  169. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  170. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  171. var zooKeeperService = serviceConfigs.findProperty('serviceName', 'ZOOKEEPER');
  172. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  173. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  174. var mapReduce2Service = serviceConfigs.findProperty('serviceName', 'MAPREDUCE2');
  175. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  176. if (oozieService) {
  177. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  178. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  179. var oozieSpnegoPrincipal = oozieService.configs.findProperty('name', 'oozie_http_principal_name');
  180. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  181. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  182. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue;
  183. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue;
  184. }
  185. }
  186. if (hiveService) {
  187. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  188. if (hiveServerHost) {
  189. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  190. }
  191. }
  192. if (webHcatService) {
  193. var webHcatHost = webHcatService.configs.findProperty('name', 'webhcatserver_host');
  194. var webHcatSpnegoPrincipal = webHcatService.configs.findProperty('name', 'webHCat_http_principal_name');
  195. if (webHcatHost && webHcatSpnegoPrincipal) {
  196. webHcatHost.defaultValue = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  197. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost.defaultValue;
  198. }
  199. }
  200. if (nagiosService) {
  201. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  202. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  203. if (nagiosServerHost && nagiosServerPrincipal) {
  204. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  205. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue;
  206. }
  207. }
  208. if (hdfsService) {
  209. var namenodeHost = hdfsService.configs.findProperty('name', 'namenode_host');
  210. var sNamenodeHost = hdfsService.configs.findProperty('name', 'snamenode_host');
  211. if (namenodeHost && sNamenodeHost) {
  212. namenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('host.hostName');
  213. sNamenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
  214. }
  215. }
  216. if (mapReduceService) {
  217. var jobTrackerHost = mapReduceService.configs.findProperty('name', 'jobtracker_host');
  218. if (jobTrackerHost) {
  219. jobTrackerHost.defaultValue = App.Service.find('MAPREDUCE').get('hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  220. }
  221. }
  222. if (mapReduce2Service) {
  223. var jobHistoryServerHost = mapReduce2Service.configs.findProperty('name', 'jobhistoryserver_host');
  224. if (jobHistoryServerHost) {
  225. jobHistoryServerHost.defaultValue = App.Service.find('MAPREDUCE2').get('hostComponents').findProperty('componentName', 'HISTORYSERVER').get('host.hostName');
  226. }
  227. }
  228. if (yarnService) {
  229. var resourceManagerHost = yarnService.configs.findProperty('name', 'resourcemanager_host');
  230. if (resourceManagerHost) {
  231. resourceManagerHost.defaultValue = App.Service.find('YARN').get('hostComponents').findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName');
  232. }
  233. }
  234. this.setHostsToConfig(hbaseService, 'hbasemaster_host', 'HBASE_MASTER');
  235. this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
  236. },
  237. changeCategoryOnHa: function (serviceConfigs) {
  238. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  239. if (hdfsService) {
  240. var secureProperties = require('data/HDP2/secure_properties').configProperties;
  241. var configCategories = hdfsService.configCategories;
  242. var dfsHttpPrincipal = secureProperties.findProperty('name', 'hadoop_http_principal_name');
  243. var dfsHttpKeytab = secureProperties.findProperty('name', 'hadoop_http_keytab');
  244. if ((App.testMode && App.testNameNodeHA) || (this.get('content.isNnHa') === 'true')) {
  245. if (dfsHttpPrincipal && dfsHttpKeytab) {
  246. dfsHttpPrincipal.category = 'NameNode';
  247. dfsHttpKeytab.category = 'NameNode';
  248. } else {
  249. dfsHttpPrincipal.category = 'General';
  250. dfsHttpKeytab.category = 'General';
  251. }
  252. var generalCategory = configCategories.findProperty('name','General');
  253. var snCategory = configCategories.findProperty('name','SNameNode');
  254. if(generalCategory) {
  255. configCategories.removeObject(generalCategory);
  256. }
  257. if(snCategory) {
  258. configCategories.removeObject(snCategory);
  259. }
  260. } else {
  261. var jnCategory = configCategories.findProperty('name','JournalNode');
  262. if(jnCategory) {
  263. configCategories.removeObject(jnCategory);
  264. }
  265. }
  266. }
  267. },
  268. /**
  269. * submit and move to step3
  270. */
  271. submit: function () {
  272. if (!this.get('isSubmitDisabled')) {
  273. App.router.send('next');
  274. }
  275. }
  276. });