step2.js 13 KB

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