step7_controller.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. // Update existing values
  73. var seenStoredConfigs = {};
  74. _content.get('configs').forEach(function (_config) {
  75. var componentVal = storedServices.findProperty('name', _config.get('name'));
  76. //if we have config for specified component
  77. if (componentVal) {
  78. //set it
  79. seenStoredConfigs[componentVal.name] = 'true';
  80. _config.set('value', componentVal.value)
  81. this.updateHostOverrides(_config, componentVal);
  82. }
  83. }, this);
  84. // Create new values
  85. var currentServiceStoredConfigs = storedServices.filterProperty('service', _content.serviceName);
  86. currentServiceStoredConfigs.forEach(function (storedConfig) {
  87. if(!(storedConfig.name in seenStoredConfigs)){
  88. console.log("loadStep7(): New property from local storage: ", storedConfig);
  89. // Determine category
  90. var configCategory = 'Advanced';
  91. var serviceConfigMetaData = serviceConfigs.findProperty('serviceName', _content.serviceName);
  92. var categoryMetaData = serviceConfigMetaData == null ? null : serviceConfigMetaData.configCategories.findProperty('siteFileName', storedConfig.filename);
  93. if (categoryMetaData != null) {
  94. configCategory = categoryMetaData.get('name');
  95. }
  96. // Configuration data
  97. var configData = {
  98. id: storedConfig.id,
  99. name: storedConfig.name,
  100. displayName: storedConfig.name,
  101. serviceName: _content.serviceName,
  102. value: storedConfig.value,
  103. defaultValue: storedConfig.defaultValue,
  104. displayType: "advanced",
  105. filename: storedConfig.filename,
  106. category: configCategory,
  107. isUserProperty: true
  108. }
  109. var serviceConfigProperty = App.ServiceConfigProperty.create(configData);
  110. serviceConfigProperty.serviceConfig = _content;
  111. serviceConfigProperty.initialValue();
  112. this.updateHostOverrides(serviceConfigProperty, storedConfig);
  113. _content.configs.pushObject(serviceConfigProperty);
  114. serviceConfigProperty.validate();
  115. }
  116. }, this);
  117. }, this);
  118. }
  119. },
  120. updateHostOverrides: function (configProperty, storedConfigProperty) {
  121. if(storedConfigProperty.overrides!=null && storedConfigProperty.overrides.length>0){
  122. var overrides = configProperty.get('overrides');
  123. if (!overrides) {
  124. overrides = [];
  125. configProperty.set('overrides', overrides);
  126. }
  127. storedConfigProperty.overrides.forEach(function(overrideEntry){
  128. // create new override with new value
  129. var newSCP = App.ServiceConfigProperty.create(configProperty);
  130. newSCP.set('value', overrideEntry.value);
  131. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  132. newSCP.set('parentSCP', configProperty);
  133. var hostsArray = Ember.A([]);
  134. overrideEntry.hosts.forEach(function(host){
  135. hostsArray.push(host);
  136. });
  137. newSCP.set('selectedHostOptions', hostsArray);
  138. overrides.pushObject(newSCP);
  139. });
  140. }
  141. },
  142. /*
  143. Loads the advanced configs fetched from the server metadata libarary
  144. */
  145. loadAdvancedConfig: function (serviceConfigs, advancedConfig) {
  146. advancedConfig.forEach(function (_config) {
  147. if (_config) {
  148. var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
  149. if (service) {
  150. if (this.get('configMapping').someProperty('name', _config.name)) {
  151. } else if (!(service.configs.someProperty('name', _config.name))) {
  152. _config.id = "site property";
  153. _config.category = 'Advanced';
  154. var serviceConfigMetaData = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  155. var categoryMetaData = serviceConfigMetaData == null ? null : serviceConfigMetaData.configCategories.findProperty('siteFileName', serviceConfigObj.filename);
  156. if (categoryMetaData != null) {
  157. _config.category = categoryMetaData.get('name');
  158. }
  159. _config.displayName = _config.name;
  160. _config.defaultValue = _config.value;
  161. // make all advanced configs optional and populated by default
  162. /*
  163. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  164. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  165. * false; _config.value = ''; } else if
  166. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  167. */
  168. _config.isRequired = false;
  169. _config.isVisible = true;
  170. _config.displayType = 'advanced';
  171. service.configs.pushObject(_config);
  172. }
  173. }
  174. }
  175. }, this);
  176. },
  177. /**
  178. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  179. */
  180. loadCustomConfig: function () {
  181. var serviceConfigs = this.get('serviceConfigs');
  182. this.get('customConfigs').forEach(function (_config) {
  183. var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
  184. if (service) {
  185. if (!(service.configs.someProperty('name', _config.name))) {
  186. if( Object.prototype.toString.call( _config.defaultValue ) === '[object Array]' ) {
  187. this.loadDefaultCustomConfig(_config);
  188. }
  189. service.configs.pushObject(_config);
  190. }
  191. }
  192. }, this);
  193. },
  194. loadDefaultCustomConfig: function (customConfig) {
  195. var customValue = '';
  196. var length = customConfig.defaultValue.length;
  197. customConfig.defaultValue.forEach(function (_config, index) {
  198. customValue += _config.name + '=' + _config.value;
  199. if (index !== length - 1) {
  200. customValue += '\n';
  201. }
  202. }, this);
  203. customConfig.value = customValue;
  204. },
  205. /**
  206. * Render configs for active services
  207. * @param serviceConfigs
  208. */
  209. renderServiceConfigs: function (serviceConfigs) {
  210. serviceConfigs.forEach(function (_serviceConfig) {
  211. var serviceConfig = App.ServiceConfig.create({
  212. filename: _serviceConfig.filename,
  213. serviceName: _serviceConfig.serviceName,
  214. displayName: _serviceConfig.displayName,
  215. configCategories: _serviceConfig.configCategories,
  216. showConfig: false,
  217. configs: []
  218. });
  219. if (this.get('allInstalledServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  220. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  221. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  222. if (this.get('selectedServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  223. serviceConfig.showConfig = true;
  224. }
  225. this.get('stepConfigs').pushObject(serviceConfig);
  226. } else {
  227. console.log('skipping ' + serviceConfig.serviceName);
  228. }
  229. }, this);
  230. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  231. var showProxyGroup = this.get('selectedServiceNames').contains('HIVE') ||
  232. this.get('selectedServiceNames').contains('HCATALOG') ||
  233. this.get('selectedServiceNames').contains('OOZIE');
  234. miscConfigs.findProperty('name', 'proxyuser_group').set('isVisible', showProxyGroup);
  235. miscConfigs.findProperty('name', 'hbase_user').set('isVisible', this.get('selectedServiceNames').contains('HBASE'));
  236. miscConfigs.findProperty('name', 'mapred_user').set('isVisible', this.get('selectedServiceNames').contains('MAPREDUCE'));
  237. miscConfigs.findProperty('name', 'hive_user').set('isVisible', this.get('selectedServiceNames').contains('HIVE'));
  238. miscConfigs.findProperty('name', 'hcat_user').set('isVisible', this.get('selectedServiceNames').contains('HCATALOG'));
  239. miscConfigs.findProperty('name', 'webhcat_user').set('isVisible', this.get('selectedServiceNames').contains('WEBHCAT'));
  240. miscConfigs.findProperty('name', 'oozie_user').set('isVisible', this.get('selectedServiceNames').contains('OOZIE'));
  241. miscConfigs.findProperty('name', 'pig_user').set('isVisible', this.get('selectedServiceNames').contains('PIG'));
  242. miscConfigs.findProperty('name', 'sqoop_user').set('isVisible', this.get('selectedServiceNames').contains('SQOOP'));
  243. miscConfigs.findProperty('name', 'zk_user').set('isVisible', this.get('selectedServiceNames').contains('ZOOKEEPER'));
  244. miscConfigs.findProperty('name', 'rrdcached_base_dir').set('isVisible', this.get('selectedServiceNames').contains('GANGLIA'));
  245. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  246. },
  247. /**
  248. * Load child components to service config object
  249. * @param _componentConfig
  250. * @param componentConfig
  251. */
  252. loadComponentConfigs: function (_componentConfig, componentConfig) {
  253. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  254. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  255. serviceConfigProperty.serviceConfig = componentConfig;
  256. serviceConfigProperty.initialValue();
  257. componentConfig.configs.pushObject(serviceConfigProperty);
  258. serviceConfigProperty.validate();
  259. }, this);
  260. },
  261. /**
  262. * @param: An array of display names
  263. */
  264. setDisplayMessage: function (siteProperty, displayNames) {
  265. var displayMsg = null;
  266. if (displayNames && displayNames.length) {
  267. if (displayNames.length === 1) {
  268. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + displayNames[0];
  269. } else {
  270. var name = null;
  271. displayNames.forEach(function (_name, index) {
  272. if (index === 0) {
  273. name = _name;
  274. } else if (index === displayNames.length - 1) {
  275. name = name + ' ' + Em.I18n.t('and') + ' ' + _name;
  276. } else {
  277. name = name + ', ' + _name;
  278. }
  279. }, this);
  280. displayMsg = siteProperty + ' ' + Em.I18n.t('as') + ' ' + name;
  281. }
  282. } else {
  283. displayMsg = siteProperty;
  284. }
  285. return displayMsg;
  286. },
  287. /**
  288. * Set display names of the property tfrom he puppet/global names
  289. * @param displayNames: a field to be set with displayNames
  290. * @param names: array of property puppet/global names
  291. * @param configProperties: array of config properties of the respective service to the name param
  292. */
  293. setPropertyDisplayNames: function (displayNames, names, configProperties) {
  294. names.forEach(function (_name, index) {
  295. if (configProperties.someProperty('name', _name)) {
  296. displayNames.push(configProperties.findProperty('name', _name).displayName);
  297. }
  298. }, this);
  299. },
  300. /**
  301. * Display Error Message with service name, its custom configuration name and displaynames on the page
  302. * @param customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
  303. */
  304. showCustomConfigErrMsg: function (customConfig) {
  305. App.ModalPopup.show({
  306. header: Em.I18n.t('installer.step7.ConfigErrMsg.header'),
  307. primary: Em.I18n.t('ok'),
  308. secondary: null,
  309. onPrimary: function () {
  310. this.hide();
  311. },
  312. bodyClass: Ember.View.extend({
  313. message: Em.I18n.t('installer.step7.ConfigErrMsg.message'),
  314. siteProperties: customConfig,
  315. getDisplayMessage: function () {
  316. }.property('customConfig.@each.siteProperties.@each.siteProperty'),
  317. customConfig: customConfig,
  318. template: Ember.Handlebars.compile([
  319. '<h5>{{view.message}}</h5>',
  320. '<br/>',
  321. '<div class="pre-scrollable" style="max-height: 250px;">',
  322. '<ul>',
  323. '{{#each val in view.customConfig}}',
  324. '{{#if val.siteProperties}}',
  325. '<li>',
  326. '{{val.serviceName}}',
  327. '<ul>',
  328. '{{#each item in val.siteProperties}}',
  329. '<li>',
  330. '{{item.displayMsg}}',
  331. '</li>',
  332. '{{/each}}',
  333. '</ul>',
  334. '</li>',
  335. '{{/if}}',
  336. '{{/each}}',
  337. '</ul>',
  338. '</div>'
  339. ].join('\n'))
  340. })
  341. });
  342. },
  343. submit: function () {
  344. if (!this.get('isSubmitDisabled')) {
  345. App.router.send('next');
  346. }
  347. },
  348. /**
  349. * Provides service component name and display-name information for
  350. * the current selected service.
  351. */
  352. getCurrentServiceComponents: function () {
  353. var selectedServiceName = this.get('selectedService.serviceName');
  354. var masterComponents = this.get('content.masterComponentHosts');
  355. var slaveComponents = this.get('content.slaveComponentHosts');
  356. var scMaps = require('data/service_components');
  357. var validComponents = Ember.A([]);
  358. var seenComponents = {};
  359. masterComponents.forEach(function(component){
  360. var cn = component.component
  361. var cdn = component.display_name;
  362. if(component.serviceId===selectedServiceName && !seenComponents[cn]){
  363. validComponents.pushObject(Ember.Object.create({
  364. componentName: cn,
  365. displayName: cdn,
  366. selected: false
  367. }));
  368. seenComponents[cn] = cn;
  369. }
  370. });
  371. slaveComponents.forEach(function(component){
  372. var cn = component.componentName
  373. var cdn = component.displayName;
  374. var componentDef = scMaps.findProperty('component_name', cn);
  375. if(componentDef!=null && selectedServiceName===componentDef.service_name && !seenComponents[cn]){
  376. validComponents.pushObject(Ember.Object.create({
  377. componentName: cn,
  378. displayName: cdn,
  379. selected: false
  380. }));
  381. seenComponents[cn] = cn;
  382. }
  383. });
  384. return validComponents;
  385. }.property('content'),
  386. getAllHosts: function () {
  387. // Load hosts
  388. var allHosts = Ember.A([]);
  389. var hostNameToHostMap = {};
  390. var hosts = this.get('content.hosts');
  391. for ( var hostName in hosts) {
  392. var host = hosts[hostName];
  393. hostNameToHostMap[hostName] = App.Host.createRecord({
  394. id: host.name,
  395. hostName: host.name,
  396. publicHostName: host.name,
  397. cpu: host.cpu,
  398. memory: host.memory
  399. });
  400. allHosts.pushObject(hostNameToHostMap[hostName]);
  401. }
  402. // Load host-components
  403. var masterComponents = this.get('content.masterComponentHosts');
  404. var slaveComponents = this.get('content.slaveComponentHosts');
  405. masterComponents.forEach(function (component) {
  406. var host = hostNameToHostMap[component.hostName];
  407. var hc = App.HostComponent.createRecord({
  408. componentName: component.component,
  409. host: host
  410. });
  411. if (host != null) {
  412. host.get('hostComponents').pushObject(hc);
  413. }
  414. });
  415. slaveComponents.forEach(function (component) {
  416. component.hosts.forEach(function (host) {
  417. var h = hostNameToHostMap[host.hostName];
  418. var hc = App.HostComponent.createRecord({
  419. componentName: component.componentName,
  420. host: h
  421. });
  422. if (h != null) {
  423. h.get('hostComponents').pushObject(hc);
  424. }
  425. });
  426. });
  427. return allHosts;
  428. }.property('content')
  429. });