step7_controller.js 55 KB

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