step7_controller.js 62 KB

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