step7_controller.js 57 KB

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