step8_controller.js 63 KB

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