step7_controller.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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 serviceConfigProperty = !!params.configKeyToConfigMap[fileName] ? params.configKeyToConfigMap[fileName][prop] : false;
  433. if (serviceConfigProperty) {
  434. var hostOverrideValue = App.config.formatPropertyValue(serviceConfigProperty, properties[prop]);
  435. var hostOverrideIsFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]);
  436. App.config.createOverride(serviceConfigProperty, {
  437. "value": hostOverrideValue,
  438. "savedValue": hostOverrideValue,
  439. "isFinal": hostOverrideIsFinal,
  440. "savedIsFinal": hostOverrideIsFinal,
  441. "isEditable": false
  442. }, group, true);
  443. } else {
  444. params.serviceConfigs.push(App.config.createCustomGroupConfig(prop, fileName, config.properties[prop], group));
  445. }
  446. }
  447. });
  448. this.onLoadOverrides(params.serviceConfigs);
  449. },
  450. onLoadOverrides: function (configs) {
  451. var serviceName = configs[0].serviceName,
  452. service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  453. var serviceConfig = App.config.createServiceConfig(serviceName);
  454. service.set('selectedConfigGroup', this.get('preSelectedConfigGroup'));
  455. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  456. // override if a property isRequired or not
  457. this.overrideConfigIsRequired(service);
  458. service.set('configs', serviceConfig.get('configs'));
  459. },
  460. /**
  461. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  462. * Based on user's permissions and selected config group
  463. * @param {Ember.Object} serviceConfigProperty
  464. * @param {bool} defaultGroupSelected
  465. * @returns {Ember.Object} Updated config-object
  466. * @method _updateIsEditableFlagForConfig
  467. */
  468. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  469. if (App.isAuthorized('AMBARI.ADD_DELETE_CLUSTERS')) {
  470. if (defaultGroupSelected && !this.get('isHostsConfigsPage') && !Em.get(serviceConfigProperty, 'group')) {
  471. if (serviceConfigProperty.get('serviceName') === 'MISC') {
  472. var service = App.config.get('serviceByConfigTypeMap')[App.config.getConfigTagFromFileName(serviceConfigProperty.get('filename'))];
  473. serviceConfigProperty.set('isEditable', service && !this.get('installedServiceNames').contains(service.get('serviceName')));
  474. } else {
  475. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isEditable') && serviceConfigProperty.get('isReconfigurable'));
  476. }
  477. } else if (!(Em.get(serviceConfigProperty, 'group') && Em.get(serviceConfigProperty, 'group.name') == this.get('selectedConfigGroup.name'))) {
  478. serviceConfigProperty.set('isEditable', false);
  479. }
  480. }
  481. else {
  482. serviceConfigProperty.set('isEditable', false);
  483. }
  484. return serviceConfigProperty;
  485. },
  486. /**
  487. * Set configs with overrides, recommended defaults to component
  488. * @param {Ember.Object[]} configs
  489. * @param {Ember.Object} componentConfig
  490. * @param {Ember.Object} component
  491. * @method loadComponentConfigs
  492. */
  493. loadComponentConfigs: function (configs, componentConfig, component) {
  494. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  495. configs.forEach(function (serviceConfigProperty) {
  496. if (!serviceConfigProperty) return;
  497. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  498. serviceConfigProperty.set('isOverridable', true);
  499. }
  500. if (!Em.isNone(serviceConfigProperty.get('group'))) {
  501. serviceConfigProperty.get('group.properties').pushObject(serviceConfigProperty);
  502. }
  503. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  504. componentConfig.get('configs').pushObject(serviceConfigProperty);
  505. serviceConfigProperty.validate();
  506. }, this);
  507. component.get('configGroups').filterProperty('isDefault', false).forEach(function (configGroup) {
  508. configGroup.set('hash', this.get('wizardController').getConfigGroupHash(configGroup));
  509. }, this);
  510. var overrideToAdd = this.get('overrideToAdd');
  511. if (overrideToAdd) {
  512. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  513. if (overrideToAdd) {
  514. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  515. var newSCP = App.config.createOverride(overrideToAdd, {isEditable: true}, group);
  516. group.get('properties').pushObject(newSCP);
  517. component.set('overrideToAdd', null);
  518. }
  519. }
  520. },
  521. /**
  522. * On load function
  523. * @method loadStep
  524. */
  525. loadStep: function () {
  526. if (!this.get('isConfigsLoaded')) {
  527. return;
  528. }
  529. console.time('wizard loadStep: ');
  530. this.clearStep();
  531. var self = this;
  532. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  533. var storedConfigs = this.get('content.serviceConfigProperties');
  534. var configs = (storedConfigs && storedConfigs.length) ? storedConfigs : App.configsCollection.getAll();
  535. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  536. if (this.get('wizardController.name') === 'addServiceController' && !this.get('content.serviceConfigProperties.length')) {
  537. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (loadedConfigs) {
  538. configs = self.setInstalledServiceConfigs(configs, loadedConfigs, self.get('installedServiceNames'));
  539. self.applyServicesConfigs(configs);
  540. });
  541. } else {
  542. this.applyServicesConfigs(configs);
  543. }
  544. },
  545. /**
  546. * Update hawq configuration depending on the state of the cluster
  547. * @param {Array} configs
  548. */
  549. updateHawqConfigs: function (configs) {
  550. if (this.get('wizardController.name') == 'addServiceController') {
  551. if (App.get('isHaEnabled')) this.addHawqConfigsOnNnHa(configs);
  552. if (App.get('isRMHaEnabled')) this.addHawqConfigsOnRMHa(configs);
  553. }
  554. if (this.get('content.hosts') && Object.keys(this.get('content.hosts')).length === 1) this.removeHawqStandbyHostAddressConfig(configs);
  555. return configs
  556. },
  557. /**
  558. * Remove hawq_standby_address_host config from HAWQ configs
  559. * @param {Array} configs
  560. */
  561. removeHawqStandbyHostAddressConfig: function(configs) {
  562. var hawqStandbyAddressHostIndex = configs.indexOf(configs.findProperty('name', 'hawq_standby_address_host'));
  563. if (hawqStandbyAddressHostIndex > -1) configs.removeAt(hawqStandbyAddressHostIndex) ;
  564. return configs
  565. },
  566. applyServicesConfigs: function (configs) {
  567. if (!this.get('installedServiceNames').contains('HAWQ') && this.get('allSelectedServiceNames').contains('HAWQ')) {
  568. this.updateHawqConfigs(configs);
  569. }
  570. if (App.get('isKerberosEnabled') && this.get('wizardController.name') == 'addServiceController') {
  571. this.addKerberosDescriptorConfigs(configs, this.get('wizardController.kerberosDescriptorConfigs') || []);
  572. }
  573. App.configTheme.resolveConfigThemeConditions(configs);
  574. var stepConfigs = this.createStepConfigs();
  575. var serviceConfigs = this.renderConfigs(stepConfigs, configs);
  576. // if HA is enabled -> Make some reconfigurations
  577. if (this.get('wizardController.name') === 'addServiceController') {
  578. this.updateComponentActionConfigs(configs, serviceConfigs);
  579. if (App.get('isHaEnabled')) {
  580. serviceConfigs = this._reconfigureServicesOnNnHa(serviceConfigs);
  581. }
  582. }
  583. this.set('stepConfigs', serviceConfigs);
  584. this.checkHostOverrideInstaller();
  585. this.selectProperService();
  586. var self = this;
  587. var rangerService = App.StackService.find().findProperty('serviceName', 'RANGER');
  588. if (rangerService && !rangerService.get('isInstalled') && !rangerService.get('isSelected')) {
  589. App.config.removeRangerConfigs(self.get('stepConfigs'));
  590. }
  591. this.loadConfigRecommendations(null, this.completeConfigLoading.bind(this));
  592. },
  593. /**
  594. *
  595. * Makes installed service's configs resulting into component actions (add/delete) non editable on Add Service Wizard
  596. * @param configs Object[]
  597. * @param stepConfigs Object[]
  598. * @private
  599. * @method updateComponentActionConfigs
  600. */
  601. updateComponentActionConfigs: function(configs, stepConfigs) {
  602. App.ConfigAction.find().forEach(function(item){
  603. var configName = item.get('configName');
  604. var fileName = item.get('fileName');
  605. var config = configs.filterProperty('filename', fileName).findProperty('name', configName);
  606. if (config) {
  607. var isServiceInstalled = App.Service.find().findProperty('serviceName', config.serviceName);
  608. if (isServiceInstalled) {
  609. var serviceConfigs = stepConfigs.findProperty('serviceName', config.serviceName).get('configs');
  610. var serviceConfig = serviceConfigs.filterProperty('filename', fileName).findProperty('name', configName);
  611. serviceConfig.set('isEditable', false);
  612. config.isEditable = false;
  613. }
  614. }
  615. }, this);
  616. },
  617. completeConfigLoading: function() {
  618. this.clearRecommendationsByServiceName(App.StackService.find().filterProperty('isSelected').mapProperty('serviceName'));
  619. console.timeEnd('wizard loadStep: ');
  620. this.set('isRecommendedLoaded', true);
  621. if (this.get('content.skipConfigStep')) {
  622. App.router.send('next');
  623. }
  624. this.set('hash', this.getHash());
  625. },
  626. /**
  627. * Update initialValues only while loading recommendations first time
  628. *
  629. * @param serviceName
  630. * @returns {boolean}
  631. * @override
  632. */
  633. updateInitialOnRecommendations: function(serviceName) {
  634. return this._super(serviceName) && !this.get('isRecommendedLoaded');
  635. },
  636. /**
  637. * Mark descriptor properties in configuration object.
  638. *
  639. * @param {Object[]} configs - config properties to change
  640. * @param {App.ServiceConfigProperty[]} descriptor - parsed kerberos descriptor
  641. * @method addKerberosDescriptorConfigs
  642. */
  643. addKerberosDescriptorConfigs: function (configs, descriptor) {
  644. descriptor.forEach(function (item) {
  645. var property = configs.findProperty('name', item.get('name'));
  646. if (property) {
  647. Em.setProperties(property, {
  648. isSecureConfig: true,
  649. displayName: Em.get(item, 'name'),
  650. isUserProperty: false,
  651. isOverridable: false,
  652. category: 'Advanced ' + Em.get(item, 'filename')
  653. });
  654. }
  655. });
  656. },
  657. /**
  658. * Load config groups
  659. * and (if some services are already installed) load config groups for installed services
  660. * @method checkHostOverrideInstaller
  661. */
  662. checkHostOverrideInstaller: function () {
  663. if (this.get('wizardController.name') !== 'kerberosWizardController') {
  664. this.loadConfigGroups(this.get('content.configGroups'));
  665. }
  666. if (this.get('installedServiceNames').length > 0 && !this.get('wizardController.areInstalledConfigGroupsLoaded')) {
  667. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  668. }
  669. },
  670. /**
  671. * Create stepConfigs array with all info except configs list
  672. *
  673. * @return {Object[]}
  674. * @method createStepConfigs
  675. */
  676. createStepConfigs: function() {
  677. var stepConfigs = [];
  678. App.config.get('preDefinedServiceConfigs').forEach(function (service) {
  679. var serviceName = service.get('serviceName');
  680. if (['MISC'].concat(this.get('allSelectedServiceNames')).contains(serviceName)) {
  681. var serviceConfig = App.config.createServiceConfig(serviceName);
  682. serviceConfig.set('showConfig', App.StackService.find(serviceName).get('isInstallable'));
  683. if (this.get('wizardController.name') == 'addServiceController') {
  684. serviceConfig.set('selected', !this.get('installedServiceNames').concat('MISC').contains(serviceName));
  685. if (serviceName === 'MISC') {
  686. serviceConfig.set('configCategories', serviceConfig.get('configCategories').rejectProperty('name', 'Notifications'));
  687. }
  688. } else if (this.get('wizardController.name') == 'kerberosWizardController') {
  689. serviceConfig.set('showConfig', true);
  690. }
  691. stepConfigs.pushObject(serviceConfig);
  692. }
  693. }, this);
  694. return stepConfigs;
  695. },
  696. /**
  697. * For Namenode HA, HAWQ service requires additional config parameters in hdfs-client.xml
  698. * This method ensures that these additional parameters are added to hdfs-client.xml
  699. * @param configs existing configs on cluster
  700. * @returns {Object[]} existing configs + additional config parameters in hdfs-client.xml
  701. */
  702. addHawqConfigsOnNnHa: function(configs) {
  703. var nameService = configs.findProperty('id', 'dfs.nameservices__hdfs-site').value;
  704. var propertyNames = [
  705. 'dfs.nameservices',
  706. 'dfs.ha.namenodes.' + nameService,
  707. 'dfs.namenode.rpc-address.'+ nameService +'.nn1',
  708. 'dfs.namenode.rpc-address.'+ nameService +'.nn2',
  709. 'dfs.namenode.http-address.'+ nameService +'.nn1',
  710. 'dfs.namenode.http-address.'+ nameService +'.nn2'
  711. ];
  712. propertyNames.forEach(function(propertyName, propertyIndex) {
  713. var propertyFromHdfs = configs.findProperty('id', App.config.configId(propertyName, 'hdfs-site'));
  714. var newProperty = App.config.createDefaultConfig(propertyName, 'hdfs-client.xml', true);
  715. Em.setProperties(newProperty, {
  716. serviceName: 'HAWQ',
  717. description: propertyFromHdfs.description,
  718. displayName: propertyFromHdfs.displayName,
  719. displayType: 'string',
  720. index: propertyIndex,
  721. isOverridable: false,
  722. isReconfigurable: false,
  723. value: propertyFromHdfs.value,
  724. recommendedValue: propertyFromHdfs.recommendedValue
  725. });
  726. configs.push(App.ServiceConfigProperty.create(newProperty));
  727. });
  728. return configs;
  729. },
  730. /**
  731. * For ResourceManager HA, HAWQ service requires additional config parameters in yarn-client.xml
  732. * This method ensures that these additional parameters are added to yarn-client.xml
  733. * @param configs existing configs on cluster
  734. * @returns {Object[]} existing configs + additional config parameters in yarn-client.xml
  735. */
  736. addHawqConfigsOnRMHa: function(configs) {
  737. var rmHost1 = configs.findProperty('id', App.config.configId('yarn.resourcemanager.hostname.rm1', 'yarn-site')).value ;
  738. var rmHost2 = configs.findProperty('id', App.config.configId('yarn.resourcemanager.hostname.rm2', 'yarn-site')).value ;
  739. var yarnConfigToBeAdded = [
  740. {
  741. name: 'yarn.resourcemanager.ha',
  742. displayName: 'yarn.resourcemanager.ha',
  743. description: 'Comma separated yarn resourcemanager host addresses with port',
  744. port: '8032'
  745. },
  746. {
  747. name: 'yarn.resourcemanager.scheduler.ha',
  748. displayName: 'yarn.resourcemanager.scheduler.ha',
  749. description: 'Comma separated yarn resourcemanager scheduler addresses with port',
  750. port: '8030'
  751. }
  752. ];
  753. yarnConfigToBeAdded.forEach(function(propertyDetails) {
  754. var newProperty = App.config.createDefaultConfig(propertyDetails.name, 'yarn-client.xml', true);
  755. var value = rmHost1 + ':' + propertyDetails.port + ',' + rmHost2 + ':' + propertyDetails.port;
  756. Em.setProperties(newProperty, {
  757. serviceName: 'HAWQ',
  758. description: propertyDetails.description,
  759. displayName: propertyDetails.displayName,
  760. isOverridable: false,
  761. isReconfigurable: false,
  762. value: value,
  763. recommendedValue: value
  764. });
  765. configs.push(App.ServiceConfigProperty.create(newProperty));
  766. });
  767. return configs;
  768. },
  769. /**
  770. * render configs, distribute them by service
  771. * and wrap each in ServiceConfigProperty object
  772. * @param stepConfigs
  773. * @param configs
  774. * @return {App.ServiceConfig[]}
  775. */
  776. renderConfigs: function (stepConfigs, configs) {
  777. var localDB = {
  778. hosts: this.get('wizardController.content.hosts'),
  779. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  780. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  781. };
  782. var configsByService = {}, dependencies = this.get('configDependencies');
  783. configs.forEach(function (_config) {
  784. if (!configsByService[_config.serviceName]) {
  785. configsByService[_config.serviceName] = [];
  786. }
  787. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  788. this.updateHostOverrides(serviceConfigProperty, _config);
  789. if (this.get('wizardController.name') === 'addServiceController') {
  790. this._updateIsEditableFlagForConfig(serviceConfigProperty, true);
  791. }
  792. if (!this.get('content.serviceConfigProperties.length') && !serviceConfigProperty.get('hasInitialValue')) {
  793. App.ConfigInitializer.initialValue(serviceConfigProperty, localDB, dependencies);
  794. }
  795. serviceConfigProperty.validate();
  796. configsByService[_config.serviceName].pushObject(serviceConfigProperty);
  797. }, this);
  798. stepConfigs.forEach(function (service) {
  799. if (service.get('serviceName') === 'YARN') {
  800. configsByService[service.get('serviceName')] = App.config.addYarnCapacityScheduler(configsByService[service.get('serviceName')]);
  801. }
  802. service.set('configs', configsByService[service.get('serviceName')]);
  803. if (['addServiceController', 'installerController'].contains(this.get('wizardController.name'))) {
  804. this.addHostNamesToConfigs(service, localDB.masterComponentHosts, localDB.slaveComponentHosts);
  805. }
  806. }, this);
  807. return stepConfigs;
  808. },
  809. /**
  810. * Add host name properties to appropriate categories (for installer and add service)
  811. *
  812. * @param {Object} serviceConfig
  813. * @param {Object[]} masterComponents - info from localStorage
  814. * @param {Object[]} slaveComponents - info from localStorage
  815. */
  816. addHostNamesToConfigs: function(serviceConfig, masterComponents, slaveComponents) {
  817. serviceConfig.get('configCategories').forEach(function(c) {
  818. if (c.showHost) {
  819. var value = [];
  820. var componentName = c.name;
  821. var masters = masterComponents && masterComponents.filterProperty('component', componentName);
  822. if (masters.length) {
  823. value = masters.mapProperty('hostName');
  824. } else {
  825. var slaves = slaveComponents && slaveComponents.findProperty('componentName', componentName);
  826. if (slaves) {
  827. value = slaves.hosts.mapProperty('hostName');
  828. }
  829. }
  830. var stackComponent = App.StackServiceComponent.find(componentName);
  831. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), componentName, value, stackComponent);
  832. var newConfigName = Em.get(hProperty, 'name');
  833. if (!serviceConfig.get('configs').someProperty('name', newConfigName)) {
  834. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  835. }
  836. }
  837. }, this);
  838. },
  839. /**
  840. * create new child configs from overrides, attach them to parent config
  841. * override - value of config, related to particular host(s)
  842. * @param configProperty
  843. * @param storedConfigProperty
  844. */
  845. updateHostOverrides: function (configProperty, storedConfigProperty) {
  846. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  847. var overrides = [];
  848. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  849. // create new override with new value
  850. var newSCP = App.ServiceConfigProperty.create(configProperty);
  851. newSCP.set('value', overrideEntry.value);
  852. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  853. newSCP.set('parentSCP', configProperty);
  854. overrides.pushObject(newSCP);
  855. });
  856. configProperty.set('overrides', overrides);
  857. }
  858. },
  859. /**
  860. * When NameNode HA is enabled some configs based on <code>dfs.nameservices</code> should be changed
  861. * This happens only if service is added AFTER NN HA is enabled
  862. *
  863. * @param {App.ServiceConfig[]} serviceConfigs
  864. * @method _reconfigureServiceOnNnHa
  865. * @private
  866. * @returns {App.ServiceConfig[]}
  867. */
  868. _reconfigureServicesOnNnHa: function (serviceConfigs) {
  869. var selectedServiceNames = this.get('selectedServiceNames');
  870. var nameServiceId = serviceConfigs.findProperty('serviceName', 'HDFS').configs.findProperty('name', 'dfs.nameservices');
  871. Em.A([
  872. {
  873. serviceName: 'HBASE',
  874. configToUpdate: 'hbase.rootdir'
  875. },
  876. {
  877. serviceName: 'ACCUMULO',
  878. configToUpdate: 'instance.volumes'
  879. },
  880. {
  881. serviceName: 'HAWQ',
  882. configToUpdate: 'hawq_dfs_url',
  883. regexPattern: /(^.*:[0-9]+)(?=\/)/,
  884. replacementValue: nameServiceId.get('value')
  885. }
  886. ]).forEach(function (c) {
  887. if (selectedServiceNames.contains(c.serviceName) && nameServiceId) {
  888. var cfg = serviceConfigs.findProperty('serviceName', c.serviceName).configs.findProperty('name', c.configToUpdate);
  889. var regexPattern = /\/\/.*:[0-9]+/i;
  890. var replacementValue = '//' + nameServiceId.get('value');
  891. if (typeof(c.regexPattern) !== "undefined" && typeof(c.replacementValue) !== "undefined") {
  892. regexPattern = c.regexPattern;
  893. replacementValue = c.replacementValue;
  894. }
  895. var newValue = cfg.get('value').replace(regexPattern, replacementValue);
  896. cfg.setProperties({
  897. value: newValue,
  898. recommendedValue: newValue
  899. });
  900. }
  901. });
  902. return serviceConfigs;
  903. },
  904. /**
  905. * Select first addable service for <code>addServiceWizard</code>
  906. * Select first service at all in other cases
  907. * @method selectProperService
  908. */
  909. selectProperService: function () {
  910. if (this.get('wizardController.name') === 'addServiceController') {
  911. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  912. } else {
  913. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  914. }
  915. },
  916. /**
  917. * Load config tags
  918. * @return {$.ajax|null}
  919. * @method getConfigTags
  920. */
  921. getConfigTags: function () {
  922. this.set('isAppliedConfigLoaded', false);
  923. return App.ajax.send({
  924. name: 'config.tags',
  925. sender: this,
  926. success: 'getConfigTagsSuccess'
  927. });
  928. },
  929. /**
  930. * Success callback for config tags request
  931. * Updates <code>serviceConfigTags</code> with tags received from server
  932. * @param {object} data
  933. * @method getConfigTagsSuccess
  934. */
  935. getConfigTagsSuccess: function (data) {
  936. var installedServiceSites = [];
  937. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  938. if (!service.get('configTypes')) return;
  939. var configTypes = Object.keys(service.get('configTypes'));
  940. installedServiceSites = installedServiceSites.concat(configTypes);
  941. }, this);
  942. installedServiceSites = installedServiceSites.uniq();
  943. var serviceConfigTags = [];
  944. for (var site in data.Clusters.desired_configs) {
  945. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  946. if (installedServiceSites.contains(site) || site == 'cluster-env') {
  947. serviceConfigTags.push({
  948. siteName: site,
  949. tagName: data.Clusters.desired_configs[site].tag,
  950. newTagName: null
  951. });
  952. }
  953. }
  954. }
  955. this.set('serviceConfigTags', serviceConfigTags);
  956. this.set('isAppliedConfigLoaded', true);
  957. },
  958. /**
  959. * set configs actual values from server
  960. * @param configs
  961. * @param configsByTags
  962. * @param installedServiceNames
  963. * @method setInstalledServiceConfigs
  964. */
  965. setInstalledServiceConfigs: function (configs, configsByTags, installedServiceNames) {
  966. var configsMap = {};
  967. configsByTags.forEach(function (configSite) {
  968. configsMap[configSite.type] = configSite.properties || {};
  969. });
  970. var allConfigs = configs.filter(function (_config) {
  971. // filter out alert_notification configs on add service //TODO find better place for this!
  972. if (_config.filename === 'alert_notification') return false;
  973. if ((['MISC'].concat(installedServiceNames).contains(_config.serviceName))) {
  974. var type = _config.filename ? App.config.getConfigTagFromFileName(_config.filename) : null;
  975. var mappedConfigValue = type && configsMap[type] ? configsMap[type][_config.name] : null;
  976. if (Em.isNone(mappedConfigValue)) {
  977. //for now ranger plugin properties are not sending by recommendations if they are missed - it should be added
  978. return _config.serviceName == 'MISC' || /^ranger-/.test(_config.filename);
  979. } else {
  980. if (_config.savedValue != mappedConfigValue) {
  981. _config.savedValue = App.config.formatPropertyValue(_config, mappedConfigValue);
  982. }
  983. _config.value = App.config.formatPropertyValue(_config, mappedConfigValue);
  984. _config.hasInitialValue = true;
  985. this.updateDependencies(_config);
  986. delete configsMap[type][_config.name];
  987. return true;
  988. }
  989. } else {
  990. return true;
  991. }
  992. }, this);
  993. //add user properties
  994. Em.keys(configsMap).forEach(function (filename) {
  995. Em.keys(configsMap[filename]).forEach(function (propertyName) {
  996. allConfigs.push(App.config.createDefaultConfig(propertyName, App.config.getOriginalFileName(filename), false, {
  997. value: configsMap[filename][propertyName],
  998. savedValue: configsMap[filename][propertyName],
  999. hasInitialValue: true
  1000. }));
  1001. });
  1002. });
  1003. return allConfigs;
  1004. },
  1005. /**
  1006. * update dependencies according to current config value
  1007. *
  1008. * @param config
  1009. */
  1010. updateDependencies: function(config) {
  1011. if (config.name === 'hive.metastore.uris' && config.filename === 'hive-site.xml') {
  1012. this.get('configDependencies')['hive.metastore.uris'] = config.savedValue;
  1013. } else if (config.name === 'clientPort' && config.filename === 'hive-site.xml') {
  1014. this.get('configDependencies')['clientPort'] = config.savedValue;
  1015. }
  1016. },
  1017. /**
  1018. * Add group ids to <code>groupsToDelete</code>
  1019. * Also save <code>groupsToDelete</code> to local storage
  1020. * @param {Ember.Object[]} groups
  1021. * @method setGroupsToDelete
  1022. */
  1023. setGroupsToDelete: function (groups) {
  1024. var groupsToDelete = this.get('groupsToDelete');
  1025. groups.forEach(function (group) {
  1026. if (group.get('id'))
  1027. groupsToDelete.push({
  1028. id: group.get('id')
  1029. });
  1030. });
  1031. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  1032. },
  1033. /**
  1034. * Update <code>configGroups</code> with selected service configGroups
  1035. * Also set default group to first position
  1036. * Update <code>selectedConfigGroup</code> with new default group
  1037. * @method selectedServiceObserver
  1038. */
  1039. selectedServiceObserver: function () {
  1040. if (this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  1041. var serviceGroups = this.get('selectedService.configGroups');
  1042. serviceGroups.forEach(function (item, index, array) {
  1043. if (item.isDefault) {
  1044. array.unshift(item);
  1045. array.splice(index + 1, 1);
  1046. }
  1047. });
  1048. this.set('configGroups', serviceGroups);
  1049. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  1050. }
  1051. }.observes('selectedService.configGroups.@each'),
  1052. /**
  1053. * load default groups for each service in case of initial load
  1054. * @param serviceConfigGroups
  1055. * @method loadConfigGroups
  1056. */
  1057. loadConfigGroups: function (serviceConfigGroups) {
  1058. var services = this.get('stepConfigs');
  1059. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  1060. services.forEach(function (service) {
  1061. if (service.get('serviceName') === 'MISC') return;
  1062. var serviceRawGroups = serviceConfigGroups.filterProperty('service_name', service.serviceName);
  1063. var id = App.ServiceConfigGroup.getParentConfigGroupId(service.get('serviceName'));
  1064. if (!serviceRawGroups.length) {
  1065. App.store.load(App.ServiceConfigGroup, App.configGroupsMapper.generateDefaultGroup(service.get('serviceName'), hosts));
  1066. App.store.commit();
  1067. service.set('configGroups', [App.ServiceConfigGroup.find(id)]);
  1068. }
  1069. else {
  1070. App.store.commit();
  1071. App.store.loadMany(App.ServiceConfigGroup, serviceRawGroups);
  1072. App.store.commit();
  1073. serviceRawGroups.forEach(function(item){
  1074. var modelGroup = App.ServiceConfigGroup.find(item.id);
  1075. var wrappedProperties = [];
  1076. item.properties.forEach(function (propertyData) {
  1077. var overriddenSCP, parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  1078. if (parentSCP) {
  1079. overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  1080. overriddenSCP.set('parentSCP', parentSCP);
  1081. } else {
  1082. overriddenSCP = App.config.createCustomGroupConfig(propertyData.name, propertyData.filename, propertyData.value, modelGroup, true, false);
  1083. this.get('stepConfigs').findProperty('serviceName', service.serviceName).get('configs').pushObject(overriddenSCP);
  1084. }
  1085. overriddenSCP.set('isOriginalSCP', false);
  1086. overriddenSCP.set('group', modelGroup);
  1087. overriddenSCP.setProperties(propertyData);
  1088. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  1089. }, this);
  1090. modelGroup.set('properties', wrappedProperties);
  1091. }, this);
  1092. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', service.get('serviceName')));
  1093. }
  1094. }, this);
  1095. },
  1096. /**
  1097. * Click-handler on config-group to make it selected
  1098. * @param {object} event
  1099. * @method selectConfigGroup
  1100. */
  1101. selectConfigGroup: function (event) {
  1102. this.set('selectedConfigGroup', event.context);
  1103. },
  1104. /**
  1105. * Rebuild list of configs switch of config group:
  1106. * on default - display all configs from default group and configs from non-default groups as disabled
  1107. * on non-default - display all from default group as disabled and configs from selected non-default group
  1108. * @method switchConfigGroupConfigs
  1109. */
  1110. switchConfigGroupConfigs: function () {
  1111. var serviceConfigs = this.get('selectedService.configs'),
  1112. selectedGroup = this.get('selectedConfigGroup'),
  1113. overrideToAdd = this.get('overrideToAdd'),
  1114. overrides = [];
  1115. if (!selectedGroup) return;
  1116. var displayedConfigGroups = this._getDisplayedConfigGroups();
  1117. displayedConfigGroups.forEach(function (group) {
  1118. overrides.pushObjects(group.get('properties'));
  1119. });
  1120. serviceConfigs.forEach(function (config) {
  1121. this._setEditableValue(config);
  1122. this._setOverrides(config, overrides);
  1123. }, this);
  1124. }.observes('selectedConfigGroup'),
  1125. /**
  1126. * Get list of config groups to display
  1127. * Returns empty array if no <code>selectedConfigGroup</code>
  1128. * @return {Array}
  1129. * @method _getDisplayedConfigGroups
  1130. */
  1131. _getDisplayedConfigGroups: function () {
  1132. var selectedGroup = this.get('selectedConfigGroup');
  1133. if (!selectedGroup) return [];
  1134. return (selectedGroup.get('isDefault')) ?
  1135. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  1136. [this.get('selectedConfigGroup')];
  1137. },
  1138. /**
  1139. * Set <code>isEditable</code> property to <code>config</code>
  1140. * @param {Ember.Object} config
  1141. * @return {Ember.Object} updated config-object
  1142. * @method _setEditableValue
  1143. */
  1144. _setEditableValue: function (config) {
  1145. var selectedGroup = this.get('selectedConfigGroup');
  1146. if (!selectedGroup) return config;
  1147. var isEditable = config.get('isEditable'),
  1148. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  1149. if (isServiceInstalled) {
  1150. isEditable = (!isEditable || !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  1151. }
  1152. else {
  1153. isEditable = selectedGroup.get('isDefault');
  1154. }
  1155. if (config.get('group')) {
  1156. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  1157. }
  1158. config.set('isEditable', isEditable);
  1159. return config;
  1160. },
  1161. /**
  1162. * Set <code>overrides</code> property to <code>config</code>
  1163. * @param {Ember.Object} config
  1164. * @param {Ember.Enumerable} overrides
  1165. * @returns {Ember.Object}
  1166. * @method _setOverrides
  1167. */
  1168. _setOverrides: function (config, overrides) {
  1169. if (config.get('group')) return config;
  1170. var selectedGroup = this.get('selectedConfigGroup'),
  1171. overrideToAdd = this.get('overrideToAdd'),
  1172. configOverrides = overrides.filterProperty('name', config.get('name'));
  1173. if (!selectedGroup) return config;
  1174. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1175. var valueForOverride = (config.get('widget') || config.get('displayType') == 'checkbox') ? config.get('value') : '';
  1176. var group = this.get('selectedService.configGroups').findProperty('name', selectedGroup.get('name'));
  1177. var newSCP = App.config.createOverride(config, {value: valueForOverride, recommendedValue: valueForOverride}, group);
  1178. configOverrides.push(newSCP);
  1179. group.get('properties').pushObject(newSCP);
  1180. this.set('overrideToAdd', null);
  1181. }
  1182. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1183. configOverrides.setEach('parentSCP', config);
  1184. config.set('overrides', configOverrides);
  1185. return config;
  1186. },
  1187. /**
  1188. * @param serviceName
  1189. * @returns {boolean}
  1190. * @override
  1191. */
  1192. useInitialValue: function(serviceName) {
  1193. return !App.Service.find(serviceName).get('serviceName', serviceName);
  1194. },
  1195. /**
  1196. *
  1197. * @param parentProperties
  1198. * @param name
  1199. * @param fileName
  1200. * @returns {*}
  1201. * @override
  1202. */
  1203. allowUpdateProperty: function(parentProperties, name, fileName) {
  1204. if (name.contains('proxyuser')) return true;
  1205. if (['installerController'].contains(this.get('wizardController.name')) || !!(parentProperties && parentProperties.length)) {
  1206. return true;
  1207. } else if (['addServiceController'].contains(this.get('wizardController.name'))) {
  1208. var stackProperty = App.configsCollection.getConfigByName(name, fileName);
  1209. if (!stackProperty || !this.get('installedServices')[stackProperty.serviceName]) {
  1210. return true;
  1211. } else if (stackProperty.propertyDependsOn.length) {
  1212. return !!stackProperty.propertyDependsOn.filter(function (p) {
  1213. var service = App.config.get('serviceByConfigTypeMap')[p.type];
  1214. return service && !this.get('installedServices')[service.get('serviceName')];
  1215. }, this).length;
  1216. } else {
  1217. return false;
  1218. }
  1219. }
  1220. return true;
  1221. },
  1222. /**
  1223. * remove config based on recommendations
  1224. * @param config
  1225. * @param configsCollection
  1226. * @param parentProperties
  1227. * @protected
  1228. * @override
  1229. */
  1230. _removeConfigByRecommendation: function (config, configsCollection, parentProperties) {
  1231. this._super(config, configsCollection, parentProperties);
  1232. /**
  1233. * need to update wizard info when removing configs for installed services;
  1234. */
  1235. var installedServices = this.get('installedServices'), wizardController = this.get('wizardController'),
  1236. fileNamesToUpdate = wizardController ? wizardController.getDBProperty('fileNamesToUpdate') || [] : [],
  1237. fileName = Em.get(config, 'filename'), serviceName = Em.get(config, 'serviceName');
  1238. var modifiedFileNames = this.get('modifiedFileNames');
  1239. if (modifiedFileNames && !modifiedFileNames.contains(fileName)) {
  1240. modifiedFileNames.push(fileName);
  1241. } else if (wizardController && installedServices[serviceName]) {
  1242. if (!fileNamesToUpdate.contains(fileName)) {
  1243. fileNamesToUpdate.push(fileName);
  1244. }
  1245. }
  1246. if (wizardController) {
  1247. wizardController.setDBProperty('fileNamesToUpdate', fileNamesToUpdate.uniq());
  1248. }
  1249. },
  1250. /**
  1251. * @method manageConfigurationGroup
  1252. */
  1253. manageConfigurationGroup: function () {
  1254. App.router.get('manageConfigGroupsController').manageConfigurationGroups(this);
  1255. },
  1256. /**
  1257. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1258. * @return {$.ajax|null}
  1259. * @method checkMySQLHost
  1260. */
  1261. checkMySQLHost: function () {
  1262. // get ambari database type and hostname
  1263. return App.ajax.send({
  1264. name: 'ambari.service',
  1265. data: {
  1266. fields : "?fields=hostComponents/RootServiceHostComponents/properties/server.jdbc.database_name,hostComponents/RootServiceHostComponents/properties/server.jdbc.url,hostComponents/RootServiceHostComponents/properties/server.jdbc.database"
  1267. },
  1268. sender: this,
  1269. success: 'getAmbariDatabaseSuccess'
  1270. });
  1271. },
  1272. /**
  1273. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1274. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1275. * @param {object} data
  1276. * @method getAmbariDatabaseSuccess
  1277. */
  1278. getAmbariDatabaseSuccess: function (data) {
  1279. var ambariServerDBType = Em.getWithDefault(data.hostComponents, '0.RootServiceHostComponents.properties', {})['server.jdbc.database'],
  1280. ambariServerHostName = Em.getWithDefault(data.hostComponents, '0.RootServiceHostComponents.host_name', false),
  1281. hiveConnectionURL = Em.getWithDefault(App.config.findConfigProperty(this.get('stepConfigs'), 'javax.jdo.option.ConnectionURL', 'hive-site.xml') || {}, 'value', '');
  1282. if (ambariServerHostName) {
  1283. this.set('mySQLServerConflict', ambariServerDBType.contains('mysql') && hiveConnectionURL.contains(ambariServerHostName));
  1284. } else {
  1285. this.set('mySQLServerConflict', false);
  1286. }
  1287. },
  1288. /**
  1289. * Check if new MySql database was chosen for Hive service
  1290. * and it is not located on the same host as Ambari server
  1291. * that using MySql database too.
  1292. *
  1293. * @method resolveHiveMysqlDatabase
  1294. **/
  1295. resolveHiveMysqlDatabase: function () {
  1296. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1297. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1298. this.moveNext();
  1299. return;
  1300. }
  1301. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1302. if (hiveDBType == 'New MySQL Database') {
  1303. var self = this;
  1304. return this.checkMySQLHost().done(function () {
  1305. self.mySQLWarningHandler();
  1306. });
  1307. }
  1308. else {
  1309. this.moveNext();
  1310. }
  1311. },
  1312. /**
  1313. * Show warning popup about MySQL-DB issues (on post-submit)
  1314. *
  1315. * @returns {*}
  1316. * @method mySQLWarningHandler
  1317. */
  1318. mySQLWarningHandler: function () {
  1319. var self = this;
  1320. if (this.get('mySQLServerConflict')) {
  1321. // error popup before you can proceed
  1322. return App.ModalPopup.show({
  1323. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1324. body:Em.I18n.t('installer.step7.popup.mySQLWarning.body'),
  1325. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1326. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1327. encodeBody: false,
  1328. onPrimary: function () {
  1329. this._super();
  1330. self.set('submitButtonClicked', false);
  1331. },
  1332. onSecondary: function () {
  1333. var parent = this;
  1334. return App.ModalPopup.show({
  1335. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1336. body: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'),
  1337. onPrimary: function () {
  1338. this.hide();
  1339. parent.hide();
  1340. // go back to step 5: assign masters and disable default navigation warning
  1341. if ('installerController' === self.get('content.controllerName')) {
  1342. App.router.get('installerController').gotoStep(5, true);
  1343. }
  1344. else {
  1345. if ('addServiceController' === self.get('content.controllerName')) {
  1346. App.router.get('addServiceController').gotoStep(2, true);
  1347. }
  1348. }
  1349. },
  1350. onSecondary: function () {
  1351. this._super();
  1352. self.set('submitButtonClicked', false);
  1353. }
  1354. });
  1355. }
  1356. });
  1357. }
  1358. else {
  1359. return this.moveNext();
  1360. }
  1361. },
  1362. checkDatabaseConnectionTest: function () {
  1363. var deferred = $.Deferred();
  1364. var configMap = [
  1365. {
  1366. serviceName: 'OOZIE',
  1367. ignored: [Em.I18n.t('installer.step7.oozie.database.new')]
  1368. },
  1369. {
  1370. serviceName: 'HIVE',
  1371. ignored: [Em.I18n.t('installer.step7.hive.database.new.mysql'), Em.I18n.t('installer.step7.hive.database.new.postgres')]
  1372. }
  1373. ];
  1374. configMap.forEach(function (config) {
  1375. var isConnectionNotTested = false;
  1376. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1377. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1378. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1379. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1380. if (!config.ignored.contains(serviceDatabase)) {
  1381. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1382. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1383. isConnectionNotTested = true;
  1384. } else {
  1385. for (var key in filledProperties) {
  1386. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1387. isConnectionNotTested = true;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. config.isCheckIgnored = isConnectionNotTested;
  1393. }, this);
  1394. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1395. if (ignoredServices.length) {
  1396. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1397. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1398. }, this);
  1399. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1400. }
  1401. else {
  1402. deferred.resolve();
  1403. }
  1404. return deferred;
  1405. },
  1406. showChangesWarningPopup: function(goToNextStep) {
  1407. return App.ModalPopup.show({
  1408. header: Em.I18n.t('common.warning'),
  1409. body: Em.I18n.t('services.service.config.exitChangesPopup.body'),
  1410. secondary: Em.I18n.t('common.cancel'),
  1411. primary: Em.I18n.t('yes'),
  1412. onPrimary: function () {
  1413. if (goToNextStep) {
  1414. goToNextStep();
  1415. this.hide();
  1416. }
  1417. },
  1418. onSecondary: function () {
  1419. this.hide();
  1420. }
  1421. });
  1422. },
  1423. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1424. var self = this;
  1425. return App.ModalPopup.show({
  1426. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1427. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1428. secondary: Em.I18n.t('common.cancel'),
  1429. primary: Em.I18n.t('common.proceedAnyway'),
  1430. onPrimary: function () {
  1431. deferred.resolve();
  1432. this._super();
  1433. },
  1434. onSecondary: function () {
  1435. self.set('submitButtonClicked', false);
  1436. deferred.reject();
  1437. this._super();
  1438. }
  1439. });
  1440. },
  1441. showOozieDerbyWarningPopup: function(callback) {
  1442. var self = this;
  1443. if (this.get('selectedServiceNames').contains('OOZIE')) {
  1444. var databaseType = Em.getWithDefault(App.config.findConfigProperty(this.get('stepConfigs'), 'oozie_database', 'oozie-env.xml') || {}, 'value', '');
  1445. if (databaseType == Em.I18n.t('installer.step7.oozie.database.new')) {
  1446. return App.ModalPopup.show({
  1447. header: Em.I18n.t('common.warning'),
  1448. body: Em.I18n.t('installer.step7.popup.oozie.derby.warning'),
  1449. secondary: Em.I18n.t('common.cancel'),
  1450. primary: Em.I18n.t('common.proceedAnyway'),
  1451. onPrimary: function() {
  1452. this.hide();
  1453. if (callback) {
  1454. callback();
  1455. }
  1456. },
  1457. onSecondary: function() {
  1458. self.set('submitButtonClicked', false);
  1459. this.hide();
  1460. },
  1461. onClose: function() {
  1462. this.onSecondary();
  1463. }
  1464. });
  1465. }
  1466. }
  1467. if (callback) {
  1468. callback();
  1469. }
  1470. return false;
  1471. },
  1472. /**
  1473. * Proceed to the next step
  1474. **/
  1475. moveNext: function () {
  1476. App.router.nextBtnClickInProgress = true;
  1477. App.router.send('next');
  1478. this.set('submitButtonClicked', false);
  1479. },
  1480. /**
  1481. * Click-handler on Next button
  1482. * Disable "Submit"-button while server-side processes are running
  1483. * @method submit
  1484. */
  1485. submit: function () {
  1486. if (this.get('isSubmitDisabled') || App.router.nextBtnClickInProgress) {
  1487. return false;
  1488. }
  1489. if (this.get('supportsPreInstallChecks')) {
  1490. var preInstallChecksController = App.router.get('preInstallChecksController');
  1491. if (preInstallChecksController.get('preInstallChecksWhereRun')) {
  1492. return this.postSubmit();
  1493. }
  1494. return preInstallChecksController.notRunChecksWarnPopup(this.postSubmit.bind(this));
  1495. }
  1496. return this.postSubmit();
  1497. },
  1498. postSubmit: function () {
  1499. var self = this;
  1500. this.set('submitButtonClicked', true);
  1501. this.serverSideValidation().done(function() {
  1502. self.serverSideValidationCallback();
  1503. })
  1504. .fail(function (value) {
  1505. if ("invalid_configs" == value) {
  1506. self.set('submitButtonClicked', false);
  1507. App.router.nextBtnClickInProgress = false;
  1508. } else {
  1509. // Failed due to validation mechanism failure.
  1510. // Should proceed with other checks
  1511. self.serverSideValidationCallback();
  1512. }
  1513. });
  1514. },
  1515. /**
  1516. * @method serverSideValidationCallback
  1517. */
  1518. serverSideValidationCallback: function() {
  1519. var self = this;
  1520. this.showOozieDerbyWarningPopup(function() {
  1521. self.checkDatabaseConnectionTest().done(function () {
  1522. self.resolveHiveMysqlDatabase();
  1523. });
  1524. });
  1525. },
  1526. toggleIssuesFilter: function () {
  1527. this.get('filterColumns').findProperty('attributeName', 'hasIssues').toggleProperty('selected');
  1528. // if currently selected service does not have issue, jump to the first service with issue.
  1529. if (this.get('selectedService.errorCount') == 0 )
  1530. {
  1531. var errorServices = this.get('stepConfigs').filterProperty('errorCount');
  1532. if (errorServices.length > 0)
  1533. {
  1534. var service = errorServices[0];
  1535. this.set('selectedService', service);
  1536. $('a[href="#' + service.serviceName + '"]').tab('show');
  1537. }
  1538. }
  1539. }
  1540. });