step7_controller.js 62 KB

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