step7_controller.js 48 KB

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