step7_controller.js 49 KB

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