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