step7_controller.js 49 KB

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