step7_controller.js 48 KB

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