step7_controller.js 41 KB

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