step2.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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'), this.get('securityUsers'));
  41. this.addMasterHostToGlobals(this.get('content.services'));
  42. this.addSlaveHostToGlobals(this.get('content.services'));
  43. this.renderServiceConfigs(this.get('content.services'));
  44. this.changeCategoryOnHa(this.get('content.services'), this.get('stepConfigs'));
  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. securityUsers = App.db.getSecureUserInfo();
  127. }
  128. }
  129. this.set('securityUsers', securityUsers);
  130. },
  131. addUserPrincipals: function (serviceConfigs, securityUsers) {
  132. var smokeUser = securityUsers.findProperty('name', 'smokeuser');
  133. var hdfsUser = securityUsers.findProperty('name', 'hdfs_user');
  134. var hbaseUser = securityUsers.findProperty('name', 'hbase_user');
  135. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  136. var smokeUserPrincipal = generalService.configs.findProperty('name', 'smokeuser_principal_name');
  137. var hdfsUserPrincipal = generalService.configs.findProperty('name', 'hdfs_principal_name');
  138. var hbaseUserPrincipal = generalService.configs.findProperty('name', 'hbase_principal_name');
  139. var hbaseUserKeytab = generalService.configs.findProperty('name', 'hbase_user_keytab');
  140. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  141. if (smokeUser && smokeUserPrincipal) {
  142. smokeUserPrincipal.defaultValue = smokeUser.value;
  143. }
  144. if (hdfsUser && hdfsUserPrincipal) {
  145. hdfsUserPrincipal.defaultValue = hdfsUser.value;
  146. }
  147. if (hbaseService && hbaseUser && hbaseUserPrincipal) {
  148. hbaseUserPrincipal.defaultValue = hbaseUser.value;
  149. hbaseUserPrincipal.isVisible = true;
  150. hbaseUserKeytab.isVisible = true;
  151. }
  152. },
  153. addSlaveHostToGlobals: function (serviceConfigs) {
  154. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  155. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  156. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  157. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  158. this.setHostsToConfig(hdfsService, 'datanode_hosts', 'DATANODE');
  159. this.setHostsToConfig(mapReduceService, 'tasktracker_hosts', 'TASKTRACKER');
  160. this.setHostsToConfig(yarnService, 'nodemanager_host', 'NODEMANAGER');
  161. this.setHostsToConfig(hbaseService, 'regionserver_hosts', 'HBASE_REGIONSERVER');
  162. },
  163. addMasterHostToGlobals: function (serviceConfigs) {
  164. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  165. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  166. var webHcatService = serviceConfigs.findProperty('serviceName', 'WEBHCAT');
  167. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  168. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  169. var zooKeeperService = serviceConfigs.findProperty('serviceName', 'ZOOKEEPER');
  170. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  171. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  172. var mapReduce2Service = serviceConfigs.findProperty('serviceName', 'MAPREDUCE2');
  173. var yarnService = serviceConfigs.findProperty('serviceName', 'YARN');
  174. if (oozieService) {
  175. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  176. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  177. var oozieSpnegoPrincipal = oozieService.configs.findProperty('name', 'oozie_http_principal_name');
  178. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  179. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  180. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue.toLowerCase();
  181. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue.toLowerCase();
  182. }
  183. }
  184. if (hiveService) {
  185. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  186. if (hiveServerHost) {
  187. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  188. }
  189. }
  190. if (webHcatService) {
  191. var webHcatHost = webHcatService.configs.findProperty('name', 'webhcatserver_host');
  192. var webHcatSpnegoPrincipal = webHcatService.configs.findProperty('name', 'webHCat_http_principal_name');
  193. if (webHcatHost && webHcatSpnegoPrincipal) {
  194. webHcatHost.defaultValue = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  195. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost.defaultValue.toLowerCase();
  196. }
  197. }
  198. if (nagiosService) {
  199. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  200. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  201. if (nagiosServerHost && nagiosServerPrincipal) {
  202. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  203. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue.toLowerCase();
  204. }
  205. }
  206. if (hdfsService) {
  207. var namenodeHost = hdfsService.configs.findProperty('name', 'namenode_host');
  208. var sNamenodeHost = hdfsService.configs.findProperty('name', 'snamenode_host');
  209. var jnHosts = hdfsService.configs.findProperty('name', 'journalnode_hosts');
  210. var snComponent = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE');
  211. var jnComponent = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'JOURNALNODE');
  212. if (namenodeHost) {
  213. namenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').filterProperty('componentName', 'NAMENODE').mapProperty('host.hostName');
  214. }
  215. if(sNamenodeHost && snComponent) {
  216. sNamenodeHost.defaultValue = snComponent.get('host.hostName');
  217. }
  218. if(jnHosts && jnComponent) {
  219. this.setHostsToConfig(hdfsService, 'journalnode_hosts', 'JOURNALNODE');
  220. }
  221. }
  222. if (mapReduceService) {
  223. var jobTrackerHost = mapReduceService.configs.findProperty('name', 'jobtracker_host');
  224. if (jobTrackerHost) {
  225. jobTrackerHost.defaultValue = App.Service.find('MAPREDUCE').get('hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  226. }
  227. }
  228. if (mapReduce2Service) {
  229. var jobHistoryServerHost = mapReduce2Service.configs.findProperty('name', 'jobhistoryserver_host');
  230. if (jobHistoryServerHost) {
  231. jobHistoryServerHost.defaultValue = App.Service.find('MAPREDUCE2').get('hostComponents').findProperty('componentName', 'HISTORYSERVER').get('host.hostName');
  232. }
  233. }
  234. if (yarnService) {
  235. var resourceManagerHost = yarnService.configs.findProperty('name', 'resourcemanager_host');
  236. if (resourceManagerHost) {
  237. resourceManagerHost.defaultValue = App.Service.find('YARN').get('hostComponents').findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName');
  238. }
  239. }
  240. this.setHostsToConfig(hbaseService, 'hbasemaster_host', 'HBASE_MASTER');
  241. this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
  242. },
  243. changeCategoryOnHa: function (serviceConfigs, stepConfigs) {
  244. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  245. if (hdfsService) {
  246. var hdfsProperties = stepConfigs.findProperty('serviceName', 'HDFS').get('configs');
  247. var configCategories = hdfsService.configCategories;
  248. if ((App.testMode && App.testNameNodeHA) || (this.get('content.isNnHa') === 'true')) {
  249. hdfsProperties.filterProperty('category', 'SNameNode').forEach(function (_snConfig) {
  250. _snConfig.set('isVisible', false);
  251. }, this);
  252. var snCategory = configCategories.findProperty('name', 'SNameNode');
  253. if (snCategory) {
  254. configCategories.removeObject(snCategory);
  255. }
  256. } else {
  257. hdfsProperties.filterProperty('category', 'JournalNode').forEach(function (_jnConfig) {
  258. _jnConfig.set('isVisible', false);
  259. }, this);
  260. var jnCategory = configCategories.findProperty('name', 'JournalNode');
  261. if (jnCategory) {
  262. configCategories.removeObject(jnCategory);
  263. }
  264. }
  265. }
  266. },
  267. /**
  268. * submit and move to step3
  269. */
  270. submit: function () {
  271. if (!this.get('isSubmitDisabled')) {
  272. App.router.send('next');
  273. }
  274. }
  275. });