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