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