step7_controller.js 49 KB

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