step7_controller.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. /**
  20. * By Step 7, we have the following information stored in App.db and set on this
  21. * controller by the router.
  22. *
  23. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  24. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  25. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  26. *
  27. */
  28. App.WizardStep7Controller = Em.Controller.extend({
  29. name: 'wizardStep7Controller',
  30. stepConfigs: [], //contains all field properties that are viewed in this step
  31. selectedService: null,
  32. slaveHostToGroup: null,
  33. isSubmitDisabled: function () {
  34. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  35. }.property('stepConfigs.@each.errorCount'),
  36. selectedServiceNames: function () {
  37. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  38. }.property('content.services').cacheable(),
  39. allInstalledServiceNames: function () {
  40. return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
  41. }.property('content.services').cacheable(),
  42. masterComponentHosts: function () {
  43. return this.get('content.masterComponentHosts');
  44. }.property('content.masterComponentHosts'),
  45. slaveComponentHosts: function () {
  46. return this.get('content.slaveGroupProperties');
  47. }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
  48. serviceConfigs: require('data/service_configs'),
  49. configMapping: require('data/config_mapping'),
  50. customConfigs: require('data/custom_configs'),
  51. customData: [],
  52. clearStep: function () {
  53. this.get('stepConfigs').clear();
  54. },
  55. /**
  56. * On load function
  57. */
  58. loadStep: function () {
  59. console.log("TRACE: Loading step7: Configure Services");
  60. this.clearStep();
  61. var serviceConfigs = this.get('serviceConfigs');
  62. var advancedConfig = this.get('content.advancedServiceConfig') || [];
  63. this.loadAdvancedConfig(serviceConfigs, advancedConfig);
  64. this.loadCustomConfig();
  65. this.renderServiceConfigs(serviceConfigs);
  66. var storedServices = this.get('content.serviceConfigProperties');
  67. if (storedServices) {
  68. var configs = new Ember.Set();
  69. // for all services`
  70. this.get('stepConfigs').forEach(function (_content) {
  71. //for all components
  72. _content.get('configs').forEach(function (_config) {
  73. var componentVal = storedServices.findProperty('name', _config.get('name'));
  74. //if we have config for specified component
  75. if (componentVal) {
  76. //set it
  77. _config.set('value', componentVal.value)
  78. }
  79. }, this);
  80. }, this);
  81. }
  82. },
  83. /*
  84. Loads the advanced configs fetched from the server metadata libarary
  85. */
  86. loadAdvancedConfig: function (serviceConfigs, advancedConfig) {
  87. advancedConfig.forEach(function (_config) {
  88. if (_config) {
  89. var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
  90. if (service) {
  91. if (this.get('configMapping').someProperty('name', _config.name)) {
  92. } else if (!(service.configs.someProperty('name', _config.name))) {
  93. _config.id = "site property";
  94. // ////_config.category = 'Advanced';
  95. if (_config.filename === "core-site.xml")
  96. _config.category = 'AdvancedCoreSite';
  97. else if (_config.filename === "hdfs-site.xml")
  98. _config.category = 'AdvancedHDFSSite';
  99. else if (_config.filename === "mapred-site.xml")
  100. _config.category = 'AdvancedMapredSite';
  101. _config.displayName = _config.name;
  102. _config.defaultValue = _config.value;
  103. // make all advanced configs optional and populated by default
  104. /*
  105. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  106. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  107. * false; _config.value = ''; } else if
  108. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  109. */
  110. _config.isRequired = false;
  111. _config.isVisible = true;
  112. _config.displayType = 'advanced';
  113. service.configs.pushObject(_config);
  114. }
  115. }
  116. }
  117. }, this);
  118. },
  119. /**
  120. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  121. */
  122. loadCustomConfig: function () {
  123. var serviceConfigs = this.get('serviceConfigs');
  124. this.get('customConfigs').forEach(function (_config) {
  125. var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
  126. if (service) {
  127. if (!(service.configs.someProperty('name', _config.name))) {
  128. if( Object.prototype.toString.call( _config.defaultValue ) === '[object Array]' ) {
  129. this.loadDefaultCustomConfig(_config);
  130. }
  131. service.configs.pushObject(_config);
  132. }
  133. }
  134. }, this);
  135. },
  136. loadDefaultCustomConfig: function (customConfig) {
  137. var customValue = '';
  138. var length = customConfig.defaultValue.length;
  139. customConfig.defaultValue.forEach(function (_config, index) {
  140. customValue += _config.name + '=' + _config.value;
  141. if (index !== length - 1) {
  142. customValue += '\n';
  143. }
  144. }, this);
  145. customConfig.value = customValue;
  146. },
  147. /**
  148. * Render configs for active services
  149. * @param serviceConfigs
  150. */
  151. renderServiceConfigs: function (serviceConfigs) {
  152. serviceConfigs.forEach(function (_serviceConfig) {
  153. var serviceConfig = App.ServiceConfig.create({
  154. filename: _serviceConfig.filename,
  155. serviceName: _serviceConfig.serviceName,
  156. displayName: _serviceConfig.displayName,
  157. configCategories: _serviceConfig.configCategories,
  158. showConfig: false,
  159. configs: []
  160. });
  161. if (this.get('allInstalledServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  162. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  163. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  164. if (this.get('selectedServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  165. serviceConfig.showConfig = true;
  166. }
  167. this.get('stepConfigs').pushObject(serviceConfig);
  168. } else {
  169. console.log('skipping ' + serviceConfig.serviceName);
  170. }
  171. }, this);
  172. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  173. var showProxyGroup = this.get('selectedServiceNames').contains('HIVE') ||
  174. this.get('selectedServiceNames').contains('HCATALOG') ||
  175. this.get('selectedServiceNames').contains('OOZIE');
  176. miscConfigs.findProperty('name', 'proxyuser_group').set('isVisible', showProxyGroup);
  177. miscConfigs.findProperty('name', 'hbase_user').set('isVisible', this.get('selectedServiceNames').contains('HBASE'));
  178. miscConfigs.findProperty('name', 'mapred_user').set('isVisible', this.get('selectedServiceNames').contains('MAPREDUCE'));
  179. miscConfigs.findProperty('name', 'hive_user').set('isVisible', this.get('selectedServiceNames').contains('HIVE'));
  180. miscConfigs.findProperty('name', 'hcat_user').set('isVisible', this.get('selectedServiceNames').contains('HCATALOG'));
  181. miscConfigs.findProperty('name', 'webhcat_user').set('isVisible', this.get('selectedServiceNames').contains('WEBHCAT'));
  182. miscConfigs.findProperty('name', 'oozie_user').set('isVisible', this.get('selectedServiceNames').contains('OOZIE'));
  183. miscConfigs.findProperty('name', 'pig_user').set('isVisible', this.get('selectedServiceNames').contains('PIG'));
  184. miscConfigs.findProperty('name', 'sqoop_user').set('isVisible', this.get('selectedServiceNames').contains('SQOOP'));
  185. miscConfigs.findProperty('name', 'zk_user').set('isVisible', this.get('selectedServiceNames').contains('ZOOKEEPER'));
  186. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  187. },
  188. /**
  189. * Load child components to service config object
  190. * @param _componentConfig
  191. * @param componentConfig
  192. */
  193. loadComponentConfigs: function (_componentConfig, componentConfig) {
  194. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  195. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  196. serviceConfigProperty.serviceConfig = componentConfig;
  197. serviceConfigProperty.initialValue();
  198. componentConfig.configs.pushObject(serviceConfigProperty);
  199. serviceConfigProperty.validate();
  200. }, this);
  201. },
  202. validateCustomConfig: function () {
  203. var flag = true;
  204. var serviceProperties = [];
  205. this.get('stepConfigs').forEach(function (_serviceContent) {
  206. var configProperties = _serviceContent.get('configs');
  207. if (configProperties.someProperty('id', 'conf-site')) {
  208. var serviceProperty = {};
  209. serviceProperty.serviceName = _serviceContent.get("serviceName");
  210. serviceProperty.siteProperties = [];
  211. var customSite = configProperties.findProperty('id', 'conf-site');
  212. var keyValue = customSite.value.split(/\n+/);
  213. if (keyValue) {
  214. keyValue.forEach(function (_keyValue) {
  215. console.log("The value of the keyValue is: " + _keyValue.trim());
  216. _keyValue = _keyValue.trim();
  217. var key = _keyValue.match(/(.+)=/);
  218. var value = _keyValue.match(/=(.*)/);
  219. if (key) {
  220. // Check that entered config is allowed to reconfigure
  221. if (configProperties.someProperty('name', key[1]) || this.get('configMapping').someProperty('name', key[1])) {
  222. var property = {
  223. siteProperty: key[1],
  224. displayNames: [],
  225. displayMsg: null
  226. };
  227. if (this.get('configMapping').someProperty('name', key[1])) {
  228. this.setPropertyDisplayNames(property.displayNames, this.get('configMapping').findProperty('name', key[1]).templateName, configProperties);
  229. }
  230. property.displayMsg = this.setDisplayMessage(property.siteProperty, property.displayNames);
  231. serviceProperty.siteProperties.push(property);
  232. flag = false;
  233. }
  234. }
  235. }, this);
  236. }
  237. serviceProperties.push(serviceProperty);
  238. }
  239. }, this);
  240. var result = {
  241. flag: flag,
  242. value: serviceProperties
  243. };
  244. return result;
  245. },
  246. /**
  247. * @param: An array of display names
  248. */
  249. setDisplayMessage: function (siteProperty, displayNames) {
  250. var displayMsg = null;
  251. if (displayNames && displayNames.length) {
  252. if (displayNames.length === 1) {
  253. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  254. } else {
  255. var name = null;
  256. displayNames.forEach(function (_name, index) {
  257. if (index === 0) {
  258. name = _name;
  259. } else if (index === displayNames.length - 1) {
  260. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  261. } else {
  262. name = name + ', ' + _name;
  263. }
  264. }, this);
  265. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  266. }
  267. } else {
  268. displayMsg = siteProperty;
  269. }
  270. return displayMsg;
  271. },
  272. /**
  273. * Set display names of the property tfrom he puppet/global names
  274. * @param displayNames: a field to be set with displayNames
  275. * @param names: array of property puppet/global names
  276. * @param configProperties: array of config properties of the respective service to the name param
  277. */
  278. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  279. names.forEach(function (_name, index) {
  280. if (configProperties.someProperty('name', _name)) {
  281. displayNames.push(configProperties.findProperty('name', _name).displayName);
  282. }
  283. }, this);
  284. },
  285. /**
  286. * Display Error Message with service name, its custom configuration name and displaynames on the page
  287. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  288. */
  289. showCustomConfigErrMsg: function (customConfig) {
  290. App.ModalPopup.show({
  291. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  292. primary: Em.I18n.t('ok'),
  293. secondary: null,
  294. onPrimary: function () {
  295. this.hide();
  296. },
  297. bodyClass: Ember.View.extend({
  298. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  299. siteProperties: customConfig,
  300. getDisplayMessage: function () {
  301. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  302. customConfig: customConfig,
  303. template: Ember.Handlebars.compile([
  304. '<h5>{{view.message}}</h5>',
  305. '<br/>',
  306. '<div class="pre-scrollable" style="max-height: 250px;">',
  307. '<ul>',
  308. '{{#each val in view.customConfig}}',
  309. '{{#if val.siteProperties}}',
  310. '<li>',
  311. '{{val.serviceName}}',
  312. '<ul>',
  313. '{{#each item in val.siteProperties}}',
  314. '<li>',
  315. '{{item.displayMsg}}',
  316. '</li>',
  317. '{{/each}}',
  318. '</ul>',
  319. '</li>',
  320. '{{/if}}',
  321. '{{/each}}',
  322. '</ul>',
  323. '</div>'
  324. ].join('\n'))
  325. })
  326. });
  327. },
  328. submit: function () {
  329. if (!this.get('isSubmitDisabled')) {
  330. App.router.send('next');
  331. /*
  332. var result = {};
  333. result = this.validateCustomConfig();
  334. if (result.flag === true) {
  335. App.router.send('next');
  336. } else {
  337. this.showCustomConfigErrMsg(result.value);
  338. }
  339. */
  340. }
  341. },
  342. /**
  343. * Provides service component name and display-name information for
  344. * the current selected service.
  345. */
  346. getCurrentServiceComponents: function () {
  347. var selectedServiceName = this.get('selectedService.serviceName');
  348. var masterComponents = this.get('content.masterComponentHosts');
  349. var slaveComponents = this.get('content.slaveComponentHosts');
  350. var scMaps = require('data/service_components');
  351. var validComponents = Ember.A([]);
  352. var seenComponents = {};
  353. masterComponents.forEach(function(component){
  354. var cn = component.component
  355. var cdn = component.display_name;
  356. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  357. validComponents.pushObject(Ember.Object.create({
  358. componentName: cn,
  359. displayName: cdn,
  360. selected: false
  361. }));
  362. seenComponents[cn] = cn;
  363. }
  364. });
  365. slaveComponents.forEach(function(component){
  366. var cn = component.componentName
  367. var cdn = component.displayName;
  368. var componentDef = scMaps.findProperty('component_name', cn);
  369. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  370. validComponents.pushObject(Ember.Object.create({
  371. componentName: cn,
  372. displayName: cdn,
  373. selected: false
  374. }));
  375. seenComponents[cn] = cn;
  376. }
  377. });
  378. return validComponents;
  379. }.property('content'),
  380. getAllHosts: function () {
  381. // Load hosts
  382. var allHosts = Ember.A([]);
  383. var hostNameToHostMap = {};
  384. var hosts = this.get('content.hosts');
  385. for ( var hostName in hosts) {
  386. var host = hosts[hostName];
  387. hostNameToHostMap[hostName] = App.Host.createRecord({
  388. hostName: host.name,
  389. publicHostName: host.name,
  390. cpu: host.cpu,
  391. memory: host.memory
  392. });
  393. allHosts.pushObject(hostNameToHostMap[hostName]);
  394. }
  395. // Load host-components
  396. var masterComponents = this.get('content.masterComponentHosts');
  397. var slaveComponents = this.get('content.slaveComponentHosts');
  398. masterComponents.forEach(function (component) {
  399. var host = hostNameToHostMap[component.hostName];
  400. var hc = App.HostComponent.createRecord({
  401. componentName: component.component,
  402. host: host
  403. });
  404. if (host != null) {
  405. host.get('hostComponents').pushObject(hc);
  406. }
  407. });
  408. slaveComponents.forEach(function (component) {
  409. component.hosts.forEach(function (host) {
  410. var h = hostNameToHostMap[host.hostName];
  411. var hc = App.HostComponent.createRecord({
  412. componentName: component.componentName,
  413. host: h
  414. });
  415. if (h != null) {
  416. h.get('hostComponents').pushObject(hc);
  417. }
  418. });
  419. });
  420. return allHosts;
  421. }.property('content')
  422. });