step7_controller.js 50 KB

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