step8_controller.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. var dataManipulationUtils = require('utils/data_manipulation');
  21. App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wizardDeployProgressControllerMixin, App.ConfigOverridable, {
  22. name: 'wizardStep8Controller',
  23. /**
  24. * List of raw data about cluster that should be displayed
  25. * @type {Array}
  26. */
  27. rawContent: [
  28. {
  29. config_name: 'Admin',
  30. display_name: 'Admin Name',
  31. config_value: ''
  32. },
  33. {
  34. config_name: 'cluster',
  35. display_name: 'Cluster Name',
  36. config_value: ''
  37. },
  38. {
  39. config_name: 'hosts',
  40. display_name: 'Total Hosts',
  41. config_value: ''
  42. },
  43. {
  44. config_name: 'Repo',
  45. display_name: 'Local Repository',
  46. config_value: ''
  47. }
  48. ],
  49. /**
  50. * List of data about cluster (based on formatted <code>rawContent</code>)
  51. * @type {Object[]}
  52. */
  53. clusterInfo: [],
  54. /**
  55. * List of services with components assigned to hosts
  56. * @type {Object[]}
  57. */
  58. services: [],
  59. /**
  60. * @type {Object[]}
  61. */
  62. configs: [],
  63. /**
  64. * True if Kerberos is installed on the cluster and the kdc_type on the server is set to "none"
  65. * @type {Boolean}
  66. */
  67. isManualKerberos: function () {
  68. return App.get('router.mainAdminKerberosController.kdc_type') === 'none';
  69. }.property('App.router.mainAdminKerberosController.kdc_type'),
  70. showDownloadCsv: function () {
  71. return !!App.get('router.mainAdminKerberosController.kdc_type')
  72. }.property('App.router.mainAdminKerberosController.kdc_type'),
  73. /**
  74. * Should Submit button be disabled
  75. * @type {bool}
  76. */
  77. isSubmitDisabled: false,
  78. /**
  79. * Should Back button be disabled
  80. * @type {bool}
  81. */
  82. isBackBtnDisabled: false,
  83. /**
  84. * Is error appears while <code>ajaxQueue</code> executes
  85. * @type {bool}
  86. */
  87. hasErrorOccurred: false,
  88. /**
  89. * Are services installed
  90. * Used to hide Deploy Progress Bar
  91. * @type {bool}
  92. */
  93. servicesInstalled: false,
  94. /**
  95. * List of service config tags
  96. * @type {Object[]}
  97. */
  98. serviceConfigTags: [],
  99. /**
  100. * Selected config group
  101. * @type {Object}
  102. */
  103. selectedConfigGroup: null,
  104. /**
  105. * List of config groups
  106. * @type {Object[]}
  107. */
  108. configGroups: [],
  109. /**
  110. * List of selected but not installed services
  111. * @type {Object[]}
  112. */
  113. selectedServices: function () {
  114. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  115. }.property('content.services.@each.isSelected','content.services.@each.isInstalled').cacheable(),
  116. /**
  117. * List of installed services
  118. * @type {Object[]}
  119. */
  120. installedServices: function () {
  121. return this.get('content.services').filterProperty('isInstalled');
  122. }.property('content.services').cacheable(),
  123. /**
  124. * Current cluster name
  125. * @type {string}
  126. */
  127. clusterName: Em.computed.alias('content.cluster.name'),
  128. /**
  129. * List of existing cluster names
  130. * @type {string[]}
  131. */
  132. clusterNames: [],
  133. /**
  134. * Number of completed cluster delete requests
  135. * @type {number}
  136. */
  137. clusterDeleteRequestsCompleted: 0,
  138. /**
  139. * Indicates if all cluster delete requests are completed
  140. * @type {boolean}
  141. */
  142. isAllClusterDeleteRequestsCompleted: Em.computed.equalProperties('clusterDeleteRequestsCompleted', 'clusterNames.length'),
  143. /**
  144. * Error popup body views for clusters that couldn't be deleted
  145. * @type {App.AjaxDefaultErrorPopupBodyView[]}
  146. */
  147. clusterDeleteErrorViews: [],
  148. /**
  149. * Clear current step data
  150. * @method clearStep
  151. */
  152. clearStep: function () {
  153. this.get('services').clear();
  154. this.get('configs').clear();
  155. this.get('clusterInfo').clear();
  156. this.get('serviceConfigTags').clear();
  157. this.set('servicesInstalled', false);
  158. this.set('ajaxQueueLength', 0);
  159. this.set('ajaxRequestsQueue', App.ajaxQueue.create());
  160. this.set('ajaxRequestsQueue.finishedCallback', this.ajaxQueueFinished);
  161. this.get('clusterDeleteErrorViews').clear();
  162. this.set('clusterDeleteRequestsCompleted', 0);
  163. },
  164. /**
  165. * Load current step data
  166. * @method loadStep
  167. */
  168. loadStep: function () {
  169. this.clearStep();
  170. if (this.get('content.serviceConfigProperties')) {
  171. this.formatProperties();
  172. this.loadConfigs();
  173. }
  174. this.loadClusterInfo();
  175. this.loadServices();
  176. this.set('isSubmitDisabled', false);
  177. this.set('isBackBtnDisabled', false);
  178. },
  179. /**
  180. * replace whitespace character with coma between directories
  181. * @method formatProperties
  182. */
  183. formatProperties: function () {
  184. this.get('content.serviceConfigProperties').forEach(function (_configProperty) {
  185. _configProperty.value = App.config.trimProperty(_configProperty, false);
  186. });
  187. },
  188. /**
  189. * Load all site properties
  190. * @method loadConfigs
  191. */
  192. loadConfigs: function () {
  193. //storedConfigs contains custom configs as well
  194. var configs = this.get('content.serviceConfigProperties');
  195. configs.forEach(function (_config) {
  196. _config.value = (typeof _config.value === "boolean") ? _config.value.toString() : _config.value;
  197. });
  198. var customGroupConfigs = [];
  199. var allConfigs = configs.filter(function (config) {
  200. if (config.group) {
  201. customGroupConfigs.push(config);
  202. return false;
  203. } else {
  204. return true;
  205. }
  206. });
  207. this.set('customNonDefaultGroupConfigs', customGroupConfigs);
  208. this.set('configs', allConfigs);
  209. },
  210. /**
  211. * Format <code>content.hosts</code> from Object to Array
  212. * @returns {Array}
  213. * @method getRegisteredHosts
  214. */
  215. getRegisteredHosts: function () {
  216. var allHosts = this.get('content.hosts');
  217. var hosts = [];
  218. for (var hostName in allHosts) {
  219. if (allHosts.hasOwnProperty(hostName)) {
  220. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  221. allHosts[hostName].hostName = allHosts[hostName].name;
  222. hosts.pushObject(allHosts[hostName]);
  223. }
  224. }
  225. }
  226. return hosts;
  227. },
  228. /**
  229. * Load all info about cluster to <code>clusterInfo</code> variable
  230. * @method loadClusterInfo
  231. */
  232. loadClusterInfo: function () {
  233. //Admin name
  234. var admin = this.rawContent.findProperty('config_name', 'Admin');
  235. admin.config_value = App.db.getLoginName();
  236. if (admin.config_value) {
  237. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  238. }
  239. // cluster name
  240. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  241. cluster.config_value = this.get('content.cluster.name');
  242. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  243. //hosts
  244. var newHostsCount = 0;
  245. var totalHostsCount = 0;
  246. var hosts = this.get('content.hosts');
  247. for (var hostName in hosts) {
  248. newHostsCount += ~~(!hosts[hostName].isInstalled);
  249. totalHostsCount++;
  250. }
  251. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  252. totalHostsObj.config_value = totalHostsCount + ' (' + newHostsCount + ' new)';
  253. this.get('clusterInfo').pushObject(Em.Object.create(totalHostsObj));
  254. //repo
  255. if (['addHostController', 'addServiceController'].contains(this.get('content.controllerName'))) {
  256. // For some stacks there is no info regarding stack versions to upgrade, e.g. HDP-2.1
  257. if (App.StackVersion.find().get('content.length')) {
  258. this.loadRepoInfo();
  259. } else {
  260. this.loadDefaultRepoInfo();
  261. }
  262. } else {
  263. // from install wizard
  264. var selectedStack = App.Stack.find().findProperty('isSelected');
  265. var allRepos = [];
  266. if (selectedStack && selectedStack.get('operatingSystems')) {
  267. selectedStack.get('operatingSystems').forEach(function (os) {
  268. if (os.get('isSelected')) {
  269. os.get('repositories').forEach(function(repo) {
  270. allRepos.push(Em.Object.create({
  271. base_url: repo.get('baseUrl'),
  272. os_type: repo.get('osType'),
  273. repo_id: repo.get('repoId')
  274. }));
  275. }, this);
  276. }
  277. }, this);
  278. }
  279. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  280. this.get('clusterInfo').set('repoInfo', allRepos);
  281. }
  282. },
  283. /**
  284. * Load repo info for add Service/Host wizard review page
  285. * @return {$.ajax|null}
  286. * @method loadRepoInfo
  287. */
  288. loadRepoInfo: function () {
  289. var currentRepoVersion = App.StackVersion.find().findProperty('state', 'CURRENT').get('repositoryVersion.repositoryVersion');
  290. var stackName = App.get('currentStackName');
  291. return App.ajax.send({
  292. name: 'cluster.load_repo_version',
  293. sender: this,
  294. data: {
  295. stackName: stackName,
  296. repositoryVersion: currentRepoVersion
  297. },
  298. success: 'loadRepoInfoSuccessCallback',
  299. error: 'loadRepoInfoErrorCallback'
  300. });
  301. },
  302. /**
  303. * Save all repo base URL of all OS type to <code>repoInfo<code>
  304. * @param {object} data
  305. * @method loadRepoInfoSuccessCallback
  306. */
  307. loadRepoInfoSuccessCallback: function (data) {
  308. Em.assert('Current repo-version may be only one', data.items.length === 1);
  309. if (data.items.length) {
  310. var allRepos = this.generateRepoInfo(Em.getWithDefault(data, 'items.0.repository_versions.0.operating_systems', []));
  311. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  312. this.get('clusterInfo').set('repoInfo', allRepos);
  313. } else {
  314. this.loadDefaultRepoInfo();
  315. }
  316. },
  317. /**
  318. * Generate list regarding info about OS versions and repositories.
  319. *
  320. * @param {Object{}} oses - OS array
  321. * @returns {Em.Object[]}
  322. */
  323. generateRepoInfo: function(oses) {
  324. return oses.map(function(os) {
  325. return os.repositories.map(function (repository) {
  326. return Em.Object.create({
  327. base_url: repository.Repositories.base_url,
  328. os_type: repository.Repositories.os_type,
  329. repo_id: repository.Repositories.repo_id
  330. });
  331. });
  332. }).reduce(function(p, c) { return p.concat(c); });
  333. },
  334. /**
  335. * Load repo info from stack. Used if installed stack doesn't have upgrade info.
  336. *
  337. * @returns {$.Deferred}
  338. * @method loadDefaultRepoInfo
  339. */
  340. loadDefaultRepoInfo: function() {
  341. var nameVersionCombo = App.get('currentStackVersion').split('-');
  342. return App.ajax.send({
  343. name: 'cluster.load_repositories',
  344. sender: this,
  345. data: {
  346. stackName: nameVersionCombo[0],
  347. stackVersion: nameVersionCombo[1]
  348. },
  349. success: 'loadDefaultRepoInfoSuccessCallback',
  350. error: 'loadRepoInfoErrorCallback'
  351. });
  352. },
  353. /**
  354. * @param {Object} data - JSON data from server
  355. * @method loadDefaultRepoInfoSuccessCallback
  356. */
  357. loadDefaultRepoInfoSuccessCallback: function (data) {
  358. var allRepos = this.generateRepoInfo(Em.getWithDefault(data, 'items', []));
  359. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  360. this.get('clusterInfo').set('repoInfo', allRepos);
  361. },
  362. /**
  363. * @param {object} request
  364. * @method loadRepoInfoErrorCallback
  365. */
  366. loadRepoInfoErrorCallback: function (request) {
  367. var allRepos = [];
  368. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  369. this.get('clusterInfo').set('repoInfo', allRepos);
  370. },
  371. /**
  372. * Load all info about services to <code>services</code> variable
  373. * @method loadServices
  374. */
  375. loadServices: function () {
  376. this.get('selectedServices').filterProperty('isHiddenOnSelectServicePage', false).forEach(function (service) {
  377. var serviceObj = Em.Object.create({
  378. service_name: service.get('serviceName'),
  379. display_name: service.get('displayNameOnSelectServicePage'),
  380. service_components: Em.A([])
  381. });
  382. service.get('serviceComponents').forEach(function (component) {
  383. // show clients for services that have only clients components
  384. if ((component.get('isClient') || component.get('isRequiredOnAllHosts')) && !service.get('isClientOnlyService')) return;
  385. // skip components that was hide on assign master page
  386. if (component.get('isMaster') && !component.get('isShownOnInstallerAssignMasterPage')) return;
  387. // no HA component
  388. if (component.get('isHAComponentOnly')) return;
  389. var displayName;
  390. if (component.get('isClient')) {
  391. displayName = Em.I18n.t('common.clients')
  392. } else {
  393. // remove service name from component display name
  394. displayName = App.format.role(component.get('componentName')).replace(new RegExp('^' + service.get('serviceName') + '\\s', 'i'), '');
  395. }
  396. serviceObj.get('service_components').pushObject(Em.Object.create({
  397. component_name: component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName'),
  398. display_name: displayName,
  399. component_value: this.assignComponentHosts(component)
  400. }));
  401. }, this);
  402. if (service.get('customReviewHandler')) {
  403. for (var displayName in service.get('customReviewHandler')) {
  404. serviceObj.get('service_components').pushObject(Em.Object.create({
  405. display_name: displayName,
  406. component_value: this.assignComponentHosts(Em.Object.create({
  407. customHandler: service.get('customReviewHandler.' + displayName)
  408. }))
  409. }));
  410. }
  411. }
  412. this.get('services').pushObject(serviceObj);
  413. }, this);
  414. },
  415. /**
  416. * Set <code>component_value</code> property to <code>component</code>
  417. * @param {Em.Object} component
  418. * @return {String}
  419. * @method assignComponentHosts
  420. */
  421. assignComponentHosts: function (component) {
  422. var componentValue;
  423. if (component.get('customHandler')) {
  424. componentValue = this[component.get('customHandler')].call(this, component);
  425. }
  426. else {
  427. if (component.get('isMaster')) {
  428. componentValue = this.getMasterComponentValue(component.get('componentName'));
  429. }
  430. else {
  431. var componentName = component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName');
  432. var hostsLength = this.get('content.slaveComponentHosts')
  433. .findProperty('componentName', componentName).hosts.length;
  434. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  435. }
  436. }
  437. return componentValue;
  438. },
  439. getMasterComponentValue: function (componentName) {
  440. var masterComponents = this.get('content.masterComponentHosts');
  441. var hostsCount = masterComponents.filterProperty('component', componentName).length;
  442. return stringUtils.pluralize(hostsCount,
  443. masterComponents.findProperty('component', componentName).hostName,
  444. hostsCount + ' ' + Em.I18n.t('installer.step8.hosts'));
  445. },
  446. loadHiveDbValue: function() {
  447. return this.loadDbValue('HIVE');
  448. },
  449. loadOozieDbValue: function() {
  450. return this.loadDbValue('OOZIE');
  451. },
  452. /**
  453. * Set displayed Hive DB value based on DB type
  454. * @method loadHiveDbValue
  455. */
  456. loadDbValue: function (serviceName) {
  457. var serviceConfigProperties = this.get('wizardController').getDBProperty('serviceConfigProperties');
  458. var dbFull = serviceConfigProperties.findProperty('name', serviceName.toLowerCase() + '_database'),
  459. db = serviceConfigProperties.findProperty('name', serviceName.toLowerCase() + '_ambari_database');
  460. return db && dbFull ? db.value + ' (' + dbFull.value + ')' : '';
  461. },
  462. /**
  463. * Set displayed HBase master value
  464. * @param {Object} hbaseMaster
  465. * @method loadHbaseMasterValue
  466. */
  467. loadHbaseMasterValue: function (hbaseMaster) {
  468. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  469. if (hbaseHostName.length == 1) {
  470. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  471. } else {
  472. hbaseMaster.set('component_value', hbaseHostName[0].hostName + " " + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  473. }
  474. },
  475. /**
  476. * Set displayed ZooKeeper Server value
  477. * @param {Object} serverComponent
  478. * @method loadZkServerValue
  479. */
  480. loadZkServerValue: function (serverComponent) {
  481. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  482. var hostSuffix;
  483. if (zkHostNames === 1) {
  484. hostSuffix = Em.I18n.t('installer.step8.host');
  485. } else {
  486. hostSuffix = Em.I18n.t('installer.step8.hosts');
  487. }
  488. serverComponent.set('component_value', zkHostNames + hostSuffix);
  489. },
  490. /**
  491. * Onclick handler for <code>next</code> button
  492. * @method submit
  493. * @return {void}
  494. */
  495. submit: function () {
  496. var wizardController;
  497. if (!this.get('isSubmitDisabled')) {
  498. wizardController = App.router.get(this.get('content.controllerName'));
  499. wizardController.setLowerStepsDisable(wizardController.get('currentStep'));
  500. this.set('isSubmitDisabled', true);
  501. this.set('isBackBtnDisabled', true);
  502. this.showRestartWarnings()
  503. .then(this.checkKDCSession.bind(this));
  504. }
  505. },
  506. /**
  507. * Warn user about services that will be restarted during installation.
  508. *
  509. * @returns {$.Deferred}
  510. */
  511. showRestartWarnings: function() {
  512. var self = this;
  513. var dfd = $.Deferred();
  514. var wizardController = App.router.get(this.get('content.controllerName'));
  515. var selectedServiceNames = this.get('selectedServices').mapProperty('serviceName');
  516. var installedServiceNames = this.get('installedServices').mapProperty('serviceName');
  517. if (this.get('content.controllerName') === 'addServiceController' && selectedServiceNames.contains('OOZIE')) {
  518. var affectedServices = ['HDFS', 'YARN'].filter(function(serviceName) {
  519. return installedServiceNames.contains(serviceName);
  520. });
  521. if (affectedServices.length) {
  522. var serviceNames = affectedServices.length > 1 ?
  523. '<b>{0}</b> {1} <b>{2}</b>'.format(affectedServices[0], Em.I18n.t('and'), affectedServices[1]) : '<b>' + affectedServices[0] + '</b> ';
  524. App.ModalPopup.show({
  525. encodeBody: false,
  526. header: Em.I18n.t('common.warning'),
  527. body: Em.I18n.t('installer.step8.services.restart.required').format(serviceNames, stringUtils.pluralize(affectedServices.length, Em.I18n.t('common.service').toLowerCase())),
  528. secondary: Em.I18n.t('common.cancel'),
  529. primary: Em.I18n.t('common.proceedAnyway'),
  530. onPrimary: function() {
  531. this.hide();
  532. dfd.resolve();
  533. },
  534. onClose: function() {
  535. this.hide();
  536. self.set('isSubmitDisabled', false);
  537. self.set('isBackBtnDisabled', false);
  538. wizardController.setStepsEnable();
  539. dfd.reject();
  540. },
  541. onSecondary: function() {
  542. this.onClose();
  543. }
  544. });
  545. } else {
  546. dfd.resolve();
  547. }
  548. } else {
  549. dfd.resolve();
  550. }
  551. return dfd.promise();
  552. },
  553. checkKDCSession: function() {
  554. var self = this;
  555. var wizardController = App.router.get(this.get('content.controllerName'));
  556. if (this.get('content.controllerName') != 'installerController') {
  557. App.get('router.mainAdminKerberosController').getKDCSessionState(this.submitProceed.bind(this), function () {
  558. self.set('isSubmitDisabled', false);
  559. self.set('isBackBtnDisabled', false);
  560. wizardController.setStepsEnable();
  561. if (self.get('content.controllerName') === 'addServiceController') {
  562. wizardController.setSkipSlavesStep(wizardController.getDBProperty('selectedServiceNames'), 3);
  563. }
  564. });
  565. } else {
  566. this.submitProceed();
  567. }
  568. },
  569. /**
  570. * Update configurations for installed services.
  571. * Do separated PUT-request for each siteName for each service
  572. *
  573. * @param {Array} fileNamesToUpdate - file names that should be updated
  574. * @method updateConfigurations
  575. */
  576. updateConfigurations: function (fileNamesToUpdate) {
  577. var configurationController = App.router.get('mainServiceInfoConfigsController');
  578. var configs = this.get('configs').slice(0);
  579. var configsMap = [];
  580. fileNamesToUpdate.forEach(function (fileName) {
  581. // TODO - Temporarily commented out before refactoring should clean it more properly
  582. // if (!fileName || /^(core)/.test(fileName)) return;
  583. var tagName = 'version' + (new Date).getTime();
  584. var configsToSave = configs.filterProperty('filename', fileName);
  585. configsToSave.forEach(function (item) {
  586. item.value = App.config.trimProperty(item, false);
  587. });
  588. configsMap.push(configurationController.createSiteObj(fileName.replace(".xml", ""), tagName, configsToSave));
  589. }, this);
  590. if (!configsMap.length) return;
  591. this.applyConfigurationsToCluster(configsMap);
  592. },
  593. /**
  594. * Prepare <code>ajaxQueue</code> and start to execute it
  595. * @method submitProceed
  596. */
  597. submitProceed: function () {
  598. var self = this;
  599. this.set('clusterDeleteRequestsCompleted', 0);
  600. this.get('clusterDeleteErrorViews').clear();
  601. if (this.get('content.controllerName') == 'addHostController') {
  602. App.router.get('addHostController').setLowerStepsDisable(4);
  603. }
  604. // checkpoint the cluster status on the server so that the user can resume from where they left off
  605. switch (this.get('content.controllerName')) {
  606. case 'installerController':
  607. App.clusterStatus.setClusterStatus({
  608. clusterName: this.get('clusterName'),
  609. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  610. wizardControllerName: this.get('content.controllerName'),
  611. localdb: App.db.data
  612. });
  613. break;
  614. case 'addHostController':
  615. App.clusterStatus.setClusterStatus({
  616. clusterName: this.get('clusterName'),
  617. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  618. wizardControllerName: this.get('content.controllerName'),
  619. localdb: App.db.data
  620. });
  621. break;
  622. case 'addServiceController':
  623. App.clusterStatus.setClusterStatus({
  624. clusterName: this.get('clusterName'),
  625. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  626. wizardControllerName: this.get('content.controllerName'),
  627. localdb: App.db.data
  628. });
  629. break;
  630. default:
  631. break;
  632. }
  633. // delete any existing clusters to start from a clean slate
  634. // before creating a new cluster in install wizard
  635. // TODO: modify for multi-cluster support
  636. this.getExistingClusterNames().complete(function () {
  637. var clusterNames = self.get('clusterNames');
  638. if (self.get('content.controllerName') == 'installerController' && (!App.get('testMode')) && clusterNames.length) {
  639. self.deleteClusters(clusterNames);
  640. } else {
  641. self.startDeploy();
  642. }
  643. });
  644. },
  645. /**
  646. * Get list of existing cluster names
  647. * @returns {object|null}
  648. * returns an array of existing cluster names.
  649. * returns an empty array if there are no existing clusters.
  650. * @method getExistingClusterNames
  651. */
  652. getExistingClusterNames: function () {
  653. return App.ajax.send({
  654. name: 'wizard.step8.existing_cluster_names',
  655. sender: this,
  656. success: 'getExistingClusterNamesSuccessCallBack',
  657. error: 'getExistingClusterNamesErrorCallback'
  658. });
  659. },
  660. /**
  661. * Save received list to <code>clusterNames</code>
  662. * @param {Object} data
  663. * @method getExistingClusterNamesSuccessCallBack
  664. */
  665. getExistingClusterNamesSuccessCallBack: function (data) {
  666. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  667. this.set('clusterNames', clusterNames);
  668. },
  669. /**
  670. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  671. * @method getExistingClusterNamesErrorCallback
  672. */
  673. getExistingClusterNamesErrorCallback: function () {
  674. this.set('clusterNames', []);
  675. },
  676. /**
  677. * Delete cluster by name
  678. * One request for one cluster!
  679. * @param {string[]} clusterNames
  680. * @method deleteClusters
  681. */
  682. deleteClusters: function (clusterNames) {
  683. this.get('clusterDeleteErrorViews').clear();
  684. clusterNames.forEach(function (clusterName, index) {
  685. App.ajax.send({
  686. name: 'common.delete.cluster',
  687. sender: this,
  688. data: {
  689. name: clusterName,
  690. isLast: index == clusterNames.length - 1
  691. },
  692. success: 'deleteClusterSuccessCallback',
  693. error: 'deleteClusterErrorCallback'
  694. });
  695. }, this);
  696. },
  697. /**
  698. * Method to execute after successful cluster deletion
  699. * @method deleteClusterSuccessCallback
  700. */
  701. deleteClusterSuccessCallback: function () {
  702. this.incrementProperty('clusterDeleteRequestsCompleted');
  703. if (this.get('isAllClusterDeleteRequestsCompleted')) {
  704. if (this.get('clusterDeleteErrorViews.length')) {
  705. this.showDeleteClustersErrorPopup();
  706. } else {
  707. this.startDeploy();
  708. }
  709. }
  710. },
  711. /**
  712. * Method to execute after failed cluster deletion
  713. * @param {object} request
  714. * @param {string} ajaxOptions
  715. * @param {string} error
  716. * @param {object} opt
  717. * @method deleteClusterErrorCallback
  718. */
  719. deleteClusterErrorCallback: function (request, ajaxOptions, error, opt) {
  720. this.incrementProperty('clusterDeleteRequestsCompleted');
  721. try {
  722. var json = $.parseJSON(request.responseText);
  723. var message = json.message;
  724. } catch (err) {
  725. }
  726. this.get('clusterDeleteErrorViews').pushObject(App.AjaxDefaultErrorPopupBodyView.create({
  727. url: opt.url,
  728. type: opt.type,
  729. status: request.status,
  730. message: message
  731. }));
  732. if (this.get('isAllClusterDeleteRequestsCompleted')) {
  733. this.showDeleteClustersErrorPopup();
  734. }
  735. },
  736. /**
  737. * Show error popup if cluster deletion failed
  738. * @method showDeleteClustersErrorPopup
  739. */
  740. showDeleteClustersErrorPopup: function () {
  741. var self = this;
  742. this.setProperties({
  743. isSubmitDisabled: false,
  744. isBackBtnDisabled: false
  745. });
  746. App.ModalPopup.show({
  747. header: Em.I18n.t('common.error'),
  748. secondary: false,
  749. onPrimary: function () {
  750. this.hide();
  751. },
  752. bodyClass: Em.ContainerView.extend({
  753. childViews: self.get('clusterDeleteErrorViews')
  754. })
  755. });
  756. },
  757. /**
  758. * updates kerberosDescriptorConfigs
  759. * @method updateKerberosDescriptor
  760. */
  761. updateKerberosDescriptor: function(instant) {
  762. var kerberosDescriptor = App.db.get('KerberosWizard', 'kerberosDescriptorConfigs');
  763. var ajaxOpts = {
  764. name: 'admin.kerberos.cluster.artifact.update',
  765. data: {
  766. artifactName: 'kerberos_descriptor',
  767. data: {
  768. artifact_data: kerberosDescriptor
  769. }
  770. }
  771. };
  772. if (instant) {
  773. ajaxOpts.sender = this;
  774. App.ajax.send(ajaxOpts);
  775. } else {
  776. this.addRequestToAjaxQueue(ajaxOpts);
  777. }
  778. },
  779. /**
  780. * Start deploy process
  781. * @method startDeploy
  782. */
  783. startDeploy: function () {
  784. this.createCluster();
  785. this.createSelectedServices();
  786. if (this.get('content.controllerName') !== 'addHostController') {
  787. if (this.get('content.controllerName') === 'addServiceController') {
  788. // for manually enabled Kerberos descriptor was updated on transition to this step
  789. if (App.get('isKerberosEnabled') && !this.get('isManualKerberos')) {
  790. this.updateKerberosDescriptor();
  791. }
  792. var fileNamesToUpdate = this.get('wizardController').getDBProperty('fileNamesToUpdate').uniq();
  793. if (fileNamesToUpdate && fileNamesToUpdate.length) {
  794. this.updateConfigurations(fileNamesToUpdate);
  795. }
  796. }
  797. this.createConfigurations();
  798. this.applyConfigurationsToCluster(this.get('serviceConfigTags'));
  799. }
  800. this.createComponents();
  801. this.registerHostsToCluster();
  802. this.createConfigurationGroups();
  803. this.createMasterHostComponents();
  804. this.createSlaveAndClientsHostComponents();
  805. if (this.get('content.controllerName') === 'addServiceController') {
  806. this.createAdditionalClientComponents();
  807. }
  808. this.createAdditionalHostComponents();
  809. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  810. this.get('ajaxRequestsQueue').start();
  811. this.showLoadingIndicator();
  812. },
  813. /**
  814. * *******************************************************************
  815. * The following create* functions are called upon submitting Step 8.
  816. * *******************************************************************
  817. */
  818. /**
  819. * Create cluster using selected stack version
  820. * Queued request
  821. * @method createCluster
  822. */
  823. createCluster: function () {
  824. if (this.get('content.controllerName') !== 'installerController') return;
  825. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  826. this.addRequestToAjaxQueue({
  827. name: 'wizard.step8.create_cluster',
  828. data: {
  829. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  830. },
  831. success: 'createClusterSuccess'
  832. });
  833. },
  834. createClusterSuccess: function (data, xhr, params) {
  835. App.set('clusterName', params.cluster)
  836. },
  837. /**
  838. * Create selected to install services
  839. * Queued request
  840. * Skipped if no services where selected!
  841. * @method createSelectedServices
  842. */
  843. createSelectedServices: function () {
  844. var data = this.createSelectedServicesData();
  845. if (!data.length) return;
  846. this.addRequestToAjaxQueue({
  847. name: 'wizard.step8.create_selected_services',
  848. data: {
  849. data: JSON.stringify(data)
  850. }
  851. });
  852. },
  853. /**
  854. * Format data for <code>createSelectedServices</code> request
  855. * @returns {Object[]}
  856. * @method createSelectedServicesData
  857. */
  858. createSelectedServicesData: function () {
  859. return this.get('selectedServices').map(function (_service) {
  860. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  861. });
  862. },
  863. /**
  864. * Create components for selected services
  865. * Queued requests
  866. * One request for each service!
  867. * @method createComponents
  868. */
  869. createComponents: function () {
  870. var serviceComponents = App.StackServiceComponent.find();
  871. this.get('selectedServices').forEach(function (_service) {
  872. var serviceName = _service.get('serviceName');
  873. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  874. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  875. });
  876. // Service must be specified in terms of a query for creating multiple components at the same time.
  877. // See AMBARI-1018.
  878. this.addRequestToCreateComponent(componentsData, serviceName);
  879. }, this);
  880. if (this.get('content.controllerName') === 'addHostController') {
  881. var allServiceComponents = [];
  882. var services = App.Service.find().mapProperty('serviceName');
  883. services.forEach(function(_service){
  884. var _serviceComponents = App.Service.find(_service).get('serviceComponents');
  885. allServiceComponents = allServiceComponents.concat(_serviceComponents);
  886. }, this);
  887. this.get('content.slaveComponentHosts').forEach(function (component) {
  888. if (component.componentName !== 'CLIENT' && !allServiceComponents.contains(component.componentName)) {
  889. this.addRequestToCreateComponent(
  890. [{"ServiceComponentInfo": {"component_name": component.componentName}}],
  891. App.StackServiceComponent.find().findProperty('componentName', component.componentName).get('serviceName')
  892. );
  893. }
  894. }, this);
  895. this.get('content.clients').forEach(function (component) {
  896. if (!allServiceComponents.contains(component.component_name)) {
  897. this.addRequestToCreateComponent(
  898. [{"ServiceComponentInfo": {"component_name": component.component_name}}],
  899. App.StackServiceComponent.find().findProperty('componentName', component.component_name).get('serviceName')
  900. );
  901. }
  902. }, this);
  903. }
  904. },
  905. /**
  906. * Add request to ajax queue to create service component
  907. * @param componentsData
  908. * @param serviceName
  909. */
  910. addRequestToCreateComponent: function (componentsData, serviceName) {
  911. this.addRequestToAjaxQueue({
  912. name: 'wizard.step8.create_components',
  913. data: {
  914. data: JSON.stringify({"components": componentsData}),
  915. serviceName: serviceName
  916. }
  917. });
  918. },
  919. /**
  920. * Error callback for new service component request
  921. * So, if component doesn't exist we should create it
  922. * @param {object} request
  923. * @param {object} ajaxOptions
  924. * @param {string} error
  925. * @param {object} opt
  926. * @param {object} params
  927. * @method newServiceComponentErrorCallback
  928. */
  929. newServiceComponentErrorCallback: function (request, ajaxOptions, error, opt, params) {
  930. this.addRequestToAjaxQueue({
  931. name: 'wizard.step8.create_components',
  932. data: {
  933. serviceName: params.serviceName,
  934. data: JSON.stringify({
  935. "components": [
  936. {
  937. "ServiceComponentInfo": {
  938. "component_name": params.componentName
  939. }
  940. }
  941. ]
  942. })
  943. }
  944. });
  945. },
  946. /**
  947. * Register hosts
  948. * Queued request
  949. * @method registerHostsToCluster
  950. */
  951. registerHostsToCluster: function () {
  952. var data = this.createRegisterHostData();
  953. if (!data.length) return;
  954. this.addRequestToAjaxQueue({
  955. name: 'wizard.step8.register_host_to_cluster',
  956. data: {
  957. data: JSON.stringify(data)
  958. }
  959. });
  960. },
  961. /**
  962. * Format request-data for <code>registerHostsToCluster</code>
  963. * @returns {Object}
  964. * @method createRegisterHostData
  965. */
  966. createRegisterHostData: function () {
  967. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  968. return {"Hosts": { "host_name": host.hostName}};
  969. });
  970. },
  971. /**
  972. * Register new master components
  973. * @uses registerHostsToComponent
  974. * @method createMasterHostComponents
  975. */
  976. createMasterHostComponents: function () {
  977. // create master components for only selected services.
  978. var selectedMasterComponents = this.get('content.masterComponentHosts').filter(function (_component) {
  979. return this.get('selectedServices').mapProperty('serviceName').contains(_component.serviceId)
  980. }, this);
  981. selectedMasterComponents.mapProperty('component').uniq().forEach(function (component) {
  982. var hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  983. this.registerHostsToComponent(hostNames, component);
  984. }, this);
  985. },
  986. getClientsMap: function (flag) {
  987. var clientNames = App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName'),
  988. clientsMap = {},
  989. dependedComponents = flag ? App.StackServiceComponent.find().filterProperty(flag) : App.StackServiceComponent.find();
  990. clientNames.forEach(function (clientName) {
  991. clientsMap[clientName] = Em.A([]);
  992. dependedComponents.forEach(function (component) {
  993. if (component.get('dependencies').mapProperty('componentName').contains(clientName)) clientsMap[clientName].push(component.get('componentName'));
  994. });
  995. if (!clientsMap[clientName].length) delete clientsMap[clientName];
  996. });
  997. return clientsMap;
  998. },
  999. /**
  1000. * Register slave components and clients
  1001. * @uses registerHostsToComponent
  1002. * @method createSlaveAndClientsHostComponents
  1003. */
  1004. createSlaveAndClientsHostComponents: function () {
  1005. var masterHosts = this.get('content.masterComponentHosts');
  1006. var slaveHosts = this.get('content.slaveComponentHosts');
  1007. var clients = this.get('content.clients').filterProperty('isInstalled', false);
  1008. /**
  1009. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1010. * @type {Object}
  1011. * Format:
  1012. * <code>
  1013. * {
  1014. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1015. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1016. * ...
  1017. * }
  1018. * </code>
  1019. */
  1020. var clientsToMasterMap = this.getClientsMap('isMaster');
  1021. slaveHosts.forEach(function (_slave) {
  1022. if (_slave.componentName !== 'CLIENT') {
  1023. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1024. this.registerHostsToComponent(hostNames, _slave.componentName);
  1025. }
  1026. else {
  1027. clients.forEach(function (_client) {
  1028. var hostNames = _slave.hosts.mapProperty('hostName');
  1029. // The below logic to install clients to existing/New master hosts should not be applied to Add Host wizard.
  1030. // This is with the presumption that Add Host controller does not add any new Master component to the cluster
  1031. if (this.get('content.controllerName') !== 'addHostController') {
  1032. if (clientsToMasterMap[_client.component_name]) {
  1033. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1034. masterHosts.filterProperty('component', componentName).forEach(function (_masterHost) {
  1035. hostNames.pushObject(_masterHost.hostName);
  1036. });
  1037. });
  1038. }
  1039. }
  1040. hostNames = hostNames.uniq();
  1041. this.registerHostsToComponent(hostNames, _client.component_name);
  1042. }, this);
  1043. }
  1044. }, this);
  1045. },
  1046. /**
  1047. * This function is specific to addServiceController
  1048. * Newly introduced master components requires some existing client components to be hosted along with them
  1049. */
  1050. createAdditionalClientComponents: function () {
  1051. var masterHosts = this.get('content.masterComponentHosts');
  1052. var clientHosts = [];
  1053. if (this.get('content.slaveComponentHosts').someProperty('componentName', 'CLIENT')) {
  1054. clientHosts = this.get('content.slaveComponentHosts').findProperty('componentName', 'CLIENT').hosts;
  1055. }
  1056. var clients = this.get('content.clients').filterProperty('isInstalled', false);
  1057. var clientsToMasterMap = this.getClientsMap('isMaster');
  1058. var clientsToClientMap = this.getClientsMap('isClient');
  1059. var installedClients = [];
  1060. // Get all the installed Client components
  1061. this.get('content.services').filterProperty('isInstalled').forEach(function (_service) {
  1062. var serviceClients = App.StackServiceComponent.find().filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  1063. serviceClients.forEach(function (client) {
  1064. installedClients.push(client.get('componentName'));
  1065. }, this);
  1066. }, this);
  1067. // Check if there is a dependency for being co-hosted between existing client and selected new master
  1068. installedClients.forEach(function (_clientName) {
  1069. if (clientsToMasterMap[_clientName] || clientsToClientMap[_clientName]) {
  1070. var hostNames = [];
  1071. if (clientsToMasterMap[_clientName]) {
  1072. clientsToMasterMap[_clientName].forEach(function (componentName) {
  1073. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1074. hostNames.pushObject(_masterHost.hostName);
  1075. }, this);
  1076. }, this);
  1077. }
  1078. if (clientsToClientMap[_clientName]) {
  1079. clientsToClientMap[_clientName].forEach(function (componentName) {
  1080. clientHosts.forEach(function (_clientHost) {
  1081. var host = this.get('content.hosts')[_clientHost.hostName];
  1082. if (host.isInstalled && !host.hostComponents.someProperty('HostRoles.component_name', componentName)) {
  1083. hostNames.pushObject(_clientHost.hostName);
  1084. }
  1085. }, this);
  1086. }, this);
  1087. }
  1088. hostNames = hostNames.uniq();
  1089. if (hostNames.length > 0) {
  1090. // If a dependency for being co-hosted is derived between existing client and selected new master but that
  1091. // dependency is already satisfied in the cluster then disregard the derived dependency
  1092. this.removeClientsFromList(_clientName, hostNames);
  1093. this.registerHostsToComponent(hostNames, _clientName);
  1094. if(hostNames.length > 0) {
  1095. this.get('content.additionalClients').pushObject({hostNames: hostNames, componentName: _clientName});
  1096. }
  1097. }
  1098. }
  1099. }, this);
  1100. },
  1101. /**
  1102. *
  1103. * @param clientName
  1104. * @param hostList
  1105. */
  1106. removeClientsFromList: function (clientName, hostList) {
  1107. var clientHosts = [];
  1108. var installedHosts = this.get('content.hosts');
  1109. for (var hostName in installedHosts) {
  1110. if (installedHosts[hostName].isInstalled) {
  1111. if (installedHosts[hostName].hostComponents.mapProperty('HostRoles.component_name').contains(clientName)) {
  1112. clientHosts.push(hostName);
  1113. }
  1114. }
  1115. }
  1116. if (clientHosts.length > 0) {
  1117. clientHosts.forEach(function (hostName) {
  1118. if (hostList.contains(hostName)) {
  1119. hostList.splice(hostList.indexOf(hostName), 1);
  1120. }
  1121. }, this);
  1122. }
  1123. },
  1124. /**
  1125. * Register additional components
  1126. * Based on availability of some services
  1127. * @uses registerHostsToComponent
  1128. * @method createAdditionalHostComponents
  1129. */
  1130. createAdditionalHostComponents: function () {
  1131. var masterHosts = this.get('content.masterComponentHosts');
  1132. // add all components with cardinality == ALL of selected services
  1133. var registeredHosts = this.getRegisteredHosts();
  1134. var notInstalledHosts = registeredHosts.filterProperty('isInstalled', false);
  1135. this.get('content.services').filterProperty('isSelected').forEach(function (service) {
  1136. service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) {
  1137. if (service.get('isInstalled') && notInstalledHosts.length) {
  1138. this.registerHostsToComponent(notInstalledHosts.mapProperty('hostName'), component.get('componentName'));
  1139. } else if (!service.get('isInstalled') && registeredHosts.length) {
  1140. this.registerHostsToComponent(registeredHosts.mapProperty('hostName'), component.get('componentName'));
  1141. }
  1142. }, this);
  1143. }, this);
  1144. // add MySQL Server if Hive is selected
  1145. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1146. if (hiveService) {
  1147. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1148. if (hiveDb.value == "New MySQL Database") {
  1149. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1150. } else if (hiveDb.value === "New PostgreSQL Database") {
  1151. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'POSTGRESQL_SERVER');
  1152. }
  1153. }
  1154. },
  1155. /**
  1156. * Register component to hosts
  1157. * Queued request
  1158. * @param {String[]} hostNames
  1159. * @param {String} componentName
  1160. * @method registerHostsToComponent
  1161. */
  1162. registerHostsToComponent: function (hostNames, componentName) {
  1163. if (!hostNames.length) return;
  1164. var queryStr = '';
  1165. hostNames.forEach(function (hostName) {
  1166. queryStr += 'Hosts/host_name=' + hostName + '|';
  1167. });
  1168. //slice off last symbol '|'
  1169. queryStr = queryStr.slice(0, -1);
  1170. var data = {
  1171. "RequestInfo": {
  1172. "query": queryStr
  1173. },
  1174. "Body": {
  1175. "host_components": [
  1176. {
  1177. "HostRoles": {
  1178. "component_name": componentName
  1179. }
  1180. }
  1181. ]
  1182. }
  1183. };
  1184. this.addRequestToAjaxQueue({
  1185. name: 'wizard.step8.register_host_to_component',
  1186. data: {
  1187. data: JSON.stringify(data)
  1188. }
  1189. });
  1190. },
  1191. /**
  1192. * Compare generated config object with current configs that were filled
  1193. * on "Customize Services" page.
  1194. *
  1195. * @param {Object} properties - generated by createSiteObj|createCoreSiteObj
  1196. * @param {Array} configs - current configs to compare
  1197. * @return {Boolean}
  1198. * @method isConfigsChanged
  1199. **/
  1200. isConfigsChanged: function (properties, configs) {
  1201. var isChanged = false;
  1202. for (var property in properties) {
  1203. var config = configs.findProperty('name', property);
  1204. // if config not found then it's looks like a new config
  1205. if (!config) {
  1206. isChanged = true;
  1207. } else {
  1208. if (!config.hasInitialValue || config.isNotDefaultValue) {
  1209. isChanged = true;
  1210. }
  1211. }
  1212. }
  1213. return isChanged;
  1214. },
  1215. /**
  1216. * Create config objects for cluster and services
  1217. * @method createConfigurations
  1218. */
  1219. createConfigurations: function () {
  1220. var selectedServices = this.get('selectedServices');
  1221. var coreSiteObject = this.createCoreSiteObj();
  1222. var tag = 'version1';
  1223. var clusterSiteObj = this.createSiteObj('cluster-env', tag);
  1224. if (this.get('content.controllerName') == 'installerController') {
  1225. this.get('serviceConfigTags').pushObject(clusterSiteObj);
  1226. }
  1227. if (this.get('content.controllerName') == 'addServiceController') {
  1228. tag = 'version' + (new Date).getTime();
  1229. coreSiteObject.tag = tag;
  1230. var coreSiteConfigs = this.get('configs').filterProperty('filename', 'core-site.xml');
  1231. if (this.isConfigsChanged(coreSiteObject.properties, coreSiteConfigs)) {
  1232. coreSiteObject.service_config_version_note = Em.I18n.t('dashboard.configHistory.table.notes.addService');
  1233. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1234. }
  1235. }
  1236. selectedServices.forEach(function (service) {
  1237. Object.keys(service.get('configTypes')).forEach(function (type) {
  1238. if (!this.get('serviceConfigTags').someProperty('type', type)) {
  1239. var serviceVersionNotes = Em.I18n.t('dashboard.configHistory.table.notes.default').format(service.get('displayName'));
  1240. if (type === 'core-site') {
  1241. coreSiteObject.service_config_version_note = serviceVersionNotes;
  1242. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1243. } else if (type === 'storm-site') {
  1244. var obj = this.createStormSiteObj(tag);
  1245. obj.service_config_version_note = serviceVersionNotes;
  1246. this.get('serviceConfigTags').pushObject(obj);
  1247. } else {
  1248. var obj = this.createSiteObj(type, tag);
  1249. obj.service_config_version_note = serviceVersionNotes;
  1250. this.get('serviceConfigTags').pushObject(obj);
  1251. }
  1252. }
  1253. }, this);
  1254. }, this);
  1255. this.createNotification();
  1256. },
  1257. /**
  1258. * Send <code>serviceConfigTags</code> to server
  1259. * Queued request
  1260. * One request for each service config tag
  1261. * @param serviceConfigTags
  1262. * @method applyConfigurationsToCluster
  1263. */
  1264. applyConfigurationsToCluster: function (serviceConfigTags) {
  1265. var allServices = this.get('installedServices').concat(this.get('selectedServices'));
  1266. var allConfigData = [];
  1267. allServices.forEach(function (service) {
  1268. var serviceConfigData = [];
  1269. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  1270. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  1271. if (serviceConfigTag) {
  1272. serviceConfigData.pushObject(serviceConfigTag);
  1273. }
  1274. }, this);
  1275. if (serviceConfigData.length) {
  1276. allConfigData.pushObject(JSON.stringify({
  1277. Clusters: {
  1278. desired_config: serviceConfigData
  1279. }
  1280. }));
  1281. }
  1282. }, this);
  1283. var clusterConfig = serviceConfigTags.findProperty('type', 'cluster-env');
  1284. if (clusterConfig) {
  1285. allConfigData.pushObject(JSON.stringify({
  1286. Clusters: {
  1287. desired_config: [clusterConfig]
  1288. }
  1289. }));
  1290. }
  1291. this.addRequestToAjaxQueue({
  1292. name: 'common.across.services.configurations',
  1293. data: {
  1294. data: '[' + allConfigData.toString() + ']'
  1295. }
  1296. });
  1297. },
  1298. /**
  1299. * Create and update config groups
  1300. * @method createConfigurationGroups
  1301. */
  1302. createConfigurationGroups: function () {
  1303. var configGroups = this.get('content.configGroups').filterProperty('is_default', false);
  1304. var clusterName = this.get('clusterName');
  1305. var sendData = [];
  1306. var updateData = [];
  1307. var timeTag = (new Date).getTime();
  1308. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1309. if (groupsToDelete && groupsToDelete.length > 0) {
  1310. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1311. }
  1312. configGroups.forEach(function (configGroup) {
  1313. var groupConfigs = [];
  1314. var groupData = {
  1315. "cluster_name": clusterName,
  1316. "group_name": configGroup.name,
  1317. "tag": configGroup.service_id,
  1318. "description": configGroup.description,
  1319. "hosts": [],
  1320. "desired_configs": []
  1321. };
  1322. configGroup.hosts.forEach(function (hostName) {
  1323. groupData.hosts.push({"host_name": hostName});
  1324. });
  1325. // get properties that was created for non-default config group
  1326. configGroup.properties = configGroup.properties.concat(this.get('customNonDefaultGroupConfigs').filterProperty('group', configGroup.name));
  1327. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1328. configGroup.properties.forEach(function (property) {
  1329. groupConfigs.push(Em.Object.create(property));
  1330. });
  1331. groupData.desired_configs = this.buildGroupDesiredConfigs(groupConfigs, timeTag);
  1332. // check for group from installed service
  1333. if (configGroup.is_for_installed_service === true) {
  1334. // if group is a new one, create it
  1335. if (!configGroup.id) {
  1336. sendData.push({"ConfigGroup": groupData});
  1337. } else if (configGroup.is_for_update){
  1338. // update an existing group
  1339. groupData.id = configGroup.id;
  1340. updateData.push({"ConfigGroup": groupData});
  1341. }
  1342. } else {
  1343. sendData.push({"ConfigGroup": groupData});
  1344. }
  1345. //each group should have unique tag to prevent overriding configs from common sites
  1346. timeTag++;
  1347. }, this);
  1348. if (sendData.length > 0) {
  1349. this.applyConfigurationGroups(sendData);
  1350. }
  1351. if (updateData.length > 0) {
  1352. this.applyInstalledServicesConfigurationGroup(updateData);
  1353. }
  1354. },
  1355. /**
  1356. * construct desired_configs for config groups from overriden properties
  1357. * @param configs
  1358. * @param timeTag
  1359. * @return {Array}
  1360. * @private
  1361. * @method buildGroupDesiredConfigs
  1362. */
  1363. buildGroupDesiredConfigs: function (configs, timeTag) {
  1364. var sites = [];
  1365. var time = timeTag || (new Date).getTime();
  1366. var siteFileNames = configs.mapProperty('filename').uniq();
  1367. sites = siteFileNames.map(function (filename) {
  1368. return {
  1369. type: filename.replace('.xml', ''),
  1370. tag: 'version' + time,
  1371. properties: []
  1372. };
  1373. });
  1374. configs.forEach(function (config) {
  1375. var type = config.get('filename').replace('.xml', '');
  1376. var site = sites.findProperty('type', type);
  1377. site.properties.push(config);
  1378. });
  1379. return sites.map(function (site) {
  1380. return App.router.get('mainServiceInfoConfigsController').createSiteObj(site.type, site.tag, site.properties);
  1381. }, this);
  1382. },
  1383. /**
  1384. * Create new config groups request
  1385. * Queued request
  1386. * @param {Object[]} sendData
  1387. * @method applyConfigurationGroups
  1388. */
  1389. applyConfigurationGroups: function (sendData) {
  1390. this.addRequestToAjaxQueue({
  1391. name: 'wizard.step8.apply_configuration_groups',
  1392. data: {
  1393. data: JSON.stringify(sendData)
  1394. }
  1395. });
  1396. },
  1397. /**
  1398. * Update existed config groups
  1399. * Separated request for each group
  1400. * @param {Object[]} updateData
  1401. * @method applyInstalledServicesConfigurationGroup
  1402. */
  1403. applyInstalledServicesConfigurationGroup: function (updateData) {
  1404. updateData.forEach(function (item) {
  1405. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1406. });
  1407. },
  1408. /**
  1409. * Delete selected config groups
  1410. * @param {Object[]} groupsToDelete
  1411. * @method removeInstalledServicesConfigurationGroups
  1412. */
  1413. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1414. var self = this;
  1415. groupsToDelete.forEach(function (item) {
  1416. self.deleteConfigurationGroup(Em.Object.create(item));
  1417. });
  1418. },
  1419. /**
  1420. * Create Core Site object
  1421. * @returns {{type: string, tag: string, properties: {}}}
  1422. * @method createCoreSiteObj
  1423. */
  1424. createCoreSiteObj: function () {
  1425. var installedAndSelectedServices = Em.A([]);
  1426. installedAndSelectedServices.pushObjects(this.get('installedServices'));
  1427. installedAndSelectedServices.pushObjects(this.get('selectedServices'));
  1428. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml'),
  1429. coreSiteProperties = this.createSiteObj('core-site', 'version1').properties,
  1430. isGLUSTERFSSelected = installedAndSelectedServices.someProperty('serviceName', 'GLUSTERFS');
  1431. coreSiteObj.forEach(function (_coreSiteObj) {
  1432. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1433. coreSiteProperties[_coreSiteObj.name] =
  1434. this.get('configs').someProperty('name', 'fs_glusterfs_default_name') ?
  1435. this.get('configs').findProperty('name', 'fs_glusterfs_default_name').value : null;
  1436. }
  1437. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1438. coreSiteProperties[_coreSiteObj.name] =
  1439. this.get('configs').someProperty('name', 'glusterfs_defaultFS_name') ?
  1440. this.get('configs').findProperty('name', 'glusterfs_defaultFS_name').value : null;
  1441. }
  1442. }, this);
  1443. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(coreSiteObj);
  1444. var configObj = {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1445. if (attributes) {
  1446. configObj['properties_attributes'] = attributes;
  1447. }
  1448. return configObj;
  1449. },
  1450. /**
  1451. * Create siteObj for custom service with it own configs
  1452. * @param {string} site
  1453. * @param tag
  1454. * @returns {{type: string, tag: string, properties: {}}}
  1455. * @method createSiteObj
  1456. */
  1457. createSiteObj: function (site, tag) {
  1458. var properties = {};
  1459. var configs = this.get('configs').filterProperty('filename', site + '.xml');
  1460. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(configs);
  1461. configs.forEach(function (_configProperty) {
  1462. var heapsizeExceptions = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize',
  1463. 'jobhistory_heapsize', 'nfsgateway_heapsize', 'accumulo_master_heapsize', 'accumulo_tserver_heapsize', 'accumulo_monitor_heapsize', 'accumulo_gc_heapsize',
  1464. 'accumulo_other_heapsize', 'hbase_master_heapsize', 'hbase_regionserver_heapsize', 'metrics_collector_heapsize'];
  1465. // do not pass any globals whose name ends with _host or _hosts
  1466. if (_configProperty.isRequiredByAgent !== false) {
  1467. // append "m" to JVM memory options except for heapsizeExtensions
  1468. if (/_heapsize|_newsize|_maxnewsize|_permsize|_maxpermsize$/.test(_configProperty.name) && !heapsizeExceptions.contains(_configProperty.name) && !(_configProperty.value).endsWith("m")) {
  1469. properties[_configProperty.name] = _configProperty.value + "m";
  1470. } else {
  1471. properties[_configProperty.name] = _configProperty.value;
  1472. }
  1473. }
  1474. }, this);
  1475. var configObj = {"type": site, "tag": tag, "properties": properties };
  1476. if (attributes) {
  1477. configObj['properties_attributes'] = attributes;
  1478. }
  1479. return configObj;
  1480. },
  1481. /**
  1482. * Create site obj for Storm
  1483. * Some config-properties should be modified in custom way
  1484. * @param tag
  1485. * @returns {{type: string, tag: string, properties: {}}}
  1486. * @method createStormSiteObj
  1487. */
  1488. createStormSiteObj: function (tag) {
  1489. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1490. var stormProperties = {};
  1491. configs.forEach(function (_configProperty) {
  1492. if (["nimbus.seeds", "storm.zookeeper.servers"].contains(_configProperty.name)) {
  1493. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1494. } else {
  1495. stormProperties[_configProperty.name] = _configProperty.value;
  1496. }
  1497. }, this);
  1498. return {type: 'storm-site', tag: tag, properties: stormProperties};
  1499. },
  1500. /**
  1501. * Create one Alert Notification (if user select this on step7)
  1502. * Only for Install Wizard and stack
  1503. * @method createNotification
  1504. */
  1505. createNotification: function () {
  1506. if (this.get('content.controllerName') !== 'installerController') return;
  1507. var miscConfigs = this.get('configs').filterProperty('serviceName', 'MISC'),
  1508. createNotification = miscConfigs.findProperty('name', 'create_notification').value;
  1509. if (createNotification !== 'yes') return;
  1510. var predefinedNotificationConfigNames = require('data/HDP2/alert_notification').mapProperty('name'),
  1511. configsForNotification = this.get('configs').filterProperty('filename', 'alert_notification');
  1512. var properties = {},
  1513. names = [
  1514. 'ambari.dispatch.recipients',
  1515. 'mail.smtp.host',
  1516. 'mail.smtp.port',
  1517. 'mail.smtp.from',
  1518. 'mail.smtp.starttls.enable',
  1519. 'mail.smtp.startssl.enable'
  1520. ];
  1521. if (miscConfigs.findProperty('name', 'smtp_use_auth').value == 'true') { // yes, it's not converted to boolean
  1522. names.pushObjects(['ambari.dispatch.credential.username', 'ambari.dispatch.credential.password']);
  1523. }
  1524. names.forEach(function (name) {
  1525. properties[name] = miscConfigs.findProperty('name', name).value;
  1526. });
  1527. properties['ambari.dispatch.recipients'] = properties['ambari.dispatch.recipients'].replace(/\s/g, '').split(',');
  1528. configsForNotification.forEach(function (config) {
  1529. if (predefinedNotificationConfigNames.contains(config.name)) return;
  1530. properties[config.name] = config.value;
  1531. });
  1532. var apiObject = {
  1533. AlertTarget: {
  1534. name: 'Initial Notification',
  1535. description: 'Notification created during cluster installing',
  1536. global: true,
  1537. notification_type: 'EMAIL',
  1538. alert_states: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
  1539. properties: properties
  1540. }
  1541. };
  1542. this.addRequestToAjaxQueue({
  1543. name: 'alerts.create_alert_notification',
  1544. data: {
  1545. urlParams: 'overwrite_existing=true',
  1546. data: apiObject
  1547. }
  1548. });
  1549. },
  1550. /**
  1551. * Should ajax-queue progress bar be displayed
  1552. * @method showLoadingIndicator
  1553. */
  1554. showLoadingIndicator: function () {
  1555. return App.ModalPopup.show({
  1556. header: '',
  1557. showFooter: false,
  1558. showCloseButton: false,
  1559. bodyClass: Em.View.extend({
  1560. templateName: require('templates/wizard/step8/step8_log_popup'),
  1561. controllerBinding: 'App.router.wizardStep8Controller',
  1562. /**
  1563. * Css-property for progress-bar
  1564. * @type {string}
  1565. */
  1566. barWidth: '',
  1567. /**
  1568. * Popup-message
  1569. * @type {string}
  1570. */
  1571. message: '',
  1572. /**
  1573. * Set progress bar width and popup message when ajax-queue requests are proccessed
  1574. * @method ajaxQueueChangeObs
  1575. */
  1576. ajaxQueueChangeObs: function () {
  1577. var length = this.get('controller.ajaxQueueLength');
  1578. var left = this.get('controller.ajaxRequestsQueue.queue.length');
  1579. this.set('barWidth', 'width: ' + ((length - left) / length * 100) + '%;');
  1580. this.set('message', Em.I18n.t('installer.step8.deployPopup.message').format((length - left), length));
  1581. }.observes('controller.ajaxQueueLength', 'controller.ajaxRequestsQueue.queue.length'),
  1582. /**
  1583. * Hide popup when ajax-queue is finished
  1584. * @method autoHide
  1585. */
  1586. autoHide: function () {
  1587. if (this.get('controller.servicesInstalled')) {
  1588. this.get('parentView').hide();
  1589. }
  1590. }.observes('controller.servicesInstalled')
  1591. })
  1592. });
  1593. }
  1594. });