step7_controller.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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 numberUtils = require('utils/number_utils');
  20. /**
  21. * By Step 7, we have the following information stored in App.db and set on this
  22. * controller by the router.
  23. *
  24. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  27. *
  28. */
  29. App.WizardStep7Controller = Em.Controller.extend({
  30. name: 'wizardStep7Controller',
  31. /**
  32. * Contains all field properties that are viewed in this step
  33. * @type {object[]}
  34. */
  35. stepConfigs: [],
  36. selectedService: null,
  37. slaveHostToGroup: null,
  38. secureConfigs: require('data/secure_mapping'),
  39. /**
  40. * If miscConfigChange Modal is shown
  41. * @type {bool}
  42. */
  43. miscModalVisible: false,
  44. gangliaAvailableSpace: null,
  45. /**
  46. * @type {string}
  47. */
  48. gangliaMoutDir: '/',
  49. overrideToAdd: null,
  50. /**
  51. * Is installer controller used
  52. * @type {bool}
  53. */
  54. isInstaller: true,
  55. /**
  56. * List of config groups
  57. * @type {object[]}
  58. */
  59. configGroups: [],
  60. /**
  61. * List of config group to be deleted
  62. * @type {object[]}
  63. */
  64. groupsToDelete: [],
  65. preSelectedConfigGroup: null,
  66. /**
  67. * Currently selected config group
  68. * @type {object}
  69. */
  70. selectedConfigGroup: null,
  71. /**
  72. * Config tags of actually installed services
  73. * @type {array}
  74. */
  75. serviceConfigTags: [],
  76. serviceConfigsData: require('data/service_configs'),
  77. /**
  78. * Are advanced configs loaded
  79. * @type {bool}
  80. */
  81. isAdvancedConfigLoaded: true,
  82. /**
  83. * Are applied to service configs loaded
  84. * @type {bool}
  85. */
  86. isAppliedConfigLoaded: true,
  87. isConfigsLoaded: function () {
  88. return (this.get('isAdvancedConfigLoaded') && this.get('isAppliedConfigLoaded'));
  89. }.property('isAdvancedConfigLoaded', 'isAppliedConfigLoaded'),
  90. /**
  91. * Should Next-button be disabled
  92. * @type {bool}
  93. */
  94. isSubmitDisabled: function () {
  95. return (!this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  96. }.property('stepConfigs.@each.errorCount', 'miscModalVisible'),
  97. /**
  98. * List of selected to install service names
  99. * @type {string[]}
  100. */
  101. selectedServiceNames: function () {
  102. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  103. }.property('content.services').cacheable(),
  104. /**
  105. * List of installed and selected to install service names
  106. * @type {string[]}
  107. */
  108. allSelectedServiceNames: function () {
  109. return this.get('content.services').filterProperty('isSelected').mapProperty('serviceName');
  110. }.property('content.services').cacheable(),
  111. /**
  112. * List of installed service names
  113. * Sqoop and HCatalog are excluded if not installer wizard running
  114. * @type {string[]}
  115. */
  116. installedServiceNames: function () {
  117. var serviceNames = this.get('content.services').filterProperty('isInstalled').mapProperty('serviceName');
  118. if (this.get('content.controllerName') !== 'installerController') {
  119. return serviceNames.without('SQOOP').without('HCATALOG');
  120. }
  121. return serviceNames;
  122. }.property('content.services').cacheable(),
  123. /**
  124. * List of master components
  125. * @type {Ember.Enumerable}
  126. */
  127. masterComponentHosts: function () {
  128. return this.get('content.masterComponentHosts');
  129. }.property('content.masterComponentHosts'),
  130. /**
  131. * List of slave components
  132. * @type {Ember.Enumerable}
  133. */
  134. slaveComponentHosts: function () {
  135. return this.get('content.slaveGroupProperties');
  136. }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
  137. customData: [],
  138. /**
  139. * Filter text will be located here
  140. * @type {string}
  141. */
  142. filter: '',
  143. /**
  144. * Dropdown menu items in filter combobox
  145. * @type {Ember.Object[]}
  146. */
  147. filterColumns: function () {
  148. var result = [];
  149. for (var i = 1; i < 2; i++) {
  150. result.push(Em.Object.create({
  151. name: this.t('common.combobox.dropdown.' + i),
  152. selected: false
  153. }));
  154. }
  155. return result;
  156. }.property(),
  157. /**
  158. * Clear controller's properties:
  159. * <ul>
  160. * <li>stepConfigs</li>
  161. * <li>filter</li>
  162. * </ul>
  163. * and desect all <code>filterColumns</code>
  164. * @method clearStep
  165. */
  166. clearStep: function () {
  167. this.get('stepConfigs').clear();
  168. this.set('filter', '');
  169. this.get('filterColumns').setEach('selected', false);
  170. },
  171. /**
  172. * Load config groups for installed services
  173. * One ajax-request for each service
  174. * @param {string[]} servicesNames
  175. * @method loadInstalledServicesConfigGroups
  176. */
  177. loadInstalledServicesConfigGroups: function (servicesNames) {
  178. servicesNames.forEach(function (serviceName) {
  179. App.ajax.send({
  180. name: 'config.tags_and_groups',
  181. sender: this,
  182. data: {
  183. serviceName: serviceName,
  184. serviceConfigsDef: App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName)
  185. },
  186. success: 'loadServiceTagsSuccess'
  187. });
  188. }, this);
  189. },
  190. /**
  191. * Create site to tag map. Format:
  192. * <code>
  193. * {
  194. * site1: tag1,
  195. * site1: tag2,
  196. * site2: tag3
  197. * ...
  198. * }
  199. * </code>
  200. * @param {object} desired_configs
  201. * @param {string[]} sites
  202. * @returns {object}
  203. * @private
  204. * @method _createSiteToTagMap
  205. */
  206. _createSiteToTagMap: function (desired_configs, sites) {
  207. var siteToTagMap = {};
  208. for (var site in desired_configs) {
  209. if (desired_configs.hasOwnProperty(site)) {
  210. if (sites.indexOf(site) > -1) {
  211. siteToTagMap[site] = desired_configs[site].tag;
  212. }
  213. }
  214. }
  215. return siteToTagMap;
  216. },
  217. /**
  218. * Load config groups success callback
  219. * @param {object} data
  220. * @param {object} opt
  221. * @param {object} params
  222. * @method loadServiceTagsSuccess
  223. */
  224. loadServiceTagsSuccess: function (data, opt, params) {
  225. var serviceName = params.serviceName,
  226. service = this.get('stepConfigs').findProperty('serviceName', serviceName),
  227. defaultConfigGroupHosts = this.get('wizardController.allHosts').mapProperty('hostName'),
  228. siteToTagMap = this._createSiteToTagMap(data.Clusters.desired_configs, params.serviceConfigsDef.sites),
  229. selectedConfigGroup;
  230. this.set('loadedClusterSiteToTagMap', siteToTagMap);
  231. //parse loaded config groups
  232. if (App.get('supports.hostOverrides')) {
  233. var configGroups = [];
  234. if (data.config_groups.length) {
  235. data.config_groups.forEach(function (item) {
  236. item = item.ConfigGroup;
  237. if (item.tag === serviceName) {
  238. var groupHosts = item.hosts.mapProperty('host_name');
  239. var newConfigGroup = App.ConfigGroup.create({
  240. id: item.id,
  241. name: item.group_name,
  242. description: item.description,
  243. isDefault: false,
  244. parentConfigGroup: null,
  245. service: App.Service.find().findProperty('serviceName', item.tag),
  246. hosts: groupHosts,
  247. configSiteTags: []
  248. });
  249. groupHosts.forEach(function (host) {
  250. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  251. }, this);
  252. item.desired_configs.forEach(function (config) {
  253. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  254. site: config.type,
  255. tag: config.tag
  256. }));
  257. }, this);
  258. configGroups.push(newConfigGroup);
  259. }
  260. }, this);
  261. }
  262. }
  263. var defaultConfigGroup = App.ConfigGroup.create({
  264. name: App.Service.DisplayNames[serviceName] + " Default",
  265. description: "Default cluster level " + serviceName + " configuration",
  266. isDefault: true,
  267. hosts: defaultConfigGroupHosts,
  268. parentConfigGroup: null,
  269. service: Em.Object.create({
  270. id: serviceName
  271. }),
  272. serviceName: serviceName,
  273. configSiteTags: []
  274. });
  275. if (!selectedConfigGroup) {
  276. selectedConfigGroup = defaultConfigGroup;
  277. }
  278. configGroups = configGroups.sortProperty('name');
  279. configGroups.unshift(defaultConfigGroup);
  280. if (App.get('supports.hostOverrides')) {
  281. service.set('configGroups', configGroups);
  282. var loadedGroupToOverrideSiteToTagMap = {};
  283. if (App.get('supports.hostOverrides')) {
  284. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') ? service.get('configGroups') : [selectedConfigGroup];
  285. configGroupsWithOverrides.forEach(function (item) {
  286. var groupName = item.get('name');
  287. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  288. item.get('configSiteTags').forEach(function (siteTag) {
  289. var site = siteTag.get('site');
  290. loadedGroupToOverrideSiteToTagMap[groupName][site] = siteTag.get('tag');
  291. }, this);
  292. }, this);
  293. }
  294. this.set('preSelectedConfigGroup', selectedConfigGroup);
  295. App.config.loadServiceConfigGroupOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'), this.onLoadOverrides, this);
  296. }
  297. },
  298. onLoadOverrides: function (configs) {
  299. var serviceName = configs[0].serviceName,
  300. service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  301. if (App.get('supports.hostOverrides')) {
  302. var serviceConfig = App.config.createServiceConfig(serviceName);
  303. if (serviceConfig.get('serviceName') === 'HDFS') {
  304. App.config.OnNnHAHideSnn(serviceConfig);
  305. }
  306. service.set('selectedConfigGroup', this.get('preSelectedConfigGroup'));
  307. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  308. }
  309. service.set('configs', serviceConfig.get('configs'));
  310. },
  311. /**
  312. * Get object with recommended default values for config properties
  313. * Format:
  314. * <code>
  315. * {
  316. * configName1: configValue1,
  317. * configName2: configValue2
  318. * ...
  319. * }
  320. * </code>
  321. * @param {string} serviceName
  322. * @returns {object}
  323. * @method _getRecommendedDefaultsForComponent
  324. */
  325. _getRecommendedDefaultsForComponent: function (serviceName) {
  326. var s = this.get('serviceConfigsData').findProperty('serviceName', serviceName),
  327. recommendedDefaults = {},
  328. localDB = this.getInfoForDefaults();
  329. if (s.defaultsProviders) {
  330. s.defaultsProviders.forEach(function (defaultsProvider) {
  331. var d = defaultsProvider.getDefaults(localDB);
  332. for (var name in d) {
  333. if (d.hasOwnProperty(name)) {
  334. recommendedDefaults[name] = d[name];
  335. }
  336. }
  337. });
  338. }
  339. return recommendedDefaults;
  340. },
  341. /**
  342. * Get info about hosts and host components to configDefaultsProviders
  343. * Work specifically in Add Service wizard
  344. * @slaveComponentHosts - contains slaves and clients as well
  345. * @returns {{masterComponentHosts: Array, slaveComponentHosts: Array, hosts: {}}}
  346. */
  347. getInfoForDefaults: function() {
  348. var slaveComponentHosts = [];
  349. var hosts = this.get('content.hosts');
  350. var slaveHostMap = {};
  351. //get clients and slaves from stack
  352. App.StackServiceComponent.find().forEach(function (component) {
  353. if (component.get('isClient') || component.get('isSlave')) {
  354. slaveHostMap[component.get('componentName')] = [];
  355. }
  356. });
  357. //assign hosts of every component
  358. for (var hostName in hosts) {
  359. hosts[hostName].hostComponents.forEach(function (componentName) {
  360. if (slaveHostMap[componentName]) {
  361. slaveHostMap[componentName].push({hostName: hostName});
  362. }
  363. });
  364. }
  365. //push slaves and clients into @slaveComponentHosts
  366. for (var componentName in slaveHostMap) {
  367. if(slaveHostMap[componentName].length > 0) {
  368. slaveComponentHosts.push({
  369. componentName: componentName,
  370. hosts: slaveHostMap[componentName]
  371. })
  372. }
  373. }
  374. var masterComponentHosts = App.HostComponent.find().filterProperty('isMaster', true).map(function(item) {
  375. return {
  376. component: item.get('componentName'),
  377. serviceId: item.get('service.serviceName'),
  378. host: item.get('hostName')
  379. }
  380. });
  381. return {
  382. masterComponentHosts: masterComponentHosts,
  383. slaveComponentHosts: slaveComponentHosts,
  384. hosts: hosts
  385. };
  386. },
  387. /**
  388. * By default <code>value</code>-property is string "true|false".
  389. * Should update it to boolean type
  390. * Also affects <code>defaultValue</code>
  391. * @param {Ember.Object} serviceConfigProperty
  392. * @returns {Ember.Object} Updated config-object
  393. * @method _updateValueForCheckBoxConfig
  394. */
  395. _updateValueForCheckBoxConfig: function (serviceConfigProperty) {
  396. var v = serviceConfigProperty.get('value');
  397. switch (serviceConfigProperty.get('value')) {
  398. case 'true':
  399. v = true;
  400. break;
  401. case 'false':
  402. v = false;
  403. break;
  404. }
  405. serviceConfigProperty.setProperties({value: v, defaultValue: v});
  406. return serviceConfigProperty;
  407. },
  408. /**
  409. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  410. * Based on user's permissions and selected config group
  411. * @param {Ember.Object} serviceConfigProperty
  412. * @param {bool} defaultGroupSelected
  413. * @returns {Ember.Object} Updated config-object
  414. * @method _updateIsEditableFlagForConfig
  415. */
  416. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  417. if (App.get('isAdmin')) {
  418. if (defaultGroupSelected && !this.get('isHostsConfigsPage')) {
  419. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  420. }
  421. else {
  422. serviceConfigProperty.set('isEditable', false);
  423. }
  424. }
  425. else {
  426. serviceConfigProperty.set('isEditable', false);
  427. }
  428. return serviceConfigProperty;
  429. },
  430. /**
  431. * Set <code>overrides</code>-property to <code>serviceConfigProperty<code>
  432. * @param {Ember.Object} serviceConfigProperty
  433. * @param {Ember.Object} component
  434. * @return {Ember.Object} Updated config-object
  435. * @method _updateOverridesForConfig
  436. */
  437. _updateOverridesForConfig: function (serviceConfigProperty, component) {
  438. var overrides = serviceConfigProperty.get('overrides');
  439. if (Em.isNone(overrides)) {
  440. serviceConfigProperty.set('overrides', Em.A([]));
  441. return serviceConfigProperty;
  442. }
  443. serviceConfigProperty.set('overrides', null);
  444. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  445. // Wrap each override to App.ServiceConfigProperty
  446. overrides.forEach(function (override) {
  447. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  448. newSCP.set('value', override.value);
  449. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  450. newSCP.set('parentSCP', serviceConfigProperty);
  451. if (App.get('supports.hostOverrides') && defaultGroupSelected) {
  452. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  453. // prevent cycle in proto object, clean link
  454. if (group.get('properties').length == 0) {
  455. group.set('properties', Em.A([]));
  456. }
  457. group.get('properties').push(newSCP);
  458. newSCP.set('group', override.group);
  459. newSCP.set('isEditable', false);
  460. }
  461. var parentOverridesArray = serviceConfigProperty.get('overrides');
  462. if (Em.isNone(parentOverridesArray)) {
  463. parentOverridesArray = Em.A([]);
  464. serviceConfigProperty.set('overrides', parentOverridesArray);
  465. }
  466. serviceConfigProperty.get('overrides').pushObject(newSCP);
  467. }, this);
  468. return serviceConfigProperty;
  469. },
  470. /**
  471. * Set <code>serviceValidator</code>-property to <code>serviceConfigProperty</code> if config's serviceName is equal
  472. * to component's serviceName
  473. * othervise set <code>isVisible</code>-property to <code>false</code>
  474. * @param {Ember.Object} serviceConfigProperty
  475. * @param {Ember.Object} component
  476. * @param {object} serviceConfigsData
  477. * @returns {Ember.Object} updated config-object
  478. * @mrthod _updateValidatorsForConfig
  479. */
  480. _updateValidatorsForConfig: function (serviceConfigProperty, component, serviceConfigsData) {
  481. if (serviceConfigProperty.get('serviceName') === component.get('serviceName')) {
  482. if (serviceConfigsData.configsValidator) {
  483. var validators = serviceConfigsData.configsValidator.get('configValidators');
  484. for (var validatorName in validators) {
  485. if (validators.hasOwnProperty(validatorName)) {
  486. if (serviceConfigProperty.get('name') == validatorName) {
  487. serviceConfigProperty.set('serviceValidator', serviceConfigsData.configsValidator);
  488. }
  489. }
  490. }
  491. }
  492. }
  493. else {
  494. serviceConfigProperty.set('isVisible', false);
  495. }
  496. return serviceConfigProperty;
  497. },
  498. /**
  499. * Set configs with overrides, recommended defaults to component
  500. * @param {Ember.Object[]} configs
  501. * @param {Ember.Object} componentConfig
  502. * @param {Ember.Object} component
  503. * @method loadComponentConfigs
  504. */
  505. loadComponentConfigs: function (configs, componentConfig, component) {
  506. var s = this.get('serviceConfigsData').findProperty('serviceName', component.get('serviceName')),
  507. defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  508. if (s.configsValidator) {
  509. var recommendedDefaults = this._getRecommendedDefaultsForComponent(component.get('serviceName'));
  510. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  511. }
  512. configs.forEach(function (serviceConfigProperty) {
  513. if (!serviceConfigProperty) return;
  514. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  515. serviceConfigProperty.set('isOverridable', true);
  516. }
  517. if (serviceConfigProperty.get('displayType') === 'checkbox') {
  518. this._updateValueForCheckBoxConfig(serviceConfigProperty);
  519. }
  520. this._updateValidatorsForConfig(serviceConfigProperty, component, s);
  521. this._updateOverridesForConfig(serviceConfigProperty, component);
  522. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  523. componentConfig.get('configs').pushObject(serviceConfigProperty);
  524. serviceConfigProperty.validate();
  525. }, this);
  526. var overrideToAdd = this.get('overrideToAdd');
  527. if (overrideToAdd) {
  528. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  529. if (overrideToAdd) {
  530. this.addOverrideProperty(overrideToAdd);
  531. component.set('overrideToAdd', null);
  532. }
  533. }
  534. },
  535. /**
  536. * Resolve dependency between configs.
  537. * @param serviceName {String}
  538. * @param configs {Ember.Enumerable}
  539. */
  540. resolveServiceDependencyConfigs: function (serviceName, configs) {
  541. switch (serviceName) {
  542. case 'STORM':
  543. this.resolveStormConfigs(configs);
  544. break;
  545. default:
  546. break;
  547. }
  548. },
  549. /**
  550. * Update some Storm configs
  551. * If Ganglia is selected to install or already installed, Ganglia host should be added to configs
  552. * @param {Ember.Enumerable} configs
  553. * @method resolveStormConfigs
  554. */
  555. resolveStormConfigs: function (configs) {
  556. var dependentConfigs, gangliaServerHost;
  557. dependentConfigs = ['nimbus.childopts', 'supervisor.childopts', 'worker.childopts'];
  558. // if Ganglia selected or installed, set ganglia host to configs
  559. if (this.get('installedServiceNames').contains('STORM') && this.get('installedServiceNames').contains('GANGLIA')) return;
  560. if (this.get('allSelectedServiceNames').contains('GANGLIA') || this.get('installedServiceNames').contains('GANGLIA')) {
  561. gangliaServerHost = this.get('wizardController').getDBProperty('masterComponentHosts').findProperty('component', 'GANGLIA_SERVER').hostName;
  562. dependentConfigs.forEach(function (configName) {
  563. var config = configs.findProperty('name', configName);
  564. var replaceStr = config.value.match(/.jar=host[^,]+/)[0];
  565. var replaceWith = replaceStr.slice(0, replaceStr.lastIndexOf('=') - replaceStr.length + 1) + gangliaServerHost;
  566. config.value = config.defaultValue = config.value.replace(replaceStr, replaceWith);
  567. config.forceUpdate = true;
  568. }, this);
  569. }
  570. },
  571. /**
  572. * On load function
  573. * @method loadStep
  574. */
  575. loadStep: function () {
  576. console.log("TRACE: Loading step7: Configure Services");
  577. if (!this.get('isConfigsLoaded')) {
  578. return;
  579. }
  580. this.clearStep();
  581. //STEP 1: Load advanced configs
  582. var advancedConfigs = this.get('content.advancedServiceConfig');
  583. //STEP 2: Load on-site configs by service from local DB
  584. var storedConfigs = this.get('content.serviceConfigProperties');
  585. //STEP 3: Merge pre-defined configs with loaded on-site configs
  586. var configs = App.config.mergePreDefinedWithStored(
  587. storedConfigs,
  588. advancedConfigs,
  589. this.get('selectedServiceNames').concat(this.get('installedServiceNames'))
  590. );
  591. //STEP 4: Add advanced configs
  592. App.config.addAdvancedConfigs(configs, advancedConfigs);
  593. //STEP 5: Add custom configs
  594. App.config.addCustomConfigs(configs);
  595. //put properties from capacity-scheduler.xml into one config with textarea view
  596. if (this.get('allSelectedServiceNames').contains('YARN') && !App.get('supports.capacitySchedulerUi')) {
  597. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  598. }
  599. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  600. if (this.get('wizardController.name') === 'addServiceController') {
  601. this.setInstalledServiceConfigs(this.get('serviceConfigTags'), configs);
  602. }
  603. if (this.get('allSelectedServiceNames').contains('STORM') || this.get('installedServiceNames').contains('STORM')) {
  604. this.resolveServiceDependencyConfigs('STORM', configs);
  605. }
  606. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  607. this.setStepConfigs(configs, storedConfigs);
  608. this.checkHostOverrideInstaller();
  609. this.activateSpecialConfigs();
  610. this.selectProperService();
  611. if (this.get('content.skipConfigStep')) {
  612. App.router.send('next');
  613. }
  614. },
  615. /**
  616. * If <code>App.supports.hostOverridesInstaller</code> is enabled should load config groups
  617. * and (if some services are already installed) load config groups for installed services
  618. * @method checkHostOverrideInstaller
  619. */
  620. checkHostOverrideInstaller: function () {
  621. if (App.get('supports.hostOverridesInstaller')) {
  622. this.loadConfigGroups(this.get('content.configGroups'));
  623. if (this.get('installedServiceNames').length > 0) {
  624. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  625. }
  626. }
  627. },
  628. /**
  629. * Set init <code>stepConfigs</code> value
  630. * Set <code>selected</code> for addable services if addServiceController is used
  631. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  632. * @param {Ember.Object[]} configs
  633. * @param {Ember.Object[]} storedConfigs
  634. * @method setStepConfigs
  635. */
  636. setStepConfigs: function (configs, storedConfigs) {
  637. var localDB = {
  638. hosts: this.get('wizardController.content.hosts'),
  639. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  640. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  641. };
  642. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB);
  643. if (this.get('wizardController.name') === 'addServiceController') {
  644. serviceConfigs.setEach('showConfig', true);
  645. serviceConfigs.setEach('selected', false);
  646. this.get('selectedServiceNames').forEach(function (serviceName) {
  647. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  648. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  649. });
  650. // Remove SNameNode if HA is enabled
  651. if (App.get('isHaEnabled')) {
  652. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  653. var removedConfigs = c.filterProperty('category', 'SNameNode');
  654. removedConfigs.map(function (config) {
  655. c = c.without(config);
  656. });
  657. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  658. }
  659. }
  660. this.set('stepConfigs', serviceConfigs);
  661. },
  662. /**
  663. * Select first addable service for <code>addServiceWizard</code>
  664. * Select first service at all in other cases
  665. * @method selectProperService
  666. */
  667. selectProperService: function () {
  668. if (this.get('wizardController.name') === 'addServiceController') {
  669. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  670. }
  671. else {
  672. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  673. }
  674. },
  675. /**
  676. * Load config tags
  677. * @return {$.ajax|null}
  678. * @method getConfigTags
  679. */
  680. getConfigTags: function () {
  681. this.set('isAppliedConfigLoaded', false);
  682. return App.ajax.send({
  683. name: 'config.tags',
  684. sender: this,
  685. success: 'getConfigTagsSuccess'
  686. });
  687. },
  688. /**
  689. * Success callback for config tags request
  690. * Updates <code>serviceConfigTags</code> with tags received from server
  691. * @param {object} data
  692. * @method getConfigTagsSuccess
  693. */
  694. getConfigTagsSuccess: function (data) {
  695. var installedServiceSites = [];
  696. this.get('serviceConfigsData').filter(function (service) {
  697. if (this.get('installedServiceNames').contains(service.serviceName)) {
  698. installedServiceSites = installedServiceSites.concat(service.sites);
  699. }
  700. }, this);
  701. installedServiceSites = installedServiceSites.uniq();
  702. var serviceConfigTags = [];
  703. for (var site in data.Clusters.desired_configs) {
  704. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  705. if (installedServiceSites.contains(site)) {
  706. serviceConfigTags.push({
  707. siteName: site,
  708. tagName: data.Clusters.desired_configs[site].tag,
  709. newTagName: null
  710. });
  711. }
  712. }
  713. }
  714. this.set('serviceConfigTags', serviceConfigTags);
  715. this.set('isAppliedConfigLoaded', true);
  716. },
  717. /**
  718. * set configs actual values from server
  719. * @param serviceConfigTags
  720. * @param configs
  721. * @method setInstalledServiceConfigs
  722. */
  723. setInstalledServiceConfigs: function (serviceConfigTags, configs) {
  724. var configsMap = {};
  725. App.router.get('configurationController').getConfigsByTags(serviceConfigTags).forEach(function (configSite) {
  726. $.extend(configsMap, configSite.properties);
  727. });
  728. configs.forEach(function (_config) {
  729. if (configsMap[_config.name] !== undefined) {
  730. // prevent overriding already edited properties
  731. if (_config.defaultValue != configsMap[_config.name])
  732. _config.value = configsMap[_config.name];
  733. _config.defaultValue = configsMap[_config.name];
  734. App.config.handleSpecialProperties(_config);
  735. }
  736. })
  737. },
  738. /**
  739. * Add group ids to <code>groupsToDelete</code>
  740. * Also save <code>groupsToDelete</code> to local storage
  741. * @param {Ember.Object[]} groups
  742. * @method setGroupsToDelete
  743. */
  744. setGroupsToDelete: function (groups) {
  745. var groupsToDelete = this.get('groupsToDelete');
  746. groups.forEach(function (group) {
  747. if (group.get('id'))
  748. groupsToDelete.push({
  749. id: group.get('id')
  750. });
  751. });
  752. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  753. },
  754. /**
  755. * Update <code>configGroups</code> with selected service configGroups
  756. * Also set default group to first position
  757. * Update <code>selectedConfigGroup</code> with new default group
  758. * @method selectedServiceObserver
  759. */
  760. selectedServiceObserver: function () {
  761. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  762. var serviceGroups = this.get('selectedService.configGroups');
  763. serviceGroups.forEach(function (item, index, array) {
  764. if (item.isDefault) {
  765. array.unshift(item);
  766. array.splice(index + 1, 1);
  767. }
  768. });
  769. this.set('configGroups', serviceGroups);
  770. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  771. }
  772. }.observes('selectedService.configGroups.@each'),
  773. /**
  774. * load default groups for each service in case of initial load
  775. * @param serviceConfigGroups
  776. * @method loadConfigGroups
  777. */
  778. loadConfigGroups: function (serviceConfigGroups) {
  779. var services = this.get('stepConfigs');
  780. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  781. services.forEach(function (service) {
  782. if (service.get('serviceName') === 'MISC') return;
  783. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  784. if (!serviceRawGroups.length) {
  785. service.set('configGroups', [
  786. App.ConfigGroup.create({
  787. name: App.Service.DisplayNames[service.serviceName] + " Default",
  788. description: "Default cluster level " + service.serviceName + " configuration",
  789. isDefault: true,
  790. hosts: Em.copy(hosts),
  791. service: Em.Object.create({
  792. id: service.serviceName
  793. }),
  794. serviceName: service.serviceName
  795. })
  796. ]);
  797. }
  798. else {
  799. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  800. var serviceGroups = service.get('configGroups');
  801. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  802. var readyGroup = App.ConfigGroup.create(configGroup);
  803. var wrappedProperties = [];
  804. readyGroup.get('properties').forEach(function (property) {
  805. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  806. });
  807. wrappedProperties.setEach('group', readyGroup);
  808. readyGroup.set('properties', wrappedProperties);
  809. readyGroup.set('parentConfigGroup', defaultGroup);
  810. serviceGroups.pushObject(readyGroup);
  811. });
  812. defaultGroup.set('childConfigGroups', serviceGroups);
  813. serviceGroups.pushObject(defaultGroup);
  814. }
  815. });
  816. },
  817. /**
  818. * Click-handler on config-group to make it selected
  819. * @param {object} event
  820. * @method selectConfigGroup
  821. */
  822. selectConfigGroup: function (event) {
  823. this.set('selectedConfigGroup', event.context);
  824. },
  825. /**
  826. * Rebuild list of configs switch of config group:
  827. * on default - display all configs from default group and configs from non-default groups as disabled
  828. * on non-default - display all from default group as disabled and configs from selected non-default group
  829. * @method switchConfigGroupConfigs
  830. */
  831. switchConfigGroupConfigs: function () {
  832. var serviceConfigs = this.get('selectedService.configs'),
  833. selectedGroup = this.get('selectedConfigGroup'),
  834. overrideToAdd = this.get('overrideToAdd'),
  835. overrides = [];
  836. if (!selectedGroup) return;
  837. var displayedConfigGroups = this._getDisplayedConfigGroups();
  838. displayedConfigGroups.forEach(function (group) {
  839. overrides.pushObjects(group.get('properties'));
  840. });
  841. serviceConfigs.forEach(function (config) {
  842. this._setEditableValue(config);
  843. this._setOverrides(config, overrides);
  844. }, this);
  845. }.observes('selectedConfigGroup'),
  846. /**
  847. * Get list of config groups to display
  848. * Returns empty array if no <code>selectedConfigGroup</code>
  849. * @return {Array}
  850. * @method _getDisplayedConfigGroups
  851. */
  852. _getDisplayedConfigGroups: function () {
  853. var selectedGroup = this.get('selectedConfigGroup');
  854. if (!selectedGroup) return [];
  855. return (selectedGroup.get('isDefault')) ?
  856. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  857. [this.get('selectedConfigGroup')];
  858. },
  859. /**
  860. * Set <code>isEditable</code> property to <code>config</code>
  861. * @param {Ember.Object} config
  862. * @return {Ember.Object} updated config-object
  863. * @method _setEditableValue
  864. */
  865. _setEditableValue: function (config) {
  866. var selectedGroup = this.get('selectedConfigGroup');
  867. if (!selectedGroup) return config;
  868. var isEditable = config.get('isEditable'),
  869. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  870. if (isServiceInstalled) {
  871. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  872. }
  873. else {
  874. isEditable = selectedGroup.get('isDefault');
  875. }
  876. config.set('isEditable', isEditable);
  877. return config;
  878. },
  879. /**
  880. * Set <code>overrides</code> property to <code>config</code>
  881. * @param {Ember.Object} config
  882. * @param {Ember.Enumerable} overrides
  883. * @returns {Ember.Object}
  884. * @method _setOverrides
  885. */
  886. _setOverrides: function (config, overrides) {
  887. var selectedGroup = this.get('selectedConfigGroup'),
  888. overrideToAdd = this.get('overrideToAdd'),
  889. configOverrides = overrides.filterProperty('name', config.get('name'));
  890. if (!selectedGroup) return config;
  891. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  892. configOverrides.push(this.addOverrideProperty(config));
  893. this.set('overrideToAdd', null);
  894. }
  895. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  896. configOverrides.setEach('parentSCP', config);
  897. config.set('overrides', configOverrides);
  898. return config;
  899. },
  900. /**
  901. * create overriden property and push it into Config group
  902. * @param {App.ServiceConfigProperty} serviceConfigProperty
  903. * @return {App.ServiceConfigProperty}
  904. * @method addOverrideProperty
  905. */
  906. addOverrideProperty: function (serviceConfigProperty) {
  907. var overrides = serviceConfigProperty.get('overrides') || [];
  908. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  909. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  910. newSCP.set('group', group);
  911. newSCP.set('value', '');
  912. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  913. newSCP.set('parentSCP', serviceConfigProperty);
  914. newSCP.set('isEditable', true);
  915. group.get('properties').pushObject(newSCP);
  916. overrides.pushObject(newSCP);
  917. return newSCP;
  918. },
  919. /**
  920. * @method manageConfigurationGroup
  921. */
  922. manageConfigurationGroup: function () {
  923. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  924. },
  925. /**
  926. * Make some configs visible depending on active services
  927. * @method activateSpecialConfigs
  928. */
  929. activateSpecialConfigs: function () {
  930. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  931. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  932. },
  933. /**
  934. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  935. * @return {$.ajax|null}
  936. * @method checkMySQLHost
  937. */
  938. checkMySQLHost: function () {
  939. // get ambari database type and hostname
  940. return App.ajax.send({
  941. name: 'config.ambari.database.info',
  942. sender: this,
  943. success: 'getAmbariDatabaseSuccess'
  944. });
  945. },
  946. /**
  947. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  948. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  949. * @param {object} data
  950. * @method getAmbariDatabaseSuccess
  951. */
  952. getAmbariDatabaseSuccess: function (data) {
  953. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  954. var ambariServiceHostComponents = data.hostComponents;
  955. if (!!ambariServiceHostComponents.length) {
  956. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  957. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  958. } else {
  959. this.set('mySQLServerConflict', false);
  960. }
  961. },
  962. /**
  963. * Check if new MySql database was chosen for Hive service
  964. * and it is not located on the same host as Ambari server
  965. * that using MySql database too.
  966. *
  967. * @method resolveHiveMysqlDatabase
  968. **/
  969. resolveHiveMysqlDatabase: function() {
  970. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  971. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  972. this.moveNext();
  973. return;
  974. }
  975. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  976. if (hiveDBType == 'New MySQL Database') {
  977. var self= this;
  978. this.checkMySQLHost().done(function () {
  979. if (self.get('mySQLServerConflict')) {
  980. // error popup before you can proceed
  981. return App.ModalPopup.show({
  982. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  983. bodyClass: Ember.View.extend({
  984. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  985. }),
  986. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  987. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  988. onSecondary: function (){
  989. var parent = this;
  990. return App.ModalPopup.show({
  991. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  992. bodyClass: Ember.View.extend({
  993. template: Ember.Handlebars.compile( Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  994. }),
  995. onPrimary: function (){
  996. this.hide();
  997. parent.hide();
  998. // go back to step 5: assign masters and disable default navigation warning
  999. App.router.get('installerController').gotoStep(5, true);
  1000. }
  1001. });
  1002. }
  1003. });
  1004. } else {
  1005. self.moveNext();
  1006. }
  1007. });
  1008. } else {
  1009. this.moveNext();
  1010. }
  1011. },
  1012. checkDatabaseConnectionTest: function() {
  1013. var deferred = $.Deferred();
  1014. if (!App.supports.databaseConnection) {
  1015. deferred.resolve();
  1016. return deferred;
  1017. }
  1018. var configMap = [
  1019. {
  1020. serviceName: 'OOZIE',
  1021. ignored: Em.I18n.t('installer.step7.oozie.database.new')
  1022. },
  1023. {
  1024. serviceName: 'HIVE',
  1025. ignored: Em.I18n.t('installer.step7.hive.database.new')
  1026. }
  1027. ];
  1028. configMap.forEach(function(config) {
  1029. var isConnectionNotTested = false;
  1030. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1031. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1032. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1033. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1034. if (serviceDatabase !== config.ignored) {
  1035. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1036. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1037. isConnectionNotTested = true;
  1038. } else {
  1039. for (var key in filledProperties) {
  1040. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1041. isConnectionNotTested = true;
  1042. }
  1043. }
  1044. }
  1045. }
  1046. config.isCheckIgnored = isConnectionNotTested;
  1047. }, this);
  1048. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1049. if (ignoredServices.length) {
  1050. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function(serviceName) {
  1051. return App.Service.DisplayNames[serviceName];
  1052. }, this);
  1053. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1054. }
  1055. else {
  1056. deferred.resolve();
  1057. }
  1058. return deferred;
  1059. },
  1060. showDatabaseConnectionWarningPopup: function(serviceNames, deferred) {
  1061. return App.ModalPopup.show({
  1062. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1063. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1064. secondary: Em.I18n.t('common.cancel'),
  1065. primary: Em.I18n.t('common.proceedAnyway'),
  1066. onPrimary: function() {
  1067. deferred.resolve();
  1068. this._super();
  1069. },
  1070. onSecondary: function() {
  1071. deferred.reject();
  1072. this._super();
  1073. }
  1074. })
  1075. },
  1076. /**
  1077. * Proceed to the next step
  1078. **/
  1079. moveNext: function() {
  1080. App.router.send('next');
  1081. },
  1082. /**
  1083. * Click-handler on Next button
  1084. * @method submit
  1085. */
  1086. submit: function () {
  1087. var _this = this;
  1088. if (!this.get('isSubmitDisabled')) {
  1089. this.checkDatabaseConnectionTest().done(function() {
  1090. _this.resolveHiveMysqlDatabase();
  1091. });
  1092. }
  1093. }
  1094. });