step7_controller.js 49 KB

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