step7_controller.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  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. /**
  38. * Is Submit-click processing now
  39. * @type {bool}
  40. */
  41. submitButtonClicked: false,
  42. isRecommendedLoaded: false,
  43. /**
  44. * used in services_config.js view to mark a config with security icon
  45. */
  46. secureConfigs: function () {
  47. if (App.get('isHadoop2Stack')) {
  48. return require('data/HDP2/secure_mapping');
  49. } else {
  50. return require('data/secure_mapping');
  51. }
  52. }.property('isHadoop2Stack'),
  53. /**
  54. * config categories with secure properties
  55. * use only for add service wizard when security is enabled;
  56. */
  57. secureServices: function () {
  58. return (App.get('isHadoop2Stack')) ?
  59. $.extend(true, [], require('data/HDP2/secure_configs')) :
  60. $.extend(true, [], require('data/secure_configs'));
  61. }.property('App.isHadoop2Stack'),
  62. /**
  63. * uses for add service - find out is security is enabled
  64. */
  65. securityEnabled: function () {
  66. return App.router.get('mainAdminSecurityController.securityEnabled');
  67. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  68. /**
  69. * If miscConfigChange Modal is shown
  70. * @type {bool}
  71. */
  72. miscModalVisible: false,
  73. gangliaAvailableSpace: null,
  74. /**
  75. * @type {string}
  76. */
  77. gangliaMoutDir: '/',
  78. overrideToAdd: null,
  79. /**
  80. * Is installer controller used
  81. * @type {bool}
  82. */
  83. isInstaller: true,
  84. /**
  85. * List of config groups
  86. * @type {object[]}
  87. */
  88. configGroups: [],
  89. /**
  90. * List of config group to be deleted
  91. * @type {object[]}
  92. */
  93. groupsToDelete: [],
  94. preSelectedConfigGroup: null,
  95. /**
  96. * Currently selected config group
  97. * @type {object}
  98. */
  99. selectedConfigGroup: null,
  100. /**
  101. * Config tags of actually installed services
  102. * @type {array}
  103. */
  104. serviceConfigTags: [],
  105. serviceConfigsData: require('data/service_configs'),
  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.get('isAdmin')) {
  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();
  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. this.loadConfigGroups(this.get('content.configGroups'));
  617. if (this.get('installedServiceNames').length > 0) {
  618. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  619. }
  620. },
  621. /**
  622. * Set init <code>stepConfigs</code> value
  623. * Set <code>selected</code> for addable services if addServiceController is used
  624. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  625. * @param {Ember.Object[]} configs
  626. * @param {Ember.Object[]} storedConfigs
  627. * @method setStepConfigs
  628. */
  629. setStepConfigs: function (configs, storedConfigs) {
  630. var localDB = {
  631. hosts: this.get('wizardController.content.hosts'),
  632. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  633. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  634. };
  635. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB, this.get('recommendationsConfigs'));
  636. if (this.get('wizardController.name') === 'addServiceController') {
  637. serviceConfigs.setEach('showConfig', true);
  638. serviceConfigs.setEach('selected', false);
  639. this.get('selectedServiceNames').forEach(function (serviceName) {
  640. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  641. var selectedService = serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  642. // add secure configs when security is enabled
  643. if (this.get('securityEnabled')) {
  644. this.addSecureConfigs(selectedService, serviceName);
  645. }
  646. }, this);
  647. this.get('installedServiceNames').forEach(function (serviceName) {
  648. var serviceConfigObj = serviceConfigs.findProperty('serviceName', serviceName);
  649. if (this.get('securityEnabled')) {
  650. this.setSecureConfigs(serviceConfigObj, serviceName);
  651. }
  652. }, this);
  653. // Remove SNameNode if HA is enabled
  654. if (App.get('isHaEnabled')) {
  655. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  656. var removedConfigs = c.filterProperty('category', 'SECONDARY_NAMENODE');
  657. removedConfigs.map(function (config) {
  658. c = c.without(config);
  659. });
  660. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  661. }
  662. }
  663. this.set('stepConfigs', serviceConfigs);
  664. },
  665. /**
  666. * Set secure properties for installed services. Mark secure properties and
  667. * properties with default empty value as non required to pass validation.
  668. *
  669. * @param {Em.Object} serviceConfigObj
  670. * @param {String} serviceName
  671. */
  672. setSecureConfigs: function (serviceConfigObj, serviceName) {
  673. var configProperties = serviceConfigObj.get('configs');
  674. if (!configProperties) return;
  675. var secureConfigs = this.get('secureConfigs').filterProperty('serviceName', serviceName);
  676. secureConfigs.forEach(function (secureConfig) {
  677. var property = configProperties.findProperty('name', secureConfig.name);
  678. if (property) {
  679. property.set('isRequired', secureConfig.value != "");
  680. if (!property.get('isRequired')) property.set('errorMessage', '');
  681. }
  682. });
  683. },
  684. /**
  685. *
  686. * @param selectedService
  687. * @param serviceName
  688. */
  689. addSecureConfigs: function (selectedService, serviceName) {
  690. var secureService = this.get('secureServices').findProperty('serviceName', serviceName);
  691. if (!secureService) {
  692. return;
  693. }
  694. secureService.configCategories.forEach(function (category) {
  695. selectedService.get('configCategories').push(category);
  696. });
  697. secureService.configs.forEach(function (conf) {
  698. conf.isVisible = !conf.displayType.contains('masterHost') && !conf.displayType.contains('slaveHost');
  699. var config = App.ServiceConfigProperty.create(conf);
  700. selectedService.get('configs').push(config);
  701. }, this);
  702. },
  703. /**
  704. * Select first addable service for <code>addServiceWizard</code>
  705. * Select first service at all in other cases
  706. * @method selectProperService
  707. */
  708. selectProperService: function () {
  709. if (this.get('wizardController.name') === 'addServiceController') {
  710. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  711. } else {
  712. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  713. }
  714. },
  715. /**
  716. * Load config tags
  717. * @return {$.ajax|null}
  718. * @method getConfigTags
  719. */
  720. getConfigTags: function () {
  721. this.set('isAppliedConfigLoaded', false);
  722. return App.ajax.send({
  723. name: 'config.tags',
  724. sender: this,
  725. success: 'getConfigTagsSuccess'
  726. });
  727. },
  728. /**
  729. * Success callback for config tags request
  730. * Updates <code>serviceConfigTags</code> with tags received from server
  731. * @param {object} data
  732. * @method getConfigTagsSuccess
  733. */
  734. getConfigTagsSuccess: function (data) {
  735. var installedServiceSites = [];
  736. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  737. if (!service.get('configTypes')) return;
  738. var configTypes = Object.keys(service.get('configTypes'));
  739. installedServiceSites = installedServiceSites.concat(configTypes);
  740. }, this);
  741. installedServiceSites = installedServiceSites.uniq();
  742. var serviceConfigTags = [];
  743. for (var site in data.Clusters.desired_configs) {
  744. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  745. if (installedServiceSites.contains(site)) {
  746. serviceConfigTags.push({
  747. siteName: site,
  748. tagName: data.Clusters.desired_configs[site].tag,
  749. newTagName: null
  750. });
  751. }
  752. }
  753. }
  754. this.set('serviceConfigTags', serviceConfigTags);
  755. this.set('isAppliedConfigLoaded', true);
  756. },
  757. /**
  758. * set configs actual values from server
  759. * @param serviceConfigTags
  760. * @param configs
  761. * @param configsByTags
  762. * @param installedServiceNames
  763. * @method setInstalledServiceConfigs
  764. */
  765. setInstalledServiceConfigs: function (serviceConfigTags, configs, configsByTags, installedServiceNames) {
  766. var configsMap = {};
  767. var configTypeMap = {};
  768. var configMixin = App.get('config');
  769. var self = this;
  770. configsByTags.forEach(function (configSite) {
  771. configsMap[configSite.type] = configSite.properties;
  772. });
  773. configs.forEach(function (_config) {
  774. var nonServiceTab = require('data/service_configs');
  775. var type = _config.filename ? App.config.getConfigTagFromFileName(_config.filename) : null;
  776. var mappedConfigValue = type && configsMap[type] ? configsMap[type][_config.name] : null;
  777. if (!Em.isNone(mappedConfigValue) && ((installedServiceNames && installedServiceNames.contains(_config.serviceName) || nonServiceTab.someProperty('serviceName', _config.serviceName)))) {
  778. // prevent overriding already edited properties
  779. if (_config.defaultValue != mappedConfigValue) {
  780. _config.value = mappedConfigValue;
  781. }
  782. _config.defaultValue = mappedConfigValue;
  783. _config.hasInitialValue = true;
  784. App.config.handleSpecialProperties(_config);
  785. delete configsMap[type][_config.name];
  786. }
  787. });
  788. self.setServiceDatabaseConfigs(configs);
  789. //add user properties
  790. Em.keys(configsMap).forEach(function (filename) {
  791. Em.keys(configsMap[filename]).forEach(function (propertyName) {
  792. configs.push(configMixin.addUserProperty({
  793. id: 'site property',
  794. name: propertyName,
  795. serviceName: configMixin.getServiceNameByConfigType(filename),
  796. value: configsMap[filename][propertyName],
  797. defaultValue: configsMap[filename][propertyName],
  798. filename: configMixin.get('filenameExceptions').contains(filename) ? filename : filename + '.xml',
  799. category: 'Advanced',
  800. hasInitialValue: true,
  801. isUserProperty: true,
  802. isOverridable: true,
  803. overrides: [],
  804. isRequired: true,
  805. isVisible: true,
  806. showLabel: true
  807. }, false, []));
  808. });
  809. });
  810. },
  811. /**
  812. * Check if Oozie, Hive or MetricsSink use existing database then need
  813. * to restore missed properties
  814. *
  815. * @param {Object[]} configs
  816. **/
  817. setServiceDatabaseConfigs: function (configs) {
  818. var serviceNames = this.get('installedServiceNames').filter(function (serviceName) {
  819. return ['OOZIE', 'HIVE', 'HDFS'].contains(serviceName);
  820. });
  821. serviceNames.forEach(function (serviceName) {
  822. var propertyPrefix = serviceName.toLowerCase();
  823. if(/HDFS/gi.test(serviceName)) propertyPrefix = 'sink';
  824. var dbTypeConfig = configs.findProperty('name', propertyPrefix + '_database');
  825. if (!/existing/gi.test(dbTypeConfig.value)) return;
  826. var dbHostName = propertyPrefix + '_hostname';
  827. var database = dbTypeConfig.value.match(/MySQL|PostgreSQL|Oracle|Derby|MSSQL/gi)[0];
  828. var dbPrefix = database.toLowerCase();
  829. if(database.toLowerCase() == 'mssql') {
  830. dbHostName = 'sink.dbservername';
  831. if(/integrated/gi.test(dbTypeConfig.value)) {
  832. dbPrefix = 'mssql_server';
  833. } else {
  834. dbPrefix = 'mssql_server_2';
  835. }
  836. }
  837. var propertyName = propertyPrefix + '_existing_' + dbPrefix + '_host';
  838. var existingDBConfig = configs.findProperty('name', propertyName);
  839. if (!existingDBConfig.value)
  840. existingDBConfig.value = existingDBConfig.defaultValue = configs.findProperty('name', dbHostName).value;
  841. }, this);
  842. },
  843. /**
  844. * Add group ids to <code>groupsToDelete</code>
  845. * Also save <code>groupsToDelete</code> to local storage
  846. * @param {Ember.Object[]} groups
  847. * @method setGroupsToDelete
  848. */
  849. setGroupsToDelete: function (groups) {
  850. var groupsToDelete = this.get('groupsToDelete');
  851. groups.forEach(function (group) {
  852. if (group.get('id'))
  853. groupsToDelete.push({
  854. id: group.get('id')
  855. });
  856. });
  857. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  858. },
  859. /**
  860. * Update <code>configGroups</code> with selected service configGroups
  861. * Also set default group to first position
  862. * Update <code>selectedConfigGroup</code> with new default group
  863. * @method selectedServiceObserver
  864. */
  865. selectedServiceObserver: function () {
  866. if (this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  867. var serviceGroups = this.get('selectedService.configGroups');
  868. serviceGroups.forEach(function (item, index, array) {
  869. if (item.isDefault) {
  870. array.unshift(item);
  871. array.splice(index + 1, 1);
  872. }
  873. });
  874. this.set('configGroups', serviceGroups);
  875. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  876. }
  877. }.observes('selectedService.configGroups.@each'),
  878. /**
  879. * load default groups for each service in case of initial load
  880. * @param serviceConfigGroups
  881. * @method loadConfigGroups
  882. */
  883. loadConfigGroups: function (serviceConfigGroups) {
  884. var services = this.get('stepConfigs');
  885. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  886. var manageCGController = App.router.get('manageConfigGroupsController');
  887. this.setupManageConfigGroupsController();
  888. services.forEach(function (service) {
  889. if (service.get('serviceName') === 'MISC') return;
  890. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  891. if (!serviceRawGroups.length) {
  892. service.set('configGroups', [
  893. App.ConfigGroup.create({
  894. name: service.displayName + " Default",
  895. description: "Default cluster level " + service.serviceName + " configuration",
  896. isDefault: true,
  897. hosts: Em.copy(hosts),
  898. publicHosts: Em.copy(manageCGController.hostsToPublic(hosts)),
  899. service: Em.Object.create({
  900. id: service.serviceName
  901. }),
  902. serviceName: service.serviceName
  903. })
  904. ]);
  905. }
  906. else {
  907. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  908. var serviceGroups = service.get('configGroups');
  909. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  910. var readyGroup = App.ConfigGroup.create(configGroup);
  911. var wrappedProperties = [];
  912. readyGroup.get('properties').forEach(function (propertyData) {
  913. var parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  914. var overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  915. overriddenSCP.set('isOriginalSCP', false);
  916. overriddenSCP.set('parentSCP', parentSCP);
  917. overriddenSCP.set('group', readyGroup);
  918. overriddenSCP.setProperties(propertyData);
  919. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  920. });
  921. wrappedProperties.setEach('group', readyGroup);
  922. readyGroup.set('properties', wrappedProperties);
  923. readyGroup.set('parentConfigGroup', defaultGroup);
  924. serviceGroups.pushObject(readyGroup);
  925. });
  926. defaultGroup.set('childConfigGroups', serviceGroups);
  927. serviceGroups.pushObject(defaultGroup);
  928. }
  929. });
  930. },
  931. setupManageConfigGroupsController: function () {
  932. var manageCGController = App.router.get('manageConfigGroupsController');
  933. manageCGController.set('isInstaller', true);
  934. manageCGController.set('isAddService', this.get('wizardController.name') === 'addServiceController');
  935. },
  936. /**
  937. * Click-handler on config-group to make it selected
  938. * @param {object} event
  939. * @method selectConfigGroup
  940. */
  941. selectConfigGroup: function (event) {
  942. this.set('selectedConfigGroup', event.context);
  943. },
  944. /**
  945. * Rebuild list of configs switch of config group:
  946. * on default - display all configs from default group and configs from non-default groups as disabled
  947. * on non-default - display all from default group as disabled and configs from selected non-default group
  948. * @method switchConfigGroupConfigs
  949. */
  950. switchConfigGroupConfigs: function () {
  951. var serviceConfigs = this.get('selectedService.configs'),
  952. selectedGroup = this.get('selectedConfigGroup'),
  953. overrideToAdd = this.get('overrideToAdd'),
  954. overrides = [];
  955. if (!selectedGroup) return;
  956. var displayedConfigGroups = this._getDisplayedConfigGroups();
  957. displayedConfigGroups.forEach(function (group) {
  958. overrides.pushObjects(group.get('properties'));
  959. });
  960. serviceConfigs.forEach(function (config) {
  961. this._setEditableValue(config);
  962. this._setOverrides(config, overrides);
  963. }, this);
  964. }.observes('selectedConfigGroup'),
  965. /**
  966. * Get list of config groups to display
  967. * Returns empty array if no <code>selectedConfigGroup</code>
  968. * @return {Array}
  969. * @method _getDisplayedConfigGroups
  970. */
  971. _getDisplayedConfigGroups: function () {
  972. var selectedGroup = this.get('selectedConfigGroup');
  973. if (!selectedGroup) return [];
  974. return (selectedGroup.get('isDefault')) ?
  975. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  976. [this.get('selectedConfigGroup')];
  977. },
  978. /**
  979. * Set <code>isEditable</code> property to <code>config</code>
  980. * @param {Ember.Object} config
  981. * @return {Ember.Object} updated config-object
  982. * @method _setEditableValue
  983. */
  984. _setEditableValue: function (config) {
  985. var selectedGroup = this.get('selectedConfigGroup');
  986. if (!selectedGroup) return config;
  987. var isEditable = config.get('isEditable'),
  988. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  989. if (isServiceInstalled) {
  990. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  991. }
  992. else {
  993. isEditable = selectedGroup.get('isDefault');
  994. }
  995. if (config.get('group')) {
  996. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  997. }
  998. config.set('isEditable', isEditable);
  999. return config;
  1000. },
  1001. /**
  1002. * Set <code>overrides</code> property to <code>config</code>
  1003. * @param {Ember.Object} config
  1004. * @param {Ember.Enumerable} overrides
  1005. * @returns {Ember.Object}
  1006. * @method _setOverrides
  1007. */
  1008. _setOverrides: function (config, overrides) {
  1009. var selectedGroup = this.get('selectedConfigGroup'),
  1010. overrideToAdd = this.get('overrideToAdd'),
  1011. configOverrides = overrides.filterProperty('name', config.get('name'));
  1012. if (!selectedGroup) return config;
  1013. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1014. configOverrides.push(this.addOverrideProperty(config));
  1015. this.set('overrideToAdd', null);
  1016. }
  1017. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1018. configOverrides.setEach('parentSCP', config);
  1019. config.set('overrides', configOverrides);
  1020. return config;
  1021. },
  1022. /**
  1023. * create overriden property and push it into Config group
  1024. * @param {App.ServiceConfigProperty} serviceConfigProperty
  1025. * @return {App.ServiceConfigProperty}
  1026. * @method addOverrideProperty
  1027. */
  1028. addOverrideProperty: function (serviceConfigProperty) {
  1029. var overrides = serviceConfigProperty.get('overrides') || [];
  1030. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  1031. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  1032. newSCP.set('group', group);
  1033. newSCP.set('value', '');
  1034. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  1035. newSCP.set('parentSCP', serviceConfigProperty);
  1036. newSCP.set('isEditable', true);
  1037. group.get('properties').pushObject(newSCP);
  1038. overrides.pushObject(newSCP);
  1039. return newSCP;
  1040. },
  1041. /**
  1042. * @method manageConfigurationGroup
  1043. */
  1044. manageConfigurationGroup: function () {
  1045. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  1046. },
  1047. /**
  1048. * Make some configs visible depending on active services
  1049. * @method activateSpecialConfigs
  1050. */
  1051. activateSpecialConfigs: function () {
  1052. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  1053. if (this.get('wizardController.name') == "addServiceController") {
  1054. miscConfigs.findProperty('name', 'smokeuser').set('value', this.get('content.smokeuser')).set('isEditable', false);
  1055. miscConfigs.findProperty('name', 'user_group').set('value', this.get('content.group')).set('isEditable', false);
  1056. }
  1057. App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  1058. },
  1059. /**
  1060. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1061. * @return {$.ajax|null}
  1062. * @method checkMySQLHost
  1063. */
  1064. checkMySQLHost: function () {
  1065. // get ambari database type and hostname
  1066. return App.ajax.send({
  1067. name: 'config.ambari.database.info',
  1068. sender: this,
  1069. success: 'getAmbariDatabaseSuccess'
  1070. });
  1071. },
  1072. /**
  1073. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1074. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1075. * @param {object} data
  1076. * @method getAmbariDatabaseSuccess
  1077. */
  1078. getAmbariDatabaseSuccess: function (data) {
  1079. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  1080. var ambariServiceHostComponents = data.hostComponents;
  1081. if (!!ambariServiceHostComponents.length) {
  1082. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  1083. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  1084. } else {
  1085. this.set('mySQLServerConflict', false);
  1086. }
  1087. },
  1088. /**
  1089. * Check if new MySql database was chosen for Hive service
  1090. * and it is not located on the same host as Ambari server
  1091. * that using MySql database too.
  1092. *
  1093. * @method resolveHiveMysqlDatabase
  1094. **/
  1095. resolveHiveMysqlDatabase: function () {
  1096. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1097. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1098. this.moveNext();
  1099. return;
  1100. }
  1101. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1102. if (hiveDBType == 'New MySQL Database') {
  1103. var self = this;
  1104. this.checkMySQLHost().done(function () {
  1105. if (self.get('mySQLServerConflict')) {
  1106. // error popup before you can proceed
  1107. return App.ModalPopup.show({
  1108. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1109. bodyClass: Ember.View.extend({
  1110. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  1111. }),
  1112. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1113. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1114. onSecondary: function () {
  1115. var parent = this;
  1116. return App.ModalPopup.show({
  1117. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1118. bodyClass: Ember.View.extend({
  1119. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  1120. }),
  1121. onPrimary: function () {
  1122. this.hide();
  1123. parent.hide();
  1124. // go back to step 5: assign masters and disable default navigation warning
  1125. App.router.get('installerController').gotoStep(5, true);
  1126. }
  1127. });
  1128. }
  1129. });
  1130. } else {
  1131. self.moveNext();
  1132. }
  1133. });
  1134. } else {
  1135. this.moveNext();
  1136. }
  1137. },
  1138. checkDatabaseConnectionTest: function () {
  1139. var deferred = $.Deferred();
  1140. var configMap = [
  1141. {
  1142. serviceName: 'OOZIE',
  1143. ignored: [Em.I18n.t('installer.step7.oozie.database.new')]
  1144. },
  1145. {
  1146. serviceName: 'HIVE',
  1147. ignored: [Em.I18n.t('installer.step7.hive.database.new.mysql'), Em.I18n.t('installer.step7.hive.database.new.postgres')]
  1148. }
  1149. ];
  1150. configMap.forEach(function (config) {
  1151. var isConnectionNotTested = false;
  1152. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1153. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1154. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1155. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1156. if (!config.ignored.contains(serviceDatabase)) {
  1157. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1158. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1159. isConnectionNotTested = true;
  1160. } else {
  1161. for (var key in filledProperties) {
  1162. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1163. isConnectionNotTested = true;
  1164. }
  1165. }
  1166. }
  1167. }
  1168. config.isCheckIgnored = isConnectionNotTested;
  1169. }, this);
  1170. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1171. if (ignoredServices.length) {
  1172. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1173. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1174. }, this);
  1175. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1176. }
  1177. else {
  1178. deferred.resolve();
  1179. }
  1180. return deferred;
  1181. },
  1182. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1183. return App.ModalPopup.show({
  1184. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1185. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1186. secondary: Em.I18n.t('common.cancel'),
  1187. primary: Em.I18n.t('common.proceedAnyway'),
  1188. onPrimary: function () {
  1189. deferred.resolve();
  1190. this._super();
  1191. },
  1192. onSecondary: function () {
  1193. deferred.reject();
  1194. this._super();
  1195. }
  1196. })
  1197. },
  1198. /**
  1199. * Proceed to the next step
  1200. **/
  1201. moveNext: function () {
  1202. App.router.send('next');
  1203. },
  1204. /**
  1205. * Click-handler on Next button
  1206. * Disable "Submit"-button while server-side processes are running
  1207. * @method submit
  1208. */
  1209. submit: function () {
  1210. if (this.get('isSubmitDisabled')) {
  1211. return;
  1212. }
  1213. var self = this;
  1214. this.set('submitButtonClicked', true);
  1215. this.serverSideValidation().done(function () {
  1216. self.checkDatabaseConnectionTest().done(function () {
  1217. self.resolveHiveMysqlDatabase();
  1218. self.set('submitButtonClicked', false);
  1219. });
  1220. }).fail(function (value) {
  1221. if ("invalid_configs" == value) {
  1222. self.set('submitButtonClicked', false);
  1223. } else {
  1224. // Failed due to validation mechanism failure.
  1225. // Should proceed with other checks
  1226. self.checkDatabaseConnectionTest().done(function () {
  1227. self.resolveHiveMysqlDatabase();
  1228. self.set('submitButtonClicked', false);
  1229. });
  1230. }
  1231. });
  1232. }
  1233. });