step7_controller.js 52 KB

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