step7_controller.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. if (_config.filename) {
  776. var type = _config.filename.replace(/.xml$/, '');
  777. }
  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. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  1055. if (this.get('wizardController.name') == "addServiceController") {
  1056. miscConfigs.findProperty('name', 'smokeuser').set('value', this.get('content.smokeuser')).set('isEditable', false);
  1057. miscConfigs.findProperty('name', 'user_group').set('value', this.get('content.group')).set('isEditable', false);
  1058. }
  1059. App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  1060. },
  1061. /**
  1062. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1063. * @return {$.ajax|null}
  1064. * @method checkMySQLHost
  1065. */
  1066. checkMySQLHost: function () {
  1067. // get ambari database type and hostname
  1068. return App.ajax.send({
  1069. name: 'config.ambari.database.info',
  1070. sender: this,
  1071. success: 'getAmbariDatabaseSuccess'
  1072. });
  1073. },
  1074. /**
  1075. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1076. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1077. * @param {object} data
  1078. * @method getAmbariDatabaseSuccess
  1079. */
  1080. getAmbariDatabaseSuccess: function (data) {
  1081. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  1082. var ambariServiceHostComponents = data.hostComponents;
  1083. if (!!ambariServiceHostComponents.length) {
  1084. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  1085. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  1086. } else {
  1087. this.set('mySQLServerConflict', false);
  1088. }
  1089. },
  1090. /**
  1091. * Check if new MySql database was chosen for Hive service
  1092. * and it is not located on the same host as Ambari server
  1093. * that using MySql database too.
  1094. *
  1095. * @method resolveHiveMysqlDatabase
  1096. **/
  1097. resolveHiveMysqlDatabase: function () {
  1098. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1099. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1100. this.moveNext();
  1101. return;
  1102. }
  1103. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1104. if (hiveDBType == 'New MySQL Database') {
  1105. var self = this;
  1106. this.checkMySQLHost().done(function () {
  1107. if (self.get('mySQLServerConflict')) {
  1108. // error popup before you can proceed
  1109. return App.ModalPopup.show({
  1110. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1111. bodyClass: Ember.View.extend({
  1112. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  1113. }),
  1114. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1115. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1116. onSecondary: function () {
  1117. var parent = this;
  1118. return App.ModalPopup.show({
  1119. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1120. bodyClass: Ember.View.extend({
  1121. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  1122. }),
  1123. onPrimary: function () {
  1124. this.hide();
  1125. parent.hide();
  1126. // go back to step 5: assign masters and disable default navigation warning
  1127. App.router.get('installerController').gotoStep(5, true);
  1128. }
  1129. });
  1130. }
  1131. });
  1132. } else {
  1133. self.moveNext();
  1134. }
  1135. });
  1136. } else {
  1137. this.moveNext();
  1138. }
  1139. },
  1140. checkDatabaseConnectionTest: function () {
  1141. var deferred = $.Deferred();
  1142. var configMap = [
  1143. {
  1144. serviceName: 'OOZIE',
  1145. ignored: [Em.I18n.t('installer.step7.oozie.database.new')]
  1146. },
  1147. {
  1148. serviceName: 'HIVE',
  1149. ignored: [Em.I18n.t('installer.step7.hive.database.new.mysql'), Em.I18n.t('installer.step7.hive.database.new.postgres')]
  1150. }
  1151. ];
  1152. configMap.forEach(function (config) {
  1153. var isConnectionNotTested = false;
  1154. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1155. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1156. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1157. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1158. if (!config.ignored.contains(serviceDatabase)) {
  1159. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1160. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1161. isConnectionNotTested = true;
  1162. } else {
  1163. for (var key in filledProperties) {
  1164. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1165. isConnectionNotTested = true;
  1166. }
  1167. }
  1168. }
  1169. }
  1170. config.isCheckIgnored = isConnectionNotTested;
  1171. }, this);
  1172. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1173. if (ignoredServices.length) {
  1174. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1175. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1176. }, this);
  1177. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1178. }
  1179. else {
  1180. deferred.resolve();
  1181. }
  1182. return deferred;
  1183. },
  1184. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1185. return App.ModalPopup.show({
  1186. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1187. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1188. secondary: Em.I18n.t('common.cancel'),
  1189. primary: Em.I18n.t('common.proceedAnyway'),
  1190. onPrimary: function () {
  1191. deferred.resolve();
  1192. this._super();
  1193. },
  1194. onSecondary: function () {
  1195. deferred.reject();
  1196. this._super();
  1197. }
  1198. })
  1199. },
  1200. /**
  1201. * Proceed to the next step
  1202. **/
  1203. moveNext: function () {
  1204. App.router.send('next');
  1205. },
  1206. /**
  1207. * Click-handler on Next button
  1208. * Disable "Submit"-button while server-side processes are running
  1209. * @method submit
  1210. */
  1211. submit: function () {
  1212. if (this.get('isSubmitDisabled')) {
  1213. return;
  1214. }
  1215. var self = this;
  1216. this.set('submitButtonClicked', true);
  1217. this.serverSideValidation().done(function () {
  1218. self.checkDatabaseConnectionTest().done(function () {
  1219. self.resolveHiveMysqlDatabase();
  1220. self.set('submitButtonClicked', false);
  1221. });
  1222. }).fail(function (value) {
  1223. if ("invalid_configs" == value) {
  1224. self.set('submitButtonClicked', false);
  1225. } else {
  1226. // Failed due to validation mechanism failure.
  1227. // Should proceed with other checks
  1228. self.checkDatabaseConnectionTest().done(function () {
  1229. self.resolveHiveMysqlDatabase();
  1230. self.set('submitButtonClicked', false);
  1231. });
  1232. }
  1233. });
  1234. }
  1235. });